getch 0.0.9 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +45 -0
- data/README.md +57 -11
- data/bin/setup.sh +4 -2
- data/lib/getch.rb +27 -10
- data/lib/getch/command.rb +25 -4
- data/lib/getch/config.rb +58 -0
- data/lib/getch/filesystem.rb +6 -0
- data/lib/getch/filesystem/clean.rb +58 -0
- data/lib/getch/filesystem/device.rb +61 -0
- data/lib/getch/filesystem/ext4/config.rb +8 -9
- data/lib/getch/filesystem/ext4/device.rb +2 -7
- data/lib/getch/filesystem/ext4/encrypt/config.rb +8 -9
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +3 -19
- data/lib/getch/filesystem/ext4/encrypt/device.rb +3 -8
- data/lib/getch/filesystem/ext4/encrypt/format.rb +3 -5
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +6 -43
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +19 -38
- data/lib/getch/filesystem/ext4/format.rb +3 -5
- data/lib/getch/filesystem/ext4/mount.rb +7 -46
- data/lib/getch/filesystem/ext4/partition.rb +16 -39
- data/lib/getch/filesystem/lvm/config.rb +11 -15
- data/lib/getch/filesystem/lvm/deps.rb +5 -20
- data/lib/getch/filesystem/lvm/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +5 -22
- data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -3
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +20 -31
- data/lib/getch/filesystem/lvm/format.rb +11 -7
- data/lib/getch/filesystem/lvm/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/partition.rb +19 -31
- data/lib/getch/filesystem/mount.rb +56 -0
- data/lib/getch/filesystem/partition.rb +77 -0
- data/lib/getch/filesystem/zfs.rb +14 -0
- data/lib/getch/filesystem/zfs/config.rb +57 -0
- data/lib/getch/filesystem/zfs/deps.rb +95 -0
- data/lib/getch/filesystem/zfs/device.rb +58 -0
- data/lib/getch/filesystem/zfs/encrypt.rb +15 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +67 -0
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +97 -0
- data/lib/getch/filesystem/zfs/encrypt/device.rb +60 -0
- data/lib/getch/filesystem/zfs/encrypt/format.rb +104 -0
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +51 -0
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +66 -0
- data/lib/getch/filesystem/zfs/format.rb +113 -0
- data/lib/getch/filesystem/zfs/mount.rb +48 -0
- data/lib/getch/filesystem/zfs/partition.rb +65 -0
- data/lib/getch/gentoo.rb +11 -4
- data/lib/getch/gentoo/boot.rb +34 -16
- data/lib/getch/gentoo/chroot.rb +16 -25
- data/lib/getch/gentoo/config.rb +59 -7
- data/lib/getch/gentoo/sources.rb +54 -26
- data/lib/getch/gentoo/use.rb +43 -0
- data/lib/getch/gentoo/use_flag.rb +64 -0
- data/lib/getch/guard.rb +62 -0
- data/lib/getch/helpers.rb +31 -13
- data/lib/getch/options.rb +24 -9
- data/lib/getch/version.rb +1 -1
- metadata +40 -18
- metadata.gz.sig +0 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Deps < Getch::FileSystem::Zfs::Device
|
5
|
+
def make
|
6
|
+
unstable_zfs
|
7
|
+
install_deps
|
8
|
+
zfs_mountpoint
|
9
|
+
auto_module_rebuild
|
10
|
+
hostid
|
11
|
+
options_make
|
12
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def unstable_zfs
|
18
|
+
conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
|
19
|
+
data = [
|
20
|
+
"sys-fs/zfs-kmod",
|
21
|
+
"sys-fs/zfs"
|
22
|
+
]
|
23
|
+
File.write(conf, data.join("\n"), mode: "w")
|
24
|
+
end
|
25
|
+
|
26
|
+
def install_deps
|
27
|
+
Getch::Bask.new('-a zfs').run!
|
28
|
+
Getch::Make.new("make modules_prepare").run!
|
29
|
+
Getch::Make.new("make -j$(nproc)").run!
|
30
|
+
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
31
|
+
end
|
32
|
+
|
33
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
34
|
+
def zfs_mountpoint
|
35
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
36
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
37
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
38
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
39
|
+
exec("systemctl start zfs-zed.service")
|
40
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
41
|
+
exec("systemctl enable zfs-zed.service")
|
42
|
+
exec("systemctl enable zfs.target")
|
43
|
+
end
|
44
|
+
|
45
|
+
def auto_module_rebuild
|
46
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
47
|
+
Helpers::mkdir(g_dir)
|
48
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
49
|
+
content=<<EOF
|
50
|
+
post_pkg_postinst() {
|
51
|
+
# BUG: reinstalls of a source will cause errors
|
52
|
+
CURRENT_KV=$(uname -r)
|
53
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
54
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
55
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
56
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
57
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
58
|
+
else # No valid configs known
|
59
|
+
genkernel all
|
60
|
+
fi
|
61
|
+
}
|
62
|
+
EOF
|
63
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
64
|
+
end
|
65
|
+
|
66
|
+
def hostid
|
67
|
+
hostid_value=`hostid`.chomp
|
68
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
69
|
+
end
|
70
|
+
|
71
|
+
def options_make
|
72
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
73
|
+
datas = [
|
74
|
+
'',
|
75
|
+
bootloader,
|
76
|
+
'INSTALL="yes"',
|
77
|
+
'MENUCONFIG="no"',
|
78
|
+
'CLEAN="yes"',
|
79
|
+
'SAVE_CONFIG="yes"',
|
80
|
+
'MOUNTBOOT="no"',
|
81
|
+
'MRPROPER="no"',
|
82
|
+
'ZFS="yes"',
|
83
|
+
'MODULEREBUILD="yes"'
|
84
|
+
]
|
85
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
86
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
87
|
+
end
|
88
|
+
|
89
|
+
def exec(cmd)
|
90
|
+
Getch::Chroot.new(cmd).run!
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Device < Getch::FileSystem::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@id = Helpers::pool_id(@dev_root)
|
8
|
+
@boot_pool_name = "bpool-#{@id}"
|
9
|
+
@pool_name = "rpool-#{@id}"
|
10
|
+
@zfs_home = @user ? true : false
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def search_boot
|
16
|
+
if @efi
|
17
|
+
if @boot_disk
|
18
|
+
@dev_esp = "/dev/#{@boot_disk}1"
|
19
|
+
else
|
20
|
+
@dev_esp = "/dev/#{@disk}1"
|
21
|
+
@root_part += 1
|
22
|
+
end
|
23
|
+
else
|
24
|
+
if @boot_disk
|
25
|
+
@dev_gpt = "/dev/#{@boot_disk}1"
|
26
|
+
@dev_boot = "/dev/#{@boot_disk}2"
|
27
|
+
@dev_grub = "/dev/#{@boot_disk}"
|
28
|
+
else
|
29
|
+
@dev_gpt = "/dev/#{@disk}1"
|
30
|
+
@dev_boot = "/dev/#{@disk}2"
|
31
|
+
@dev_grub = "/dev/#{@disk}"
|
32
|
+
@root_part += 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_swap
|
38
|
+
if @cache_disk
|
39
|
+
@dev_swap = "/dev/#{@cache_disk}1"
|
40
|
+
@dev_log = "/dev/#{@cache_disk}2"
|
41
|
+
@dev_cache = "/dev/#{@cache_disk}3"
|
42
|
+
else
|
43
|
+
@dev_swap = "/dev/#{@disk}#{@root_part}"
|
44
|
+
@root_part += 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def search_root
|
49
|
+
if @root_part == 1
|
50
|
+
@dev_root = "/dev/#{@disk}"
|
51
|
+
else
|
52
|
+
@dev_root = "/dev/#{@disk}#{@root_part}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative 'encrypt/device'
|
11
|
+
require_relative 'encrypt/partition'
|
12
|
+
require_relative 'encrypt/format'
|
13
|
+
require_relative 'encrypt/mount'
|
14
|
+
require_relative 'encrypt/config'
|
15
|
+
require_relative 'encrypt/deps'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Config < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
gen_uuid
|
9
|
+
@root_dir = MOUNTPOINT
|
10
|
+
@init = '/usr/lib/systemd/systemd'
|
11
|
+
crypttab
|
12
|
+
end
|
13
|
+
|
14
|
+
def fstab
|
15
|
+
file = "#{@root_dir}/etc/fstab"
|
16
|
+
datas = data_fstab
|
17
|
+
File.write(file, datas.join("\n"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def systemd_boot
|
21
|
+
return if ! @efi
|
22
|
+
esp = '/efi'
|
23
|
+
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
24
|
+
datas_gentoo = [
|
25
|
+
'title Gentoo Linux',
|
26
|
+
'linux /vmlinuz',
|
27
|
+
'initrd /initramfs',
|
28
|
+
"options root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}"
|
29
|
+
]
|
30
|
+
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def crypttab
|
34
|
+
datas = [
|
35
|
+
"cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512"
|
36
|
+
]
|
37
|
+
File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
|
38
|
+
end
|
39
|
+
|
40
|
+
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
41
|
+
def grub
|
42
|
+
return if @efi
|
43
|
+
file = "#{@root_dir}/etc/default/grub"
|
44
|
+
cmdline = [
|
45
|
+
"GRUB_CMDLINE_LINUX=\"root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}\""
|
46
|
+
]
|
47
|
+
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def gen_uuid
|
53
|
+
@partuuid_swap = Helpers::partuuid(@dev_swap)
|
54
|
+
@uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
|
55
|
+
end
|
56
|
+
|
57
|
+
def data_fstab
|
58
|
+
boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
59
|
+
swap = @dev_swap ? "/dev/mapper/cryptswap none swap discard 0 0" : ''
|
60
|
+
|
61
|
+
[ boot_efi, swap ]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Deps < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def make
|
7
|
+
unstable_zfs
|
8
|
+
install_deps
|
9
|
+
zfs_mountpoint
|
10
|
+
auto_module_rebuild
|
11
|
+
hostid
|
12
|
+
options_make
|
13
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def unstable_zfs
|
18
|
+
conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
|
19
|
+
data = [
|
20
|
+
"sys-fs/zfs-kmod",
|
21
|
+
"sys-fs/zfs"
|
22
|
+
]
|
23
|
+
File.write(conf, data.join("\n"), mode: "w")
|
24
|
+
end
|
25
|
+
|
26
|
+
def install_deps
|
27
|
+
Getch::Bask.new('-a zfs').run!
|
28
|
+
Getch::Make.new("make modules_prepare").run!
|
29
|
+
Getch::Make.new("make -j$(nproc)").run!
|
30
|
+
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
31
|
+
end
|
32
|
+
|
33
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
34
|
+
def zfs_mountpoint
|
35
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
36
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
37
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
38
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
39
|
+
exec("systemctl start zfs-zed.service")
|
40
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
41
|
+
exec("systemctl enable zfs-zed.service")
|
42
|
+
exec("systemctl enable zfs.target")
|
43
|
+
end
|
44
|
+
|
45
|
+
def auto_module_rebuild
|
46
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
47
|
+
Helpers::mkdir(g_dir)
|
48
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
49
|
+
content=<<EOF
|
50
|
+
post_pkg_postinst() {
|
51
|
+
# BUG: reinstalls of a source will cause errors
|
52
|
+
CURRENT_KV=$(uname -r)
|
53
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
54
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
55
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
56
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
57
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
58
|
+
else # No valid configs known
|
59
|
+
genkernel all
|
60
|
+
fi
|
61
|
+
}
|
62
|
+
EOF
|
63
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
64
|
+
end
|
65
|
+
|
66
|
+
def hostid
|
67
|
+
hostid_value=`hostid`.chomp
|
68
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
69
|
+
end
|
70
|
+
|
71
|
+
def options_make
|
72
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
73
|
+
datas = [
|
74
|
+
'',
|
75
|
+
bootloader,
|
76
|
+
'INSTALL="yes"',
|
77
|
+
'MENUCONFIG="no"',
|
78
|
+
'CLEAN="yes"',
|
79
|
+
'KEYMAP="yes"',
|
80
|
+
'SAVE_CONFIG="yes"',
|
81
|
+
'MOUNTBOOT="no"',
|
82
|
+
'MRPROPER="no"',
|
83
|
+
'ZFS="yes"',
|
84
|
+
'MODULEREBUILD="yes"'
|
85
|
+
]
|
86
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
87
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
88
|
+
end
|
89
|
+
|
90
|
+
def exec(cmd)
|
91
|
+
Getch::Chroot.new(cmd).run!
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Device < Getch::FileSystem::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@id = Helpers::pool_id(@dev_root)
|
9
|
+
@boot_pool_name = "bpool-#{@id}"
|
10
|
+
@pool_name = "rpool-#{@id}"
|
11
|
+
@zfs_home = @user ? true : false
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def search_boot
|
17
|
+
if @efi
|
18
|
+
if @boot_disk
|
19
|
+
@dev_esp = "/dev/#{@boot_disk}1"
|
20
|
+
else
|
21
|
+
@dev_esp = "/dev/#{@disk}1"
|
22
|
+
@root_part += 1
|
23
|
+
end
|
24
|
+
else
|
25
|
+
if @boot_disk
|
26
|
+
@dev_gpt = "/dev/#{@boot_disk}1"
|
27
|
+
@dev_boot = "/dev/#{@boot_disk}2"
|
28
|
+
@dev_grub = "/dev/#{@boot_disk}"
|
29
|
+
else
|
30
|
+
@dev_gpt = "/dev/#{@disk}1"
|
31
|
+
@dev_boot = "/dev/#{@disk}2"
|
32
|
+
@dev_grub = "/dev/#{@disk}"
|
33
|
+
@root_part += 2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def search_swap
|
39
|
+
if @cache_disk
|
40
|
+
@dev_swap = "/dev/#{@cache_disk}1"
|
41
|
+
@dev_log = "/dev/#{@cache_disk}2"
|
42
|
+
@dev_cache = "/dev/#{@cache_disk}3"
|
43
|
+
else
|
44
|
+
@dev_swap = "/dev/#{@disk}#{@root_part}"
|
45
|
+
@root_part += 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def search_root
|
50
|
+
if @root_part == 1
|
51
|
+
@dev_root = "/dev/#{@disk}"
|
52
|
+
else
|
53
|
+
@dev_root = "/dev/#{@disk}#{@root_part}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Format < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@log = Getch::Log.new()
|
9
|
+
@state = Getch::States.new()
|
10
|
+
if ! @id
|
11
|
+
@log.info "Research pool id for #{@dev_root}..."
|
12
|
+
@id = Helpers::pool_id(@dev_root)
|
13
|
+
@boot_pool_name = "bpool-#{@id}"
|
14
|
+
@pool_name = "rpool-#{@id}"
|
15
|
+
end
|
16
|
+
format
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def format
|
22
|
+
return if STATES[:format]
|
23
|
+
raise "Error, no id found for #{@dev_root}." if ! @id
|
24
|
+
system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
25
|
+
system("mkswap -f #{@dev_swap}")
|
26
|
+
zfs
|
27
|
+
datasets
|
28
|
+
@state.format
|
29
|
+
end
|
30
|
+
|
31
|
+
def zfs
|
32
|
+
bloc=`blockdev --getpbsz #{@dev_root}`
|
33
|
+
ashift = case bloc
|
34
|
+
when /8096/
|
35
|
+
13
|
36
|
+
when /4096/
|
37
|
+
12
|
38
|
+
else # 512
|
39
|
+
9
|
40
|
+
end
|
41
|
+
|
42
|
+
Helpers::mkdir(MOUNTPOINT)
|
43
|
+
|
44
|
+
@log.debug("ashift found for #{bloc} - #{ashift}")
|
45
|
+
if @dev_boot
|
46
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
47
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
48
|
+
exec("zpool create -f \\
|
49
|
+
-o ashift=#{ashift} -o autotrim=on -d \\
|
50
|
+
-o feature@async_destroy=enabled \\
|
51
|
+
-o feature@bookmarks=enabled \\
|
52
|
+
-o feature@embedded_data=enabled \\
|
53
|
+
-o feature@empty_bpobj=enabled \\
|
54
|
+
-o feature@enabled_txg=enabled \\
|
55
|
+
-o feature@extensible_dataset=enabled \\
|
56
|
+
-o feature@filesystem_limits=enabled \\
|
57
|
+
-o feature@hole_birth=enabled \\
|
58
|
+
-o feature@large_blocks=enabled \\
|
59
|
+
-o feature@lz4_compress=enabled \\
|
60
|
+
-o feature@spacemap_histogram=enabled \\
|
61
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
62
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
63
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
64
|
+
#{@boot_pool_name} #{@dev_boot}
|
65
|
+
")
|
66
|
+
end
|
67
|
+
|
68
|
+
exec("zpool create -f -o ashift=#{ashift} -o autotrim=on \\
|
69
|
+
-O encryption=aes-256-gcm \\
|
70
|
+
-O keylocation=prompt -O keyformat=passphrase \\
|
71
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
72
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
73
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
74
|
+
#{@pool_name} #{@dev_root}
|
75
|
+
")
|
76
|
+
end
|
77
|
+
|
78
|
+
def datasets
|
79
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
80
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
81
|
+
|
82
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
83
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
84
|
+
|
85
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
86
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
87
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
88
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
89
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
90
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
91
|
+
|
92
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
93
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
94
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
95
|
+
end
|
96
|
+
|
97
|
+
def exec(cmd)
|
98
|
+
Helpers::sys(cmd)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|