getch 0.1.6 → 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 (88) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +17 -26
  4. data/assets/system.conf +38 -0
  5. data/lib/cmdline.rb +128 -0
  6. data/lib/getch/command.rb +31 -21
  7. data/lib/getch/config/gentoo.rb +22 -23
  8. data/lib/getch/config/void.rb +8 -10
  9. data/lib/getch/config.rb +5 -2
  10. data/lib/getch/filesystem/clean.rb +15 -15
  11. data/lib/getch/filesystem/device.rb +3 -1
  12. data/lib/getch/filesystem/ext4/config.rb +8 -4
  13. data/lib/getch/filesystem/ext4/deps.rb +3 -1
  14. data/lib/getch/filesystem/ext4/device.rb +2 -3
  15. data/lib/getch/filesystem/ext4/encrypt/config.rb +12 -7
  16. data/lib/getch/filesystem/ext4/encrypt/deps.rb +4 -2
  17. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
  18. data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -1
  19. data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -2
  20. data/lib/getch/filesystem/ext4/encrypt/partition.rb +21 -21
  21. data/lib/getch/filesystem/ext4/encrypt/void.rb +22 -21
  22. data/lib/getch/filesystem/ext4/encrypt.rb +2 -0
  23. data/lib/getch/filesystem/ext4/format.rb +3 -0
  24. data/lib/getch/filesystem/ext4/mount.rb +3 -0
  25. data/lib/getch/filesystem/ext4/partition.rb +9 -6
  26. data/lib/getch/filesystem/ext4/void.rb +8 -7
  27. data/lib/getch/filesystem/ext4.rb +2 -0
  28. data/lib/getch/filesystem/lvm/config.rb +7 -22
  29. data/lib/getch/filesystem/lvm/deps.rb +6 -4
  30. data/lib/getch/filesystem/lvm/device.rb +2 -0
  31. data/lib/getch/filesystem/lvm/encrypt/config.rb +12 -9
  32. data/lib/getch/filesystem/lvm/encrypt/deps.rb +6 -3
  33. data/lib/getch/filesystem/lvm/encrypt/device.rb +4 -2
  34. data/lib/getch/filesystem/lvm/encrypt/format.rb +4 -0
  35. data/lib/getch/filesystem/lvm/encrypt/mount.rb +3 -0
  36. data/lib/getch/filesystem/lvm/encrypt/partition.rb +7 -7
  37. data/lib/getch/filesystem/lvm/encrypt/void.rb +20 -19
  38. data/lib/getch/filesystem/lvm/encrypt.rb +2 -0
  39. data/lib/getch/filesystem/lvm/format.rb +3 -0
  40. data/lib/getch/filesystem/lvm/mount.rb +3 -0
  41. data/lib/getch/filesystem/lvm/partition.rb +8 -5
  42. data/lib/getch/filesystem/lvm/void.rb +7 -6
  43. data/lib/getch/filesystem/lvm.rb +2 -0
  44. data/lib/getch/filesystem/mount.rb +19 -12
  45. data/lib/getch/filesystem/partition.rb +16 -8
  46. data/lib/getch/filesystem/zfs/config.rb +9 -23
  47. data/lib/getch/filesystem/zfs/deps.rb +22 -57
  48. data/lib/getch/filesystem/zfs/device.rb +3 -1
  49. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -26
  50. data/lib/getch/filesystem/zfs/encrypt/deps.rb +25 -60
  51. data/lib/getch/filesystem/zfs/encrypt/device.rb +3 -1
  52. data/lib/getch/filesystem/zfs/encrypt/format.rb +12 -8
  53. data/lib/getch/filesystem/zfs/encrypt/mount.rb +13 -8
  54. data/lib/getch/filesystem/zfs/encrypt/partition.rb +18 -15
  55. data/lib/getch/filesystem/zfs/encrypt/void.rb +23 -22
  56. data/lib/getch/filesystem/zfs/encrypt.rb +2 -0
  57. data/lib/getch/filesystem/zfs/format.rb +9 -5
  58. data/lib/getch/filesystem/zfs/mount.rb +9 -7
  59. data/lib/getch/filesystem/zfs/partition.rb +15 -12
  60. data/lib/getch/filesystem/zfs/void.rb +20 -20
  61. data/lib/getch/filesystem/zfs.rb +2 -0
  62. data/lib/getch/filesystem.rb +2 -0
  63. data/lib/getch/gentoo/boot.rb +21 -72
  64. data/lib/getch/gentoo/bootloader.rb +68 -0
  65. data/lib/getch/gentoo/chroot.rb +26 -33
  66. data/lib/getch/gentoo/config.rb +30 -26
  67. data/lib/getch/gentoo/sources.rb +55 -66
  68. data/lib/getch/gentoo/stage.rb +12 -12
  69. data/lib/getch/gentoo/use.rb +3 -7
  70. data/lib/getch/gentoo/use_flag.rb +77 -51
  71. data/lib/getch/gentoo.rb +22 -8
  72. data/lib/getch/guard.rb +50 -43
  73. data/lib/getch/helpers.rb +155 -143
  74. data/lib/getch/log.rb +7 -5
  75. data/lib/getch/options.rb +16 -14
  76. data/lib/getch/states.rb +10 -3
  77. data/lib/getch/version.rb +1 -1
  78. data/lib/getch/void/boot.rb +18 -14
  79. data/lib/getch/void/chroot.rb +20 -19
  80. data/lib/getch/void/config.rb +20 -17
  81. data/lib/getch/void/stage.rb +13 -14
  82. data/lib/getch/void.rb +7 -1
  83. data/lib/getch.rb +13 -5
  84. data.tar.gz.sig +0 -0
  85. metadata +6 -5
  86. metadata.gz.sig +0 -0
  87. data/lib/getch/filesystem/.mount.rb.swp +0 -0
  88. data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -6,57 +8,39 @@ module Getch
