getch 0.1.2 → 0.1.9

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 (93) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +66 -32
  4. data/assets/network-stack.conf +63 -0
  5. data/assets/system.conf +38 -0
  6. data/bin/getch +12 -4
  7. data/lib/cmdline.rb +128 -0
  8. data/lib/getch/command.rb +32 -22
  9. data/lib/getch/config/gentoo.rb +58 -0
  10. data/lib/getch/config/void.rb +47 -0
  11. data/lib/getch/config.rb +45 -0
  12. data/lib/getch/filesystem/clean.rb +22 -15
  13. data/lib/getch/filesystem/device.rb +8 -6
  14. data/lib/getch/filesystem/ext4/config.rb +8 -4
  15. data/lib/getch/filesystem/ext4/deps.rb +3 -1
  16. data/lib/getch/filesystem/ext4/device.rb +2 -3
  17. data/lib/getch/filesystem/ext4/encrypt/config.rb +15 -11
  18. data/lib/getch/filesystem/ext4/encrypt/deps.rb +5 -10
  19. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
  20. data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -2
  21. data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -3
  22. data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -35
  23. data/lib/getch/filesystem/ext4/encrypt/void.rb +101 -0
  24. data/lib/getch/filesystem/ext4/encrypt.rb +3 -0
  25. data/lib/getch/filesystem/ext4/format.rb +4 -1
  26. data/lib/getch/filesystem/ext4/mount.rb +3 -0
  27. data/lib/getch/filesystem/ext4/partition.rb +11 -8
  28. data/lib/getch/filesystem/ext4/void.rb +44 -0
  29. data/lib/getch/filesystem/ext4.rb +3 -0
  30. data/lib/getch/filesystem/lvm/config.rb +10 -29
  31. data/lib/getch/filesystem/lvm/deps.rb +7 -11
  32. data/lib/getch/filesystem/lvm/device.rb +5 -3
  33. data/lib/getch/filesystem/lvm/encrypt/config.rb +17 -17
  34. data/lib/getch/filesystem/lvm/encrypt/deps.rb +8 -12
  35. data/lib/getch/filesystem/lvm/encrypt/device.rb +7 -5
  36. data/lib/getch/filesystem/lvm/encrypt/format.rb +5 -2
  37. data/lib/getch/filesystem/lvm/encrypt/mount.rb +4 -2
  38. data/lib/getch/filesystem/lvm/encrypt/partition.rb +17 -13
  39. data/lib/getch/filesystem/lvm/encrypt/void.rb +101 -0
  40. data/lib/getch/filesystem/lvm/encrypt.rb +3 -0
  41. data/lib/getch/filesystem/lvm/format.rb +4 -1
  42. data/lib/getch/filesystem/lvm/mount.rb +3 -0
  43. data/lib/getch/filesystem/lvm/partition.rb +10 -7
  44. data/lib/getch/filesystem/lvm/void.rb +46 -0
  45. data/lib/getch/filesystem/lvm.rb +3 -0
  46. data/lib/getch/filesystem/mount.rb +19 -12
  47. data/lib/getch/filesystem/partition.rb +19 -11
  48. data/lib/getch/filesystem/zfs/config.rb +10 -24
  49. data/lib/getch/filesystem/zfs/deps.rb +28 -58
  50. data/lib/getch/filesystem/zfs/device.rb +9 -1
  51. data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -28
  52. data/lib/getch/filesystem/zfs/encrypt/deps.rb +29 -60
  53. data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -1
  54. data/lib/getch/filesystem/zfs/encrypt/format.rb +24 -22
  55. data/lib/getch/filesystem/zfs/encrypt/mount.rb +15 -14
  56. data/lib/getch/filesystem/zfs/encrypt/partition.rb +24 -18
  57. data/lib/getch/filesystem/zfs/encrypt/void.rb +97 -0
  58. data/lib/getch/filesystem/zfs/encrypt.rb +3 -0
  59. data/lib/getch/filesystem/zfs/format.rb +21 -18
  60. data/lib/getch/filesystem/zfs/mount.rb +12 -13
  61. data/lib/getch/filesystem/zfs/partition.rb +20 -15
  62. data/lib/getch/filesystem/zfs/void.rb +81 -0
  63. data/lib/getch/filesystem/zfs.rb +3 -0
  64. data/lib/getch/filesystem.rb +2 -0
  65. data/lib/getch/gentoo/boot.rb +29 -67
  66. data/lib/getch/gentoo/bootloader.rb +68 -0
  67. data/lib/getch/gentoo/chroot.rb +26 -29
  68. data/lib/getch/gentoo/config.rb +69 -31
  69. data/lib/getch/gentoo/sources.rb +73 -38
  70. data/lib/getch/gentoo/stage.rb +12 -13
  71. data/lib/getch/gentoo/use.rb +39 -0
  72. data/lib/getch/gentoo/use_flag.rb +89 -0
  73. data/lib/getch/gentoo.rb +39 -21
  74. data/lib/getch/guard.rb +71 -0
  75. data/lib/getch/helpers.rb +180 -48
  76. data/lib/getch/log.rb +10 -7
  77. data/lib/getch/options.rb +50 -41
  78. data/lib/getch/states.rb +10 -3
  79. data/lib/getch/version.rb +1 -1
  80. data/lib/getch/void/boot.rb +84 -0
  81. data/lib/getch/void/chroot.rb +56 -0
  82. data/lib/getch/void/config.rb +90 -0
  83. data/lib/getch/void/stage.rb +69 -0
  84. data/lib/getch/void.rb +65 -0
  85. data/lib/getch.rb +125 -74
  86. data.tar.gz.sig +0 -0
  87. metadata +28 -10
  88. metadata.gz.sig +0 -0
  89. data/.gitignore +0 -2
  90. data/CHANGELOG.md +0 -80
  91. data/Rakefile +0 -21
  92. data/bin/setup.sh +0 -90
  93. data/getch.gemspec +0 -25
