getch 0.1.6 → 0.1.9
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/README.md +17 -26
- data/assets/system.conf +38 -0
- data/lib/cmdline.rb +128 -0
- data/lib/getch/command.rb +31 -21
- data/lib/getch/config/gentoo.rb +22 -23
- data/lib/getch/config/void.rb +8 -10
- data/lib/getch/config.rb +5 -2
- data/lib/getch/filesystem/clean.rb +15 -15
- data/lib/getch/filesystem/device.rb +3 -1
- data/lib/getch/filesystem/ext4/config.rb +8 -4
- data/lib/getch/filesystem/ext4/deps.rb +3 -1
- data/lib/getch/filesystem/ext4/device.rb +2 -3
- data/lib/getch/filesystem/ext4/encrypt/config.rb +12 -7
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +4 -2
- data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
- data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -1
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -2
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +21 -21
- data/lib/getch/filesystem/ext4/encrypt/void.rb +22 -21
- data/lib/getch/filesystem/ext4/encrypt.rb +2 -0
- data/lib/getch/filesystem/ext4/format.rb +3 -0
- data/lib/getch/filesystem/ext4/mount.rb +3 -0
- data/lib/getch/filesystem/ext4/partition.rb +9 -6
- data/lib/getch/filesystem/ext4/void.rb +8 -7
- data/lib/getch/filesystem/ext4.rb +2 -0
- data/lib/getch/filesystem/lvm/config.rb +7 -22
- data/lib/getch/filesystem/lvm/deps.rb +6 -4
- data/lib/getch/filesystem/lvm/device.rb +2 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +12 -9
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +6 -3
- data/lib/getch/filesystem/lvm/encrypt/device.rb +4 -2
- data/lib/getch/filesystem/lvm/encrypt/format.rb +4 -0
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +3 -0
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +7 -7
- data/lib/getch/filesystem/lvm/encrypt/void.rb +20 -19
- data/lib/getch/filesystem/lvm/encrypt.rb +2 -0
- data/lib/getch/filesystem/lvm/format.rb +3 -0
- data/lib/getch/filesystem/lvm/mount.rb +3 -0
- data/lib/getch/filesystem/lvm/partition.rb +8 -5
- data/lib/getch/filesystem/lvm/void.rb +7 -6
- data/lib/getch/filesystem/lvm.rb +2 -0
- data/lib/getch/filesystem/mount.rb +19 -12
- data/lib/getch/filesystem/partition.rb +16 -8
- data/lib/getch/filesystem/zfs/config.rb +9 -23
- data/lib/getch/filesystem/zfs/deps.rb +22 -57
- data/lib/getch/filesystem/zfs/device.rb +3 -1
- data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -26
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +25 -60
- data/lib/getch/filesystem/zfs/encrypt/device.rb +3 -1
- data/lib/getch/filesystem/zfs/encrypt/format.rb +12 -8
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +13 -8
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +18 -15
- data/lib/getch/filesystem/zfs/encrypt/void.rb +23 -22
- data/lib/getch/filesystem/zfs/encrypt.rb +2 -0
- data/lib/getch/filesystem/zfs/format.rb +9 -5
- data/lib/getch/filesystem/zfs/mount.rb +9 -7
- data/lib/getch/filesystem/zfs/partition.rb +15 -12
- data/lib/getch/filesystem/zfs/void.rb +20 -20
- data/lib/getch/filesystem/zfs.rb +2 -0
- data/lib/getch/filesystem.rb +2 -0
- data/lib/getch/gentoo/boot.rb +21 -72
- data/lib/getch/gentoo/bootloader.rb +68 -0
- data/lib/getch/gentoo/chroot.rb +26 -33
- data/lib/getch/gentoo/config.rb +30 -26
- data/lib/getch/gentoo/sources.rb +55 -66
- data/lib/getch/gentoo/stage.rb +12 -12
- data/lib/getch/gentoo/use.rb +3 -7
- data/lib/getch/gentoo/use_flag.rb +77 -51
- data/lib/getch/gentoo.rb +22 -8
- data/lib/getch/guard.rb +50 -43
- data/lib/getch/helpers.rb +155 -143
- data/lib/getch/log.rb +7 -5
- data/lib/getch/options.rb +16 -14
- data/lib/getch/states.rb +10 -3
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/boot.rb +18 -14
- data/lib/getch/void/chroot.rb +20 -19
- data/lib/getch/void/config.rb +20 -17
- data/lib/getch/void/stage.rb +13 -14
- data/lib/getch/void.rb +7 -1
- data/lib/getch.rb +13 -5
- data.tar.gz.sig +0 -0
- metadata +6 -5
- metadata.gz.sig +0 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Getch
|
|
4
4
|
module FileSystem
|
|
@@ -31,20 +31,20 @@ module Getch
|
|
|
31
31
|
private
|
|
32
32
|
|
|
33
33
|
def partition
|
|
34
|
-
if Helpers
|
|
34
|
+
if Helpers.efi?
|
|
35
35
|
@partition.efi(@dev_esp)
|
|
36
|
-
@partition.root(@dev_root,
|
|
36
|
+
@partition.root(@dev_root, '8e00')
|
|
37
37
|
else
|
|
38
38
|
@partition.gpt(@dev_gpt)
|
|
39
39
|
@partition.boot(@dev_boot)
|
|
40
|
-
@partition.root(@dev_root,
|
|
40
|
+
@partition.root(@dev_root, '8e00')
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def encrypting
|
|
45
|
-
@log.info(
|
|
45
|
+
@log.info('Cryptsetup')
|
|
46
46
|
encrypt(@dev_root)
|
|
47
|
-
open_crypt(@dev_root,
|
|
47
|
+
open_crypt(@dev_root, 'cryptroot')
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def lvm
|
|
@@ -61,7 +61,7 @@ module Getch
|
|
|
61
61
|
exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
exec(
|
|
64
|
+
exec('vgchange --available y')
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Getch
|
|
4
4
|
module FileSystem
|
|
@@ -6,12 +6,13 @@ module Getch
|
|
|
6
6
|
module Encrypt
|
|
7
7
|
class Void < Device
|
|
8
8
|
include Helpers::Void
|
|
9
|
+
|
|
9
10
|
attr_reader :boot_disk
|
|
10
11
|
|
|
11
12
|
# Create key to avoid enter password twice
|
|
12
13
|
def create_key
|
|
13
|
-
add_key(
|
|
14
|
-
add_key(
|
|
14
|
+
add_key('volume.key', @dev_root)
|
|
15
|
+
add_key('home.key', @dev_home) if @home_disk
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
# Key need to be added in dracut.conf.d and crypttab
|
|
@@ -26,25 +27,25 @@ module Getch
|
|
|
26
27
|
def fstab
|
|
27
28
|
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
28
29
|
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
29
|
-
line_fstab(@dev_esp,
|
|
30
|
-
line_fstab(@dev_boot,
|
|
31
|
-
add_line(conf,
|
|
30
|
+
line_fstab(@dev_esp, '/efi vfat noauto,rw,relatime 0 0') if @dev_esp
|
|
31
|
+
line_fstab(@dev_boot, '/boot ext4 noauto,rw,relatime 0 0') if @dev_boot
|
|
32
|
+
add_line(conf, '/dev/mapper/cryptswap none swap sw 0 0')
|
|
32
33
|
add_line(conf, "#{@lv_home} /home ext4 rw,discard 0 0") if @home_disk
|
|
33
34
|
add_line(conf, "#{@lv_root} / ext4 rw,relatime 0 1")
|
|
34
|
-
add_line(conf,
|
|
35
|
+
add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
def crypttab
|
|
38
39
|
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
39
40
|
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
40
41
|
add_line(conf, "cryptswap #{@lv_swap} /dev/urandom swap,discard,cipher=aes-xts-plain64:sha256,size=512")
|
|
41
|
-
line_crypttab(@vg, @dev_root,
|
|
42
|
+
line_crypttab(@vg, @dev_root, '/boot/volume.key', 'luks')
|
|
42
43
|
line_crypttab("crypthome", @dev_home, "/boot/home.key", "luks") if @home_disk
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def config_grub
|
|
46
47
|
conf = "#{MOUNTPOINT}/etc/default/grub"
|
|
47
|
-
content =
|
|
48
|
+
content = 'GRUB_ENABLE_CRYPTODISK=y'
|
|
48
49
|
unless search(conf, content)
|
|
49
50
|
File.write(conf, "#{content}\n", mode: 'a')
|
|
50
51
|
end
|
|
@@ -53,10 +54,10 @@ module Getch
|
|
|
53
54
|
def config_dracut
|
|
54
55
|
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/lvm.conf"
|
|
55
56
|
content = [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
'hostonly="yes"',
|
|
58
|
+
'omit_dracutmodules+=" btrfs "',
|
|
59
|
+
'install_items+=" /boot/volume.key /etc/crypttab "',
|
|
60
|
+
''
|
|
60
61
|
]
|
|
61
62
|
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
62
63
|
#add_line(conf, "install_items+=\" /boot/home.key \"") if @home_disk
|
|
@@ -71,17 +72,17 @@ module Getch
|
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
def finish
|
|
74
|
-
puts
|
|
75
|
-
puts
|
|
75
|
+
puts '+ Enter in your system: chroot /mnt /bin/bash'
|
|
76
|
+
puts '+ Reboot with: shutdown -r now'
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
private
|
|
79
80
|
|
|
80
81
|
def b_uuid(dev)
|
|
81
|
-
device = dev.delete_prefix(
|
|
82
|
-
Dir.glob(
|
|
82
|
+
device = dev.delete_prefix('/dev/')
|
|
83
|
+
Dir.glob('/dev/disk/by-uuid/*').each { |f|
|
|
83
84
|
link = File.readlink(f)
|
|
84
|
-
return f.delete_prefix(
|
|
85
|
+
return f.delete_prefix('/dev/disk/by-uuid/') if link.match(/#{device}$/)
|
|
85
86
|
}
|
|
86
87
|
end
|
|
87
88
|
|
|
@@ -89,7 +90,7 @@ module Getch
|
|
|
89
90
|
def line_crypttab(mapname, dev, point, rest)
|
|
90
91
|
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
91
92
|
device = s_uuid(dev)
|
|
92
|
-
raise "No partuuid for #{dev} #{device}"
|
|
93
|
+
raise "No partuuid for #{dev} #{device}" unless device
|
|
93
94
|
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
94
95
|
add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
|
|
95
96
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Lvm
|
|
@@ -10,6 +12,7 @@ module Getch
|
|
|
10
12
|
|
|
11
13
|
def format
|
|
12
14
|
return if STATES[:format]
|
|
15
|
+
|
|
13
16
|
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
14
17
|
exec("mkfs.ext4 -F #{@dev_boot}") if @dev_boot
|
|
15
18
|
exec("mkswap -f #{@lv_swap}")
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Lvm
|
|
4
6
|
class Partition < Getch::FileSystem::Lvm::Device
|
|
5
7
|
def initialize
|
|
6
8
|
super
|
|
7
|
-
@state = Getch::States.new
|
|
9
|
+
@state = Getch::States.new
|
|
8
10
|
@partition = Getch::FileSystem::Partition.new
|
|
9
11
|
@clean = Getch::FileSystem::Clean
|
|
10
12
|
run_partition
|
|
@@ -12,6 +14,7 @@ module Getch
|
|
|
12
14
|
|
|
13
15
|
def run_partition
|
|
14
16
|
return if STATES[:partition ]
|
|
17
|
+
|
|
15
18
|
@clean.old_vg(@dev_root, @vg)
|
|
16
19
|
@clean.hdd(@disk)
|
|
17
20
|
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
@@ -23,13 +26,13 @@ module Getch
|
|
|
23
26
|
private
|
|
24
27
|
|
|
25
28
|
def partition
|
|
26
|
-
if Helpers
|
|
29
|
+
if Helpers.efi?
|
|
27
30
|
@partition.efi(@dev_esp)
|
|
28
|
-
@partition.root(@dev_root,
|
|
31
|
+
@partition.root(@dev_root, '8e00')
|
|
29
32
|
else
|
|
30
33
|
@partition.gpt(@dev_gpt)
|
|
31
34
|
@partition.boot(@dev_boot)
|
|
32
|
-
@partition.root(@dev_root,
|
|
35
|
+
@partition.root(@dev_root, '8e00')
|
|
33
36
|
end
|
|
34
37
|
end
|
|
35
38
|
|
|
@@ -47,7 +50,7 @@ module Getch
|
|
|
47
50
|
exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
|
|
48
51
|
end
|
|
49
52
|
|
|
50
|
-
exec(
|
|
53
|
+
exec('vgchange --available y')
|
|
51
54
|
end
|
|
52
55
|
|
|
53
56
|
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Getch
|
|
4
4
|
module FileSystem
|
|
5
5
|
module Lvm
|
|
6
6
|
class Void < Device
|
|
7
7
|
include Helpers::Void
|
|
8
|
+
|
|
8
9
|
attr_reader :boot_disk
|
|
9
10
|
|
|
10
11
|
def fstab
|
|
11
12
|
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
12
13
|
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
13
|
-
line_fstab(@dev_esp,
|
|
14
|
-
line_fstab(@dev_boot,
|
|
14
|
+
line_fstab(@dev_esp, '/efi vfat noauto,rw,relatime 0 0') if @dev_esp
|
|
15
|
+
line_fstab(@dev_boot, '/boot ext4 noauto,rw,relatime 0 0') if @dev_boot
|
|
15
16
|
add_line(conf, "#{@lv_swap} swap swap rw,noatime,discard 0 0") if @lv_swap
|
|
16
17
|
add_line(conf, "#{@lv_home} /home/#{@user} ext4 rw,noatime,discard 0 2") if @lv_home
|
|
17
18
|
add_line(conf, "#{@lv_root} / ext4 rw,relatime 0 1")
|
|
18
|
-
add_line(conf,
|
|
19
|
+
add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def config_dracut
|
|
@@ -36,8 +37,8 @@ module Getch
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def finish
|
|
39
|
-
puts
|
|
40
|
-
puts
|
|
40
|
+
puts '+ Enter in your system: chroot /mnt /bin/bash'
|
|
41
|
+
puts '+ Reboot with: shutdown -r now'
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
data/lib/getch/filesystem/lvm.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'fileutils'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
@@ -8,13 +10,14 @@ module Getch
|
|
|
8
10
|
@boot_dir = "#{@root_dir}/boot"
|
|
9
11
|
@boot_efi_dir = "#{@root_dir}/efi"
|
|
10
12
|
@home_dir = "#{@root_dir}/home"
|
|
11
|
-
@state = Getch::States.new
|
|
13
|
+
@state = Getch::States.new
|
|
12
14
|
@log = Getch::Log.new
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def swap(dev)
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
+
return unless dev
|
|
19
|
+
|
|
20
|
+
if Helpers.grep?('/proc/swaps', /^\/dev/)
|
|
18
21
|
exec("swapoff #{dev}")
|
|
19
22
|
end
|
|
20
23
|
|
|
@@ -22,26 +25,30 @@ module Getch
|
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def root(dev)
|
|
25
|
-
return
|
|
26
|
-
|
|
28
|
+
return unless dev
|
|
29
|
+
|
|
30
|
+
Helpers.mkdir(@root_dir)
|
|
27
31
|
exec("mount #{dev} #{@root_dir}")
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
def esp(dev)
|
|
31
|
-
return
|
|
32
|
-
|
|
35
|
+
return unless dev
|
|
36
|
+
|
|
37
|
+
Helpers.mkdir(@boot_efi_dir)
|
|
33
38
|
exec("mount #{dev} #{@boot_efi_dir}")
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
def boot(dev)
|
|
37
|
-
return
|
|
38
|
-
|
|
42
|
+
return unless dev
|
|
43
|
+
|
|
44
|
+
Helpers.mkdir(@boot_dir)
|
|
39
45
|
exec("mount #{dev} #{@boot_dir}")
|
|
40
46
|
end
|
|
41
47
|
|
|
42
48
|
def home(dev)
|
|
43
|
-
return
|
|
44
|
-
|
|
49
|
+
return unless dev
|
|
50
|
+
|
|
51
|
+
Helpers.mkdir(@home_dir)
|
|
45
52
|
exec("mount #{dev} #{@home_dir}")
|
|
46
53
|
end
|
|
47
54
|
|
|
@@ -49,7 +56,7 @@ module Getch
|
|
|
49
56
|
|
|
50
57
|
def exec(cmd)
|
|
51
58
|
@log.info("==> #{cmd}")
|
|
52
|
-
Helpers
|
|
59
|
+
Helpers.sys(cmd)
|
|
53
60
|
end
|
|
54
61
|
end
|
|
55
62
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
class Partition
|
|
@@ -6,17 +8,19 @@ module Getch
|
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def gpt(dev)
|
|
9
|
-
return
|
|
11
|
+
return unless dev
|
|
12
|
+
|
|
10
13
|
disk = disk_name(dev)
|
|
11
14
|
part = dev.match(/[0-9]/)
|
|
12
15
|
exec("sgdisk -n#{part}:1MiB:+1MiB -t#{part}:EF02 #{disk}")
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def boot(dev)
|
|
16
|
-
return
|
|
19
|
+
return unless dev
|
|
20
|
+
|
|
17
21
|
disk = disk_name(dev)
|
|
18
22
|
part = dev.match(/[0-9]/)
|
|
19
|
-
if Getch::OPTIONS[:fs] ==
|
|
23
|
+
if Getch::OPTIONS[:fs] == 'zfs'
|
|
20
24
|
exec("sgdisk -n#{part}:0:+2G -t#{part}:BE00 #{disk}")
|
|
21
25
|
else
|
|
22
26
|
exec("sgdisk -n#{part}:0:+128MiB -t#{part}:8300 #{disk}")
|
|
@@ -24,14 +28,16 @@ module Getch
|
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
def efi(dev)
|
|
27
|
-
return
|
|
31
|
+
return unless dev
|
|
32
|
+
|
|
28
33
|
disk = disk_name(dev)
|
|
29
34
|
part = dev.match(/[0-9]/)
|
|
30
35
|
exec("sgdisk -n#{part}:1M:+260M -t#{part}:EF00 #{disk}")
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def swap(dev)
|
|
34
|
-
return
|
|
39
|
+
return unless dev
|
|
40
|
+
|
|
35
41
|
disk = disk_name(dev)
|
|
36
42
|
part = dev.match(/[0-9]/)
|
|
37
43
|
if Getch::OPTIONS[:cache_disk]
|
|
@@ -43,14 +49,16 @@ module Getch
|
|
|
43
49
|
end
|
|
44
50
|
|
|
45
51
|
def root(dev, code)
|
|
46
|
-
return
|
|
52
|
+
return unless dev
|
|
53
|
+
|
|
47
54
|
disk = disk_name(dev)
|
|
48
55
|
part = dev.match(/[0-9]/)
|
|
49
56
|
exec("sgdisk -n#{part}:0:0 -t#{part}:#{code} #{disk}")
|
|
50
57
|
end
|
|
51
58
|
|
|
52
59
|
def home(dev, code)
|
|
53
|
-
return
|
|
60
|
+
return unless dev
|
|
61
|
+
|
|
54
62
|
disk = disk_name(dev)
|
|
55
63
|
part = dev.match(/[0-9]/)
|
|
56
64
|
if Getch::OPTIONS[:home_disk]
|
|
@@ -67,7 +75,7 @@ module Getch
|
|
|
67
75
|
def exec(cmd)
|
|
68
76
|
@log.debug "Partition disk with #{cmd}"
|
|
69
77
|
if Getch::OPTIONS[:encrypt]
|
|
70
|
-
Helpers
|
|
78
|
+
Helpers.sys(cmd)
|
|
71
79
|
else
|
|
72
80
|
Getch::Command.new(cmd).run!
|
|
73
81
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Zfs
|
|
@@ -5,37 +7,21 @@ module Getch
|
|
|
5
7
|
def initialize
|
|
6
8
|
super
|
|
7
9
|
gen_uuid
|
|
8
|
-
@root_dir = MOUNTPOINT
|
|
9
10
|
@init = '/usr/lib/systemd/systemd'
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def fstab
|
|
13
|
-
file = "#{
|
|
14
|
+
file = "#{MOUNTPOINT}/etc/fstab"
|
|
14
15
|
datas = data_fstab
|
|
15
|
-
File.write
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def systemd_boot
|
|
19
|
-
return if ! Helpers::efi?
|
|
20
|
-
esp = '/efi'
|
|
21
|
-
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
|
22
|
-
datas_gentoo = [
|
|
23
|
-
'title Gentoo Linux',
|
|
24
|
-
'linux /vmlinuz',
|
|
25
|
-
'initrd /initramfs',
|
|
26
|
-
"options resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/#{@n} init=#{@init} dozfs"
|
|
27
|
-
]
|
|
28
|
-
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
|
16
|
+
File.write file, datas.join("\n")
|
|
29
17
|
end
|
|
30
18
|
|
|
31
19
|
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]
|
|
38
|
-
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
|
20
|
+
# https://github.com/openzfs/zfs/blob/master/contrib/dracut/README.dracut.markdown
|
|
21
|
+
def cmdline
|
|
22
|
+
src = "#{MOUNTPOINT}/etc/dracut.conf.d/cmdline.conf"
|
|
23
|
+
line = "kernel_cmdline=\"resume=UUID=#{@uuid_swap} root=zfs:#{@pool_name}/ROOT/#{@n} init=#{@init} zfs.force=1 zfs.zfs_arc_max=536870912\""
|
|
24
|
+
Helpers.echo src, line
|
|
39
25
|
end
|
|
40
26
|
|
|
41
27
|
private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Zfs
|
|
@@ -6,10 +8,8 @@ module Getch
|
|
|
6
8
|
unstable_zfs
|
|
7
9
|
install_deps
|
|
8
10
|
zfs_mountpoint
|
|
9
|
-
auto_module_rebuild
|
|
10
11
|
hostid
|
|
11
|
-
|
|
12
|
-
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
|
12
|
+
config_dracut
|
|
13
13
|
zed_update_path
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -18,79 +18,44 @@ module Getch
|
|
|
18
18
|
def unstable_zfs
|
|
19
19
|
conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
|
|
20
20
|
data = [
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
'sys-fs/zfs-kmod',
|
|
22
|
+
'sys-fs/zfs'
|
|
23
23
|
]
|
|
24
|
-
File.write(conf, data.join("\n"), mode:
|
|
24
|
+
File.write(conf, data.join("\n"), mode: 'w')
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def install_deps
|
|
28
|
-
Getch::
|
|
29
|
-
Getch::
|
|
30
|
-
Getch::Make.new("make -j$(nproc)").run!
|
|
31
|
-
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
|
28
|
+
Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
|
|
29
|
+
Getch::Emerge.new('sys-fs/zfs').pkg!
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
|
35
33
|
def zfs_mountpoint
|
|
36
|
-
Helpers
|
|
37
|
-
Helpers
|
|
38
|
-
Helpers
|
|
39
|
-
exec(
|
|
40
|
-
exec(
|
|
41
|
-
exec(
|
|
42
|
-
exec(
|
|
34
|
+
Helpers.mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
|
35
|
+
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
|
36
|
+
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
|
37
|
+
exec('ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/')
|
|
38
|
+
exec('systemctl start zfs-zed.service')
|
|
39
|
+
exec('systemctl enable zfs-zed.service')
|
|
40
|
+
exec('systemctl enable zfs.target')
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
def zed_update_path
|
|
46
44
|
Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each { |f|
|
|
47
|
-
|
|
48
|
-
raise
|
|
45
|
+
unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
|
|
46
|
+
raise 'system exec sed'
|
|
49
47
|
end
|
|
50
48
|
}
|
|
51
49
|
end
|
|
52
50
|
|
|
53
|
-
def auto_module_rebuild
|
|
54
|
-
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
|
55
|
-
Helpers::mkdir(g_dir)
|
|
56
|
-
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
|
57
|
-
content=<<EOF
|
|
58
|
-
post_pkg_postinst() {
|
|
59
|
-
# BUG: reinstalls of a source will cause errors
|
|
60
|
-
CURRENT_KV=$(uname -r)
|
|
61
|
-
# Check to see if genkernel has been run previously for the running kernel and use that config
|
|
62
|
-
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
|
63
|
-
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
|
64
|
-
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
|
65
|
-
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
|
66
|
-
else # No valid configs known
|
|
67
|
-
genkernel all
|
|
68
|
-
fi
|
|
69
|
-
}
|
|
70
|
-
EOF
|
|
71
|
-
File.write("#{g_dir}/gentoo-sources", content)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
51
|
def hostid
|
|
75
|
-
exec
|
|
52
|
+
exec 'zgenhostid $(hostid)'
|
|
76
53
|
end
|
|
77
54
|
|
|
78
|
-
def
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
bootloader,
|
|
83
|
-
'INSTALL="yes"',
|
|
84
|
-
'MENUCONFIG="no"',
|
|
85
|
-
'CLEAN="yes"',
|
|
86
|
-
'SAVE_CONFIG="yes"',
|
|
87
|
-
'MOUNTBOOT="no"',
|
|
88
|
-
'MRPROPER="no"',
|
|
89
|
-
'ZFS="yes"',
|
|
90
|
-
'MODULEREBUILD="yes"'
|
|
91
|
-
]
|
|
92
|
-
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
|
93
|
-
File.write(file, datas.join("\n"), mode: 'a')
|
|
55
|
+
def config_dracut
|
|
56
|
+
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
|
|
57
|
+
content = 'hostonly="yes"'
|
|
58
|
+
Helpers.echo conf, content
|
|
94
59
|
end
|
|
95
60
|
|
|
96
61
|
def exec(cmd)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Zfs
|
|
4
6
|
class Device < Getch::FileSystem::Device
|
|
5
7
|
def initialize
|
|
6
8
|
super
|
|
7
|
-
@id = Helpers
|
|
9
|
+
@id = Helpers.pool_id(@dev_root)
|
|
8
10
|
@boot_pool_name = "bpool-#{@id}"
|
|
9
11
|
@pool_name = "rpool-#{@id}"
|
|
10
12
|
@zfs_home = @user ? true : false
|