6
8
  def initialize
7
9
  super
8
10
  gen_uuid
9
- @root_dir = MOUNTPOINT
10
11
  @init = '/usr/lib/systemd/systemd'
11
12
  crypttab
12
13
  end
13
14
 
14
15
  def fstab
15
- file = "#{@root_dir}/etc/fstab"
16
+ file = "#{MOUNTPOINT}/etc/fstab"
16
17
  datas = data_fstab
17
18
  File.write(file, datas.join("\n"))
18
19
  end
19
20
 
20
- def systemd_boot
21
- return if ! @efi
22
- esp = '/efi'
23
- dir = "#{@root_dir}/#{esp}/loader/entries/"
24
- datas_gentoo = [
25
- 'title Gentoo Linux',
26
- 'linux /vmlinuz',
27
- 'initrd /initramfs',
28
- "options root=ZFS=#{@pool_name}/ROOT/#{@n} init=#{@init} dozfs keymap=#{Getch::OPTIONS[:keymap]}"
29
- ]
30
- File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
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
31
25
  end
32
26
 
33
27
  def crypttab
34
28
  datas = [
35
29
  "cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,discard,cipher=aes-xts-plain64:sha256,size=512"
36
30
  ]
37
- File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
38
- end
39
-
40
- # See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
41
- def grub
42
- return if @efi
43
- file = "#{@root_dir}/etc/default/grub"
44
- cmdline = [
45
- "GRUB_CMDLINE_LINUX=\"root=ZFS=#{@pool_name}/ROOT/#{@n} init=#{@init} dozfs keymap=#{Getch::OPTIONS[:keymap]}\""
46
- ]
47
- File.write("#{file}", cmdline.join("\n"), mode: 'a')
31
+ File.write("#{MOUNTPOINT}/etc/crypttab", datas.join("\n"))
48
32
  end
49
33
 
50
34
  private
51
35
 
52
36
  def gen_uuid
53
- @partuuid_swap = Helpers::partuuid(@dev_swap)
37
+ @partuuid_swap = Helpers.partuuid(@dev_swap)
54
38
  @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
55
39
  end
56
40
 
57
41
  def data_fstab
58
42
  boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
59
- swap = @dev_swap ? "/dev/mapper/cryptswap none swap sw 0 0" : ''
43
+ swap = @dev_swap ? '/dev/mapper/cryptswap none swap sw 0 0' : ''
60
44
 