@@ -1,93 +1,62 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
4
6
  module Encrypt
5
- class Deps < Getch::FileSystem::Zfs::Encrypt::Device
7
+ class Deps < Device
6
8
  def make
7
9
  unstable_zfs
8
10
  install_deps
9
11
  zfs_mountpoint
10
- auto_module_rebuild
11
12
  hostid
12
- options_make
13
- Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
13
+ config_dracut
14
+ zed_update_path
14
15
  end
15
16
 
16
17
  private
18
+
17
19
  def unstable_zfs
18
20
  conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
19
21
  data = [
20
- "sys-fs/zfs-kmod",
21
- "sys-fs/zfs"
22
+ 'sys-fs/zfs-kmod',
23
+ 'sys-fs/zfs'
22
24
  ]
23
- File.write(conf, data.join("\n"), mode: "w")
25
+ File.write(conf, data.join("\n"), mode: 'w')
24
26
  end
25
27
 
26
28
  def install_deps
27
- exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
28
- exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
29
- exec("euse -E cryptsetup") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /cryptsetup/)
30
- Getch::Bask.new('-a zfs').run!
31
- Getch::Make.new("make modules_prepare").run!
32
- Getch::Make.new("make -j$(nproc)").run!
33
- Getch::Emerge.new('genkernel sys-fs/zfs sys-apps/systemd sys-fs/cryptsetup').pkg!
29
+ Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
30
+ Getch::Emerge.new('sys-fs/zfs').pkg!
34
31
  end
35
32
 
36
33
  # See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
37
34
  def zfs_mountpoint
38
- Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
39
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
40
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
41
- exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
42
- exec("systemctl start zfs-zed.service")
43
- Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
44
- exec("systemctl enable zfs-zed.service")
45
- exec("systemctl enable zfs.target")
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')
46
42
  end
47
43
 
48
- def auto_module_rebuild
49
- g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
50
- Helpers::mkdir(g_dir)
51
- # See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
52
- content=<<EOF
53
- post_pkg_postinst() {
54
- # BUG: reinstalls of a source will cause errors
55
- CURRENT_KV=$(uname -r)
56
- # Check to see if genkernel has been run previously for the running kernel and use that config
57
- if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
58
- genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
59
- elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
60
- genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
61
- else # No valid configs known
62
- genkernel all
63
- fi
64
- }
65
- EOF
66
- File.write("#{g_dir}/gentoo-sources", content)
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
49
+ end
67
50
  end
68
51
 
69
52
  def hostid
70
- hostid_value=`hostid`.chomp
71
- File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
53
+ exec 'zgenhostid $(hostid)'
72
54
  end
73
55
 
