getch 0.1.9 → 0.3.0

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 (161) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +35 -29
  4. data/bin/getch +8 -6
  5. data/lib/clean.rb +149 -0
  6. data/lib/cryptsetup.rb +132 -0
  7. data/lib/devs.rb +199 -0
  8. data/lib/dracut/encrypt.rb +36 -0
  9. data/lib/dracut/hybrid.rb +15 -0
  10. data/lib/dracut/lvm.rb +14 -0
  11. data/lib/dracut/minimal.rb +11 -0
  12. data/lib/dracut/root.rb +45 -0
  13. data/lib/dracut/zfs.rb +35 -0
  14. data/lib/dracut.rb +11 -0
  15. data/lib/fstab/encrypt.rb +44 -0
  16. data/lib/fstab/hybrid.rb +34 -0
  17. data/lib/fstab/lvm.rb +25 -0
  18. data/lib/fstab/minimal.rb +6 -0
  19. data/lib/fstab/root.rb +93 -0
  20. data/lib/fstab/zfs.rb +23 -0
  21. data/lib/fstab.rb +11 -0
  22. data/lib/getch/assembly.rb +150 -0
  23. data/lib/getch/command.rb +88 -128
  24. data/lib/getch/config/account.rb +39 -0
  25. data/lib/getch/config/dhcp.rb +104 -0
  26. data/lib/getch/config/grub.rb +42 -0
  27. data/lib/getch/config/iwd.rb +60 -0
  28. data/lib/getch/config/keymap.rb +78 -0
  29. data/lib/getch/config/locale.rb +96 -0
  30. data/lib/getch/config/portage.rb +90 -0
  31. data/lib/getch/config/pre_network.rb +37 -0
  32. data/lib/getch/config/timezone.rb +52 -0
  33. data/lib/getch/config/void.rb +0 -36
  34. data/lib/getch/config.rb +16 -37
  35. data/lib/getch/device.rb +67 -0
  36. data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
  37. data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
  38. data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
  39. data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
  40. data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
  41. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
  42. data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
  43. data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
  44. data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
  45. data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
  46. data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
  47. data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
  48. data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
  49. data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
  50. data/lib/getch/filesystem/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
  51. data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
  52. data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
  53. data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
  54. data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
  55. data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
  56. data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
  57. data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
  58. data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +6 -4
  59. data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
  60. data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
  61. data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
  62. data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
  63. data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
  64. data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
  65. data/lib/getch/filesystem/ext4/minimal.rb +19 -0
  66. data/lib/getch/filesystem/ext4.rb +7 -7
  67. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
  68. data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
  69. data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
  70. data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
  71. data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
  72. data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
  73. data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
  74. data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
  75. data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
  76. data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
  77. data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
  78. data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
  79. data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
  80. data/lib/getch/filesystem/zfs/minimal.rb +19 -0
  81. data/lib/getch/filesystem/zfs.rb +1 -7
  82. data/lib/getch/filesystem.rb +0 -6
  83. data/lib/getch/gentoo/bootloader.rb +23 -44
  84. data/lib/getch/gentoo/finalize.rb +25 -0
  85. data/lib/getch/gentoo/post_config.rb +75 -0
  86. data/lib/getch/gentoo/pre_config.rb +37 -0
  87. data/lib/getch/gentoo/services.rb +18 -0
  88. data/lib/getch/gentoo/sources.rb +39 -33
  89. data/lib/getch/gentoo/tarball.rb +91 -0
  90. data/lib/getch/gentoo/terraform.rb +34 -0
  91. data/lib/getch/gentoo/update.rb +54 -0
  92. data/lib/getch/gentoo/use.rb +9 -6
  93. data/lib/getch/gentoo/use_flag.rb +17 -20
  94. data/lib/getch/gentoo.rb +9 -75
  95. data/lib/getch/guard.rb +2 -2
  96. data/lib/getch/helpers.rb +63 -115
  97. data/lib/getch/log.rb +87 -25
  98. data/lib/getch/options.rb +41 -11
  99. data/lib/getch/states.rb +28 -8
  100. data/lib/getch/tree.rb +56 -0
  101. data/lib/getch/version.rb +1 -1
  102. data/lib/getch/void/bootloader.rb +18 -0
  103. data/lib/getch/void/finalize.rb +31 -0
  104. data/lib/getch/void/post_config.rb +19 -0
  105. data/lib/getch/void/pre_config.rb +18 -0
  106. data/lib/getch/void/services.rb +18 -0
  107. data/lib/getch/void/{stage.rb → tarball.rb} +34 -14
  108. data/lib/getch/void/terraform.rb +28 -0
  109. data/lib/getch/void/update.rb +33 -0
  110. data/lib/getch/void.rb +9 -59
  111. data/lib/getch.rb +58 -90
  112. data/lib/luks.rb +239 -0
  113. data/lib/lvm2.rb +112 -0
  114. data/lib/mkfs/zfs.rb +167 -0
  115. data/lib/mkfs.rb +140 -0
  116. data/lib/mountfs.rb +154 -0
  117. data/lib/nito.rb +131 -0
  118. data/lib/sgdisk.rb +160 -0
  119. data.tar.gz.sig +0 -0
  120. metadata +83 -47
  121. metadata.gz.sig +0 -0
  122. data/lib/getch/config/gentoo.rb +0 -58
  123. data/lib/getch/filesystem/clean.rb +0 -58
  124. data/lib/getch/filesystem/device.rb +0 -63
  125. data/lib/getch/filesystem/ext4/config.rb +0 -62
  126. data/lib/getch/filesystem/ext4/deps.rb +0 -24
  127. data/lib/getch/filesystem/ext4/format.rb +0 -31
  128. data/lib/getch/filesystem/ext4/mount.rb +0 -26
  129. data/lib/getch/filesystem/ext4/partition.rb +0 -55
  130. data/lib/getch/filesystem/ext4/void.rb +0 -44
  131. data/lib/getch/filesystem/lvm/config.rb +0 -44
  132. data/lib/getch/filesystem/lvm/deps.rb +0 -44
  133. data/lib/getch/filesystem/lvm/device.rb +0 -45
  134. data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
  135. data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
  136. data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
  137. data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
  138. data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
  139. data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
  140. data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
  141. data/lib/getch/filesystem/lvm/format.rb +0 -32
  142. data/lib/getch/filesystem/lvm/mount.rb +0 -26
  143. data/lib/getch/filesystem/lvm/partition.rb +0 -72
  144. data/lib/getch/filesystem/lvm/void.rb +0 -46
  145. data/lib/getch/filesystem/mount.rb +0 -63
  146. data/lib/getch/filesystem/partition.rb +0 -85
  147. data/lib/getch/filesystem/zfs/config.rb +0 -43
  148. data/lib/getch/filesystem/zfs/deps.rb +0 -67
  149. data/lib/getch/filesystem/zfs/device.rb +0 -66
  150. data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
  151. data/lib/getch/filesystem/zfs/format.rb +0 -117
  152. data/lib/getch/filesystem/zfs/mount.rb +0 -47
  153. data/lib/getch/filesystem/zfs/partition.rb +0 -69
  154. data/lib/getch/filesystem/zfs/void.rb +0 -81
  155. data/lib/getch/gentoo/boot.rb +0 -64
  156. data/lib/getch/gentoo/chroot.rb +0 -75
  157. data/lib/getch/gentoo/config.rb +0 -167
  158. data/lib/getch/gentoo/stage.rb +0 -73
  159. data/lib/getch/void/boot.rb +0 -84
  160. data/lib/getch/void/chroot.rb +0 -56
  161. data/lib/getch/void/config.rb +0 -90
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkfs'
4
+
5
+ module Getch
6
+ module FileSystem
7
+ module Ext4
8
+ module Minimal
9
+ class Format
10
+ def initialize
11
+ x
12
+ end
13
+
14
+ private
15
+
16
+ def x
17
+ Mkfs::Root.new(DEVS, OPTIONS)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mountfs'
4
+
5
+ module Getch
6
+ module FileSystem
7
+ module Ext4
8
+ module Minimal
9
+ class Mount
10
+ def initialize
11
+ x
12
+ end
13
+
14
+ def x
15
+ MountFs::Minimal.new(DEVS, OPTIONS)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sgdisk'
4
+
5
+ module Getch
6
+ module FileSystem
7
+ module Ext4
8
+ module Minimal
9
+ class Partition
10
+ def initialize
11
+ x
12
+ end
13
+
14
+ private
15
+
16
+ # Follow https://wiki.archlinux.org/index.php/Partitioning
17
+ # 1 - /efi of GPT
18
+ # 2 - Swap
19
+ # 3 - /
20
+ # 4 - /home if --separate-home DISK is used
21
+ def x
22
+ Sgdisk::Ext4.new(DEVS)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Ext4
6
+ module Minimal
7
+ def self.end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ require_relative 'minimal/device'
15
+ require_relative 'minimal/partition'
16
+ require_relative 'minimal/format'
17
+ require_relative 'minimal/mount'
18
+ require_relative 'minimal/deps'
19
+ require_relative 'minimal/config'
@@ -3,15 +3,15 @@
3
3
  module Getch
