getch 0.1.0 → 0.1.6
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/README.md +95 -22
- data/assets/network-stack.conf +63 -0
- data/bin/getch +12 -4
- data/lib/getch.rb +116 -66
- data/lib/getch/command.rb +19 -5
- data/lib/getch/config.rb +42 -0
- data/lib/getch/config/gentoo.rb +59 -0
- data/lib/getch/config/void.rb +49 -0
- data/lib/getch/filesystem.rb +5 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/clean.rb +58 -0
- data/lib/getch/filesystem/device.rb +61 -0
- data/lib/getch/filesystem/ext4.rb +1 -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.rb +1 -0
- 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 -6
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +5 -43
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -54
- data/lib/getch/filesystem/ext4/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/ext4/format.rb +4 -6
- data/lib/getch/filesystem/ext4/mount.rb +7 -46
- data/lib/getch/filesystem/ext4/partition.rb +16 -39
- data/lib/getch/filesystem/ext4/void.rb +43 -0
- data/lib/getch/filesystem/lvm.rb +1 -0
- data/lib/getch/filesystem/lvm/config.rb +11 -15
- data/lib/getch/filesystem/lvm/deps.rb +4 -19
- data/lib/getch/filesystem/lvm/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt.rb +1 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +4 -21
- data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -4
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -47
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +30 -38
- data/lib/getch/filesystem/lvm/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/lvm/format.rb +12 -8
- data/lib/getch/filesystem/lvm/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/partition.rb +19 -31
- data/lib/getch/filesystem/lvm/void.rb +45 -0
- data/lib/getch/filesystem/mount.rb +56 -0
- data/lib/getch/filesystem/partition.rb +77 -0
- data/lib/getch/filesystem/zfs.rb +1 -0
- data/lib/getch/filesystem/zfs/config.rb +7 -8
- data/lib/getch/filesystem/zfs/deps.rb +24 -12
- data/lib/getch/filesystem/zfs/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt.rb +1 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +11 -11
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +24 -14
- data/lib/getch/filesystem/zfs/encrypt/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt/format.rb +84 -3
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +8 -28
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +26 -109
- data/lib/getch/filesystem/zfs/encrypt/void.rb +96 -0
- data/lib/getch/filesystem/zfs/format.rb +97 -4
- data/lib/getch/filesystem/zfs/mount.rb +10 -32
- data/lib/getch/filesystem/zfs/partition.rb +25 -106
- data/lib/getch/filesystem/zfs/void.rb +81 -0
- data/lib/getch/gentoo.rb +20 -16
- data/lib/getch/gentoo/boot.rb +24 -16
- data/lib/getch/gentoo/chroot.rb +16 -25
- data/lib/getch/gentoo/config.rb +67 -15
- data/lib/getch/gentoo/sources.rb +55 -13
- data/lib/getch/gentoo/stage.rb +0 -1
- data/lib/getch/gentoo/use.rb +43 -0
- data/lib/getch/gentoo/use_flag.rb +63 -0
- data/lib/getch/guard.rb +64 -0
- data/lib/getch/helpers.rb +133 -0
- data/lib/getch/log.rb +3 -2
- data/lib/getch/options.rb +46 -24
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void.rb +59 -0
- data/lib/getch/void/boot.rb +80 -0
- data/lib/getch/void/chroot.rb +55 -0
- data/lib/getch/void/config.rb +87 -0
- data/lib/getch/void/stage.rb +70 -0
- metadata +46 -25
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -60
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
|
@@ -2,29 +2,33 @@ module Getch
|
|
|
2
2
|
module FileSystem
|
|
3
3
|
module Zfs
|
|
4
4
|
module Encrypt
|
|
5
|
-
class Deps <
|
|
6
|
-
def
|
|
7
|
-
|
|
5
|
+
class Deps < Device
|
|
6
|
+
def make
|
|
7
|
+
unstable_zfs
|
|
8
8
|
install_deps
|
|
9
9
|
zfs_mountpoint
|
|
10
10
|
auto_module_rebuild
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def make
|
|
14
11
|
hostid
|
|
15
12
|
options_make
|
|
16
13
|
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
|
14
|
+
zed_update_path
|
|
17
15
|
end
|
|
18
16
|
|
|
19
17
|
private
|
|
18
|
+
def unstable_zfs
|
|
19
|
+
conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
|
|
20
|
+
data = [
|
|
21
|
+
"sys-fs/zfs-kmod",
|
|
22
|
+
"sys-fs/zfs"
|
|
23
|
+
]
|
|
24
|
+
File.write(conf, data.join("\n"), mode: "w")
|
|
25
|
+
end
|
|
26
|
+
|
|
20
27
|
def install_deps
|
|
21
|
-
|
|
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!
|
|
28
|
+
Getch::Bask.new('-a zfs').run!
|
|
25
29
|
Getch::Make.new("make modules_prepare").run!
|
|
26
30
|
Getch::Make.new("make -j$(nproc)").run!
|
|
27
|
-
Getch::Emerge.new('genkernel sys-fs/zfs
|
|
31
|
+
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
|
@@ -34,11 +38,18 @@ module Getch
|
|
|
34
38
|
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
|
35
39
|
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
|
36
40
|
exec("systemctl start zfs-zed.service")
|
|
37
|
-
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
|
38
41
|
exec("systemctl enable zfs-zed.service")
|
|
39
42
|
exec("systemctl enable zfs.target")
|
|
40
43
|
end
|
|
41
44
|
|
|
45
|
+
def zed_update_path
|
|
46
|
+
Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each { |f|
|
|
47
|
+
if !system("sed", "-Ei", "s|#{MOUNTPOINT}/?|/|", f)
|
|
48
|
+
raise "System exec sed"
|
|
49
|
+
end
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
42
53
|
def auto_module_rebuild
|
|
43
54
|
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
|
44
55
|
Helpers::mkdir(g_dir)
|
|
@@ -61,8 +72,7 @@ EOF
|
|
|
61
72
|
end
|
|
62
73
|
|
|
63
74
|
def hostid
|
|
64
|
-
|
|
65
|
-
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
|
75
|
+
exec "zgenhostid $(hostid)"
|
|
66
76
|
end
|
|
67
77
|
|
|
68
78
|
def options_make
|
|
@@ -2,17 +2,62 @@ 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
|
|
12
|
+
@n = Getch::OPTIONS[:os]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def search_boot
|
|
18
|
+
if @efi
|
|
19
|
+
if @boot_disk
|
|
20
|
+
@dev_esp = "/dev/#{@boot_disk}1"
|
|
21
|
+
@dev_boot = "/dev/#{@boot_disk}2" if Getch::OPTIONS[:os] == 'void'
|
|
22
|
+
else
|
|
23
|
+
@dev_esp = "/dev/#{@disk}1"
|
|
24
|
+
@root_part += 1
|
|
25
|
+
if Getch::OPTIONS[:os] == 'void'
|
|
26
|
+
@dev_boot = "/dev/#{@disk}#{@root_part}"
|
|
27
|
+
@root_part += 1
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
if @boot_disk
|
|
32
|
+
@dev_gpt = "/dev/#{@boot_disk}1"
|
|
33
|
+
@dev_boot = "/dev/#{@boot_disk}2"
|
|
34
|
+
@dev_grub = "/dev/#{@boot_disk}"
|
|
35
|
+
else
|
|
36
|
+
@dev_gpt = "/dev/#{@disk}1"
|
|
37
|
+
@dev_boot = "/dev/#{@disk}2"
|
|
38
|
+
@dev_grub = "/dev/#{@disk}"
|
|
39
|
+
@root_part += 2
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def search_swap
|
|
45
|
+
if @cache_disk
|
|
46
|
+
@dev_swap = "/dev/#{@cache_disk}1"
|
|
47
|
+
@dev_log = "/dev/#{@cache_disk}2"
|
|
48
|
+
@dev_cache = "/dev/#{@cache_disk}3"
|
|
49
|
+
else
|
|
50
|
+
@dev_swap = "/dev/#{@disk}#{@root_part}"
|
|
51
|
+
@root_part += 1
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def search_root
|
|
56
|
+
if @root_part == 1
|
|
57
|
+
@dev_root = "/dev/#{@disk}"
|
|
58
|
+
else
|
|
59
|
+
@dev_root = "/dev/#{@disk}#{@root_part}"
|
|
60
|
+
end
|
|
16
61
|
end
|
|
17
62
|
end
|
|
18
63
|
end
|
|
@@ -2,19 +2,100 @@ module Getch
|
|
|
2
2
|
module FileSystem
|
|
3
3
|
module Zfs
|
|
4
4
|
module Encrypt
|
|
5
|
-
class Format <
|
|
5
|
+
class Format < 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
|
+
@id = Helpers::pool_id(@dev_root)
|
|
13
|
+
@boot_pool_name = "bpool-#{@id}"
|
|
14
|
+
@pool_name = "rpool-#{@id}"
|
|
15
|
+
end
|
|
9
16
|
format
|
|
10
17
|
end
|
|
11
18
|
|
|
19
|
+
private
|
|
20
|
+
|
|
12
21
|
def format
|
|
13
22
|
return if STATES[:format]
|
|
14
|
-
|
|
15
|
-
system("
|
|
23
|
+
raise "Error, no id found for #{@dev_root}." if ! @id
|
|
24
|
+
system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
25
|
+
zfs
|
|
26
|
+
datasets
|
|
16
27
|
@state.format
|
|
17
28
|
end
|
|
29
|
+
|
|
30
|
+
def zfs
|
|
31
|
+
bloc=`blockdev --getpbsz #{@dev_root}`
|
|
32
|
+
ashift = case bloc
|
|
33
|
+
when /8096/
|
|
34
|
+
13
|
|
35
|
+
when /4096/
|
|
36
|
+
12
|
|
37
|
+
else # 512
|
|
38
|
+
9
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
Helpers::mkdir(MOUNTPOINT)
|
|
42
|
+
|
|
43
|
+
@log.debug("ashift found for #{bloc} - #{ashift}")
|
|
44
|
+
if @dev_boot
|
|
45
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
|
46
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
|
47
|
+
exec("zpool create -f \\
|
|
48
|
+
-o ashift=#{ashift} -o autotrim=on -d \\
|
|
49
|
+
-o feature@async_destroy=enabled \\
|
|
50
|
+
-o feature@bookmarks=enabled \\
|
|
51
|
+
-o feature@embedded_data=enabled \\
|
|
52
|
+
-o feature@empty_bpobj=enabled \\
|
|
53
|
+
-o feature@enabled_txg=enabled \\
|
|
54
|
+
-o feature@extensible_dataset=enabled \\
|
|
55
|
+
-o feature@filesystem_limits=enabled \\
|
|
56
|
+
-o feature@hole_birth=enabled \\
|
|
57
|
+
-o feature@large_blocks=enabled \\
|
|
58
|
+
-o feature@lz4_compress=enabled \\
|
|
59
|
+
-o feature@spacemap_histogram=enabled \\
|
|
60
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
|
61
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
|
62
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
|
63
|
+
#{@boot_pool_name} #{@dev_boot}
|
|
64
|
+
")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
exec("zpool create -f -o ashift=#{ashift} -o autotrim=on \\
|
|
68
|
+
-O encryption=aes-256-gcm \\
|
|
69
|
+
-O keylocation=prompt -O keyformat=passphrase \\
|
|
70
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
|
71
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
|
72
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
|
73
|
+
#{@pool_name} #{@dev_root}
|
|
74
|
+
")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def datasets
|
|
78
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
|
79
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
|
80
|
+
|
|
81
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/#{@n}")
|
|
82
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/#{@n}") if @dev_boot
|
|
83
|
+
|
|
84
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/usr")
|
|
85
|
+
exec("zfs create #{@pool_name}/ROOT/#{@n}/usr/src")
|
|
86
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/var")
|
|
87
|
+
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/log")
|
|
88
|
+
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/db")
|
|
89
|
+
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/tmp")
|
|
90
|
+
|
|
91
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
|
92
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
|
93
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def exec(cmd)
|
|
97
|
+
Helpers::sys(cmd)
|
|
98
|
+
end
|
|
18
99
|
end
|
|
19
100
|
end
|
|
20
101
|
end
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
|
|
3
1
|
module Getch
|
|
4
2
|
module FileSystem
|
|
5
3
|
module Zfs
|
|
6
4
|
module Encrypt
|
|
7
|
-
class Mount <
|
|
5
|
+
class Mount < Device
|
|
8
6
|
def initialize
|
|
9
7
|
super
|
|
10
|
-
@
|
|
11
|
-
@
|
|
12
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
|
13
|
-
@state = Getch::States.new()
|
|
8
|
+
@mount = Getch::FileSystem::Mount.new
|
|
9
|
+
@state = Getch::States.new
|
|
14
10
|
@log = Getch::Log.new
|
|
15
11
|
end
|
|
16
12
|
|
|
@@ -19,41 +15,25 @@ module Getch
|
|
|
19
15
|
exec("zpool export -a")
|
|
20
16
|
exec("rm -rf #{MOUNTPOINT}/*")
|
|
21
17
|
exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
|
|
22
|
-
exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
|
18
|
+
exec("zpool import -f -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
|
23
19
|
exec("zfs load-key -a")
|
|
24
|
-
mount_swap
|
|
25
20
|
mount_root
|
|
26
21
|
mount_boot
|
|
27
|
-
|
|
22
|
+
@mount.esp(@dev_esp)
|
|
28
23
|
exec("zfs mount -a")
|
|
29
24
|
@state.mount
|
|
30
25
|
end
|
|
31
26
|
|
|
32
27
|
private
|
|
33
28
|
|
|
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
29
|
def mount_root
|
|
43
|
-
Helpers::mkdir(
|
|
44
|
-
exec("zfs mount #{@pool_name}/ROOT
|
|
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}")
|
|
30
|
+
Helpers::mkdir(MOUNTPOINT)
|
|
31
|
+
exec("zfs mount #{@pool_name}/ROOT/#{@n}")
|
|
51
32
|
end
|
|
52
33
|
|
|
53
34
|
def mount_boot
|
|
54
35
|
return if ! @dev_boot
|
|
55
|
-
|
|
56
|
-
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
|
36
|
+
exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
|
|
57
37
|
end
|
|
58
38
|
|
|
59
39
|
def exec(cmd)
|
|
@@ -2,138 +2,54 @@ module Getch
|
|
|
2
2
|
module FileSystem
|
|
3
3
|
module Zfs
|
|
4
4
|
module Encrypt
|
|
5
|
-
class Partition <
|
|
5
|
+
class Partition < Device
|
|
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.hdd(@disk)
|
|
19
|
+
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
20
|
+
|
|
17
21
|
partition
|
|
18
|
-
|
|
22
|
+
cache
|
|
19
23
|
@state.partition
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
private
|
|
23
27
|
|
|
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
28
|
def partition
|
|
52
|
-
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
|
53
29
|
if Helpers::efi?
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
30
|
+
@partition.efi(@dev_esp)
|
|
31
|
+
@partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
|
|
32
|
+
@partition.swap(@dev_swap) if !@cache_disk
|
|
33
|
+
@partition.root(@dev_root, "BF00") if @root_part != 1
|
|
57
34
|
else
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
35
|
+
@partition.gpt(@dev_gpt)
|
|
36
|
+
@partition.boot(@dev_boot)
|
|
37
|
+
@partition.swap(@dev_swap) if !@cache_disk
|
|
38
|
+
@partition.root(@dev_root, "BF00") if @root_part != 1
|
|
62
39
|
end
|
|
63
40
|
end
|
|
64
41
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
")
|
|
42
|
+
def cache
|
|
43
|
+
if @cache_disk
|
|
44
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
|
45
|
+
exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
|
|
46
|
+
exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
|
|
47
|
+
exec("sgdisk -n3:0:0 -t3:BF08 /dev/#{@cache_disk}")
|
|
99
48
|
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
49
|
end
|
|
133
50
|
|
|
134
|
-
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
135
51
|
# Partition_efi
|
|
136
|
-
# /
|
|
52
|
+
# /efi - EFI system partition - 260MB
|
|
137
53
|
# / - Root
|
|
138
54
|
|
|
139
55
|
# Partition_bios
|
|
@@ -142,6 +58,7 @@ module Getch
|
|
|
142
58
|
# / - Root
|
|
143
59
|
|
|
144
60
|
def exec(cmd)
|
|
61
|
+
@log.info("===> #{cmd}")
|
|
145
62
|
Helpers::sys(cmd)
|
|
146
63
|
end
|
|
147
64
|
end
|