getch 0.1.3 → 0.3.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/README.md +75 -35
- data/assets/network-stack.conf +63 -0
- data/assets/system.conf +38 -0
- data/bin/getch +14 -4
- data/lib/clean.rb +149 -0
- data/lib/cmdline.rb +128 -0
- data/lib/cryptsetup.rb +132 -0
- data/lib/devs.rb +199 -0
- data/lib/dracut/encrypt.rb +36 -0
- data/lib/dracut/hybrid.rb +15 -0
- data/lib/dracut/lvm.rb +14 -0
- data/lib/dracut/minimal.rb +11 -0
- data/lib/dracut/root.rb +45 -0
- data/lib/dracut/zfs.rb +35 -0
- data/lib/dracut.rb +11 -0
- data/lib/fstab/encrypt.rb +44 -0
- data/lib/fstab/hybrid.rb +34 -0
- data/lib/fstab/lvm.rb +25 -0
- data/lib/fstab/minimal.rb +6 -0
- data/lib/fstab/root.rb +93 -0
- data/lib/fstab/zfs.rb +23 -0
- data/lib/fstab.rb +11 -0
- data/lib/getch/assembly.rb +150 -0
- data/lib/getch/command.rb +94 -124
- data/lib/getch/config/account.rb +39 -0
- data/lib/getch/config/dhcp.rb +104 -0
- data/lib/getch/config/grub.rb +42 -0
- data/lib/getch/config/iwd.rb +60 -0
- data/lib/getch/config/keymap.rb +78 -0
- data/lib/getch/config/locale.rb +96 -0
- data/lib/getch/config/portage.rb +90 -0
- data/lib/getch/config/pre_network.rb +37 -0
- data/lib/getch/config/timezone.rb +52 -0
- data/lib/getch/config/void.rb +11 -0
- data/lib/getch/config.rb +19 -53
- data/lib/getch/device.rb +67 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +11 -68
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +17 -25
- data/lib/getch/filesystem/ext4/encrypt/device.rb +13 -5
- data/lib/getch/filesystem/ext4/encrypt/format.rb +8 -15
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +9 -13
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -82
- data/lib/getch/filesystem/ext4/encrypt/void.rb +63 -0
- data/lib/getch/filesystem/ext4/encrypt.rb +4 -0
- data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
- data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
- data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
- data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
- data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
- data/lib/getch/filesystem/ext4/hybrid/void.rb +62 -0
- data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
- data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
- data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
- data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
- data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
- data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +8 -3
- data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
- data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +4 -3
- data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
- data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
- data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
- data/lib/getch/filesystem/ext4/minimal.rb +19 -0
- data/lib/getch/filesystem/ext4.rb +9 -6
- data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -57
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +7 -86
- data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -45
- data/lib/getch/filesystem/zfs/encrypt/format.rb +8 -90
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -34
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +8 -50
- data/lib/getch/filesystem/zfs/encrypt.rb +4 -0
- data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
- data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
- data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
- data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal.rb +19 -0
- data/lib/getch/filesystem/zfs.rb +3 -6
- data/lib/getch/filesystem.rb +2 -6
- data/lib/getch/gentoo/bootloader.rb +47 -0
- data/lib/getch/gentoo/finalize.rb +25 -0
- data/lib/getch/gentoo/post_config.rb +75 -0
- data/lib/getch/gentoo/pre_config.rb +37 -0
- data/lib/getch/gentoo/services.rb +18 -0
- data/lib/getch/gentoo/sources.rb +82 -52
- data/lib/getch/gentoo/tarball.rb +91 -0
- data/lib/getch/gentoo/terraform.rb +34 -0
- data/lib/getch/gentoo/update.rb +54 -0
- data/lib/getch/gentoo/use.rb +11 -12
- data/lib/getch/gentoo/use_flag.rb +74 -52
- data/lib/getch/gentoo.rb +11 -63
- data/lib/getch/guard.rb +71 -0
- data/lib/getch/helpers.rb +128 -48
- data/lib/getch/log.rb +91 -26
- data/lib/getch/options.rb +79 -40
- data/lib/getch/states.rb +37 -10
- data/lib/getch/tree.rb +56 -0
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/bootloader.rb +18 -0
- data/lib/getch/void/finalize.rb +31 -0
- data/lib/getch/void/post_config.rb +19 -0
- data/lib/getch/void/pre_config.rb +18 -0
- data/lib/getch/void/services.rb +18 -0
- data/lib/getch/void/tarball.rb +89 -0
- data/lib/getch/void/terraform.rb +28 -0
- data/lib/getch/void/update.rb +33 -0
- data/lib/getch/void.rb +15 -0
- data/lib/getch.rb +104 -92
- data/lib/luks.rb +239 -0
- data/lib/lvm2.rb +112 -0
- data/lib/mkfs/zfs.rb +167 -0
- data/lib/mkfs.rb +140 -0
- data/lib/mountfs.rb +154 -0
- data/lib/nito.rb +131 -0
- data/lib/sgdisk.rb +160 -0
- data.tar.gz.sig +0 -0
- metadata +96 -45
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -90
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
- data/lib/getch/filesystem/clean.rb +0 -51
- data/lib/getch/filesystem/device.rb +0 -61
- data/lib/getch/filesystem/ext4/config.rb +0 -58
- data/lib/getch/filesystem/ext4/deps.rb +0 -22
- data/lib/getch/filesystem/ext4/format.rb +0 -28
- data/lib/getch/filesystem/ext4/mount.rb +0 -23
- data/lib/getch/filesystem/ext4/partition.rb +0 -52
- data/lib/getch/filesystem/lvm/config.rb +0 -59
- data/lib/getch/filesystem/lvm/deps.rb +0 -42
- data/lib/getch/filesystem/lvm/device.rb +0 -43
- data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -71
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -46
- data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -46
- data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -32
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -25
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -80
- data/lib/getch/filesystem/lvm/encrypt.rb +0 -15
- data/lib/getch/filesystem/lvm/format.rb +0 -29
- data/lib/getch/filesystem/lvm/mount.rb +0 -23
- data/lib/getch/filesystem/lvm/partition.rb +0 -69
- data/lib/getch/filesystem/mount.rb +0 -56
- data/lib/getch/filesystem/partition.rb +0 -77
- data/lib/getch/filesystem/zfs/config.rb +0 -57
- data/lib/getch/filesystem/zfs/deps.rb +0 -95
- data/lib/getch/filesystem/zfs/device.rb +0 -58
- data/lib/getch/filesystem/zfs/format.rb +0 -114
- data/lib/getch/filesystem/zfs/mount.rb +0 -48
- data/lib/getch/filesystem/zfs/partition.rb +0 -64
- data/lib/getch/gentoo/boot.rb +0 -109
- data/lib/getch/gentoo/chroot.rb +0 -77
- data/lib/getch/gentoo/config.rb +0 -129
- data/lib/getch/gentoo/stage.rb +0 -74
@@ -1,80 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Lvm
|
4
|
-
module Encrypt
|
5
|
-
class Partition < Getch::FileSystem::Lvm::Encrypt::Device
|
6
|
-
def initialize
|
7
|
-
super
|
8
|
-
@state = Getch::States.new()
|
9
|
-
@clean = Getch::FileSystem::Clean
|
10
|
-
@partition = Getch::FileSystem::Partition.new
|
11
|
-
@log = Log.new
|
12
|
-
run_partition
|
13
|
-
end
|
14
|
-
|
15
|
-
def run_partition
|
16
|
-
return if STATES[:partition ]
|
17
|
-
@clean.old_vg(@dev_root, @vg)
|
18
|
-
@clean.struct(@disk, @cache_disk, @home_disk)
|
19
|
-
@clean.hdd(@disk, @cache_disk, @home_disk)
|
20
|
-
partition
|
21
|
-
encrypt
|
22
|
-
lvm
|
23
|
-
@state.partition
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def partition
|
29
|
-
if Helpers::efi?
|
30
|
-
@partition.efi(@dev_esp)
|
31
|
-
@partition.root(@dev_root, "8e00")
|
32
|
-
else
|
33
|
-
@partition.gpt(@dev_gpt)
|
34
|
-
@partition.boot(@dev_boot)
|
35
|
-
@partition.root(@dev_root, "8e00")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def encrypt
|
40
|
-
@log.info("Format root")
|
41
|
-
Helpers::sys("cryptsetup luksFormat #{@dev_root}")
|
42
|
-
@log.debug("Opening root")
|
43
|
-
Helpers::sys("cryptsetup open --type luks #{@dev_root} cryptroot")
|
44
|
-
end
|
45
|
-
|
46
|
-
def lvm
|
47
|
-
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
48
|
-
exec("pvcreate -f #{@luks_root}")
|
49
|
-
exec("vgcreate -f #{@vg} #{@luks_root}")
|
50
|
-
# Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
|
51
|
-
exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
|
52
|
-
|
53
|
-
if @user
|
54
|
-
exec("lvcreate -y -Wy -Zy -L 18G -n root #{@vg}")
|
55
|
-
exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}")
|
56
|
-
else
|
57
|
-
exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
|
58
|
-
end
|
59
|
-
|
60
|
-
exec("vgchange --available y")
|
61
|
-
end
|
62
|
-
|
63
|
-
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
64
|
-
# Partition_efi
|
65
|
-
# /efi - EFI system partition - 260MB
|
66
|
-
# / - Root
|
67
|
-
|
68
|
-
# Partition_bios
|
69
|
-
# None - Bios Boot Partition - 1MiB
|
70
|
-
# /boot - Boot - 8300
|
71
|
-
# / - Root
|
72
|
-
|
73
|
-
def exec(cmd)
|
74
|
-
Getch::Command.new(cmd).run!
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Lvm
|
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'
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Lvm
|
4
|
-
class Format < Getch::FileSystem::Lvm::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@state = Getch::States.new()
|
8
|
-
format
|
9
|
-
end
|
10
|
-
|
11
|
-
def format
|
12
|
-
return if STATES[:format]
|
13
|
-
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
14
|
-
exec("mkfs.ext4 -F #{@dev_boot}") if @dev_boot
|
15
|
-
exec("mkswap -f #{@lv_swap}")
|
16
|
-
exec("mkfs.ext4 -F #{@lv_root}")
|
17
|
-
exec("mkfs.ext4 -F #{@lv_home}") if @lv_home
|
18
|
-
@state.format
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def exec(cmd)
|
24
|
-
Getch::Command.new(cmd).run!
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Lvm
|
4
|
-
class Mount < Getch::FileSystem::Lvm::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@mount = Getch::FileSystem::Mount.new
|
8
|
-
@state = Getch::States.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def run
|
12
|
-
return if STATES[:mount]
|
13
|
-
@mount.swap(@lv_swap)
|
14
|
-
@mount.root(@lv_root)
|
15
|
-
@mount.boot(@dev_boot)
|
16
|
-
@mount.esp(@dev_esp)
|
17
|
-
@mount.home(@lv_home)
|
18
|
-
@state.mount
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Lvm
|
4
|
-
class Partition < Getch::FileSystem::Lvm::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@state = Getch::States.new()
|
8
|
-
@partition = Getch::FileSystem::Partition.new
|
9
|
-
@clean = Getch::FileSystem::Clean
|
10
|
-
run_partition
|
11
|
-
end
|
12
|
-
|
13
|
-
def run_partition
|
14
|
-
return if STATES[:partition ]
|
15
|
-
@clean.old_vg(@dev_root, @vg)
|
16
|
-
@clean.struct(@disk, @cache_disk, @home_disk)
|
17
|
-
@clean.hdd(@disk, @cache_disk, @home_disk)
|
18
|
-
partition
|
19
|
-
lvm
|
20
|
-
@state.partition
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def partition
|
26
|
-
if Helpers::efi?
|
27
|
-
@partition.efi(@dev_esp)
|
28
|
-
@partition.root(@dev_root, "8e00")
|
29
|
-
else
|
30
|
-
@partition.gpt(@dev_gpt)
|
31
|
-
@partition.boot(@dev_boot)
|
32
|
-
@partition.root(@dev_root, "8e00")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def lvm
|
37
|
-
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
38
|
-
exec("pvcreate -f #{@dev_root}")
|
39
|
-
exec("vgcreate -f #{@vg} #{@dev_root}")
|
40
|
-
# Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
|
41
|
-
exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
|
42
|
-
|
43
|
-
if @user
|
44
|
-
exec("lvcreate -y -Wy -Zy -L 18G -n root #{@vg}")
|
45
|
-
exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}")
|
46
|
-
else
|
47
|
-
exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
|
48
|
-
end
|
49
|
-
|
50
|
-
exec("vgchange --available y")
|
51
|
-
end
|
52
|
-
|
53
|
-
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
54
|
-
# Partition_efi
|
55
|
-
# /efi - EFI system partition - 260MB
|
56
|
-
# / - Root
|
57
|
-
|
58
|
-
# Partition_bios
|
59
|
-
# None - Bios Boot Partition - 1MiB
|
60
|
-
# /boot - Boot - 8300
|
61
|
-
# / - Root
|
62
|
-
|
63
|
-
def exec(cmd)
|
64
|
-
Getch::Command.new(cmd).run!
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Getch
|
4
|
-
module FileSystem
|
5
|
-
class Mount
|
6
|
-
def initialize
|
7
|
-
@root_dir = MOUNTPOINT
|
8
|
-
@boot_dir = "#{@root_dir}/boot"
|
9
|
-
@boot_efi_dir = "#{@root_dir}/efi"
|
10
|
-
@home_dir = "#{@root_dir}/home"
|
11
|
-
@state = Getch::States.new()
|
12
|
-
@log = Getch::Log.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def swap(dev)
|
16
|
-
return if ! dev
|
17
|
-
if Helpers::grep?('/proc/swaps', /^\/dev/)
|
18
|
-
exec("swapoff #{dev}")
|
19
|
-
end
|
20
|
-
|
21
|
-
exec("swapon #{dev}")
|
22
|
-
end
|
23
|
-
|
24
|
-
def root(dev)
|
25
|
-
return if ! dev
|
26
|
-
Helpers::mkdir(@root_dir)
|
27
|
-
exec("mount #{dev} #{@root_dir}")
|
28
|
-
end
|
29
|
-
|
30
|
-
def esp(dev)
|
31
|
-
return if ! dev
|
32
|
-
Helpers::mkdir(@boot_efi_dir)
|
33
|
-
exec("mount #{dev} #{@boot_efi_dir}")
|
34
|
-
end
|
35
|
-
|
36
|
-
def boot(dev)
|
37
|
-
return if ! dev
|
38
|
-
Helpers::mkdir(@boot_dir)
|
39
|
-
exec("mount #{dev} #{@boot_dir}")
|
40
|
-
end
|
41
|
-
|
42
|
-
def home(dev)
|
43
|
-
return if ! dev
|
44
|
-
Helpers::mkdir(@home_dir)
|
45
|
-
exec("mount #{dev} #{@home_dir}")
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def exec(cmd)
|
51
|
-
@log.info("==> #{cmd}")
|
52
|
-
Helpers::sys(cmd)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
class Partition
|
4
|
-
def initialize
|
5
|
-
@log = Getch::Log.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def gpt(dev)
|
9
|
-
return if ! dev
|
10
|
-
disk = disk_name(dev)
|
11
|
-
part = dev.match(/[0-9]/)
|
12
|
-
exec("sgdisk -n#{part}:1MiB:+1MiB -t#{part}:EF02 #{disk}")
|
13
|
-
end
|
14
|
-
|
15
|
-
def boot(dev)
|
16
|
-
return if ! dev
|
17
|
-
disk = disk_name(dev)
|
18
|
-
part = dev.match(/[0-9]/)
|
19
|
-
if DEFAULT_OPTIONS[:fs] == "zfs"
|
20
|
-
exec("sgdisk -n#{part}:0:+2G -t#{part}:BE00 #{disk}")
|
21
|
-
else
|
22
|
-
exec("sgdisk -n#{part}:0:+128MiB -t#{part}:8300 #{disk}")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def efi(dev)
|
27
|
-
return if ! dev
|
28
|
-
disk = disk_name(dev)
|
29
|
-
part = dev.match(/[0-9]/)
|
30
|
-
exec("sgdisk -n#{part}:1M:+260M -t#{part}:EF00 #{disk}")
|
31
|
-
end
|
32
|
-
|
33
|
-
def swap(dev)
|
34
|
-
return if ! dev
|
35
|
-
disk = disk_name(dev)
|
36
|
-
part = dev.match(/[0-9]/)
|
37
|
-
if DEFAULT_OPTIONS[:cache_disk]
|
38
|
-
exec("sgdisk -n#{part}:0:0 -t#{part}:8200 #{disk}")
|
39
|
-
else
|
40
|
-
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
41
|
-
exec("sgdisk -n#{part}:0:+#{mem} -t#{part}:8200 #{disk}")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def root(dev, code)
|
46
|
-
return if ! dev
|
47
|
-
disk = disk_name(dev)
|
48
|
-
part = dev.match(/[0-9]/)
|
49
|
-
exec("sgdisk -n#{part}:0:0 -t#{part}:#{code} #{disk}")
|
50
|
-
end
|
51
|
-
|
52
|
-
def home(dev, code)
|
53
|
-
return if ! dev
|
54
|
-
disk = disk_name(dev)
|
55
|
-
part = dev.match(/[0-9]/)
|
56
|
-
if DEFAULT_OPTIONS[:home_disk]
|
57
|
-
exec("sgdisk -n#{part}:0:0 -t#{part}:#{code} #{disk}")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def disk_name(dev)
|
64
|
-
dev.match(/[^0-9]+/)
|
65
|
-
end
|
66
|
-
|
67
|
-
def exec(cmd)
|
68
|
-
@log.debug "Partition disk with #{cmd}"
|
69
|
-
if DEFAULT_OPTIONS[:encrypt]
|
70
|
-
Helpers::sys(cmd)
|
71
|
-
else
|
72
|
-
Getch::Command.new(cmd).run!
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Zfs
|
4
|
-
class Config < Getch::FileSystem::Zfs::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
gen_uuid
|
8
|
-
@root_dir = MOUNTPOINT
|
9
|
-
@init = '/usr/lib/systemd/systemd'
|
10
|
-
end
|
11
|
-
|
12
|
-
def fstab
|
13
|
-
file = "#{@root_dir}/etc/fstab"
|
14
|
-
datas = data_fstab
|
15
|
-
File.write(file, datas.join("\n"))
|
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/gentoo init=#{@init} dozfs"
|
27
|
-
]
|
28
|
-
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
29
|
-
end
|
30
|
-
|
31
|
-
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
32
|
-
def grub
|
33
|
-
return if Helpers::efi?
|
34
|
-
file = "#{@root_dir}/etc/default/grub"
|
35
|
-
cmdline = [
|
36
|
-
"GRUB_CMDLINE_LINUX=\"resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs\""
|
37
|
-
]
|
38
|
-
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def gen_uuid
|
44
|
-
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
|
45
|
-
@uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
|
46
|
-
end
|
47
|
-
|
48
|
-
def data_fstab
|
49
|
-
efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
50
|
-
swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
51
|
-
|
52
|
-
[ efi, swap ]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,95 +0,0 @@
|
|
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
|
@@ -1,58 +0,0 @@
|
|
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
|
@@ -1,114 +0,0 @@
|
|
1
|
-
module Getch
|
2
|
-
module FileSystem
|
3
|
-
module Zfs
|
4
|
-
class Format < Getch::FileSystem::Zfs::Device
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
@log = Getch::Log.new
|
8
|
-
@state = Getch::States.new
|
9
|
-
if ! @id
|
10
|
-
@log.info "Research pool id for #{@dev_root}..."
|
11
|
-
sleep 2 until Helpers::pool_id(@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
|
-
@log.info "Create #{@id} for #{@pool_name}"
|
25
|
-
system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
26
|
-
zfs
|
27
|
-
cache
|
28
|
-
datasets
|
29
|
-
@state.format
|
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
|
-
@log.debug("ashift found for #{bloc} - #{ashift}")
|
45
|
-
|
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} -o autotrim=on -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} -o autotrim=on \\
|
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 cache
|
78
|
-
system("mkswap -f #{@dev_swap}")
|
79
|
-
if @dev_log
|
80
|
-
exec("zpool add #{@pool_name} log #{@dev_log}")
|
81
|
-
end
|
82
|
-
if @dev_cache
|
83
|
-
exec("zpool add #{@pool_name} cache #{@dev_cache}")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def datasets
|
88
|
-
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
89
|
-
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
90
|
-
|
91
|
-
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
92
|
-
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
93
|
-
|
94
|
-
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
95
|
-
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
96
|
-
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
97
|
-
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
98
|
-
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
99
|
-
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
100
|
-
|
101
|
-
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
102
|
-
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
103
|
-
if @user
|
104
|
-
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def exec(cmd)
|
109
|
-
Getch::Command.new(cmd).run!
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|