getch 0.1.0 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +95 -22
- data/assets/network-stack.conf +63 -0
- data/bin/getch +12 -4
- data/lib/getch.rb +116 -66
- data/lib/getch/command.rb +19 -5
- data/lib/getch/config.rb +42 -0
- data/lib/getch/config/gentoo.rb +59 -0
- data/lib/getch/config/void.rb +49 -0
- data/lib/getch/filesystem.rb +5 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/clean.rb +58 -0
- data/lib/getch/filesystem/device.rb +61 -0
- data/lib/getch/filesystem/ext4.rb +1 -0
- data/lib/getch/filesystem/ext4/config.rb +8 -9
- data/lib/getch/filesystem/ext4/device.rb +2 -7
- data/lib/getch/filesystem/ext4/encrypt.rb +1 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +8 -9
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +3 -19
- data/lib/getch/filesystem/ext4/encrypt/device.rb +3 -8
- data/lib/getch/filesystem/ext4/encrypt/format.rb +3 -6
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +5 -43
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -54
- data/lib/getch/filesystem/ext4/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/ext4/format.rb +4 -6
- data/lib/getch/filesystem/ext4/mount.rb +7 -46
- data/lib/getch/filesystem/ext4/partition.rb +16 -39
- data/lib/getch/filesystem/ext4/void.rb +43 -0
- data/lib/getch/filesystem/lvm.rb +1 -0
- data/lib/getch/filesystem/lvm/config.rb +11 -15
- data/lib/getch/filesystem/lvm/deps.rb +4 -19
- data/lib/getch/filesystem/lvm/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt.rb +1 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +4 -21
- data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -4
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -47
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +30 -38
- data/lib/getch/filesystem/lvm/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/lvm/format.rb +12 -8
- data/lib/getch/filesystem/lvm/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/partition.rb +19 -31
- data/lib/getch/filesystem/lvm/void.rb +45 -0
- data/lib/getch/filesystem/mount.rb +56 -0
- data/lib/getch/filesystem/partition.rb +77 -0
- data/lib/getch/filesystem/zfs.rb +1 -0
- data/lib/getch/filesystem/zfs/config.rb +7 -8
- data/lib/getch/filesystem/zfs/deps.rb +24 -12
- data/lib/getch/filesystem/zfs/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt.rb +1 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +11 -11
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +24 -14
- data/lib/getch/filesystem/zfs/encrypt/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt/format.rb +84 -3
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +8 -28
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +26 -109
- data/lib/getch/filesystem/zfs/encrypt/void.rb +96 -0
- data/lib/getch/filesystem/zfs/format.rb +97 -4
- data/lib/getch/filesystem/zfs/mount.rb +10 -32
- data/lib/getch/filesystem/zfs/partition.rb +25 -106
- data/lib/getch/filesystem/zfs/void.rb +81 -0
- data/lib/getch/gentoo.rb +20 -16
- data/lib/getch/gentoo/boot.rb +24 -16
- data/lib/getch/gentoo/chroot.rb +16 -25
- data/lib/getch/gentoo/config.rb +67 -15
- data/lib/getch/gentoo/sources.rb +55 -13
- data/lib/getch/gentoo/stage.rb +0 -1
- data/lib/getch/gentoo/use.rb +43 -0
- data/lib/getch/gentoo/use_flag.rb +63 -0
- data/lib/getch/guard.rb +64 -0
- data/lib/getch/helpers.rb +133 -0
- data/lib/getch/log.rb +3 -2
- data/lib/getch/options.rb +46 -24
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void.rb +59 -0
- data/lib/getch/void/boot.rb +80 -0
- data/lib/getch/void/chroot.rb +55 -0
- data/lib/getch/void/config.rb +87 -0
- data/lib/getch/void/stage.rb +70 -0
- metadata +46 -25
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -60
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
|
@@ -1,60 +1,20 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
|
|
3
1
|
module Getch
|
|
4
2
|
module FileSystem
|
|
5
3
|
module Lvm
|
|
6
4
|
module Encrypt
|
|
7
|
-
class Mount <
|
|
5
|
+
class Mount < Device
|
|
8
6
|
def initialize
|
|
9
7
|
super
|
|
10
|
-
@
|
|
11
|
-
@
|
|
12
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
|
13
|
-
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
|
14
|
-
@state = Getch::States.new()
|
|
8
|
+
@mount = Getch::FileSystem::Mount.new
|
|
9
|
+
@state = Getch::States.new
|
|
15
10
|
end
|
|
16
11
|
|
|
17
12
|
def run
|
|
18
13
|
return if STATES[:mount]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
mount_boot_efi
|
|
24
|
-
@state.mount
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def mount_swap
|
|
30
|
-
return if ! @lv_swap
|
|
31
|
-
system("swapon #{@lv_swap}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def mount_root
|
|
35
|
-
return if ! @lv_root
|
|
36
|
-
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
|
37
|
-
system("mount #{@lv_root} #{@root_dir}")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def mount_boot_efi
|
|
41
|
-
return if ! @dev_boot_efi
|
|
42
|
-
FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
|
|
43
|
-
system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def mount_boot
|
|
47
|
-
return if ! @dev_boot
|
|
48
|
-
FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
|
|
49
|
-
system("mount #{@dev_boot} #{@boot_dir}")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def mount_home
|
|
53
|
-
return if ! @lv_home
|
|
54
|
-
if @user != nil then
|
|
55
|
-
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
|
56
|
-
system("mount #{@lv_home} #{@home_dir}")
|
|
57
|
-
end
|
|
14
|
+
@mount.root(@lv_root)
|
|
15
|
+
@mount.boot(@dev_boot)
|
|
16
|
+
@mount.esp(@dev_esp)
|
|
17
|
+
@mount.home(@lv_home)
|
|
58
18
|
@state.mount
|
|
59
19
|
end
|
|
60
20
|
end
|
|
@@ -1,64 +1,50 @@
|
|
|
1
|
+
require_relative '../../../helpers'
|
|
2
|
+
|
|
1
3
|
module Getch
|
|
2
4
|
module FileSystem
|
|
3
5
|
module Lvm
|
|
4
6
|
module Encrypt
|
|
5
|
-
class Partition <
|
|
7
|
+
class Partition < Device
|
|
8
|
+
include Helpers::Cryptsetup
|
|
9
|
+
|
|
6
10
|
def initialize
|
|
7
11
|
super
|
|
8
12
|
@state = Getch::States.new()
|
|
13
|
+
@clean = Getch::FileSystem::Clean
|
|
14
|
+
@partition = Getch::FileSystem::Partition.new
|
|
9
15
|
@log = Log.new
|
|
10
16
|
run_partition
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
def run_partition
|
|
14
20
|
return if STATES[:partition ]
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
@clean.old_vg(@dev_root, @vg)
|
|
22
|
+
@clean.hdd(@disk)
|
|
23
|
+
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
24
|
+
|
|
17
25
|
partition
|
|
18
|
-
|
|
26
|
+
encrypting
|
|
19
27
|
lvm
|
|
20
28
|
@state.partition
|
|
21
29
|
end
|
|
22
30
|
|
|
23
31
|
private
|
|
24
32
|
|
|
25
|
-
def clear_struct
|
|
26
|
-
oldvg = `vgdisplay | grep #{@vg}`.chomp
|
|
27
|
-
exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
|
|
28
|
-
exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
|
|
29
|
-
|
|
30
|
-
exec("sgdisk -Z /dev/#{@disk}")
|
|
31
|
-
exec("wipefs -a /dev/#{@disk}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def cleaning
|
|
35
|
-
puts
|
|
36
|
-
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
|
37
|
-
case gets.chomp
|
|
38
|
-
when /^y|^Y/
|
|
39
|
-
bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
|
40
|
-
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
|
|
41
|
-
else
|
|
42
|
-
return
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
33
|
def partition
|
|
47
34
|
if Helpers::efi?
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
@partition.efi(@dev_esp)
|
|
36
|
+
@partition.root(@dev_root, "8e00")
|
|
50
37
|
else
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
@partition.gpt(@dev_gpt)
|
|
39
|
+
@partition.boot(@dev_boot)
|
|
40
|
+
@partition.root(@dev_root, "8e00")
|
|
54
41
|
end
|
|
55
42
|
end
|
|
56
43
|
|
|
57
|
-
def
|
|
58
|
-
@log.info("
|
|
59
|
-
|
|
60
|
-
@
|
|
61
|
-
Helpers::sys("cryptsetup open --type luks #{@dev_root} cryptroot")
|
|
44
|
+
def encrypting
|
|
45
|
+
@log.info("Cryptsetup")
|
|
46
|
+
encrypt(@dev_root)
|
|
47
|
+
open_crypt(@dev_root, "cryptroot")
|
|
62
48
|
end
|
|
63
49
|
|
|
64
50
|
def lvm
|
|
@@ -66,15 +52,21 @@ module Getch
|
|
|
66
52
|
exec("pvcreate -f #{@luks_root}")
|
|
67
53
|
exec("vgcreate -f #{@vg} #{@luks_root}")
|
|
68
54
|
# Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
|
|
69
|
-
exec("lvcreate -y -Wy -Zy -L 15G -n root #{@vg}")
|
|
70
55
|
exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
|
|
71
|
-
|
|
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
|
+
|
|
72
64
|
exec("vgchange --available y")
|
|
73
65
|
end
|
|
74
66
|
|
|
75
67
|
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
76
68
|
# Partition_efi
|
|
77
|
-
# /
|
|
69
|
+
# /efi - EFI system partition - 260MB
|
|
78
70
|
# / - Root
|
|
79
71
|
|
|
80
72
|
# Partition_bios
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require_relative '../../../helpers'
|
|
2
|
+
|
|
3
|
+
module Getch
|
|
4
|
+
module FileSystem
|
|
5
|
+
module Lvm
|
|
6
|
+
module Encrypt
|
|
7
|
+
class Void < Device
|
|
8
|
+
include Helpers::Void
|
|
9
|
+
attr_reader :boot_disk
|
|
10
|
+
|
|
11
|
+
# Create key to avoid enter password twice
|
|
12
|
+
def create_key
|
|
13
|
+
add_key("volume.key", @dev_root)
|
|
14
|
+
add_key("home.key", @dev_home) if @home_disk
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Key need to be added in dracut.conf.d and crypttab
|
|
18
|
+
def add_key(name, dev)
|
|
19
|
+
command "dd bs=1 count=64 if=/dev/urandom of=/boot/#{name}"
|
|
20
|
+
puts " => Creating a key for #{dev}, password required:"
|
|
21
|
+
chroot "cryptsetup luksAddKey #{dev} /boot/#{name}"
|
|
22
|
+
command "chmod 000 /boot/#{name}"
|
|
23
|
+
#command "chmod -R g-rwx,o-rwx /boot"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fstab
|
|
27
|
+
conf = "#{MOUNTPOINT}/etc/fstab"
|
|
28
|
+
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
29
|
+
line_fstab(@dev_esp, "/efi vfat noauto,rw,relatime 0 0") if @dev_esp
|
|
30
|
+
line_fstab(@dev_boot, "/boot ext4 noauto,rw,relatime 0 0") if @dev_boot
|
|
31
|
+
add_line(conf, "/dev/mapper/cryptswap none swap sw 0 0")
|
|
32
|
+
add_line(conf, "#{@lv_home} /home ext4 rw,discard 0 0") if @home_disk
|
|
33
|
+
add_line(conf, "#{@lv_root} / ext4 rw,relatime 0 1")
|
|
34
|
+
add_line(conf, "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def crypttab
|
|
38
|
+
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
39
|
+
File.write(conf, "\n", mode: 'w', chmod: 0644)
|
|
40
|
+
add_line(conf, "cryptswap #{@lv_swap} /dev/urandom swap,discard,cipher=aes-xts-plain64:sha256,size=512")
|
|
41
|
+
line_crypttab(@vg, @dev_root, "/boot/volume.key", "luks")
|
|
42
|
+
line_crypttab("crypthome", @dev_home, "/boot/home.key", "luks") if @home_disk
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def config_grub
|
|
46
|
+
conf = "#{MOUNTPOINT}/etc/default/grub"
|
|
47
|
+
content = "GRUB_ENABLE_CRYPTODISK=y"
|
|
48
|
+
unless search(conf, content)
|
|
49
|
+
File.write(conf, "#{content}\n", mode: 'a')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def config_dracut
|
|
54
|
+
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/lvm.conf"
|
|
55
|
+
content = [
|
|
56
|
+
"hostonly=\"yes\"",
|
|
57
|
+
"omit_dracutmodules+=\" btrfs \"",
|
|
58
|
+
"install_items+=\" /boot/volume.key /etc/crypttab \"",
|
|
59
|
+
""
|
|
60
|
+
]
|
|
61
|
+
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
62
|
+
#add_line(conf, "install_items+=\" /boot/home.key \"") if @home_disk
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def kernel_cmdline_dracut
|
|
66
|
+
conf = "#{MOUNTPOINT}/etc/dracut.conf.d/cmdline.conf"
|
|
67
|
+
root_uuid = b_uuid(@dev_root)
|
|
68
|
+
args = "rd.lvm.vg=#{@vg} rd.luks.uuid=#{root_uuid} rootflags=rw,relatime"
|
|
69
|
+
line = "kernel_cmdline=\"#{args}\""
|
|
70
|
+
File.write(conf, "#{line}\n", mode: 'w', chmod: 0644)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def finish
|
|
74
|
+
puts "+ Enter in your system: chroot /mnt /bin/bash"
|
|
75
|
+
puts "+ Reboot with: shutdown -r now"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def b_uuid(dev)
|
|
81
|
+
device = dev.delete_prefix("/dev/")
|
|
82
|
+
Dir.glob("/dev/disk/by-uuid/*").each { |f|
|
|
83
|
+
link = File.readlink(f)
|
|
84
|
+
return f.delete_prefix("/dev/disk/by-uuid/") if link.match(/#{device}$/)
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# line_crypttab("cryptswap", "sda2", "/dev/urandom", "luks")
|
|
89
|
+
def line_crypttab(mapname, dev, point, rest)
|
|
90
|
+
conf = "#{MOUNTPOINT}/etc/crypttab"
|
|
91
|
+
device = s_uuid(dev)
|
|
92
|
+
raise "No partuuid for #{dev} #{device}" if !device
|
|
93
|
+
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
94
|
+
add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -4,21 +4,25 @@ module Getch
|
|
|
4
4
|
class Format < Getch::FileSystem::Lvm::Device
|
|
5
5
|
def initialize
|
|
6
6
|
super
|
|
7
|
-
@
|
|
8
|
-
@state = Getch::States.new()
|
|
7
|
+
@state = Getch::States.new
|
|
9
8
|
format
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def format
|
|
13
12
|
return if STATES[:format]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
system("mkfs.#{@fs} -F #{@lv_home}") if @lv_home
|
|
13
|
+
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
14
|
+
exec("mkfs.ext4 -F #{@dev_boot}") if @dev_boot
|
|
15
|
+
exec("mkswap -f #{@lv_swap}")
|
|
16
|
+
exec("mkfs.ext4 -F #{@lv_root}")
|
|
17
|
+
exec("mkfs.ext4 -F #{@lv_home}") if @lv_home
|
|
20
18
|
@state.format
|
|
21
19
|
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def exec(cmd)
|
|
24
|
+
Getch::Command.new(cmd).run!
|
|
25
|
+
end
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
require 'fileutils'
|
|
2
|
-
|
|
3
1
|
module Getch
|
|
4
2
|
module FileSystem
|
|
5
3
|
module Lvm
|
|
6
4
|
class Mount < Getch::FileSystem::Lvm::Device
|
|
7
5
|
def initialize
|
|
8
6
|
super
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
|
12
|
-
@home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
|
|
13
|
-
@state = Getch::States.new()
|
|
7
|
+
@mount = Getch::FileSystem::Mount.new
|
|
8
|
+
@state = Getch::States.new
|
|
14
9
|
end
|
|
15
10
|
|
|
16
11
|
def run
|
|
17
12
|
return if STATES[:mount]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@state.mount
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def mount_swap
|
|
29
|
-
return if ! @lv_swap
|
|
30
|
-
system("swapon #{@lv_swap}")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def mount_root
|
|
34
|
-
return if ! @lv_root
|
|
35
|
-
Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
|
|
36
|
-
system("mount #{@lv_root} #{@root_dir}")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def mount_boot_efi
|
|
40
|
-
return if ! @dev_boot_efi
|
|
41
|
-
FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
|
|
42
|
-
system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def mount_boot
|
|
46
|
-
return if ! @dev_boot
|
|
47
|
-
FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
|
|
48
|
-
system("mount #{@dev_boot} #{@boot_dir}")
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def mount_home
|
|
52
|
-
return if ! @lv_home
|
|
53
|
-
if @user != nil then
|
|
54
|
-
FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
|
|
55
|
-
system("mount #{@lv_home} #{@home_dir}")
|
|
56
|
-
end
|
|
13
|
+
@mount.swap(@lv_swap)
|
|
14
|
+
@mount.root(@lv_root)
|
|
15
|
+
@mount.boot(@dev_boot)
|
|
16
|
+
@mount.esp(@dev_esp)
|
|
17
|
+
@mount.home(@lv_home)
|
|
57
18
|
@state.mount
|
|
58
19
|
end
|
|
59
20
|
end
|
|
@@ -5,13 +5,16 @@ module Getch
|
|
|
5
5
|
def initialize
|
|
6
6
|
super
|
|
7
7
|
@state = Getch::States.new()
|
|
8
|
+
@partition = Getch::FileSystem::Partition.new
|
|
9
|
+
@clean = Getch::FileSystem::Clean
|
|
8
10
|
run_partition
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def run_partition
|
|
12
14
|
return if STATES[:partition ]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
@clean.old_vg(@dev_root, @vg)
|
|
16
|
+
@clean.hdd(@disk)
|
|
17
|
+
@clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
|
|
15
18
|
partition
|
|
16
19
|
lvm
|
|
17
20
|
@state.partition
|
|
@@ -19,35 +22,14 @@ module Getch
|
|
|
19
22
|
|
|
20
23
|
private
|
|
21
24
|
|
|
22
|
-
def clear_struct
|
|
23
|
-
oldvg = `vgdisplay | grep #{@vg}`.chomp
|
|
24
|
-
exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
|
|
25
|
-
exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
|
|
26
|
-
|
|
27
|
-
exec("sgdisk -Z /dev/#{@disk}")
|
|
28
|
-
exec("wipefs -a /dev/#{@disk}")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def cleaning
|
|
32
|
-
puts
|
|
33
|
-
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
|
34
|
-
case gets.chomp
|
|
35
|
-
when /^y|^Y/
|
|
36
|
-
bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
|
37
|
-
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
|
|
38
|
-
else
|
|
39
|
-
return
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
25
|
def partition
|
|
44
26
|
if Helpers::efi?
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
@partition.efi(@dev_esp)
|
|
28
|
+
@partition.root(@dev_root, "8e00")
|
|
47
29
|
else
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
@partition.gpt(@dev_gpt)
|
|
31
|
+
@partition.boot(@dev_boot)
|
|
32
|
+
@partition.root(@dev_root, "8e00")
|
|
51
33
|
end
|
|
52
34
|
end
|
|
53
35
|
|
|
@@ -56,15 +38,21 @@ module Getch
|
|
|
56
38
|
exec("pvcreate -f #{@dev_root}")
|
|
57
39
|
exec("vgcreate -f #{@vg} #{@dev_root}")
|
|
58
40
|
# Wipe old signature: https://github.com/chef-cookbooks/lvm/issues/45
|
|
59
|
-
exec("lvcreate -y -Wy -Zy -L 15G -n root #{@vg}")
|
|
60
41
|
exec("lvcreate -y -Wy -Zy -L #{mem} -n swap #{@vg}")
|
|
61
|
-
|
|
42
|
+
|
|
43
|
+
if @user
|
|
44
|
+
exec("lvcreate -y -Wy -Zy -L 18G -n root #{@vg}")
|
|
45
|
+
exec("lvcreate -y -Wy -Zy -l 100%FREE -n home #{@vg}")
|
|
46
|
+
else
|
|
47
|
+
exec("lvcreate -y -Wy -Zy -l 100%FREE -n root #{@vg}")
|
|
48
|
+
end
|
|
49
|
+
|
|
62
50
|
exec("vgchange --available y")
|
|
63
51
|
end
|
|
64
52
|
|
|
65
53
|
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
|
66
54
|
# Partition_efi
|
|
67
|
-
# /
|
|
55
|
+
# /efi - EFI system partition - 260MB
|
|
68
56
|
# / - Root
|
|
69
57
|
|
|
70
58
|
# Partition_bios
|