getch 0.1.9 → 0.3.3
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/CHANGELOG.md +132 -0
- data/LICENSE +10 -0
- data/README.md +35 -29
- data/bin/getch +8 -6
- data/getch.gemspec +31 -0
- data/lib/clean.rb +149 -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 +88 -128
- 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 +0 -36
- data/lib/getch/config.rb +16 -37
- data/lib/getch/device.rb +67 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
- data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
- data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
- data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
- data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
- 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/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
- 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} +6 -4
- data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
- data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
- 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 +7 -7
- data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
- data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
- data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
- data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
- 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 +1 -7
- data/lib/getch/filesystem.rb +0 -6
- data/lib/getch/gentoo/bootloader.rb +23 -44
- 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 +39 -33
- 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 +9 -6
- data/lib/getch/gentoo/use_flag.rb +17 -20
- data/lib/getch/gentoo.rb +9 -75
- data/lib/getch/guard.rb +3 -3
- data/lib/getch/helpers.rb +63 -115
- data/lib/getch/log.rb +87 -25
- data/lib/getch/options.rb +41 -11
- data/lib/getch/states.rb +28 -8
- 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/{stage.rb → tarball.rb} +34 -14
- data/lib/getch/void/terraform.rb +28 -0
- data/lib/getch/void/update.rb +33 -0
- data/lib/getch/void.rb +9 -59
- data/lib/getch.rb +58 -90
- data/lib/luks.rb +239 -0
- data/lib/lvm2.rb +112 -0
- data/lib/mkfs/zfs.rb +167 -0
- data/lib/mkfs.rb +144 -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 +113 -74
- metadata.gz.sig +0 -0
- data/lib/getch/config/gentoo.rb +0 -58
- data/lib/getch/filesystem/clean.rb +0 -58
- data/lib/getch/filesystem/device.rb +0 -63
- data/lib/getch/filesystem/ext4/config.rb +0 -62
- data/lib/getch/filesystem/ext4/deps.rb +0 -24
- data/lib/getch/filesystem/ext4/format.rb +0 -31
- data/lib/getch/filesystem/ext4/mount.rb +0 -26
- data/lib/getch/filesystem/ext4/partition.rb +0 -55
- data/lib/getch/filesystem/ext4/void.rb +0 -44
- data/lib/getch/filesystem/lvm/config.rb +0 -44
- data/lib/getch/filesystem/lvm/deps.rb +0 -44
- data/lib/getch/filesystem/lvm/device.rb +0 -45
- data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
- data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
- data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
- data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
- data/lib/getch/filesystem/lvm/format.rb +0 -32
- data/lib/getch/filesystem/lvm/mount.rb +0 -26
- data/lib/getch/filesystem/lvm/partition.rb +0 -72
- data/lib/getch/filesystem/lvm/void.rb +0 -46
- data/lib/getch/filesystem/mount.rb +0 -63
- data/lib/getch/filesystem/partition.rb +0 -85
- data/lib/getch/filesystem/zfs/config.rb +0 -43
- data/lib/getch/filesystem/zfs/deps.rb +0 -67
- data/lib/getch/filesystem/zfs/device.rb +0 -66
- data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
- data/lib/getch/filesystem/zfs/format.rb +0 -117
- data/lib/getch/filesystem/zfs/mount.rb +0 -47
- data/lib/getch/filesystem/zfs/partition.rb +0 -69
- data/lib/getch/filesystem/zfs/void.rb +0 -81
- data/lib/getch/gentoo/boot.rb +0 -64
- data/lib/getch/gentoo/chroot.rb +0 -75
- data/lib/getch/gentoo/config.rb +0 -167
- data/lib/getch/gentoo/stage.rb +0 -73
- data/lib/getch/void/boot.rb +0 -84
- data/lib/getch/void/chroot.rb +0 -56
- data/lib/getch/void/config.rb +0 -90
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module FileSystem
|
|
5
|
-
module Zfs
|
|
6
|
-
class Device < Getch::FileSystem::Device
|
|
7
|
-
def initialize
|
|
8
|
-
super
|
|
9
|
-
@id = Helpers.pool_id(@dev_root)
|
|
10
|
-
@boot_pool_name = "bpool-#{@id}"
|
|
11
|
-
@pool_name = "rpool-#{@id}"
|
|
12
|
-
@zfs_home = @user ? true : false
|
|
13
|
-
@n = Getch::OPTIONS[:os]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def search_boot
|
|
19
|
-
if @efi
|
|
20
|
-
if @boot_disk
|
|
21
|
-
@dev_esp = "/dev/#{@boot_disk}1"
|
|
22
|
-
@dev_boot = "/dev/#{@boot_disk}2" if Getch::OPTIONS[:os] == 'void'
|
|
23
|
-
else
|
|
24
|
-
@dev_esp = "/dev/#{@disk}1"
|
|
25
|
-
@root_part += 1
|
|
26
|
-
if Getch::OPTIONS[:os] == 'void'
|
|
27
|
-
@dev_boot = "/dev/#{@disk}#{@root_part}"
|
|
28
|
-
@root_part += 1
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
else
|
|
32
|
-
if @boot_disk
|
|
33
|
-
@dev_gpt = "/dev/#{@boot_disk}1"
|
|
34
|
-
@dev_boot = "/dev/#{@boot_disk}2"
|
|
35
|
-
@dev_grub = "/dev/#{@boot_disk}"
|
|
36
|
-
else
|
|
37
|
-
@dev_gpt = "/dev/#{@disk}1"
|
|
38
|
-
@dev_boot = "/dev/#{@disk}2"
|
|
39
|
-
@dev_grub = "/dev/#{@disk}"
|
|
40
|
-
@root_part += 2
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def search_swap
|
|
46
|
-
if @cache_disk
|
|
47
|
-
@dev_swap = "/dev/#{@cache_disk}1"
|
|
48
|
-
@dev_log = "/dev/#{@cache_disk}2"
|
|
49
|
-
@dev_cache = "/dev/#{@cache_disk}3"
|
|
50
|
-
else
|
|
51
|
-
@dev_swap = "/dev/#{@disk}#{@root_part}"
|
|
52
|
-
@root_part += 1
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def search_root
|
|
57
|
-
if @root_part == 1
|
|
58
|
-
@dev_root = "/dev/#{@disk}"
|
|
59
|
-
else
|
|
60
|
-
@dev_root = "/dev/#{@disk}#{@root_part}"
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module FileSystem
|
|
5
|
-
module Zfs
|
|
6
|
-
module Encrypt
|
|
7
|
-
class Void < Device
|
|
8
|
-
include Helpers::Void
|
|
9
|
-
|
|
10
|
-
attr_reader :boot_disk
|
|
11
|
-
|
|
12
|
-
def initialize
|
|
13
|
-
super
|
|
14
|
-
hostid
|
|
15
|
-
zfs_zed # mountpoint for zfs
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Fstab contain:
|
|
19
|
-
# > /efi noauto
|
|
20
|
-
# > swap
|
|
21
|
-
# > /boot zfs-legacy
|
|
22
|
-
# > /tmp
|
|
23
|
-
def fstab
|
|
24
|
-
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
25
|
-
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
26
|
-
line_fstab(@dev_esp, "/efi vfat noauto,rw,relatime 0 0") if @dev_esp
|
|
27
|
-
add_line(conf, '/dev/mapper/cryptswap none swap sw 0 0')
|
|
28
|
-
add_line(conf, "##{@boot_pool_name}/BOOT/#{@n} /boot zfs defaults 0 0") if @dev_boot
|
|
29
|
-
add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def config_dracut
|
|
33
|
-
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
|
|
34
|
-
# dracut: value+= should be surrounding by white space
|
|
35
|
-
content = [
|
|
36
|
-
'hostonly="yes"',
|
|
37
|
-
'omit_dracutmodules+=" btrfs lvm "',
|
|
38
|
-
'install_items+=" /etc/crypttab "',
|
|
39
|
-
]
|
|
40
|
-
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def kernel_cmdline_dracut
|
|
44
|
-
#command "zfs set mountpoint=legacy #{@boot_pool_name}/BOOT/#{@n}"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def config_grub
|
|
48
|
-
grub_cmdline("root=zfs:#{@pool_name}/ROOT/#{@n}", 'zfs_force=1', 'zfs.zfs_arc_max=536870912')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def finish
|
|
52
|
-
zed_update_path
|
|
53
|
-
puts '+ Enter in your system: chroot /mnt /bin/bash'
|
|
54
|
-
puts '+ Reboot with: shutdown -r now'
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def crypttab
|
|
58
|
-
line_crypttab('cryptswap', @dev_swap, '/dev/urandom', 'swap,discard,cipher=aes-xts-plain64:sha256,size=512')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
def line_crypttab(mapname, dev, point, rest)
|
|
64
|
-
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
65
|
-
device = s_uuid(dev)
|
|
66
|
-
raise "No partuuid for #{dev} #{device}" unless device
|
|
67
|
-
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
68
|
-
|
|
69
|
-
add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def zfs_zed
|
|
73
|
-
service_dir = '/etc/runit/runsvdir/default/'
|
|
74
|
-
|
|
75
|
-
Helpers.mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
|
76
|
-
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
|
77
|
-
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
|
78
|
-
fork { command '/etc/sv/zed/run' }
|
|
79
|
-
command "ln -fs /etc/sv/zed #{service_dir}"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def zed_update_path
|
|
83
|
-
Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each do |f|
|
|
84
|
-
unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
|
|
85
|
-
raise 'System exec sed'
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def hostid
|
|
91
|
-
command 'zgenhostid $(hostid)'
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module FileSystem
|
|
5
|
-
module Zfs
|
|
6
|
-
class Format < Device
|
|
7
|
-
def initialize
|
|
8
|
-
super
|
|
9
|
-
@log = Getch::Log.new
|
|
10
|
-
@state = Getch::States.new
|
|
11
|
-
unless @id
|
|
12
|
-
@log.info "Research pool id for #{@dev_root}..."
|
|
13
|
-
@id = Helpers.pool_id(@dev_root)
|
|
14
|
-
@boot_pool_name = "bpool-#{@id}"
|
|
15
|
-
@pool_name = "rpool-#{@id}"
|
|
16
|
-
end
|
|
17
|
-
format
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def format
|
|
23
|
-
return if STATES[:format]
|
|
24
|
-
raise "Error, no id found for #{@dev_root}." unless @id
|
|
25
|
-
|
|
26
|
-
@log.info "Create #{@id} for #{@pool_name}"
|
|
27
|
-
system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
28
|
-
zfs
|
|
29
|
-
cache
|
|
30
|
-
datasets
|
|
31
|
-
@state.format
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def zfs
|
|
35
|
-
bloc=`blockdev --getpbsz #{@dev_root}`
|
|
36
|
-
ashift =
|
|
37
|
-
case bloc
|
|
38
|
-
when /8096/
|
|
39
|
-
13
|
|
40
|
-
when /4096/
|
|
41
|
-
12
|
|
42
|
-
else # 512
|
|
43
|
-
9
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
Helpers.mkdir(MOUNTPOINT)
|
|
47
|
-
@log.debug("ashift found for #{bloc} - #{ashift}")
|
|
48
|
-
|
|
49
|
-
if @dev_boot
|
|
50
|
-
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
|
51
|
-
@log.info("Creating boot pool on #{@pool_name}")
|
|
52
|
-
exec("zpool create -f \\
|
|
53
|
-
-o ashift=#{ashift} -o autotrim=on -d \\
|
|
54
|
-
-o feature@async_destroy=enabled \\
|
|
55
|
-
-o feature@bookmarks=enabled \\
|
|
56
|
-
-o feature@embedded_data=enabled \\
|
|
57
|
-
-o feature@empty_bpobj=enabled \\
|
|
58
|
-
-o feature@enabled_txg=enabled \\
|
|
59
|
-
-o feature@extensible_dataset=enabled \\
|
|
60
|
-
-o feature@filesystem_limits=enabled \\
|
|
61
|
-
-o feature@hole_birth=enabled \\
|
|
62
|
-
-o feature@large_blocks=enabled \\
|
|
63
|
-
-o feature@lz4_compress=enabled \\
|
|
64
|
-
-o feature@spacemap_histogram=enabled \\
|
|
65
|
-
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
|
66
|
-
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
|
67
|
-
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
|
68
|
-
#{@boot_pool_name} #{@dev_boot}
|
|
69
|
-
")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
exec("zpool create -f -o ashift=#{ashift} -o autotrim=on \\
|
|
73
|
-
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
|
74
|
-
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
|
75
|
-
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
|
76
|
-
#{@pool_name} #{@dev_root}
|
|
77
|
-
")
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def cache
|
|
81
|
-
system("mkswap -f #{@dev_swap}")
|
|
82
|
-
if @dev_log
|
|
83
|
-
exec("zpool add #{@pool_name} log #{@dev_log}")
|
|
84
|
-
end
|
|
85
|
-
if @dev_cache
|
|
86
|
-
exec("zpool add #{@pool_name} cache #{@dev_cache}")
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def datasets
|
|
91
|
-
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
|
92
|
-
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
|
93
|
-
|
|
94
|
-
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/#{@n}")
|
|
95
|
-
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/#{@n}") if @dev_boot
|
|
96
|
-
|
|
97
|
-
exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/usr")
|
|
98
|
-
exec("zfs create #{@pool_name}/ROOT/#{@n}/usr/src")
|
|
99
|
-
exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/var")
|
|
100
|
-
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/log")
|
|
101
|
-
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/db")
|
|
102
|
-
exec("zfs create #{@pool_name}/ROOT/#{@n}/var/tmp")
|
|
103
|
-
|
|
104
|
-
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
|
105
|
-
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
|
106
|
-
if @user
|
|
107
|
-
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}")
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def exec(cmd)
|
|
112
|
-
Getch::Command.new(cmd).run!
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
module Getch
|
|
2
|
-
module FileSystem
|
|
3
|
-
module Zfs
|
|
4
|
-
class Mount < Device
|
|
5
|
-
def initialize
|
|
6
|
-
super
|
|
7
|
-
@mount = Getch::FileSystem::Mount.new
|
|
8
|
-
@state = Getch::States.new
|
|
9
|
-
@log = Getch::Log.new
|
|
10
|
-
@import = '/dev/disk/by-id'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def run
|
|
14
|
-
return if STATES[:mount]
|
|
15
|
-
exec('zpool export -a')
|
|
16
|
-
exec("rm -rf #{MOUNTPOINT}/*")
|
|
17
|
-
exec("zpool import -N -d #{@import} -R #{MOUNTPOINT} #{@pool_name}")
|
|
18
|
-
exec("zpool import -f -N -d #{@import} -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
|
19
|
-
@mount.swap(@dev_swap)
|
|
20
|
-
mount_root
|
|
21
|
-
mount_boot
|
|
22
|
-
@mount.esp(@dev_esp)
|
|
23
|
-
exec('zfs mount -a')
|
|
24
|
-
@state.mount
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def mount_root
|
|
30
|
-
Helpers.mkdir(MOUNTPOINT)
|
|
31
|
-
exec("zfs mount #{@pool_name}/ROOT/#{@n}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def mount_boot
|
|
35
|
-
return unless @dev_boot
|
|
36
|
-
|
|
37
|
-
exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def exec(cmd)
|
|
41
|
-
@log.info("==> #{cmd}")
|
|
42
|
-
Helpers.sys(cmd)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module FileSystem
|
|
5
|
-
module Zfs
|
|
6
|
-
class Partition < Device
|
|
7
|
-
def initialize
|
|
8
|
-
super
|
|
9
|
-
@clean = Getch::FileSystem::Clean
|
|
10
|
-
@partition = Getch::FileSystem::Partition.new
|
|
11
|
-
@state = Getch::States.new
|
|
12
|
-
@log = Getch::Log.new
|
|
13
|
-
run_partition
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def run_partition
|
|
17
|
-
return if STATES[:partition ]
|
|
18
|
-
|
|
19
|
-
@clean.old_zpool
|
|
20
|
-
@clean.hdd(@disk)
|
|
21
|
-
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
22
|
-
|
|
23
|
-
partition
|
|
24
|
-
cache
|
|
25
|
-
@state.partition
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def partition
|
|
31
|
-
if @efi
|
|
32
|
-
@partition.efi(@dev_esp)
|
|
33
|
-
@partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
|
|
34
|
-
@partition.swap(@dev_swap) unless @cache_disk
|
|
35
|
-
@partition.root(@dev_root, 'BF00') if @root_part != 1
|
|
36
|
-
else
|
|
37
|
-
@partition.gpt(@dev_gpt)
|
|
38
|
-
# Boot pool for GRUB2
|
|
39
|
-
@partition.boot(@dev_boot)
|
|
40
|
-
@partition.swap(@dev_swap) unless @cache_disk
|
|
41
|
-
@partition.root(@dev_root, 'BF00') if @root_part != 1
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def cache
|
|
46
|
-
return unless @cache_disk
|
|
47
|
-
|
|
48
|
-
mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
|
49
|
-
exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
|
|
50
|
-
exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
|
|
51
|
-
exec("sgdisk -n3:0:0 -t3:BF00 /dev/#{@cache_disk}")
|
|
52
|
-
end
|
|
53
|
-
|
|
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,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module FileSystem
|
|
5
|
-
module Zfs
|
|
6
|
-
class Void < Device
|
|
7
|
-
include Helpers::Void
|
|
8
|
-
|
|
9
|
-
attr_reader :boot_disk
|
|
10
|
-
|
|
11
|
-
def initialize
|
|
12
|
-
super
|
|
13
|
-
hostid
|
|
14
|
-
zfs_zed # mountpoint for zfs
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Fstab contain:
|
|
18
|
-
# > /efi noauto
|
|
19
|
-
# > swap
|
|
20
|
-
# > /boot zfs-legacy
|
|
21
|
-
# > /tmp
|
|
22
|
-
def fstab
|
|
23
|
-
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
24
|
-
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
25
|
-
line_fstab(@dev_esp, '/efi vfat noauto,rw,relatime 0 0') if @dev_esp
|
|
26
|
-
line_fstab(@dev_swap, 'swap swap rw,noatime,discard 0 0') if @dev_swap
|
|
27
|
-
#add_line(conf, "#{@boot_pool_name}/BOOT/#{@n} /boot zfs defaults 0 0") if @dev_boot
|
|
28
|
-
add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def config_dracut
|
|
32
|
-
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
|
|
33
|
-
# dracut: value+= should be surrounding by white space
|
|
34
|
-
content = [
|
|
35
|
-
'hostonly="yes"',
|
|
36
|
-
'omit_dracutmodules+=" btrfs lvm "',
|
|
37
|
-
]
|
|
38
|
-
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def kernel_cmdline_dracut
|
|
42
|
-
#command "zfs set mountpoint=legacy #{@boot_pool_name}/BOOT/#{@n}"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def config_grub
|
|
46
|
-
grub_cmdline("root=zfs:#{@pool_name}/ROOT/#{@n}", 'zfs_force=1', 'zfs.zfs_arc_max=536870912')
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def finish
|
|
50
|
-
zed_update_path
|
|
51
|
-
puts '+ Enter in your system: chroot /mnt /bin/bash'
|
|
52
|
-
puts '+ Reboot with: shutdown -r now'
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def zfs_zed
|
|
58
|
-
service_dir = '/etc/runit/runsvdir/default/'
|
|
59
|
-
|
|
60
|
-
Helpers.mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
|
61
|
-
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
|
62
|
-
Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
|
63
|
-
fork { command '/etc/sv/zed/run' }
|
|
64
|
-
command "ln -fs /etc/sv/zed #{service_dir}"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def zed_update_path
|
|
68
|
-
Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each do |f|
|
|
69
|
-
unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
|
|
70
|
-
raise 'System exec sed'
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def hostid
|
|
76
|
-
command 'zgenhostid $(hostid)'
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
data/lib/getch/gentoo/boot.rb
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'fileutils'
|
|
4
|
-
|
|
5
|
-
module Getch
|
|
6
|
-
module Gentoo
|
|
7
|
-
class Boot
|
|
8
|
-
def initialize
|
|
9
|
-
@user = Getch::OPTIONS[:username]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def start
|
|
13
|
-
bootloader
|
|
14
|
-
password
|
|
15
|
-
permission
|
|
16
|
-
the_end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def bootloader
|
|
20
|
-
# Ensure all packages are build
|
|
21
|
-
Getch::Emerge.new('@world').pkg!
|
|
22
|
-
bootloader = Getch::Gentoo::Bootloader.new
|
|
23
|
-
bootloader.setup
|
|
24
|
-
bootloader.update
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def password
|
|
28
|
-
puts 'Password for root'
|
|
29
|
-
chroot "passwd"
|
|
30
|
-
return unless @user
|
|
31
|
-
|
|
32
|
-
puts "Creating user #{@user}"
|
|
33
|
-
Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}").run!
|
|
34
|
-
puts "Password for your user #{@user}"
|
|
35
|
-
chroot "passwd #{@user}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def permission
|
|
41
|
-
FileUtils.chmod_R 0755, "#{MOUNTPOINT}/etc/portage"
|
|
42
|
-
if @user
|
|
43
|
-
Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}").run!
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def the_end
|
|
48
|
-
puts
|
|
49
|
-
puts 'getch has finish, before reboot, you can:'
|
|
50
|
-
puts " + Chroot on your system with: chroot #{MOUNTPOINT} /bin/bash"
|
|
51
|
-
puts ' + Install more packages like networkmanager or emacs'
|
|
52
|
-
puts
|
|
53
|
-
puts ' + Add more modules for your kernel (graphic, wifi card) and recompile it with:'
|
|
54
|
-
puts ' genkernel --kernel-config=/usr/src/linux/.config all '
|
|
55
|
-
puts
|
|
56
|
-
puts 'Reboot the system when you have done !'
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def chroot(cmd)
|
|
60
|
-
system('chroot', MOUNTPOINT, '/bin/bash', '-c', cmd)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
data/lib/getch/gentoo/chroot.rb
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Getch
|
|
4
|
-
module Gentoo
|
|
5
|
-
class Chroot
|
|
6
|
-
def initialize
|
|
7
|
-
@pkgs = []
|
|
8
|
-
mount
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def cpuflags
|
|
12
|
-
Getch::Emerge.new('app-portage/cpuid2cpuflags').pkg!
|
|
13
|
-
cpuflags = `chroot #{MOUNTPOINT} /bin/bash -c "source /etc/profile; cpuid2cpuflags"`.chomp
|
|
14
|
-
File.write("#{MOUNTPOINT}/etc/portage/package.use/00cpuflags", "*/* #{cpuflags}")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def update
|
|
18
|
-
return if STATES[:gentoo_update]
|
|
19
|
-
|
|
20
|
-
puts 'Downloading the last ebuilds for Gentoo...'
|
|
21
|
-
Helpers.create_dir("#{MOUNTPOINT}/var/db/repos/gentoo")
|
|
22
|
-
cmd = 'emaint sync --auto'
|
|
23
|
-
exec_chroot(cmd)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def world
|
|
27
|
-
return if STATES[:gentoo_update]
|
|
28
|
-
|
|
29
|
-
puts 'Update Gentoo world'
|
|
30
|
-
Getch::Emerge.new('emerge --update --deep --changed-use --newuse @world').run!
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def systemd
|
|
34
|
-
puts 'Updating locale, keymap...'
|
|
35
|
-
cmd = 'locale-gen; emerge --config sys-libs/timezone-data'
|
|
36
|
-
exec_chroot(cmd)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def kernel_license
|
|
40
|
-
return if Dir.exist? "#{MOUNTPOINT}/usr/src/linux"
|
|
41
|
-
|
|
42
|
-
license = "#{MOUNTPOINT}/etc/portage/package.license"
|
|
43
|
-
File.write(license, "sys-kernel/linux-firmware linux-fw-redistributable no-source-code\n")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def install_pkgs
|
|
47
|
-
@pkgs << 'app-portage/gentoolkit'
|
|
48
|
-
@pkgs << 'app-admin/sudo'
|
|
49
|
-
@pkgs << 'app-editors/vim'
|
|
50
|
-
@pkgs << 'net-firewall/iptables'
|
|
51
|
-
@pkgs << 'sys-fs/dosftools' if Helpers.efi?
|
|
52
|
-
all_pkgs = @pkgs.join(' ')
|
|
53
|
-
puts "Installing #{all_pkgs}..."
|
|
54
|
-
Getch::Emerge.new(all_pkgs).pkg!
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
def mount
|
|
60
|
-
puts 'Populate /proc, /sys and /dev.'
|
|
61
|
-
Helpers.exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
|
|
62
|
-
Helpers.exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
|
|
63
|
-
Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
|
|
64
|
-
Helpers.exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
|
|
65
|
-
Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
|
|
66
|
-
# Maybe add /dev/shm like describe here:
|
|
67
|
-
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def exec_chroot(cmd)
|
|
71
|
-
Getch::Chroot.new(cmd).run!
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|