74
- def options_make
75
- bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
76
- datas = [
77
- '',
78
- bootloader,
79
- 'INSTALL="yes"',
80
- 'MENUCONFIG="no"',
81
- 'CLEAN="yes"',
82
- 'KEYMAP="yes"',
83
- 'SAVE_CONFIG="yes"',
84
- 'MOUNTBOOT="no"',
85
- 'MRPROPER="no"',
86
- 'ZFS="yes"',
87
- 'MODULEREBUILD="yes"'
88
- ]
89
- file = "#{MOUNTPOINT}/etc/genkernel.conf"
90
- File.write(file, datas.join("\n"), mode: 'a')
56
+ def config_dracut
57
+ conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
58
+ content = 'hostonly="yes"'
59
+ Helpers.echo conf, content
91
60
  end
92
61
 
93
62
  def exec(cmd)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -5,10 +7,11 @@ module Getch
5
7
  class Device < Getch::FileSystem::Device
6
8
  def initialize
7
9
  super
8
- @id = Helpers::pool_id(@dev_root)
10
+ @id = Helpers.pool_id(@dev_root)
9
11
  @boot_pool_name = "bpool-#{@id}"
10
12
  @pool_name = "rpool-#{@id}"
11
13
  @zfs_home = @user ? true : false
14
+ @n = Getch::OPTIONS[:os]
12
15
  end
13
16
 
14
17
  private
@@ -17,9 +20,14 @@ module Getch
17
20
  if @efi
18
21
  if @boot_disk
19
22
  @dev_esp = "/dev/#{@boot_disk}1"
23
+ @dev_boot = "/dev/#{@boot_disk}2" if Getch::OPTIONS[:os] == 'void'
20
24
  else
21
25
  @dev_esp = "/dev/#{@disk}1"
22
26
  @root_part += 1
27
+ if Getch::OPTIONS[:os] == 'void'
28
+ @dev_boot = "/dev/#{@disk}#{@root_part}"
29
+ @root_part += 1
30
+ end
23
31
  end
24
32
  else
25
33
  if @boot_disk
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
4
6
  module Encrypt
5
- class Format < Getch::FileSystem::Zfs::Encrypt::Device
7
+ class Format < Device
6
8
  def initialize
7
9
  super
8
- @log = Getch::Log.new()
9
- @state = Getch::States.new()
10
- if ! @id
10
+ @log = Getch::Log.new
11
+ @state = Getch::States.new
12
+ unless @id
11
13
  @log.info "Research pool id for #{@dev_root}..."
12
- sleep 2 until Helpers::pool_id(@dev_root)
13
- @id = Helpers::pool_id(@dev_root)
14
+ @id = Helpers.pool_id(@dev_root)
14
15
  @boot_pool_name = "bpool-#{@id}"
15
16
  @pool_name = "rpool-#{@id}"
16
17
  end
@@ -21,26 +22,27 @@ module Getch
21
22
 
22
23
  def format
23
24
  return if STATES[:format]
24
- raise "Error, no id found for #{@dev_root}." if ! @id
25
+ raise "Error, no id found for #{@dev_root}." unless @id
26
+
25
27
  system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
26
- system("mkswap -f #{@dev_swap}")
27
28
  zfs
28
29
  datasets
29
30
  @state.format
30
31
  end
31
32
 
32
33
  def zfs
33
- bloc=`blockdev --getbsz #{@dev_root}`.chomp
34
- ashift = case bloc
35
- when 8096
34
+ bloc=`blockdev --getpbsz #{@dev_root}`
35
+ ashift =
36
+ case bloc
37
+ when /8096/
36
38
  13
37
- when 4096
39
+ when /4096/
38
40
  12
39
41
  else # 512
40
42
  9
41
43
  end
42
44
 
43
- Helpers::mkdir(MOUNTPOINT)
45
+ Helpers.mkdir(MOUNTPOINT)
44
46
 
45
47
  @log.debug("ashift found for #{bloc} - #{ashift}")
46
48
  if @dev_boot
@@ -80,15 +82,15 @@ module Getch
80
82
  exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
81
83
  exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
82
84
 
83
- exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
84
- exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
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
85
87
 
86
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
87
- exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
88
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
89
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
90
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
91
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
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")
92
94
 
93
95
  exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
94
96
  exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
@@ -96,7 +98,7 @@ module Getch
96
98
  end
97
99
 
98
100
  def exec(cmd)
99
- Helpers::sys(cmd)
101
+ Helpers.sys(cmd)
100
102
  end