61
45
  [ boot_efi, swap ]
62
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -7,91 +9,54 @@ module Getch
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
14
  zed_update_path
15
15
  end
16
16
 
17
17
  private
18
+
18
19
  def unstable_zfs
19
20
  conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
20
21
  data = [
21
- "sys-fs/zfs-kmod",
22
- "sys-fs/zfs"
22
+ 'sys-fs/zfs-kmod',
23
+ 'sys-fs/zfs'
23
24
  ]
24
- File.write(conf, data.join("\n"), mode: "w")
25
+ File.write(conf, data.join("\n"), mode: 'w')
25
26
  end
26
27
 
27
28
  def install_deps
28
- Getch::Bask.new('-a zfs').run!
29
- Getch::Make.new("make modules_prepare").run!
30
- Getch::Make.new("make -j$(nproc)").run!
31
- Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
29
+ Getch::Emerge.new('sys-kernel/gentoo-kernel').pkg!
30
+ Getch::Emerge.new('sys-fs/zfs').pkg!
32
31
  end
33
32
 
34
33
  # See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
35
34
  def zfs_mountpoint
36
- Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
37
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
38
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
39
- exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
40
- exec("systemctl start zfs-zed.service")
41
- exec("systemctl enable zfs-zed.service")
42
- 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')
43
42
  end
44
43
 
45
44
  def zed_update_path
46
- Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each { |f|
47
- if !system("sed", "-Ei", "s|#{MOUNTPOINT}/?|/|", f)
48
- raise "System exec sed"
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'
49
48
  end
50
- }
51
- end
52
-
53
- def auto_module_rebuild
54
- g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
55
- Helpers::mkdir(g_dir)
56
- # See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
57
- content=<<EOF
58
- post_pkg_postinst() {
59
- # BUG: reinstalls of a source will cause errors
60
- CURRENT_KV=$(uname -r)
61
- # Check to see if genkernel has been run previously for the running kernel and use that config
62
- if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
63
- genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
64
- elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
65
- genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
66
- else # No valid configs known
67
- genkernel all
68
- fi
69
- }
70
- EOF
71
- File.write("#{g_dir}/gentoo-sources", content)
49
+ end
72
50
  end
73
51
 
74
52
  def hostid
75
- exec "zgenhostid $(hostid)"
53
+ exec 'zgenhostid $(hostid)'
76
54
  end
77
55
 
78
- def options_make
79
- bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
80
- datas = [
81
- '',
82
- bootloader,
83
- 'INSTALL="yes"',
84
- 'MENUCONFIG="no"',
85
- 'CLEAN="yes"',
86
- 'KEYMAP="yes"',
87
- 'SAVE_CONFIG="yes"',
88
- 'MOUNTBOOT="no"',
89
- 'MRPROPER="no"',
90
- 'ZFS="yes"',
91
- 'MODULEREBUILD="yes"'
92
- ]
93
- file = "#{MOUNTPOINT}/etc/genkernel.conf"
94
- 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
95
60
  end
96
61
 
97
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,7 +7,7 @@ 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -5,11 +7,11 @@ module Getch
5
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
- @id = Helpers::pool_id(@dev_root)
14
+ @id = Helpers.pool_id(@dev_root)
13
15
  @boot_pool_name = "bpool-#{@id}"
14
16
  @pool_name = "rpool-#{@id}"
15
17
  end
@@ -20,7 +22,8 @@ module Getch
20
22
 
21
23
  def format
22
24
  return if STATES[:format]
23
- raise "Error, no id found for #{@dev_root}." if ! @id
25
+ raise "Error, no id found for #{@dev_root}." unless @id
26
+
24
27
  system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
25
28
  zfs
26
29
  datasets
@@ -29,7 +32,8 @@ module Getch
29
32
 
30
33
  def zfs
31
34
  bloc=`blockdev --getpbsz #{@dev_root}`
32
- ashift = case bloc
35
+ ashift =
36
+ case bloc
33
37
  when /8096/
34
38
  13
35
39
  when /4096/
