getch 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +9 -0
- data/README.md +18 -4
- data/lib/getch.rb +14 -7
- data/lib/getch/command.rb +18 -4
- data/lib/getch/filesystem.rb +5 -0
- data/lib/getch/filesystem/clean.rb +51 -0
- data/lib/getch/filesystem/device.rb +55 -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 +9 -9
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +1 -1
- 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 +5 -5
- data/lib/getch/filesystem/lvm/deps.rb +3 -2
- data/lib/getch/filesystem/lvm/device.rb +23 -7
- data/lib/getch/filesystem/lvm/encrypt/config.rb +3 -3
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +1 -1
- data/lib/getch/filesystem/lvm/encrypt/device.rb +23 -7
- 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 +19 -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/config.rb +4 -5
- data/lib/getch/filesystem/zfs/deps.rb +3 -6
- data/lib/getch/filesystem/zfs/device.rb +30 -9
- data/lib/getch/filesystem/zfs/encrypt/config.rb +7 -7
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +2 -6
- data/lib/getch/filesystem/zfs/encrypt/device.rb +30 -9
- data/lib/getch/filesystem/zfs/encrypt/format.rb +84 -1
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +4 -20
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +15 -111
- data/lib/getch/filesystem/zfs/format.rb +84 -2
- data/lib/getch/filesystem/zfs/mount.rb +5 -24
- data/lib/getch/filesystem/zfs/partition.rb +15 -108
- data/lib/getch/gentoo.rb +2 -1
- data/lib/getch/gentoo/boot.rb +2 -2
- data/lib/getch/gentoo/chroot.rb +10 -24
- data/lib/getch/gentoo/config.rb +22 -2
- data/lib/getch/gentoo/sources.rb +11 -11
- data/lib/getch/helpers.rb +13 -0
- data/lib/getch/options.rb +20 -5
- data/lib/getch/version.rb +1 -1
- metadata +6 -2
- metadata.gz.sig +0 -0
@@ -17,7 +17,7 @@ module Getch
|
|
17
17
|
|
18
18
|
def systemd_boot
|
19
19
|
return if ! Helpers::efi?
|
20
|
-
esp = '/
|
20
|
+
esp = '/efi'
|
21
21
|
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
22
22
|
datas_gentoo = [
|
23
23
|
'title Gentoo Linux',
|
@@ -42,15 +42,14 @@ module Getch
|
|
42
42
|
|
43
43
|
def gen_uuid
|
44
44
|
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
|
45
|
-
@
|
46
|
-
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
45
|
+
@uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
|
47
46
|
end
|
48
47
|
|
49
48
|
def data_fstab
|
50
|
-
|
49
|
+
efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
51
50
|
swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
52
51
|
|
53
|
-
[
|
52
|
+
[ efi, swap ]
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -2,24 +2,21 @@ module Getch
|
|
2
2
|
module FileSystem
|
3
3
|
module Zfs
|
4
4
|
class Deps < Getch::FileSystem::Zfs::Device
|
5
|
-
def
|
6
|
-
super
|
5
|
+
def make
|
7
6
|
install_deps
|
8
7
|
zfs_mountpoint
|
9
8
|
auto_module_rebuild
|
10
|
-
end
|
11
|
-
|
12
|
-
def make
|
13
9
|
hostid
|
14
10
|
options_make
|
15
11
|
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
16
12
|
end
|
17
13
|
|
18
14
|
private
|
15
|
+
|
19
16
|
def install_deps
|
20
17
|
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
21
18
|
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
22
|
-
Getch::
|
19
|
+
Getch::Bask.new('-a zfs').run!
|
23
20
|
Getch::Make.new("make modules_prepare").run!
|
24
21
|
Getch::Make.new("make -j$(nproc)").run!
|
25
22
|
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
@@ -1,18 +1,39 @@
|
|
1
1
|
module Getch
|
2
2
|
module FileSystem
|
3
3
|
module Zfs
|
4
|
-
class Device
|
4
|
+
class Device < Getch::FileSystem::Device
|
5
5
|
def initialize
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
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'
|
6
|
+
super
|
7
|
+
@id = Helpers::pool_id(@dev_root)
|
8
|
+
@boot_pool_name = "bpool-#{@id}"
|
9
|
+
@pool_name = "rpool-#{@id}"
|
14
10
|
@zfs_home = @user ? true : false
|
15
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def search_boot
|
16
|
+
if @boot_disk
|
17
|
+
@dev_gpt = @efi ? nil : "/dev/#{@boot_disk}1"
|
18
|
+
@dev_boot = @efi ? nil : "/dev/#{@boot_disk}2"
|
19
|
+
@dev_esp = @efi ? "/dev/#{@boot_disk}1" : nil
|
20
|
+
else
|
21
|
+
@dev_gpt = @efi ? nil : "/dev/#{@disk}#{@root_part}"
|
22
|
+
@dev_esp = @efi ? "/dev/#{@disk}#{@root_part}" : nil
|
23
|
+
@boot_disk = @disk # used by grub
|
24
|
+
@root_part += 1
|
25
|
+
@dev_boot = @efi ? nil : "/dev/#{@disk}#{@root_part}"
|
26
|
+
@root_part += 1 if ! @efi
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def search_root
|
31
|
+
if @root_part == 1
|
32
|
+
@dev_root = "/dev/#{@disk}"
|
33
|
+
else
|
34
|
+
@dev_root = "/dev/#{@disk}#{@root_part}"
|
35
|
+
end
|
36
|
+
end
|
16
37
|
end
|
17
38
|
end
|
18
39
|
end
|
@@ -18,8 +18,8 @@ module Getch
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def systemd_boot
|
21
|
-
return if !
|
22
|
-
esp = '/
|
21
|
+
return if ! @efi
|
22
|
+
esp = '/efi'
|
23
23
|
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
24
24
|
datas_gentoo = [
|
25
25
|
'title Gentoo Linux',
|
@@ -32,14 +32,14 @@ module Getch
|
|
32
32
|
|
33
33
|
def crypttab
|
34
34
|
datas = [
|
35
|
-
"cryptswap
|
35
|
+
"cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=256"
|
36
36
|
]
|
37
37
|
File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
|
38
38
|
end
|
39
39
|
|
40
40
|
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
41
41
|
def grub
|
42
|
-
return if
|
42
|
+
return if @efi
|
43
43
|
file = "#{@root_dir}/etc/default/grub"
|
44
44
|
cmdline = [
|
45
45
|
"GRUB_CMDLINE_LINUX=\"root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}\""
|
@@ -50,12 +50,12 @@ module Getch
|
|
50
50
|
private
|
51
51
|
|
52
52
|
def gen_uuid
|
53
|
-
@
|
54
|
-
@
|
53
|
+
@partuuid_swap = Helpers::partuuid(@dev_swap)
|
54
|
+
@uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
|
55
55
|
end
|
56
56
|
|
57
57
|
def data_fstab
|
58
|
-
boot_efi = @
|
58
|
+
boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
59
59
|
swap = @dev_swap ? "/dev/mapper/cryptswap none swap discard 0 0" : ''
|
60
60
|
|
61
61
|
[ boot_efi, swap ]
|
@@ -3,14 +3,10 @@ module Getch
|
|
3
3
|
module Zfs
|
4
4
|
module Encrypt
|
5
5
|
class Deps < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
-
def
|
7
|
-
super
|
6
|
+
def make
|
8
7
|
install_deps
|
9
8
|
zfs_mountpoint
|
10
9
|
auto_module_rebuild
|
11
|
-
end
|
12
|
-
|
13
|
-
def make
|
14
10
|
hostid
|
15
11
|
options_make
|
16
12
|
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
@@ -21,7 +17,7 @@ module Getch
|
|
21
17
|
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
22
18
|
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
23
19
|
exec("euse -E cryptsetup") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /cryptsetup/)
|
24
|
-
Getch::
|
20
|
+
Getch::Bask.new('-a zfs').run!
|
25
21
|
Getch::Make.new("make modules_prepare").run!
|
26
22
|
Getch::Make.new("make -j$(nproc)").run!
|
27
23
|
Getch::Emerge.new('genkernel sys-fs/zfs sys-apps/systemd sys-fs/cryptsetup').pkg!
|
@@ -2,18 +2,39 @@ module Getch
|
|
2
2
|
module FileSystem
|
3
3
|
module Zfs
|
4
4
|
module Encrypt
|
5
|
-
class Device
|
5
|
+
class Device < Getch::FileSystem::Device
|
6
6
|
def initialize
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
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'
|
7
|
+
super
|
8
|
+
@id = Helpers::pool_id(@dev_root)
|
9
|
+
@boot_pool_name = "bpool-#{@id}"
|
10
|
+
@pool_name = "rpool-#{@id}"
|
15
11
|
@zfs_home = @user ? true : false
|
16
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def search_boot
|
17
|
+
if @boot_disk
|
18
|
+
@dev_gpt = @efi ? nil : "/dev/#{@boot_disk}1"
|
19
|
+
@dev_boot = @efi ? nil : "/dev/#{@boot_disk}2"
|
20
|
+
@dev_esp = @efi ? "/dev/#{@boot_disk}1" : nil
|
21
|
+
else
|
22
|
+
@dev_gpt = @efi ? nil : "/dev/#{@disk}#{@root_part}"
|
23
|
+
@dev_esp = @efi ? "/dev/#{@disk}#{@root_part}" : nil
|
24
|
+
@boot_disk = @disk # used by grub
|
25
|
+
@root_part += 1
|
26
|
+
@dev_boot = @efi ? nil : "/dev/#{@disk}#{@root_part}"
|
27
|
+
@root_part += 1 if ! @efi
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_root
|
32
|
+
if @root_part == 1
|
33
|
+
@dev_root = "/dev/#{@disk}"
|
34
|
+
else
|
35
|
+
@dev_root = "/dev/#{@disk}#{@root_part}"
|
36
|
+
end
|
37
|
+
end
|
17
38
|
end
|
18
39
|
end
|
19
40
|
end
|
@@ -5,16 +5,99 @@ module Getch
|
|
5
5
|
class Format < Getch::FileSystem::Zfs::Encrypt::Device
|
6
6
|
def initialize
|
7
7
|
super
|
8
|
+
@log = Getch::Log.new()
|
8
9
|
@state = Getch::States.new()
|
10
|
+
if ! @id
|
11
|
+
@log.info "Research pool id for #{@dev_root}..."
|
12
|
+
sleep 2 until Helpers::pool_id(@dev_root)
|
13
|
+
@id = Helpers::pool_id(@dev_root)
|
14
|
+
@boot_pool_name = "bpool-#{@id}"
|
15
|
+
@pool_name = "rpool-#{@id}"
|
16
|
+
end
|
9
17
|
format
|
10
18
|
end
|
11
19
|
|
20
|
+
private
|
21
|
+
|
12
22
|
def format
|
13
23
|
return if STATES[:format]
|
14
|
-
|
24
|
+
raise "Error, no id found for #{@dev_root}." if ! @id
|
25
|
+
system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
15
26
|
system("mkswap -f #{@dev_swap}")
|
27
|
+
zfs
|
28
|
+
datasets
|
16
29
|
@state.format
|
17
30
|
end
|
31
|
+
|
32
|
+
def zfs
|
33
|
+
bloc=`blockdev --getbsz #{@dev_root}`.chomp
|
34
|
+
ashift = case bloc
|
35
|
+
when 8096
|
36
|
+
13
|
37
|
+
when 4096
|
38
|
+
12
|
39
|
+
else # 512
|
40
|
+
9
|
41
|
+
end
|
42
|
+
|
43
|
+
Helpers::mkdir(MOUNTPOINT)
|
44
|
+
|
45
|
+
@log.debug("ashift found for #{bloc} - #{ashift}")
|
46
|
+
if @dev_boot
|
47
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
48
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
49
|
+
exec("zpool create -f \\
|
50
|
+
-o ashift=#{ashift} -d \\
|
51
|
+
-o feature@async_destroy=enabled \\
|
52
|
+
-o feature@bookmarks=enabled \\
|
53
|
+
-o feature@embedded_data=enabled \\
|
54
|
+
-o feature@empty_bpobj=enabled \\
|
55
|
+
-o feature@enabled_txg=enabled \\
|
56
|
+
-o feature@extensible_dataset=enabled \\
|
57
|
+
-o feature@filesystem_limits=enabled \\
|
58
|
+
-o feature@hole_birth=enabled \\
|
59
|
+
-o feature@large_blocks=enabled \\
|
60
|
+
-o feature@lz4_compress=enabled \\
|
61
|
+
-o feature@spacemap_histogram=enabled \\
|
62
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
63
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
64
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
65
|
+
#{@boot_pool_name} #{@dev_boot}
|
66
|
+
")
|
67
|
+
end
|
68
|
+
|
69
|
+
exec("zpool create -f -o ashift=#{ashift} \\
|
70
|
+
-O encryption=aes-256-gcm \\
|
71
|
+
-O keylocation=prompt -O keyformat=passphrase \\
|
72
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
73
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
74
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
75
|
+
#{@pool_name} #{@dev_root}
|
76
|
+
")
|
77
|
+
end
|
78
|
+
|
79
|
+
def datasets
|
80
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
81
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
82
|
+
|
83
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
84
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
85
|
+
|
86
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
87
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
88
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
89
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
90
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
91
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
92
|
+
|
93
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
94
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
95
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
96
|
+
end
|
97
|
+
|
98
|
+
def exec(cmd)
|
99
|
+
Helpers::sys(cmd)
|
100
|
+
end
|
18
101
|
end
|
19
102
|
end
|
20
103
|
end
|
@@ -8,9 +8,8 @@ module Getch
|
|
8
8
|
def initialize
|
9
9
|
super
|
10
10
|
@root_dir = MOUNTPOINT
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@state = Getch::States.new()
|
11
|
+
@mount = Getch::FileSystem::Mount.new
|
12
|
+
@state = Getch::States.new
|
14
13
|
@log = Getch::Log.new
|
15
14
|
end
|
16
15
|
|
@@ -21,38 +20,23 @@ module Getch
|
|
21
20
|
exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
|
22
21
|
exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
23
22
|
exec("zfs load-key -a")
|
24
|
-
|
23
|
+
@mount.swap(@dev_swap)
|
25
24
|
mount_root
|
26
25
|
mount_boot
|
27
|
-
|
26
|
+
@mount.esp(@dev_esp)
|
28
27
|
exec("zfs mount -a")
|
29
28
|
@state.mount
|
30
29
|
end
|
31
30
|
|
32
31
|
private
|
33
32
|
|
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
33
|
def mount_root
|
43
34
|
Helpers::mkdir(@root_dir)
|
44
35
|
exec("zfs mount #{@pool_name}/ROOT/gentoo")
|
45
36
|
end
|
46
37
|
|
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
38
|
def mount_boot
|
54
39
|
return if ! @dev_boot
|
55
|
-
Helpers::mkdir(@boot_dir)
|
56
40
|
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
57
41
|
end
|
58
42
|
|
@@ -6,134 +6,38 @@ module Getch
|
|
6
6
|
def initialize
|
7
7
|
super
|
8
8
|
@state = Getch::States.new()
|
9
|
+
@clean = Getch::FileSystem::Clean
|
10
|
+
@partition = Getch::FileSystem::Partition.new
|
9
11
|
@log = Getch::Log.new()
|
10
|
-
|
12
|
+
run
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def run
|
14
16
|
return if STATES[:partition ]
|
15
|
-
|
16
|
-
|
17
|
+
@clean.old_zpool
|
18
|
+
@clean.struct(@disk, @cache_disk, @home_disk)
|
19
|
+
@clean.hdd(@disk, @cache_disk, @home_disk)
|
17
20
|
partition
|
18
|
-
zfs
|
19
21
|
@state.partition
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
23
25
|
|
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
26
|
def partition
|
52
|
-
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
53
27
|
if Helpers::efi?
|
54
|
-
|
55
|
-
|
56
|
-
|
28
|
+
@partition.efi(@dev_esp)
|
29
|
+
@partition.swap(@dev_swap)
|
30
|
+
@partition.root(@dev_root, "BF00") if @root_part != 1
|
57
31
|
else
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
")
|
32
|
+
@partition.gpt(@dev_gpt)
|
33
|
+
@partition.boot(@dev_boot)
|
34
|
+
@partition.swap(@dev_swap)
|
35
|
+
@partition.root(@dev_root, "BF00") if @root_part != 1
|
99
36
|
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
37
|
end
|
133
38
|
|
134
|
-
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
135
39
|
# Partition_efi
|
136
|
-
# /
|
40
|
+
# /efi - EFI system partition - 260MB
|
137
41
|
# / - Root
|
138
42
|
|
139
43
|
# Partition_bios
|