4
4
  module FileSystem
5
5
  module Ext4
6
+ def self.end
7
+ puts '+ To enter in your system: chroot /mnt/getch /bin/bash'
8
+ puts '+ Reboot with: shutdown -r now'
9
+ end
6
10
  end
7
11
  end
8
12
  end
9
13
 
10
- require_relative 'ext4/device'
11
- require_relative 'ext4/partition'
12
- require_relative 'ext4/format'
13
- require_relative 'ext4/mount'
14
- require_relative 'ext4/config'
15
- require_relative 'ext4/deps'
16
- require_relative 'ext4/void'
14
+ require_relative 'ext4/minimal'
17
15
  require_relative 'ext4/encrypt'
16
+ require_relative 'ext4/lvm'
17
+ require_relative 'ext4/hybrid'
@@ -1,48 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fstab'
4
+ require 'dracut'
5
+ require 'cryptsetup'
6
+
3
7
  module Getch
4
8
  module FileSystem
5
9
  module Zfs
6
10
  module Encrypt
7
- class Config < Device
8
- def initialize
9
- super
10
- gen_uuid
11
- @init = '/usr/lib/systemd/systemd'
12
- crypttab
13
- end
14
-
15
- def fstab
16
- file = "#{MOUNTPOINT}/etc/fstab"
17
- datas = data_fstab
18
- File.write(file, datas.join("\n"))
19
- end
20
-
21
- def cmdline
22
- src = "#{MOUNTPOINT}/etc/dracut.conf.d/cmdline.conf"
23
- line = "kernel_cmdline=\"root=zfs:#{@pool_name}/ROOT/#{@n} init=#{@init} rd.vconsole.keymap=#{Getch::OPTIONS[:keymap]} zfs.force=1 zfs.zfs_arc_max=536870912\""
24
- Helpers.echo src, line
25
- end
26
-
27
- def crypttab
28
- datas = [
29
- "cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,discard,cipher=aes-xts-plain64:sha256,size=512"
30
- ]
31
- File.write("#{MOUNTPOINT}/etc/crypttab", datas.join("\n"))
32
- end
33
-
34
- private
35
-
36
- def gen_uuid
37
- @partuuid_swap = Helpers.partuuid(@dev_swap)
38
- @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
39
- end
40
-
41
- def data_fstab
42
- boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
43
- swap = @dev_swap ? '/dev/mapper/cryptswap none swap sw 0 0' : ''
44
-
45
- [ boot_efi, swap ]
11
+ class Config < Minimal::Config
12
+ def x
13
+ Fstab::Zfs.new(DEVS, OPTIONS).generate
14
+ Dracut::Zfs.new(DEVS, OPTIONS).generate
15
+ CryptSetup.new(DEVS, OPTIONS).swap_conf
16
+ grub_broken_root
46
17
  end