@@ -38,7 +42,7 @@ module Getch
38
42
  9
39
43
  end
40
44
 
41
- Helpers::mkdir(MOUNTPOINT)
45
+ Helpers.mkdir(MOUNTPOINT)
42
46
 
43
47
  @log.debug("ashift found for #{bloc} - #{ashift}")
44
48
  if @dev_boot
@@ -94,7 +98,7 @@ module Getch
94
98
  end
95
99
 
96
100
  def exec(cmd)
97
- Helpers::sys(cmd)
101
+ Helpers.sys(cmd)
98
102
  end
99
103
  end
100
104
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -8,37 +10,40 @@ module Getch
8
10
  @mount = Getch::FileSystem::Mount.new
9
11
  @state = Getch::States.new
10
12
  @log = Getch::Log.new
13
+ @import = '/dev/disk/by-id'
11
14
  end
12
15
 
13
16
  def run
14
17
  return if STATES[:mount]
15
- exec("zpool export -a")
18
+
19
+ exec('zpool export -a')
16
20
  exec("rm -rf #{MOUNTPOINT}/*")
17
- exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
18
- exec("zpool import -f -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
19
- exec("zfs load-key -a")
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')
20
24
  mount_root
21
25
  mount_boot
22
26
  @mount.esp(@dev_esp)
23
- exec("zfs mount -a")
27
+ exec('zfs mount -a')
24
28
  @state.mount
25
29
  end
26
30
 
27
31
  private
28
32
 
29
33
  def mount_root
30
- Helpers::mkdir(MOUNTPOINT)
34
+ Helpers.mkdir(MOUNTPOINT)
31
35
  exec("zfs mount #{@pool_name}/ROOT/#{@n}")
32
36
  end
33
37
 
34
38
  def mount_boot
35
- return if ! @dev_boot
39
+ return unless @dev_boot
40
+
36
41
  exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
37
42
  end
38
43
 
39
44
  def exec(cmd)
40
45
  @log.info("==> #{cmd}")
41
- Helpers::sys(cmd)
46
+ Helpers.sys(cmd)
42
47
  end
43
48
  end
44
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -5,15 +7,16 @@ module Getch
5
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
21
  @clean.hdd(@disk)
19
22
  @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
@@ -26,26 +29,26 @@ module Getch
26
29
  private
27
30
 
28
31
  def partition
29
- if Helpers::efi?
32
+ if Helpers.efi?
30
33
  @partition.efi(@dev_esp)
31
34
  @partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
32
- @partition.swap(@dev_swap) if !@cache_disk
33
- @partition.root(@dev_root, "BF00") if @root_part != 1
35
+ @partition.swap(@dev_swap) unless @cache_disk
36
+ @partition.root(@dev_root, 'BF00') if @root_part != 1
34
37
  else
35
38
  @partition.gpt(@dev_gpt)
36
39
  @partition.boot(@dev_boot)
37
- @partition.swap(@dev_swap) if !@cache_disk
38
- @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
39
42
  end
40
43
  end
41
44
 
42
45
  def cache
43
- if @cache_disk
44
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
45
- exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
46
- exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
47
- exec("sgdisk -n3:0:0 -t3:BF08 /dev/#{@cache_disk}")
48
- 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}")
49
52
  end
50
53
 
51
54
  # Partition_efi
@@ -59,7 +62,7 @@ module Getch
59
62
 
60
63
  def exec(cmd)
61
64
  @log.info("===> #{cmd}")
62
- Helpers::sys(cmd)
65
+ Helpers.sys(cmd)
63
66
  end
64
67
  end
65
68
  end
@@ -1,4 +1,4 @@
1
- require_relative '../../../helpers'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Getch
4
4
  module FileSystem
@@ -6,6 +6,7 @@ module Getch
6
6
  module Encrypt
7
7
  class Void < Device
8
8
  include Helpers::Void
9
+
9
10
  attr_reader :boot_disk
10
11
 
11
12
  def initialize
@@ -23,19 +24,18 @@ module Getch
23
24
  conf = "#{MOUNTPOINT}/etc/fstab"
