getch 0.0.5 → 0.1.0
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 +30 -0
- data/README.md +31 -6
- data/bin/setup.sh +29 -13
- data/lib/getch.rb +43 -30
- data/lib/getch/command.rb +163 -0
- data/lib/getch/filesystem.rb +8 -0
- data/lib/getch/filesystem/ext4.rb +14 -0
- data/lib/getch/filesystem/ext4/config.rb +59 -0
- data/lib/getch/filesystem/ext4/deps.rb +22 -0
- data/lib/getch/filesystem/ext4/device.rb +16 -0
- data/lib/getch/filesystem/ext4/encrypt.rb +15 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +85 -0
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +59 -0
- data/lib/getch/filesystem/ext4/encrypt/device.rb +21 -0
- data/lib/getch/filesystem/ext4/encrypt/format.rb +32 -0
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +64 -0
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +116 -0
- data/lib/getch/filesystem/ext4/format.rb +30 -0
- data/lib/getch/filesystem/ext4/mount.rb +62 -0
- data/lib/getch/filesystem/ext4/partition.rb +75 -0
- data/lib/getch/filesystem/lvm.rb +14 -0
- data/lib/getch/filesystem/lvm/config.rb +63 -0
- data/lib/getch/filesystem/lvm/deps.rb +57 -0
- data/lib/getch/filesystem/lvm/device.rb +19 -0
- data/lib/getch/filesystem/lvm/encrypt.rb +15 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +74 -0
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +63 -0
- data/lib/getch/filesystem/lvm/encrypt/device.rb +22 -0
- data/lib/getch/filesystem/lvm/encrypt/format.rb +32 -0
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +64 -0
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +92 -0
- data/lib/getch/filesystem/lvm/format.rb +25 -0
- data/lib/getch/filesystem/lvm/mount.rb +62 -0
- data/lib/getch/filesystem/lvm/partition.rb +81 -0
- data/lib/getch/filesystem/zfs.rb +14 -0
- data/lib/getch/filesystem/zfs/config.rb +58 -0
- data/lib/getch/filesystem/zfs/deps.rb +90 -0
- data/lib/getch/filesystem/zfs/device.rb +19 -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 +94 -0
- data/lib/getch/filesystem/zfs/encrypt/device.rb +21 -0
- data/lib/getch/filesystem/zfs/encrypt/format.rb +22 -0
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +67 -0
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +151 -0
- data/lib/getch/filesystem/zfs/format.rb +20 -0
- data/lib/getch/filesystem/zfs/mount.rb +67 -0
- data/lib/getch/filesystem/zfs/partition.rb +147 -0
- data/lib/getch/gentoo.rb +3 -2
- data/lib/getch/gentoo/boot.rb +29 -25
- data/lib/getch/gentoo/chroot.rb +18 -14
- data/lib/getch/gentoo/config.rb +18 -9
- data/lib/getch/gentoo/sources.rb +45 -31
- data/lib/getch/gentoo/stage.rb +2 -2
- data/lib/getch/helpers.rb +24 -6
- data/lib/getch/log.rb +54 -0
- data/lib/getch/options.rb +16 -7
- data/lib/getch/version.rb +1 -1
- metadata +48 -5
- metadata.gz.sig +0 -0
- data/lib/getch/disk.rb +0 -77
- data/lib/getch/mount.rb +0 -73
@@ -0,0 +1,90 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Deps < Getch::FileSystem::Zfs::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
install_deps
|
8
|
+
zfs_mountpoint
|
9
|
+
auto_module_rebuild
|
10
|
+
end
|
11
|
+
|
12
|
+
def make
|
13
|
+
hostid
|
14
|
+
options_make
|
15
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def install_deps
|
20
|
+
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
21
|
+
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
22
|
+
Getch::Garden.new('-a zfs').run!
|
23
|
+
Getch::Make.new("make modules_prepare").run!
|
24
|
+
Getch::Make.new("make -j$(nproc)").run!
|
25
|
+
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
26
|
+
end
|
27
|
+
|
28
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
29
|
+
def zfs_mountpoint
|
30
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
31
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
32
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
33
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
34
|
+
exec("systemctl start zfs-zed.service")
|
35
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
36
|
+
exec("systemctl enable zfs-zed.service")
|
37
|
+
exec("systemctl enable zfs.target")
|
38
|
+
end
|
39
|
+
|
40
|
+
def auto_module_rebuild
|
41
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
42
|
+
Helpers::mkdir(g_dir)
|
43
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
44
|
+
content=<<EOF
|
45
|
+
post_pkg_postinst() {
|
46
|
+
# BUG: reinstalls of a source will cause errors
|
47
|
+
CURRENT_KV=$(uname -r)
|
48
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
49
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
50
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
51
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
52
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
53
|
+
else # No valid configs known
|
54
|
+
genkernel all
|
55
|
+
fi
|
56
|
+
}
|
57
|
+
EOF
|
58
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
59
|
+
end
|
60
|
+
|
61
|
+
def hostid
|
62
|
+
hostid_value=`hostid`.chomp
|
63
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
64
|
+
end
|
65
|
+
|
66
|
+
def options_make
|
67
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
68
|
+
datas = [
|
69
|
+
'',
|
70
|
+
bootloader,
|
71
|
+
'INSTALL="yes"',
|
72
|
+
'MENUCONFIG="no"',
|
73
|
+
'CLEAN="yes"',
|
74
|
+
'SAVE_CONFIG="yes"',
|
75
|
+
'MOUNTBOOT="no"',
|
76
|
+
'MRPROPER="no"',
|
77
|
+
'ZFS="yes"',
|
78
|
+
'MODULEREBUILD="yes"'
|
79
|
+
]
|
80
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
81
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
82
|
+
end
|
83
|
+
|
84
|
+
def exec(cmd)
|
85
|
+
Getch::Chroot.new(cmd).run!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Device
|
5
|
+
def initialize
|
6
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
7
|
+
@user = DEFAULT_OPTIONS[:username]
|
8
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
9
|
+
@dev_boot = Helpers::efi? ? nil : "/dev/#{@disk}2"
|
10
|
+
@dev_swap = Helpers::efi? ? "/dev/#{@disk}2" : "/dev/#{@disk}3"
|
11
|
+
@dev_root = Helpers::efi? ? "/dev/#{@disk}3" : "/dev/#{@disk}4"
|
12
|
+
@boot_pool_name = 'bpool'
|
13
|
+
@pool_name = 'zpool'
|
14
|
+
@zfs_home = @user ? true : false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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 ! Helpers::efi?
|
22
|
+
esp = '/boot/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 UUID=#{@uuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=256"
|
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 Helpers::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
|
+
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
|
54
|
+
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
55
|
+
end
|
56
|
+
|
57
|
+
def data_fstab
|
58
|
+
boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/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,94 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Deps < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
install_deps
|
9
|
+
zfs_mountpoint
|
10
|
+
auto_module_rebuild
|
11
|
+
end
|
12
|
+
|
13
|
+
def make
|
14
|
+
hostid
|
15
|
+
options_make
|
16
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def install_deps
|
21
|
+
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
22
|
+
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
23
|
+
exec("euse -E cryptsetup") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /cryptsetup/)
|
24
|
+
Getch::Garden.new('-a zfs').run!
|
25
|
+
Getch::Make.new("make modules_prepare").run!
|
26
|
+
Getch::Make.new("make -j$(nproc)").run!
|
27
|
+
Getch::Emerge.new('genkernel sys-fs/zfs sys-apps/systemd sys-fs/cryptsetup').pkg!
|
28
|
+
end
|
29
|
+
|
30
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
31
|
+
def zfs_mountpoint
|
32
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
33
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
34
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
35
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
36
|
+
exec("systemctl start zfs-zed.service")
|
37
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
38
|
+
exec("systemctl enable zfs-zed.service")
|
39
|
+
exec("systemctl enable zfs.target")
|
40
|
+
end
|
41
|
+
|
42
|
+
def auto_module_rebuild
|
43
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
44
|
+
Helpers::mkdir(g_dir)
|
45
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
46
|
+
content=<<EOF
|
47
|
+
post_pkg_postinst() {
|
48
|
+
# BUG: reinstalls of a source will cause errors
|
49
|
+
CURRENT_KV=$(uname -r)
|
50
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
51
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
52
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
53
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
54
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
55
|
+
else # No valid configs known
|
56
|
+
genkernel all
|
57
|
+
fi
|
58
|
+
}
|
59
|
+
EOF
|
60
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
61
|
+
end
|
62
|
+
|
63
|
+
def hostid
|
64
|
+
hostid_value=`hostid`.chomp
|
65
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
66
|
+
end
|
67
|
+
|
68
|
+
def options_make
|
69
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
70
|
+
datas = [
|
71
|
+
'',
|
72
|
+
bootloader,
|
73
|
+
'INSTALL="yes"',
|
74
|
+
'MENUCONFIG="no"',
|
75
|
+
'CLEAN="yes"',
|
76
|
+
'KEYMAP="yes"',
|
77
|
+
'SAVE_CONFIG="yes"',
|
78
|
+
'MOUNTBOOT="no"',
|
79
|
+
'MRPROPER="no"',
|
80
|
+
'ZFS="yes"',
|
81
|
+
'MODULEREBUILD="yes"'
|
82
|
+
]
|
83
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
84
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
85
|
+
end
|
86
|
+
|
87
|
+
def exec(cmd)
|
88
|
+
Getch::Chroot.new(cmd).run!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Device
|
6
|
+
def initialize
|
7
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
8
|
+
@user = DEFAULT_OPTIONS[:username]
|
9
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
10
|
+
@dev_boot = Helpers::efi? ? nil : "/dev/#{@disk}2"
|
11
|
+
@dev_swap = Helpers::efi? ? "/dev/#{@disk}2" : "/dev/#{@disk}3"
|
12
|
+
@dev_root = Helpers::efi? ? "/dev/#{@disk}3" : "/dev/#{@disk}4"
|
13
|
+
@boot_pool_name = 'bpool'
|
14
|
+
@pool_name = 'zpool'
|
15
|
+
@zfs_home = @user ? true : false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
@state = Getch::States.new()
|
9
|
+
format
|
10
|
+
end
|
11
|
+
|
12
|
+
def format
|
13
|
+
return if STATES[:format]
|
14
|
+
system("mkfs.fat -F32 #{@dev_boot_efi}") if @dev_boot_efi
|
15
|
+
system("mkswap -f #{@dev_swap}")
|
16
|
+
@state.format
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module FileSystem
|
5
|
+
module Zfs
|
6
|
+
module Encrypt
|
7
|
+
class Mount < Getch::FileSystem::Zfs::Encrypt::Device
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@root_dir = MOUNTPOINT
|
11
|
+
@boot_dir = "#{@root_dir}/boot"
|
12
|
+
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
13
|
+
@state = Getch::States.new()
|
14
|
+
@log = Getch::Log.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
return if STATES[:mount]
|
19
|
+
exec("zpool export -a")
|
20
|
+
exec("rm -rf #{MOUNTPOINT}/*")
|
21
|
+
exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
|
22
|
+
exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
23
|
+
exec("zfs load-key -a")
|
24
|
+
mount_swap
|
25
|
+
mount_root
|
26
|
+
mount_boot
|
27
|
+
mount_boot_efi
|
28
|
+
exec("zfs mount -a")
|
29
|
+
@state.mount
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def mount_swap
|
35
|
+
if Helpers::grep?('/proc/swaps', /^\/dev/)
|
36
|
+
exec("swapoff #{@dev_swap}")
|
37
|
+
end
|
38
|
+
|
39
|
+
exec("swapon #{@dev_swap}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def mount_root
|
43
|
+
Helpers::mkdir(@root_dir)
|
44
|
+
exec("zfs mount #{@pool_name}/ROOT/gentoo")
|
45
|
+
end
|
46
|
+
|
47
|
+
def mount_boot_efi
|
48
|
+
return if ! @dev_boot_efi
|
49
|
+
Helpers::mkdir(@boot_efi_dir)
|
50
|
+
exec("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def mount_boot
|
54
|
+
return if ! @dev_boot
|
55
|
+
Helpers::mkdir(@boot_dir)
|
56
|
+
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
57
|
+
end
|
58
|
+
|
59
|
+
def exec(cmd)
|
60
|
+
@log.info("==> #{cmd}")
|
61
|
+
Helpers::sys(cmd)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Partition < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@state = Getch::States.new()
|
9
|
+
@log = Getch::Log.new()
|
10
|
+
run_partition
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_partition
|
14
|
+
return if STATES[:partition ]
|
15
|
+
clear_struct
|
16
|
+
cleaning
|
17
|
+
partition
|
18
|
+
zfs
|
19
|
+
@state.partition
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def clear_struct
|
25
|
+
oldvg = `vgdisplay | grep #{@vg}`.chomp
|
26
|
+
oldzpool = `zpool status | grep pool:`.gsub(/pool: /, '').delete(' ').split("\n")
|
27
|
+
if oldzpool[0] != "" and $?.success?
|
28
|
+
oldzpool.each { |p| exec("zpool destroy #{p}") if p }
|
29
|
+
end
|
30
|
+
exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
|
31
|
+
exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
|
32
|
+
|
33
|
+
exec("sgdisk -Z /dev/#{@disk}")
|
34
|
+
exec("wipefs -a /dev/#{@disk}")
|
35
|
+
end
|
36
|
+
|
37
|
+
# See https://wiki.archlinux.org/index.php/Solid_state_drive/Memory_cell_clearing
|
38
|
+
# for SSD
|
39
|
+
def cleaning
|
40
|
+
@bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
41
|
+
puts
|
42
|
+
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
43
|
+
case gets.chomp
|
44
|
+
when /^y|^Y/
|
45
|
+
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{@bloc} status=progress")
|
46
|
+
else
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def partition
|
52
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
53
|
+
if Helpers::efi?
|
54
|
+
exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
|
55
|
+
exec("sgdisk -n2:0:+#{mem} -t2:8200 /dev/#{@disk}")
|
56
|
+
exec("sgdisk -n3:0:+0 -t3:BF00 /dev/#{@disk}")
|
57
|
+
else
|
58
|
+
exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
59
|
+
exec("sgdisk -n2:0:+2G -t2:BE00 /dev/#{@disk}") # boot pool GRUB
|
60
|
+
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
61
|
+
exec("sgdisk -n4:0:+0 -t4:BF00 /dev/#{@disk}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def zfs
|
66
|
+
ashift = case @bloc
|
67
|
+
when 8096
|
68
|
+
13
|
69
|
+
when 4096
|
70
|
+
12
|
71
|
+
else # 512
|
72
|
+
9
|
73
|
+
end
|
74
|
+
|
75
|
+
Helpers::mkdir(MOUNTPOINT)
|
76
|
+
|
77
|
+
@log.debug("ashift found for #{@bloc} - #{ashift}")
|
78
|
+
if ! Helpers::efi?
|
79
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
80
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
81
|
+
exec("zpool create -f \\
|
82
|
+
-o ashift=#{ashift} -d \\
|
83
|
+
-o feature@async_destroy=enabled \\
|
84
|
+
-o feature@bookmarks=enabled \\
|
85
|
+
-o feature@embedded_data=enabled \\
|
86
|
+
-o feature@empty_bpobj=enabled \\
|
87
|
+
-o feature@enabled_txg=enabled \\
|
88
|
+
-o feature@extensible_dataset=enabled \\
|
89
|
+
-o feature@filesystem_limits=enabled \\
|
90
|
+
-o feature@hole_birth=enabled \\
|
91
|
+
-o feature@large_blocks=enabled \\
|
92
|
+
-o feature@lz4_compress=enabled \\
|
93
|
+
-o feature@spacemap_histogram=enabled \\
|
94
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
95
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
96
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
97
|
+
#{@boot_pool_name} #{@dev_boot}
|
98
|
+
")
|
99
|
+
end
|
100
|
+
|
101
|
+
exec("zpool create -f -o ashift=#{ashift} \\
|
102
|
+
-O encryption=aes-256-gcm \\
|
103
|
+
-O keylocation=prompt -O keyformat=passphrase \\
|
104
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
105
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
106
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
107
|
+
#{@pool_name} #{@dev_root}
|
108
|
+
")
|
109
|
+
|
110
|
+
add_datasets
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_datasets
|
114
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
115
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
116
|
+
|
117
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
118
|
+
# set bootfs
|
119
|
+
#exec("zpool set bootfs=#{@pool_name}/ROOT/gentoo #{@pool_name}")
|
120
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
121
|
+
|
122
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
123
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
124
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
125
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
126
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
127
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
128
|
+
|
129
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
130
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
131
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
132
|
+
end
|
133
|
+
|
134
|
+
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
135
|
+
# Partition_efi
|
136
|
+
# /boot/efi - EFI system partition - 260MB
|
137
|
+
# / - Root
|
138
|
+
|
139
|
+
# Partition_bios
|
140
|
+
# None - Bios Boot Partition - 1MiB
|
141
|
+
# /boot - Boot - 8300
|
142
|
+
# / - Root
|
143
|
+
|
144
|
+
def exec(cmd)
|
145
|
+
Helpers::sys(cmd)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|