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
data/lib/devs.rb
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'getch/device'
|
|
4
|
+
|
|
5
|
+
module Devs
|
|
6
|
+
class Settings
|
|
7
|
+
def initialize(args, options)
|
|
8
|
+
@args = args
|
|
9
|
+
@start = args[:start] ||= nil
|
|
10
|
+
@boot = args[:boot] ||= nil
|
|
11
|
+
@swap = args[:swap] ||= nil
|
|
12
|
+
@root = args[:root] ||= nil
|
|
13
|
+
@options = options
|
|
14
|
+
@encrypt = options[:encrypt] ||= false
|
|
15
|
+
@lvm = options[:lvm] ||= false
|
|
16
|
+
@whole = nil
|
|
17
|
+
@fs = options[:fs]
|
|
18
|
+
@tree = TREE[@fs.to_sym]
|
|
19
|
+
x
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def x
|
|
23
|
+
add_boot
|
|
24
|
+
add_swap
|
|
25
|
+
add_root
|
|
26
|
+
add_home
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
protected
|
|
30
|
+
|
|
31
|
+
def add_boot
|
|
32
|
+
@options[:boot_disk] || return
|
|
33
|
+
|
|
34
|
+
@fs == 'zfs' ?
|
|
35
|
+
@tree.new(@options[:boot_disk], start: @start, boot: @boot, systemd_boot: systemd_boot?) :
|
|
36
|
+
@tree.new(@options[:boot_disk], start: @start, boot: @boot)
|
|
37
|
+
|
|
38
|
+
@args.delete :start
|
|
39
|
+
@args.delete :boot if @boot
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def add_swap
|
|
43
|
+
@options[:cache_disk] || return
|
|
44
|
+
|
|
45
|
+
@fs == 'zfs' ?
|
|
46
|
+
@tree.new(@options[:cache_disk], swap: @swap, zfs_cache: true) :
|
|
47
|
+
@tree.new(@options[:cache_disk], swap: @swap)
|
|
48
|
+
@args.delete :swap if @swap
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add_root
|
|
52
|
+
if @encrypt or @lvm or @fs == 'zfs' then @whole = true end
|
|
53
|
+
@args[:whole] = @whole
|
|
54
|
+
|
|
55
|
+
if systemd_boot? and @fs == 'zfs' then @args.delete :boot end
|
|
56
|
+
@tree.new(@options[:disk], @args)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def add_home
|
|
60
|
+
@options[:home_disk] || return
|
|
61
|
+
|
|
62
|
+
if @encrypt or @lvm or @fs == 'zfs' then @whole = true end
|
|
63
|
+
@tree.new(@options[:home_disk], home: true, whole: @whole)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def efi?
|
|
69
|
+
Dir.exist? '/sys/firmware/efi/efivars'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def systemd_boot?
|
|
73
|
+
@options[:os] == 'gentoo' and not @options[:musl] and efi?
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class Matrice
|
|
78
|
+
def initialize(disk, args)
|
|
79
|
+
@disk = disk
|
|
80
|
+
@start = args[:start] ||= nil
|
|
81
|
+
@boot = args[:boot] ||= nil
|
|
82
|
+
@swap = args[:swap] ||= nil
|
|
83
|
+
@root = args[:root] ||= nil
|
|
84
|
+
@home = args[:home] ||= nil
|
|
85
|
+
@whole = args[:whole] ||= false
|
|
86
|
+
@device = Getch::Device.new
|
|
87
|
+
@@part = 1
|
|
88
|
+
x
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def x
|
|
92
|
+
start
|
|
93
|
+
boot
|
|
94
|
+
swap
|
|
95
|
+
root
|
|
96
|
+
home
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
protected
|
|
100
|
+
|
|
101
|
+
def start
|
|
102
|
+
@start || return
|
|
103
|
+
|
|
104
|
+
efi? ? add_efi : add_gpt
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def add_efi
|
|
108
|
+
@device.efi "#{@disk}#{@@part}"
|
|
109
|
+
@@part += 1
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def add_gpt
|
|
113
|
+
@device.gpt "#{@disk}#{@@part}"
|
|
114
|
+
@@part += 1
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def boot
|
|
118
|
+
@boot || return
|
|
119
|
+
|
|
120
|
+
@device.boot "#{@disk}#{@@part}"
|
|
121
|
+
@@part += 1
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def swap
|
|
125
|
+
@swap || return
|
|
126
|
+
|
|
127
|
+
@device.swap "#{@disk}#{@@part}"
|
|
128
|
+
@@part += 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def root
|
|
132
|
+
@root || return
|
|
133
|
+
|
|
134
|
+
if @whole && @@part == 1
|
|
135
|
+
@device.root @disk
|
|
136
|
+
else
|
|
137
|
+
@device.root "#{@disk}#{@@part}"
|
|
138
|
+
@@part += 1
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def home
|
|
143
|
+
@home || return
|
|
144
|
+
|
|
145
|
+
if @whole && @@part == 1
|
|
146
|
+
@device.home @disk
|
|
147
|
+
else
|
|
148
|
+
@device.home "#{@disk}#{@@part}"
|
|
149
|
+
@@part += 1
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
private
|
|
154
|
+
|
|
155
|
+
def efi?
|
|
156
|
+
Dir.exist? '/sys/firmware/efi/efivars'
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
class MatExt4 < Matrice
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
class MatZfs < Matrice
|
|
164
|
+
def initialize(disk, args)
|
|
165
|
+
@zfs_cache = args[:zfs_cache] ||= nil
|
|
166
|
+
@systemd_boot = args[:systemd_boot] ||= false
|
|
167
|
+
super
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def boot
|
|
171
|
+
@boot || return
|
|
172
|
+
|
|
173
|
+
@systemd_boot && return
|
|
174
|
+
|
|
175
|
+
@device.boot "#{@disk}#{@@part}"
|
|
176
|
+
@@part += 1
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def swap
|
|
180
|
+
@swap || return
|
|
181
|
+
|
|
182
|
+
if @zfs_cache
|
|
183
|
+
@device.swap "#{@disk}#{@@part}"
|
|
184
|
+
@@part += 1
|
|
185
|
+
@device.zlog "#{@disk}#{@@part}"
|
|
186
|
+
@@part += 1
|
|
187
|
+
@device.zcache "#{@disk}#{@@part}"
|
|
188
|
+
else
|
|
189
|
+
@device.swap "#{@disk}#{@@part}"
|
|
190
|
+
@@part += 1
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
TREE = {
|
|
196
|
+
ext4: MatExt4,
|
|
197
|
+
zfs: MatZfs,
|
|
198
|
+
}
|
|
199
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_litteral: true
|
|
2
|
+
|
|
3
|
+
module Dracut
|
|
4
|
+
class Encrypt < Root
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
@luks = options[:luks_name]
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate
|
|
11
|
+
host_only
|
|
12
|
+
cmdline
|
|
13
|
+
luks_key
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
def get_line
|
|
19
|
+
root = Getch::Helpers.uuid @root
|
|
20
|
+
dm_root = get_dm_uuid "root-#{@luks}"
|
|
21
|
+
"rd.luks.uuid=#{root} root=UUID=#{dm_root} rootfstype=#{@fs}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def luks_key
|
|
25
|
+
file = "#{@mountpoint}/etc/dracut.conf.d/luks_key.conf"
|
|
26
|
+
echo file, 'install_items+=" /boot/boot.key /boot/root.key /etc/crypttab "'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def get_dm_uuid(name)
|
|
32
|
+
dm = Getch::Helpers.get_dm name
|
|
33
|
+
Getch::Helpers.uuid dm
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dracut
|
|
4
|
+
class Hybrid < Encrypt
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@vg = options[:vg_name] ||= 'vg0'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_line
|
|
11
|
+
root = Getch::Helpers.uuid @root
|
|
12
|
+
"rd.luks.uuid=#{root} rd.lvm.vg=#{@vg} root=/dev/#{@vg}/root"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/dracut/lvm.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dracut
|
|
4
|
+
class Lvm < Root
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@vg = options[:vg_name] ||= 'vg0'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_line
|
|
11
|
+
"rd.lvm.vg=#{@vg} root=/dev/#{@vg}/root resume=/dev/#{@vg}/swap rootfstype=#{@fs}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/dracut/root.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_litteral: true
|
|
2
|
+
|
|
3
|
+
require 'nito'
|
|
4
|
+
require_relative '../getch/log'
|
|
5
|
+
|
|
6
|
+
module Dracut
|
|
7
|
+
class Root
|
|
8
|
+
include NiTo
|
|
9
|
+
|
|
10
|
+
def initialize(devs, options)
|
|
11
|
+
@log = Getch::Log.new
|
|
12
|
+
@root = devs[:root] ||= nil
|
|
13
|
+
@swap = devs[:swap] ||= nil
|
|
14
|
+
@fs = options[:fs] ||= 'ext4'
|
|
15
|
+
@mountpoint = options[:mountpoint] ||= '/mnt/getch'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def generate
|
|
19
|
+
host_only
|
|
20
|
+
cmdline
|
|
21
|
+
others
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
def host_only
|
|
27
|
+
file = "#{@mountpoint}/etc/dracut.conf.d/host.conf"
|
|
28
|
+
echo file, 'hostonly="yes"'
|
|
29
|
+
echo_a file, 'use_fstab="yes"'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# man dracut.cmdline(7)
|
|
33
|
+
def cmdline
|
|
34
|
+
file = "#{@mountpoint}/etc/dracut.conf.d/cmdline.conf"
|
|
35
|
+
line = get_line
|
|
36
|
+
echo file, "kernel_cmdline=\"#{line}\""
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_line
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def others
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/dracut/zfs.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dracut
|
|
4
|
+
class Zfs < Root
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@zfs = options[:zfs_name] ||= 'pool'
|
|
8
|
+
@encrypt = options[:encrypt]
|
|
9
|
+
@os = options[:os]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def others
|
|
13
|
+
file = "#{@mountpoint}/etc/dracut.conf.d/zfs.conf"
|
|
14
|
+
echo file, 'nofsck="yes"'
|
|
15
|
+
echo_a file, 'omit_dracutmodules+=" btrfs "'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
|
19
|
+
# https://github.com/openzfs/zfs/blob/master/contrib/dracut/README.dracut.markdown
|
|
20
|
+
def get_line
|
|
21
|
+
@encrypt ?
|
|
22
|
+
without :
|
|
23
|
+
with_swap
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def without
|
|
27
|
+
"root=zfs:r#{@zfs}/ROOT/#{@os} zfs.force=1 zfs.zfs_arc_max=536870912"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def with_swap
|
|
31
|
+
swap = Getch::Helpers.uuid @swap
|
|
32
|
+
"resume=UUID=#{swap} root=zfs:r#{@zfs}/ROOT/#{@os} zfs.force=1 zfs.zfs_arc_max=536870912"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/dracut.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_litteral: true
|
|
2
|
+
|
|
3
|
+
module Dracut
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require_relative 'dracut/root'
|
|
7
|
+
require_relative 'dracut/minimal'
|
|
8
|
+
require_relative 'dracut/lvm'
|
|
9
|
+
require_relative 'dracut/encrypt'
|
|
10
|
+
require_relative 'dracut/hybrid'
|
|
11
|
+
require_relative 'dracut/zfs'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fstab
|
|
4
|
+
class Encrypt < Root
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@luks = options[:luks_name]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def write_boot
|
|
11
|
+
@boot || return
|
|
12
|
+
|
|
13
|
+
dm = Getch::Helpers.get_dm "boot-#{@luks}"
|
|
14
|
+
uuid = gen_uuid dm
|
|
15
|
+
line = "UUID=#{uuid} /boot #{@fs} noauto,rw,relatime 0 0"
|
|
16
|
+
echo_a @conf, line
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write_swap
|
|
20
|
+
@swap || return
|
|
21
|
+
|
|
22
|
+
line = "/dev/mapper/swap-#{@luks} none swap rw,noatime,discard 0 0"
|
|
23
|
+
echo_a @conf, line
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def write_root
|
|
27
|
+
@root || return
|
|
28
|
+
|
|
29
|
+
dm = Getch::Helpers.get_dm "root-#{@luks}"
|
|
30
|
+
uuid = gen_uuid dm
|
|
31
|
+
line = "UUID=#{uuid} / #{@fs} rw,relatime 0 1"
|
|
32
|
+
echo_a @conf, line
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def write_home
|
|
36
|
+
@home || return
|
|
37
|
+
|
|
38
|
+
dm = Getch::Helpers.get_dm "home-#{@luks}"
|
|
39
|
+
uuid = gen_uuid dm
|
|
40
|
+
line = "UUID=#{uuid} /home #{@fs} rw,relatime 0 2"
|
|
41
|
+
echo_a @conf, line
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/fstab/hybrid.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
module Fstab
|
|
3
|
+
# Hybrid for Lvm + Encryption
|
|
4
|
+
class Hybrid < Encrypt
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@vg = options[:vg_name] ||= 'vg0'
|
|
8
|
+
@luks = options[:luks_name]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# The swap UUID based on the lvm volume /dev/vg/swap
|
|
12
|
+
def write_swap
|
|
13
|
+
# The both use /etc/crypttab
|
|
14
|
+
if Helpers.runit? or Helpers.systemd?
|
|
15
|
+
echo_a @conf, "/dev/mapper/swap-#{@luks} none swap sw 0 0"
|
|
16
|
+
else
|
|
17
|
+
dm = Getch::Helpers.get_dm "#{@vg}-swap"
|
|
18
|
+
uuid = Getch::Helpers.uuid dm
|
|
19
|
+
line = "UUID=#{uuid} none swap sw 0 0"
|
|
20
|
+
echo_a @conf, line
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def write_root
|
|
25
|
+
line = "/dev/#{@vg}/root / #{@fs} rw,relatime 0 1"
|
|
26
|
+
echo_a @conf, line
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def write_home
|
|
30
|
+
line = "/dev/#{@vg}/home /home #{@fs} rw,relatime 0 2"
|
|
31
|
+
echo_a @conf, line
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/fstab/lvm.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_litteral: true
|
|
2
|
+
|
|
3
|
+
module Fstab
|
|
4
|
+
class Lvm < Root
|
|
5
|
+
def initialize(devs, options)
|
|
6
|
+
super
|
|
7
|
+
@vg = options[:vg_name]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def write_swap
|
|
11
|
+
line = "/dev/#{@vg}/swap swap swap rw,noatime,discard 0 0"
|
|
12
|
+
echo_a @conf, line
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def write_root
|
|
16
|
+
line = "/dev/#{@vg}/root / #{@fs} rw,relatime 0 1"
|
|
17
|
+
echo_a @conf, line
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def write_home
|
|
21
|
+
line = "/dev/#{@vg}/home /home #{@fs} rw,relatime 0 2"
|
|
22
|
+
echo_a @conf, line
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/fstab/root.rb
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_litteral: true
|
|
2
|
+
|
|
3
|
+
require 'nito'
|
|
4
|
+
require_relative '../getch/log'
|
|
5
|
+
|
|
6
|
+
module Fstab
|
|
7
|
+
class Root
|
|
8
|
+
include NiTo
|
|
9
|
+
|
|
10
|
+
def initialize(devs, options)
|
|
11
|
+
@log = Getch::Log.new
|
|
12
|
+
@efi = devs[:efi] ||= nil
|
|
13
|
+
@boot = devs[:boot] ||= nil
|
|
14
|
+
@swap = devs[:swap] ||= nil
|
|
15
|
+
@root = devs[:root] ||= nil
|
|
16
|
+
@home = devs[:home] ||= nil
|
|
17
|
+
@fs = options[:fs] ||= 'ext4'
|
|
18
|
+
@mountpoint = options[:mountpoint] ||= '/mnt/getch'
|
|
19
|
+
@conf = "#{@mountpoint}/etc/fstab"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def generate
|
|
23
|
+
@log.info 'Generating fstab...'
|
|
24
|
+
write_efi
|
|
25
|
+
write_boot
|
|
26
|
+
write_swap
|
|
27
|
+
write_root
|
|
28
|
+
write_home
|
|
29
|
+
write_tmp
|
|
30
|
+
@log.result_ok
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def write_efi
|
|
36
|
+
@efi || return
|
|
37
|
+
|
|
38
|
+
uuid = gen_uuid @efi
|
|
39
|
+
line = "UUID=#{uuid} /efi vfat noauto,rw,relatime 0 0"
|
|
40
|
+
echo_a @conf, line
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def write_boot
|
|
44
|
+
@boot || return
|
|
45
|
+
|
|
46
|
+
uuid = gen_uuid @boot
|
|
47
|
+
line = "UUID=#{uuid} /boot #{@fs} noauto,rw,relatime 0 0"
|
|
48
|
+
echo_a @conf, line
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def write_swap
|
|
52
|
+
@swap || return
|
|
53
|
+
|
|
54
|
+
uuid = gen_uuid @swap
|
|
55
|
+
line = "UUID=#{uuid} swap swap rw,noatime,discard 0 0"
|
|
56
|
+
echo_a @conf, line
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def write_root
|
|
60
|
+
@root || return
|
|
61
|
+
|
|
62
|
+
uuid = gen_uuid @root
|
|
63
|
+
line = "UUID=#{uuid} / #{@fs} rw,relatime 0 1"
|
|
64
|
+
echo_a @conf, line
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def write_home
|
|
68
|
+
@home || return
|
|
69
|
+
|
|
70
|
+
uuid = gen_uuid @home
|
|
71
|
+
line = "UUID=#{uuid} /home #{@fs} rw,relatime 0 2"
|
|
72
|
+
echo_a @conf, line
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def write_tmp
|
|
76
|
+
Getch::Helpers.systemd? && return
|
|
77
|
+
|
|
78
|
+
line = 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0'
|
|
79
|
+
echo_a @conf, line
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def gen_uuid(dev)
|
|
85
|
+
device = dev.delete_prefix('/dev/')
|
|
86
|
+
Dir.glob('/dev/disk/by-uuid/*').each do |f|
|
|
87
|
+
link = File.readlink(f)
|
|
88
|
+
return f.delete_prefix('/dev/disk/by-uuid/') if link.match(/#{device}$/)
|
|
89
|
+
end
|
|
90
|
+
@log.fatal "No uuid found for #{device}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
data/lib/fstab/zfs.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Fstab
|
|
2
|
+
class Zfs < Root
|
|
3
|
+
def initialize(devs, options)
|
|
4
|
+
super
|
|
5
|
+
@encrypt = options[:encrypt]
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def generate
|
|
9
|
+
@log.info 'Generating fstab...'
|
|
10
|
+
write_efi
|
|
11
|
+
write_swap
|
|
12
|
+
@log.result_ok
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def write_swap
|
|
16
|
+
uuid = gen_uuid @swap
|
|
17
|
+
@encrypt ?
|
|
18
|
+
line = "/dev/mapper/swap-luks none swap sw 0 0" :
|
|
19
|
+
line = "UUID=#{uuid} swap swap rw,noatime,discard 0 0"
|
|
20
|
+
echo_a @conf, line
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/fstab.rb
ADDED