24
25
  File.write(conf, "\n", mode: 'w', chmod: 0644)
25
26
  line_fstab(@dev_esp, "/efi vfat noauto,rw,relatime 0 0") if @dev_esp
26
- add_line(conf, "/dev/mapper/cryptswap none swap sw 0 0")
27
+ add_line(conf, '/dev/mapper/cryptswap none swap sw 0 0')
27
28
  add_line(conf, "##{@boot_pool_name}/BOOT/#{@n} /boot zfs defaults 0 0") if @dev_boot
28
- add_line(conf, "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0")
29
+ add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
29
30
  end
30
31
 
31
32
  def config_dracut
32
33
  conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
33
34
  # dracut: value+= should be surrounding by white space
34
35
  content = [
35
- "hostonly=\"yes\"",
36
- "omit_dracutmodules+=\" btrfs lvm \"",
37
- "install_items+=\" /etc/crypttab \"",
38
- ""
36
+ 'hostonly="yes"',
37
+ 'omit_dracutmodules+=" btrfs lvm "',
38
+ 'install_items+=" /etc/crypttab "',
39
39
  ]
40
40
  File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
41
41
  end
@@ -45,17 +45,17 @@ module Getch
45
45
  end
46
46
 
47
47
  def config_grub
48
- grub_cmdline("root=zfs:#{@pool_name}/ROOT/#{@n}", "zfs_force=1")
48
+ grub_cmdline("root=zfs:#{@pool_name}/ROOT/#{@n}", 'zfs_force=1', 'zfs.zfs_arc_max=536870912')
49
49
  end
50
50
 
51
51
  def finish
52
52
  zed_update_path
53
- puts "+ Enter in your system: chroot /mnt /bin/bash"
54
- puts "+ Reboot with: shutdown -r now"
53
+ puts '+ Enter in your system: chroot /mnt /bin/bash'
54
+ puts '+ Reboot with: shutdown -r now'
55
55
  end
56
56
 
57
57
  def crypttab
58
- line_crypttab("cryptswap", @dev_swap, "/dev/urandom", "swap,discard,cipher=aes-xts-plain64:sha256,size=512")
58
+ line_crypttab('cryptswap', @dev_swap, '/dev/urandom', 'swap,discard,cipher=aes-xts-plain64:sha256,size=512')
59
59
  end
60
60
 
61
61
  private
@@ -63,31 +63,32 @@ module Getch
63
63
  def line_crypttab(mapname, dev, point, rest)
64
64
  conf = "#{MOUNTPOINT}/etc/crypttab"
65
65
  device = s_uuid(dev)
66
- raise "No partuuid for #{dev} #{device}" if !device
66
+ raise "No partuuid for #{dev} #{device}" unless device
67
67
  raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
68
+
68
69
  add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
69
70
  end
70
71
 
71
72
  def zfs_zed
72
- service_dir = "/etc/runit/runsvdir/default/"
73
+ service_dir = '/etc/runit/runsvdir/default/'
73
74
 
74
- Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
75
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
76
- Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
77
- fork { command "/etc/sv/zed/run" }
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' }
78
79
  command "ln -fs /etc/sv/zed #{service_dir}"
79
80
  end
80
81
 
81
82
  def zed_update_path
82
- Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each { |f|
83
- if !system("sed", "-Ei", "s|#{MOUNTPOINT}/?|/|", f)
84
- raise "System exec sed"
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'
85
86
  end
86
- }
87
+ end
87
88
  end
88
89
 
89
90
  def hostid
90
- command "zgenhostid $(hostid)"
91
+ command 'zgenhostid $(hostid)'
91
92
  end
92
93
  end
93
94
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -6,9 +8,9 @@ module Getch
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
- @id = Helpers::pool_id(@dev_root)
13
+ @id = Helpers.pool_id(@dev_root)
12
14
  @boot_pool_name = "bpool-#{@id}"
13
15
  @pool_name = "rpool-#{@id}"
14
16
  end
@@ -19,7 +21,8 @@ module Getch
19
21
 
20
22
  def format
21
23
  return if STATES[:format]
