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.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +132 -0
  4. data/LICENSE +10 -0
  5. data/README.md +35 -29
  6. data/bin/getch +8 -6
  7. data/getch.gemspec +31 -0
  8. data/lib/clean.rb +149 -0
  9. data/lib/cryptsetup.rb +132 -0
  10. data/lib/devs.rb +199 -0
  11. data/lib/dracut/encrypt.rb +36 -0
  12. data/lib/dracut/hybrid.rb +15 -0
  13. data/lib/dracut/lvm.rb +14 -0
  14. data/lib/dracut/minimal.rb +11 -0
  15. data/lib/dracut/root.rb +45 -0
  16. data/lib/dracut/zfs.rb +35 -0
  17. data/lib/dracut.rb +11 -0
  18. data/lib/fstab/encrypt.rb +44 -0
  19. data/lib/fstab/hybrid.rb +34 -0
  20. data/lib/fstab/lvm.rb +25 -0
  21. data/lib/fstab/minimal.rb +6 -0
  22. data/lib/fstab/root.rb +93 -0
  23. data/lib/fstab/zfs.rb +23 -0
  24. data/lib/fstab.rb +11 -0
  25. data/lib/getch/assembly.rb +150 -0
  26. data/lib/getch/command.rb +88 -128
  27. data/lib/getch/config/account.rb +39 -0
  28. data/lib/getch/config/dhcp.rb +104 -0
  29. data/lib/getch/config/grub.rb +42 -0
  30. data/lib/getch/config/iwd.rb +60 -0
  31. data/lib/getch/config/keymap.rb +78 -0
  32. data/lib/getch/config/locale.rb +96 -0
  33. data/lib/getch/config/portage.rb +90 -0
  34. data/lib/getch/config/pre_network.rb +37 -0
  35. data/lib/getch/config/timezone.rb +52 -0
  36. data/lib/getch/config/void.rb +0 -36
  37. data/lib/getch/config.rb +16 -37
  38. data/lib/getch/device.rb +67 -0
  39. data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
  40. data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
  41. data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
  42. data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
  43. data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
  44. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
  45. data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
  46. data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
  47. data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
  48. data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
  49. data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
  50. data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
  51. data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
  52. data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
  53. data/lib/getch/filesystem/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
  54. data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
  55. data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
  56. data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
  57. data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
  58. data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
  59. data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
  60. data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
  61. data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +6 -4
  62. data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
  63. data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
  64. data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
  65. data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
  66. data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
  67. data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
  68. data/lib/getch/filesystem/ext4/minimal.rb +19 -0
  69. data/lib/getch/filesystem/ext4.rb +7 -7
  70. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
  71. data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
  72. data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
  73. data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
  74. data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
  75. data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
  76. data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
  77. data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
  78. data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
  79. data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
  80. data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
  81. data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
  82. data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
  83. data/lib/getch/filesystem/zfs/minimal.rb +19 -0
  84. data/lib/getch/filesystem/zfs.rb +1 -7
  85. data/lib/getch/filesystem.rb +0 -6
  86. data/lib/getch/gentoo/bootloader.rb +23 -44
  87. data/lib/getch/gentoo/finalize.rb +25 -0
  88. data/lib/getch/gentoo/post_config.rb +75 -0
  89. data/lib/getch/gentoo/pre_config.rb +37 -0
  90. data/lib/getch/gentoo/services.rb +18 -0
  91. data/lib/getch/gentoo/sources.rb +39 -33
  92. data/lib/getch/gentoo/tarball.rb +91 -0
  93. data/lib/getch/gentoo/terraform.rb +34 -0
  94. data/lib/getch/gentoo/update.rb +54 -0
  95. data/lib/getch/gentoo/use.rb +9 -6
  96. data/lib/getch/gentoo/use_flag.rb +17 -20
  97. data/lib/getch/gentoo.rb +9 -75
  98. data/lib/getch/guard.rb +3 -3
  99. data/lib/getch/helpers.rb +63 -115
  100. data/lib/getch/log.rb +87 -25
  101. data/lib/getch/options.rb +41 -11
  102. data/lib/getch/states.rb +28 -8
  103. data/lib/getch/tree.rb +56 -0
  104. data/lib/getch/version.rb +1 -1
  105. data/lib/getch/void/bootloader.rb +18 -0
  106. data/lib/getch/void/finalize.rb +31 -0
  107. data/lib/getch/void/post_config.rb +19 -0
  108. data/lib/getch/void/pre_config.rb +18 -0
  109. data/lib/getch/void/services.rb +18 -0
  110. data/lib/getch/void/{stage.rb → tarball.rb} +34 -14
  111. data/lib/getch/void/terraform.rb +28 -0
  112. data/lib/getch/void/update.rb +33 -0
  113. data/lib/getch/void.rb +9 -59
  114. data/lib/getch.rb +58 -90
  115. data/lib/luks.rb +239 -0
  116. data/lib/lvm2.rb +112 -0
  117. data/lib/mkfs/zfs.rb +167 -0
  118. data/lib/mkfs.rb +144 -0
  119. data/lib/mountfs.rb +154 -0
  120. data/lib/nito.rb +131 -0
  121. data/lib/sgdisk.rb +160 -0
  122. data.tar.gz.sig +0 -0
  123. metadata +113 -74
  124. metadata.gz.sig +0 -0
  125. data/lib/getch/config/gentoo.rb +0 -58
  126. data/lib/getch/filesystem/clean.rb +0 -58
  127. data/lib/getch/filesystem/device.rb +0 -63
  128. data/lib/getch/filesystem/ext4/config.rb +0 -62
  129. data/lib/getch/filesystem/ext4/deps.rb +0 -24
  130. data/lib/getch/filesystem/ext4/format.rb +0 -31
  131. data/lib/getch/filesystem/ext4/mount.rb +0 -26
  132. data/lib/getch/filesystem/ext4/partition.rb +0 -55
  133. data/lib/getch/filesystem/ext4/void.rb +0 -44
  134. data/lib/getch/filesystem/lvm/config.rb +0 -44
  135. data/lib/getch/filesystem/lvm/deps.rb +0 -44
  136. data/lib/getch/filesystem/lvm/device.rb +0 -45
  137. data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
  138. data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
  139. data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
  140. data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
  141. data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
  142. data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
  143. data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
  144. data/lib/getch/filesystem/lvm/format.rb +0 -32
  145. data/lib/getch/filesystem/lvm/mount.rb +0 -26
  146. data/lib/getch/filesystem/lvm/partition.rb +0 -72
  147. data/lib/getch/filesystem/lvm/void.rb +0 -46
  148. data/lib/getch/filesystem/mount.rb +0 -63
  149. data/lib/getch/filesystem/partition.rb +0 -85
  150. data/lib/getch/filesystem/zfs/config.rb +0 -43
  151. data/lib/getch/filesystem/zfs/deps.rb +0 -67
  152. data/lib/getch/filesystem/zfs/device.rb +0 -66
  153. data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
  154. data/lib/getch/filesystem/zfs/format.rb +0 -117
  155. data/lib/getch/filesystem/zfs/mount.rb +0 -47
  156. data/lib/getch/filesystem/zfs/partition.rb +0 -69
  157. data/lib/getch/filesystem/zfs/void.rb +0 -81
  158. data/lib/getch/gentoo/boot.rb +0 -64
  159. data/lib/getch/gentoo/chroot.rb +0 -75
  160. data/lib/getch/gentoo/config.rb +0 -167
  161. data/lib/getch/gentoo/stage.rb +0 -73
  162. data/lib/getch/void/boot.rb +0 -84
  163. data/lib/getch/void/chroot.rb +0 -56
  164. data/lib/getch/void/config.rb +0 -90
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- module Encrypt
7
- class Device < Getch::FileSystem::Device
8
- def initialize
9
- super
10
- @vg = 'vg0'
11
- @lv_root = "/dev/#{@vg}/root"
12
- @lv_swap = "/dev/#{@vg}/swap"
13
- @lv_home = @home_disk ? "/dev/#{@vg}/home" : nil
14
- @luks_root = '/dev/mapper/cryptroot'
15
- @luks_home = @home_disk ? '/dev/mapper/crypthome' : nil
16
- end
17
-
18
- private
19
-
20
- def search_boot
21
- if @efi
22
- if @boot_disk
23
- @dev_esp = "/dev/#{@boot_disk}1"
24
- else
25
- @dev_esp = "/dev/#{@disk}1"
26
- @root_part += 1
27
- end
28
- else
29
- if @boot_disk
30
- @dev_gpt = "/dev/#{@boot_disk}1"
31
- @dev_boot = "/dev/#{@boot_disk}2"
32
- @dev_grub = "/dev/#{@boot_disk}"
33
- else
34
- @dev_gpt = "/dev/#{@disk}1"
35
- @dev_boot = "/dev/#{@disk}2"
36
- @dev_grub = "/dev/#{@disk}"
37
- @root_part += 2
38
- end
39
- end
40
- end
41
-
42
- def search_swap
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- module Encrypt
7
- class Format < Device
8
- def initialize
9
- super
10
- @fs = 'ext4'
11
- @state = Getch::States.new()
12
- format
13
- end
14
-
15
- def format
16
- return if STATES[:format]
17
-
18
- puts "Format #{@disk}"
19
- exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
20
- exec("mkfs.#{@fs} -F #{@dev_boot}") if @dev_boot
21
- exec("mkfs.#{@fs} -F #{@lv_root}")
22
- exec("mkfs.#{@fs} -F #{@lv_home}") if @lv_home
23
- @state.format
24
- end
25
-
26
- private
27
-
28
- def exec(cmd)
29
- Getch::Command.new(cmd).run!
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- module Encrypt
7
- class Mount < Device
8
- def initialize
9
- super
10
- @mount = Getch::FileSystem::Mount.new
11
- @state = Getch::States.new
12
- end
13
-
14
- def run
15
- return if STATES[:mount]
16
-
17
- @mount.root(@lv_root)
18
- @mount.boot(@dev_boot)
19
- @mount.esp(@dev_esp)
20
- @mount.home(@lv_home)
21
- @state.mount
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- module Encrypt
7
- class Partition < Device
8
- include Helpers::Cryptsetup
9
-
10
- def initialize
11
- super
12
- @state = Getch::States.new()
13
- @clean = Getch::FileSystem::Clean
14
- @partition = Getch::FileSystem::Partition.new
15
- @log = Log.new
16
- run_partition
17
- end
18
-
19
- def run_partition
20
- return if STATES[:partition ]
21
- @clean.old_vg(@dev_root, @vg)
22
- @clean.hdd(@disk)
23
- @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
24
-
25
- partition
26
- encrypting
27
- lvm
28
- @state.partition
29
- end
30
-
31
- private
32
-
33
- def partition
34
- if Helpers.efi?
35
- @partition.efi(@dev_esp)
36
- @partition.root(@dev_root, '8e00')
37
- else
38
- @partition.gpt(@dev_gpt)
39
- @partition.boot(@dev_boot)
40
- @partition.root(@dev_root, '8e00')
41
- end
42
- end
43
-
44
- def encrypting
45
- @log.info('Cryptsetup')
46
- encrypt(@dev_root)
47
- open_crypt(@dev_root, 'cryptroot')
48
- end
49
-
50
- def lvm
51
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
52
- exec("pvcreate -f #{@luks_root}")
53
- exec("vgcreate -f #{@vg} #{@luks_root}")
54
- # Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
55
- exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
56
-
57
- if @user
58
- exec("lvcreate -y -Wy -Zy -L 18G -n root #{@vg}")
59
- exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}")
60
- else
61
- exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
62
- end
63
-
64
- exec('vgchange --available y')
65
- end
66
-
67
- # Follow https://wiki.archlinux.org/index.php/Partitioning
68
- # Partition_efi
69
- # /efi - EFI system partition - 260MB
70
- # / - Root
71
-
72
- # Partition_bios
73
- # None - Bios Boot Partition - 1MiB
74
- # /boot - Boot - 8300
75
- # / - Root
76
-
77
- def exec(cmd)
78
- Getch::Command.new(cmd).run!
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- module Encrypt
7
- end
8
- end
9
- end
10
- end
11
-
12
- require_relative 'encrypt/device'
13
- require_relative 'encrypt/partition'
14
- require_relative 'encrypt/format'
15
- require_relative 'encrypt/mount'
16
- require_relative 'encrypt/config'
17
- require_relative 'encrypt/deps'
18
- require_relative 'encrypt/void'
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- class Format < Getch::FileSystem::Lvm::Device
7
- def initialize
8
- super
9
- @state = Getch::States.new
10
- format
11
- end
12
-
13
- def format
14
- return if STATES[:format]
15
-
16
- exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
17
- exec("mkfs.ext4 -F #{@dev_boot}") if @dev_boot
18
- exec("mkswap -f #{@lv_swap}")
19
- exec("mkfs.ext4 -F #{@lv_root}")
20
- exec("mkfs.ext4 -F #{@lv_home}") if @lv_home
21
- @state.format
22
- end
23
-
24
- private
25
-
26
- def exec(cmd)
27
- Getch::Command.new(cmd).run!
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- class Mount < Getch::FileSystem::Lvm::Device
7
- def initialize
8
- super
9
- @mount = Getch::FileSystem::Mount.new
10
- @state = Getch::States.new
11
- end
12
-
13
- def run
14
- return if STATES[:mount]
15
-
16
- @mount.swap(@lv_swap)
17
- @mount.root(@lv_root)
18
- @mount.boot(@dev_boot)
19
- @mount.esp(@dev_esp)
20
- @mount.home(@lv_home)
21
- @state.mount
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- class Partition < Getch::FileSystem::Lvm::Device
7
- def initialize
8
- super
9
- @state = Getch::States.new
10
- @partition = Getch::FileSystem::Partition.new
11
- @clean = Getch::FileSystem::Clean
12
- run_partition
13
- end
14
-
15
- def run_partition
16
- return if STATES[:partition ]
17
-
18
- @clean.old_vg(@dev_root, @vg)
19
- @clean.hdd(@disk)
20
- @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
21
- partition
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 lvm
40
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
41
- exec("pvcreate -f #{@dev_root}")
42
- exec("vgcreate -f #{@vg} #{@dev_root}")
43
- # Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
44
- exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
45
-
46
- if @user
47
- exec("lvcreate -y -Wy -Zy -L 18G -n root #{@vg}")
48
- exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}")
49
- else
50
- exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
51
- end
52
-
53
- exec('vgchange --available y')
54
- end
55
-
56
- # Follow https://wiki.archlinux.org/index.php/Partitioning
57
- # Partition_efi
58
- # /efi - EFI system partition - 260MB
59
- # / - Root
60
-
61
- # Partition_bios
62
- # None - Bios Boot Partition - 1MiB
63
- # /boot - Boot - 8300
64
- # / - Root
65
-
66
- def exec(cmd)
67
- Getch::Command.new(cmd).run!
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Lvm
6
- class Void < Device
7
- include Helpers::Void
8
-
9
- attr_reader :boot_disk
10
-
11
- def fstab
12
- conf = "#{MOUNTPOINT}/etc/fstab"
13
- File.write(conf, "\n", mode: 'w', chmod: 0644)
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
16
- add_line(conf, "#{@lv_swap} swap swap rw,noatime,discard 0 0") if @lv_swap
17
- add_line(conf, "#{@lv_home} /home/#{@user} ext4 rw,noatime,discard 0 2") if @lv_home
18
- add_line(conf, "#{@lv_root} / ext4 rw,relatime 0 1")
19
- add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
20
- end
21
-
22
- def config_dracut
23
- conf = "#{MOUNTPOINT}/etc/dracut.conf.d/lvm.conf"
24
- # dracut: value+= should be surrounding by white space
25
- content = [
26
- "hostonly=\"yes\"",
27
- "omit_dracutmodules+=\" btrfs \"",
28
- ""
29
- ]
30
- File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
31
- end
32
-
33
- def kernel_cmdline_dracut
34
- conf = "#{MOUNTPOINT}/etc/dracut.conf.d/cmdline.conf"
35
- c="kernel_cmdline=\"rd.lvm.vg=#{@vg} rootflags=rw,relatime\""
36
- File.write(conf, "#{c}\n", mode: 'w', chmod: 0644)
37
- end
38
-
39
- def finish
40
- puts '+ Enter in your system: chroot /mnt /bin/bash'
41
- puts '+ Reboot with: shutdown -r now'
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
-
5
- module Getch
6
- module FileSystem
7
- class Mount
8
- def initialize
9
- @root_dir = MOUNTPOINT
10
- @boot_dir = "#{@root_dir}/boot"
11
- @boot_efi_dir = "#{@root_dir}/efi"
12
- @home_dir = "#{@root_dir}/home"
13
- @state = Getch::States.new
14
- @log = Getch::Log.new
15
- end
16
-
17
- def swap(dev)
18
- return unless dev
19
-
20
- if Helpers.grep?('/proc/swaps', /^\/dev/)
21
- exec("swapoff #{dev}")
22
- end
23
-
24
- exec("swapon #{dev}")
25
- end
26
-
27
- def root(dev)
28
- return unless dev
29
-
30
- Helpers.mkdir(@root_dir)
31
- exec("mount #{dev} #{@root_dir}")
32
- end
33
-
34
- def esp(dev)
35
- return unless dev
36
-
37
- Helpers.mkdir(@boot_efi_dir)
38
- exec("mount #{dev} #{@boot_efi_dir}")
39
- end
40
-
41
- def boot(dev)
42
- return unless dev
43
-
44
- Helpers.mkdir(@boot_dir)
45
- exec("mount #{dev} #{@boot_dir}")
46
- end
47
-
48
- def home(dev)
49
- return unless dev
50
-
51
- Helpers.mkdir(@home_dir)
52
- exec("mount #{dev} #{@home_dir}")
53
- end
54
-
55
- private
56
-
57
- def exec(cmd)
58
- @log.info("==> #{cmd}")
59
- Helpers.sys(cmd)
60
- end
61
- end
62
- end
63
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- class Partition
6
- def initialize
7
- @log = Getch::Log.new
8
- end
9
-
10
- def gpt(dev)
11
- return unless dev
12
-
13
- disk = disk_name(dev)
14
- part = dev.match(/[0-9]/)
15
- exec("sgdisk -n#{part}:1MiB:+1MiB -t#{part}:EF02 #{disk}")
16
- end
17
-
18
- def boot(dev)
19
- return unless dev
20
-
21
- disk = disk_name(dev)
22
- part = dev.match(/[0-9]/)
23
- if Getch::OPTIONS[:fs] == 'zfs'
24
- exec("sgdisk -n#{part}:0:+2G -t#{part}:BE00 #{disk}")
25
- else
26
- exec("sgdisk -n#{part}:0:+128MiB -t#{part}:8300 #{disk}")
27
- end
28
- end
29
-
30
- def efi(dev)
31
- return unless dev
32
-
33
- disk = disk_name(dev)
34
- part = dev.match(/[0-9]/)
35
- exec("sgdisk -n#{part}:1M:+260M -t#{part}:EF00 #{disk}")
36
- end
37
-
38
- def swap(dev)
39
- return unless dev
40
-
41
- disk = disk_name(dev)
42
- part = dev.match(/[0-9]/)
43
- if Getch::OPTIONS[:cache_disk]
44
- exec("sgdisk -n#{part}:0:0 -t#{part}:8200 #{disk}")
45
- else
46
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
47
- exec("sgdisk -n#{part}:0:+#{mem} -t#{part}:8200 #{disk}")
48
- end
49
- end
50
-
51
- def root(dev, code)
52
- return unless dev
53
-
54
- disk = disk_name(dev)
55
- part = dev.match(/[0-9]/)
56
- exec("sgdisk -n#{part}:0:0 -t#{part}:#{code} #{disk}")
57
- end
58
-
59
- def home(dev, code)
60
- return unless dev
61
-
62
- disk = disk_name(dev)
63
- part = dev.match(/[0-9]/)
64
- if Getch::OPTIONS[:home_disk]
65
- exec("sgdisk -n#{part}:0:0 -t#{part}:#{code} #{disk}")
66
- end
67
- end
68
-
69
- private
70
-
71
- def disk_name(dev)
72
- dev.match(/[^0-9]+/)
73
- end
74
-
75
- def exec(cmd)
76
- @log.debug "Partition disk with #{cmd}"
77
- if Getch::OPTIONS[:encrypt]
78
- Helpers.sys(cmd)
79
- else
80
- Getch::Command.new(cmd).run!
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Zfs
6
- class Config < Device
7
- def initialize
8
- super
9
- gen_uuid
10
- @init = '/usr/lib/systemd/systemd'
11
- end
12
-
13
- def fstab
14
- file = "#{MOUNTPOINT}/etc/fstab"
15
- datas = data_fstab
16
- File.write file, datas.join("\n")
17
- end
18
-
19
- # See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
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
25
- end
26
-
27
- private
28
-
29
- def gen_uuid
30
- @uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
31
- @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
32
- end
33
-
34
- def data_fstab
35
- efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
36
- swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
37
-
38
- [ efi, swap ]
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Getch
4
- module FileSystem
5
- module Zfs
6
- class Deps < Device
7
- def make
8
- unstable_zfs
9
- install_deps
10
- zfs_mountpoint
11
- hostid
12
- config_dracut
13
- zed_update_path
14
- end
15
-
16
- private
17
-
18
- def unstable_zfs
19
- conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
20
- data = [
21
- 'sys-fs/zfs-kmod',
22
- 'sys-fs/zfs'
23
- ]
24
- File.write(conf, data.join("\n"), mode: 'w')
25
- end
26
-
27
- def install_deps
28
- Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
29
- Getch::Emerge.new('sys-fs/zfs').pkg!
30
- end
31
-
32
- # See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
33
- def zfs_mountpoint
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')
41
- end
42
-
43
- def zed_update_path
44
- Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each { |f|
45
- unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
46
- raise 'system exec sed'
47
- end
48
- }
49
- end
50
-
51
- def hostid
52
- exec 'zgenhostid $(hostid)'
53
- end
54
-
55
- def config_dracut
56
- conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
57
- content = 'hostonly="yes"'
58
- Helpers.echo conf, content
59
- end
60
-
61
- def exec(cmd)
62
- Getch::Chroot.new(cmd).run!
63
- end
64
- end
65
- end
66
- end
67
- end