101
103
  end
102
104
  end
@@ -1,48 +1,49 @@
1
- require 'fileutils'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Getch
4
4
  module FileSystem
5
5
  module Zfs
6
6
  module Encrypt
7
- class Mount < Getch::FileSystem::Zfs::Encrypt::Device
7
+ class Mount < Device
8
8
  def initialize
9
9
  super
10
- @root_dir = MOUNTPOINT
11
10
  @mount = Getch::FileSystem::Mount.new
12
11
  @state = Getch::States.new
13
12
  @log = Getch::Log.new
13
+ @import = '/dev/disk/by-id'
14
14
  end
15
15
 
16
16
  def run
17
17
  return if STATES[:mount]
18
- exec("zpool export -a")
18
+
19
+ exec('zpool export -a')
19
20
  exec("rm -rf #{MOUNTPOINT}/*")
20
- exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
21
- exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
22
- exec("zfs load-key -a")
23
- @mount.swap(@dev_swap)
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
24
  mount_root
25
25
  mount_boot
26
26
  @mount.esp(@dev_esp)
27
- exec("zfs mount -a")
27
+ exec('zfs mount -a')
28
28
  @state.mount
29
29
  end
30
30
 
31
31
  private
32
32
 
33
33
  def mount_root
34
- Helpers::mkdir(@root_dir)
35
- exec("zfs mount #{@pool_name}/ROOT/gentoo")
34
+ Helpers.mkdir(MOUNTPOINT)
35
+ exec("zfs mount #{@pool_name}/ROOT/#{@n}")
36
36
  end
37
37
 
38
38
  def mount_boot
39
- return if ! @dev_boot
40
- exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
39
+ return unless @dev_boot
40
+
41
+ exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
41
42
  end
42
43
 
43
44
  def exec(cmd)
44
45
  @log.info("==> #{cmd}")
45
- Helpers::sys(cmd)
46
+ Helpers.sys(cmd)
46
47
  end
47
48
  end
48
49
  end
@@ -1,22 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
4
6
  module Encrypt
5
- class Partition < Getch::FileSystem::Zfs::Encrypt::Device
7
+ class Partition < Device
6
8
  def initialize
7
9
  super
8
- @state = Getch::States.new()
10
+ @state = Getch::States.new
9
11
  @clean = Getch::FileSystem::Clean
10
12
  @partition = Getch::FileSystem::Partition.new
11
- @log = Getch::Log.new()
13
+ @log = Getch::Log.new
12
14
  run
13
15
  end
14
16
 
15
17
  def run
16
- return if STATES[:partition ]
18
+ return if STATES[:partition]
19
+
17
20
  @clean.old_zpool
18
- @clean.struct(@disk, @cache_disk, @home_disk)
19
- @clean.hdd(@disk, @cache_disk, @home_disk)
21
+ @clean.hdd(@disk)
22
+ @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
23
+
20
24
  partition
21
25
  cache
22
26
  @state.partition
@@ -25,25 +29,26 @@ module Getch
25
29
  private
26
30
 
27
31
  def partition
28
- if Helpers::efi?
32
+ if Helpers.efi?
29
33
  @partition.efi(@dev_esp)
30
- @partition.swap(@dev_swap)
31
- @partition.root(@dev_root, "BF00") if @root_part != 1
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
32
37
  else
33
38
  @partition.gpt(@dev_gpt)
34
39
  @partition.boot(@dev_boot)
35
- @partition.swap(@dev_swap)
36
- @partition.root(@dev_root, "BF00") if @root_part != 1
40
+ @partition.swap(@dev_swap) unless @cache_disk
41
+ @partition.root(@dev_root, 'BF00') if @root_part != 1
37
42
  end
38
43
  end
39
44
 
40
45
  def cache
41
- if @dev_log
42
- exec("sgdisk -n2:0:+4G -t2:BF07 #{cache_disk}")
43
- end
44
- if @dev_cache
45
- exec("sgdisk -n3:0:0 -t3:BF08 #{cache_disk}")
46
- end
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}")
47
52
  end
48
53
 
49
54
  # Partition_efi
@@ -56,7 +61,8 @@ module Getch
56
61
  # / - Root
57
62
 
58
63
  def exec(cmd)
59
- Helpers::sys(cmd)
64
+ @log.info("===> #{cmd}")
65
+ Helpers.sys(cmd)
60
66
  end