47
18
  end
48
19
  end
@@ -4,64 +4,13 @@ module Getch
4
4
  module FileSystem
5
5
  module Zfs
6
6
  module Encrypt
7
- class Deps < Device
8
- def make
9
- unstable_zfs
10
- install_deps
11
- zfs_mountpoint
12
- hostid
13
- config_dracut
14
- zed_update_path
15
- end
16
-
17
- private
18
-
19
- def unstable_zfs
20
- conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
21
- data = [
22
- 'sys-fs/zfs-kmod',
23
- 'sys-fs/zfs'
24
- ]
25
- File.write(conf, data.join("\n"), mode: 'w')
26
- end
27
-
7
+ class Deps < Minimal::Deps
28
8
  def install_deps
29
- Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
30
- Getch::Emerge.new('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
- exec('systemctl enable zfs-zed.service')
41
- exec('systemctl enable zfs.target')
42
- end
43
-
44
- def zed_update_path
45
- Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each do |f|
46
- unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
47
- raise 'System exec sed'
48
- end
9
+ case OPTIONS[:os]
10
+ when 'gentoo' then Install.new('sys-fs/cryptsetup sys-fs/zfs')
11
+ when 'void' then Install.new('cryptsetup zfs')
49
12
  end
50
13
  end
51
-
52
- def hostid
53
- exec 'zgenhostid $(hostid)'
54
- end
55
-
56
- def config_dracut
57
- conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
58
- content = 'hostonly="yes"'
59
- Helpers.echo conf, content
60
- end
61
-
62
- def exec(cmd)
63
- Getch::Chroot.new(cmd).run!
64
- end
65
14
  end
66
15
  end
67
16
  end
@@ -1,65 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'devs'
4
+
3
5
  module Getch
4
6
  module FileSystem
5
7
  module Zfs
6
8
  module Encrypt
7
- class Device < Getch::FileSystem::Device
9
+ class Device
8
10
  def initialize
9
- super
10
- @id = Helpers.pool_id(@dev_root)
11
- @boot_pool_name = "bpool-#{@id}"
12
- @pool_name = "rpool-#{@id}"
13
- @zfs_home = @user ? true : false
14
- @n = Getch::OPTIONS[:os]
11
+ @args = { start: true, boot: true, swap: true, root: true }
12
+ x
15
13
  end
16
14
 
17
15
  private
18
16
 
19
- def search_boot
20
- if @efi
21
- if @boot_disk
22
- @dev_esp = "/dev/#{@boot_disk}1"
23
- @dev_boot = "/dev/#{@boot_disk}2" if Getch::OPTIONS[:os] == 'void'
24
- else
25
- @dev_esp = "/dev/#{@disk}1"
26
- @root_part += 1
27
- if Getch::OPTIONS[:os] == 'void'
28
- @dev_boot = "/dev/#{@disk}#{@root_part}"
29
- @root_part += 1
30
- end
31
- end
32
- else
33
- if @boot_disk
34
- @dev_gpt = "/dev/#{@boot_disk}1"
35
- @dev_boot = "/dev/#{@boot_disk}2"
36
- @dev_grub = "/dev/#{@boot_disk}"
37
- else
38
- @dev_gpt = "/dev/#{@disk}1"
39
- @dev_boot = "/dev/#{@disk}2"
40
- @dev_grub = "/dev/#{@disk}"
41
- @root_part += 2
42
- end
43
- end
44
- end
45
-
46
- def search_swap
47
- if @cache_disk
48
- @dev_swap = "/dev/#{@cache_disk}1"
49
- @dev_log = "/dev/#{@cache_disk}2"
50
- @dev_cache = "/dev/#{@cache_disk}3"
51
- else
52
- @dev_swap = "/dev/#{@disk}#{@root_part}"
53
- @root_part += 1
54
- end
55
- end
56
-
57
- def search_root
58
- if @root_part == 1
59
- @dev_root = "/dev/#{@disk}"
60
- else
61
- @dev_root = "/dev/#{@disk}#{@root_part}"
62
- end
17
+ def x
18
+ Devs::Settings.new(@args, OPTIONS)
63
19
  end
64
20
  end
65
21
  end
@@ -1,104 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mkfs'
4
+
3
5
  module Getch
4
6
  module FileSystem
5
7
  module Zfs
6
8
  module Encrypt
7
- class Format < Device
9
+ class Format
8
10
  def initialize
9
- super
10
- @log = Getch::Log.new
11
- @state = Getch::States.new
12
- unless @id
13
- @log.info "Research pool id for #{@dev_root}..."
14
- @id = Helpers.pool_id(@dev_root)
15
- @boot_pool_name = "bpool-#{@id}"
16
- @pool_name = "rpool-#{@id}"
17
- end
18
- format
11
+ x
19
12
  end
20
13
 
21
14
  private
22
15
 
23
- def format
24
- return if STATES[:format]
25
- raise "Error, no id found for #{@dev_root}." unless @id
26
-
27
- system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
28
- zfs
29
- datasets
30
- @state.format
31
- end
32
-
33
- def zfs
34
- bloc=`blockdev --getpbsz #{@dev_root}`
35
- ashift =
36
- case bloc
37
- when /8096/
38
- 13
39
- when /4096/
40
- 12
41
- else # 512
42
- 9
43
- end
44
-
45
- Helpers.mkdir(MOUNTPOINT)
46
-
47
- @log.debug("ashift found for #{bloc} - #{ashift}")
48
- if @dev_boot
49
- # https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
50
- @log.info("Creating boot pool on #{@pool_name}")
51
- exec("zpool create -f \\
52
- -o ashift=#{ashift} -o autotrim=on -d \\
53
- -o feature@async_destroy=enabled \\
54
- -o feature@bookmarks=enabled \\
55
- -o feature@embedded_data=enabled \\
56
- -o feature@empty_bpobj=enabled \\
57
- -o feature@enabled_txg=enabled \\
58
- -o feature@extensible_dataset=enabled \\
59
- -o feature@filesystem_limits=enabled \\
60
- -o feature@hole_birth=enabled \\
61
- -o feature@large_blocks=enabled \\
62
- -o feature@lz4_compress=enabled \\
63
- -o feature@spacemap_histogram=enabled \\
64
- -O acltype=posixacl -O canmount=off -O compression=lz4 \\
65
- -O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
66
- -O mountpoint=/boot -R #{MOUNTPOINT} \\
67
- #{@boot_pool_name} #{@dev_boot}
68
- ")
69
- end
70
-
71
- exec("zpool create -f -o ashift=#{ashift} -o autotrim=on \\
72
- -O encryption=aes-256-gcm \\
73
- -O keylocation=prompt -O keyformat=passphrase \\
74
- -O acltype=posixacl -O canmount=off -O compression=lz4 \\
75
- -O dnodesize=auto -O normalization=formD -O atime=off \\
76
- -O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
77
- #{@pool_name} #{@dev_root}
78
- ")
79
- end
80
-
81
- def datasets
82
- exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
83
- exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
84
-
85
- exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/#{@n}")
86
- exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/#{@n}") if @dev_boot
87
-
88
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/usr")
89
- exec("zfs create #{@pool_name}/ROOT/#{@n}/usr/src")
90
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/#{@n}/var")
91
- exec("zfs create #{@pool_name}/ROOT/#{@n}/var/log")
92
- exec("zfs create #{@pool_name}/ROOT/#{@n}/var/db")
93
- exec("zfs create #{@pool_name}/ROOT/#{@n}/var/tmp")
94
-
95
- exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
96
- exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
97
- exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
98
- end
99
-
100
- def exec(cmd)
101
- Helpers.sys(cmd)
16
+ def x
17
+ Mkfs::Zfs.new(DEVS, OPTIONS)
102
18
  end
103
19
  end
104
20
  end
@@ -1,49 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mountfs'
4
+
3
5
  module Getch
4
6
  module FileSystem
5
7
  module Zfs
6
8
  module Encrypt
7
- class Mount < Device
9
+ class Mount
8
10
  def initialize
9
- super
10
- @mount = Getch::FileSystem::Mount.new
11
- @state = Getch::States.new
12
- @log = Getch::Log.new
13
- @import = '/dev/disk/by-id'
14
- end
15
-
16
- def run
17
- return if STATES[:mount]
18
-
19
- exec('zpool export -a')
20
- exec("rm -rf #{MOUNTPOINT}/*")
21
- exec("zpool import -N -d #{@import} -R #{MOUNTPOINT} #{@pool_name}")
22
- exec("zpool import -f -N -d #{@import} -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
23
- exec('zfs load-key -a')
24
- mount_root
25
- mount_boot
26
- @mount.esp(@dev_esp)
27
- exec('zfs mount -a')
28
- @state.mount
11
+ x
29
12
  end
30
13
 
31
14
  private
32
15
 
33
- def mount_root
34
- Helpers.mkdir(MOUNTPOINT)
35
- exec("zfs mount #{@pool_name}/ROOT/#{@n}")
36
- end
37
-
38
- def mount_boot
39
- return unless @dev_boot
40
-
41
- exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
42
- end
43
-
44
- def exec(cmd)
45
- @log.info("==> #{cmd}")
46
- Helpers.sys(cmd)
16
+ def x
17
+ MountFs::Zfs.new(DEVS, OPTIONS)
18
+
19
+ #exec('zpool export -a')
20
+ #exec("rm -rf #{MOUNTPOINT}/*")
21
+ #exec("zpool import -N -d #{@import} -R #{MOUNTPOINT} #{@pool_name}")
22
+ #exec("zpool import -f -N -d #{@import} -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
23
+ #exec('zfs load-key -a')
24
+ #mount_root
25
+ #mount_boot
26
+ #@mount.esp(@dev_esp)
27
+ #exec('zfs mount -a')
47
28
  end
48
29
  end
49
30
  end
@@ -1,68 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'sgdisk'
4
+
3
5
  module Getch
4
6
  module FileSystem
5
7
  module Zfs
6
8
  module Encrypt
7
- class Partition < Device
9
+ class Partition
8
10
  def initialize
9
- super
10
- @state = Getch::States.new
11
- @clean = Getch::FileSystem::Clean
12
- @partition = Getch::FileSystem::Partition.new
13
- @log = Getch::Log.new
14
- run
15
- end
16
-
17
- def run
18
- return if STATES[:partition]
19
-
20
- @clean.old_zpool
21
- @clean.hdd(@disk)
22
- @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
23
-
24
- partition
25
- cache
26
- @state.partition
11
+ x
27
12
  end
28
13
 
29
14
  private
30
15
 
31
- def partition
32
- if Helpers.efi?
33
- @partition.efi(@dev_esp)
34
- @partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
35
- @partition.swap(@dev_swap) unless @cache_disk
36
- @partition.root(@dev_root, 'BF00') if @root_part != 1
37
- else
38
- @partition.gpt(@dev_gpt)
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:BF08 /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
- @log.info("===> #{cmd}")
65
- Helpers.sys(cmd)
16
+ def x
17
+ Sgdisk::Zfs.new(DEVS)
66
18
  end
67
19
  end
68
20
  end
@@ -4,6 +4,8 @@ module Getch
4
4
  module FileSystem
5
5
  module Zfs
6
6
  module Encrypt
7
+ def self.end
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -15,4 +17,3 @@ require_relative 'encrypt/format'
15
17
  require_relative 'encrypt/mount'
16
18
  require_relative 'encrypt/config'
17
19
  require_relative 'encrypt/deps'
18
- require_relative 'encrypt/void'
@@ -0,0 +1,37 @@
1
+ require 'fstab'
2
+ require 'dracut'
3
+
4
+ module Getch
5
+ module FileSystem
6
+ module Zfs
7
+ module Minimal
8
+ class Config
9
+ def initialize
10
+ @mountpoint = OPTIONS[:mountpoint]
11
+ @zfs = OPTIONS[:zfs_name] ||= 'pool'
12
+ @os = OPTIONS[:os]
13
+ x
14
+ end
15
+
16
+ private
17
+
18
+ def x
19
+ Fstab::Zfs.new(DEVS, OPTIONS).generate
20
+ Dracut::Zfs.new(DEVS, OPTIONS).generate
21
+ grub_broken_root
22
+ end
23
+
24
+ # https://wiki.archlinux.org/title/Install_Arch_Linux_on_ZFS#Using_GRUB_for_EFI/BIOS
25
+ def grub_broken_root
26
+ return unless Helpers.grub?
27
+
28
+ file = "#{@mountpoint}/etc/default/grub"
29
+ content = "GRUB_CMDLINE_LINUX=\"$GRUB_CMDLINE_LINUX"
30
+ content << " root=ZFS=r#{@zfs}/ROOT/#{@os}\""
31
+ NiTo.echo_a file, content
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end