22
- raise "Error, no id found for #{@dev_root}." if ! @id
24
+ raise "Error, no id found for #{@dev_root}." unless @id
25
+
23
26
  @log.info "Create #{@id} for #{@pool_name}"
24
27
  system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
25
28
  zfs
@@ -30,7 +33,8 @@ module Getch
30
33
 
31
34
  def zfs
32
35
  bloc=`blockdev --getpbsz #{@dev_root}`
33
- ashift = case bloc
36
+ ashift =
37
+ case bloc
34
38
  when /8096/
35
39
  13
36
40
  when /4096/
@@ -39,7 +43,7 @@ module Getch
39
43
  9
40
44
  end
41
45
 
42
- Helpers::mkdir(MOUNTPOINT)
46
+ Helpers.mkdir(MOUNTPOINT)
43
47
  @log.debug("ashift found for #{bloc} - #{ashift}")
44
48
 
45
49
  if @dev_boot
@@ -7,37 +7,39 @@ module Getch
7
7
  @mount = Getch::FileSystem::Mount.new
8
8
  @state = Getch::States.new
9
9
  @log = Getch::Log.new
10
+ @import = '/dev/disk/by-id'
10
11
  end
11
12
 
12
13
  def run
13
14
  return if STATES[:mount]
14
- exec("zpool export -a")
15
+ exec('zpool export -a')
15
16
  exec("rm -rf #{MOUNTPOINT}/*")
16
- exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
17
- exec("zpool import -f -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
18
19
  @mount.swap(@dev_swap)
19
20
  mount_root
20
21
  mount_boot
21
22
  @mount.esp(@dev_esp)
22
- exec("zfs mount -a")
23
+ exec('zfs mount -a')
23
24
  @state.mount
24
25
  end
25
26
 
26
27
  private
27
28
 
28
29
  def mount_root
29
- Helpers::mkdir(MOUNTPOINT)
30
+ Helpers.mkdir(MOUNTPOINT)
30
31
  exec("zfs mount #{@pool_name}/ROOT/#{@n}")
31
32
  end
32
33
 
33
34
  def mount_boot
34
- return if ! @dev_boot
35
+ return unless @dev_boot
36
+
35
37
  exec("zfs mount #{@boot_pool_name}/BOOT/#{@n}")
36
38
  end
37
39
 
38
40
  def exec(cmd)
39
41
  @log.info("==> #{cmd}")
40
- Helpers::sys(cmd)
42
+ Helpers.sys(cmd)
41
43
  end
42
44
  end
43
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -6,13 +8,14 @@ module Getch
6
8
  super
7
9
  @clean = Getch::FileSystem::Clean
8
10
  @partition = Getch::FileSystem::Partition.new
9
- @state = Getch::States.new()
10
- @log = Getch::Log.new()
11
+ @state = Getch::States.new
12
+ @log = Getch::Log.new
11
13
  run_partition
12
14
  end
13
15
 
14
16
  def run_partition
15
17
  return if STATES[:partition ]
18
+
16
19
  @clean.old_zpool
17
20
  @clean.hdd(@disk)
18
21
  @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
@@ -28,24 +31,24 @@ module Getch
28
31
  if @efi
29
32
  @partition.efi(@dev_esp)
30
33
  @partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
31
- @partition.swap(@dev_swap) if !@cache_disk
32
- @partition.root(@dev_root, "BF00") if @root_part != 1
34
+ @partition.swap(@dev_swap) unless @cache_disk
35
+ @partition.root(@dev_root, 'BF00') if @root_part != 1
33
36
  else
34
37
  @partition.gpt(@dev_gpt)
35
38
  # Boot pool for GRUB2
36
39
  @partition.boot(@dev_boot)
37
- @partition.swap(@dev_swap) if !@cache_disk
38
- @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
39
42
  end
40
43
  end
41
44
 
42
45
  def cache
43
- if @cache_disk
44
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
45
- exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
46
- exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
47
- exec("sgdisk -n3:0:0 -t3:BF00 /dev/#{@cache_disk}")
48
- 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:BF00 /dev/#{@cache_disk}")
49
52
  end
50
53
 
51
54
  # Partition_efi