61
67
  end
62
68
  end
@@ -0,0 +1,97 @@
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -13,3 +15,4 @@ require_relative 'encrypt/format'
13
15
  require_relative 'encrypt/mount'
14
16
  require_relative 'encrypt/config'
15
17
  require_relative 'encrypt/deps'
18
+ require_relative 'encrypt/void'
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
4
- class Format < Getch::FileSystem::Zfs::Device
6
+ class Format < Device
5
7
  def initialize
6
8
  super
7
9
  @log = Getch::Log.new
8
10
  @state = Getch::States.new
9
- if ! @id
11
+ unless @id
10
12
  @log.info "Research pool id for #{@dev_root}..."
11
- sleep 2 until Helpers::pool_id(@dev_root)
12
- @id = Helpers::pool_id(@dev_root)
13
+ @id = Helpers.pool_id(@dev_root)
13
14
  @boot_pool_name = "bpool-#{@id}"
14
15
  @pool_name = "rpool-#{@id}"
15
16
  end
@@ -20,7 +21,8 @@ module Getch
20
21
 
21
22
  def format
22
23
  return if STATES[:format]
23
- raise "Error, no id found for #{@dev_root}." if ! @id
24
+ raise "Error, no id found for #{@dev_root}." unless @id
25
+
24
26
  @log.info "Create #{@id} for #{@pool_name}"
25
27
  system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
26
28
  zfs
@@ -30,17 +32,18 @@ module Getch
30
32
  end
31
33
 
32
34
  def zfs
33
- bloc=`blockdev --getbsz #{@dev_root}`.chomp
34
- ashift = case bloc
35
- when 8096
35
+ bloc=`blockdev --getpbsz #{@dev_root}`
36
+ ashift =
37
+ case bloc
38
+ when /8096/
36
39
  13
37
- when 4096
40
+ when /4096/
38
41
  12
39
42
  else # 512
40
43
  9
41
44
  end
42
45
 
43
- Helpers::mkdir(MOUNTPOINT)
46
+ Helpers.mkdir(MOUNTPOINT)
44
47
  @log.debug("ashift found for #{bloc} - #{ashift}")
45
48
 
46
49
  if @dev_boot
@@ -88,15 +91,15 @@ module Getch
88
91
  exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
89
92
  exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
90
93
 
91
- exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
92
- exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
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
93
96
 
94
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
95
- exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
96
- exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
97
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
98
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
99
- exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
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")
100
103
 
101
104
  exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
102
105
  exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
@@ -1,46 +1,45 @@
1
- require 'fileutils'
2
-
3
1
  module Getch
4
2
  module FileSystem
5
3
  module Zfs
6
- class Mount < Getch::FileSystem::Zfs::Device
4
+ class Mount < Device
7
5
  def initialize
8
6
  super
9
- @root_dir = MOUNTPOINT
10
7
  @mount = Getch::FileSystem::Mount.new
11
8
  @state = Getch::States.new
12
9
  @log = Getch::Log.new
10
+ @import = '/dev/disk/by-id'
13
11
  end
14
12
 
15
13
  def run
16
14
  return if STATES[:mount]
17
- exec("zpool export -a")
15
+ exec('zpool export -a')
18
16
  exec("rm -rf #{MOUNTPOINT}/*")
19
- exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
20
- exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
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
21
19
  @mount.swap(@dev_swap)
22
20
  mount_root
23
21
  mount_boot
24
22
  @mount.esp(@dev_esp)
25
- exec("zfs mount -a")
23
+ exec('zfs mount -a')
26
24
  @state.mount
27
25
  end
28
26
 
29
27
  private
30
28
 
31
29
  def mount_root
32
- Helpers::mkdir(@root_dir)
33
- exec("zfs mount #{@pool_name}/ROOT/gentoo")
30
+ Helpers.mkdir(MOUNTPOINT)
31
+ exec("zfs mount #{@pool_name}/ROOT/#{@n}")
34
32
  end
35
33
 
36
34
  def mount_boot
37
- return if ! @dev_boot
38
- exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
35
+ return unless @dev_boot
36
+
37
+ exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
39
38
  end
40
39
 
41
40
  def exec(cmd)
42
41
  @log.info("==> #{cmd}")
43
- Helpers::sys(cmd)
42
+ Helpers.sys(cmd)
44
43
  end
45
44
  end
46
45
  end