getch 0.0.9 → 0.1.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +19 -6
- data/bin/setup.sh +4 -2
- data/lib/getch.rb +4 -2
- data/lib/getch/command.rb +7 -0
- data/lib/getch/filesystem.rb +1 -0
- data/lib/getch/filesystem/lvm/deps.rb +1 -1
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +1 -1
- data/lib/getch/filesystem/zfs.rb +14 -0
- data/lib/getch/filesystem/zfs/config.rb +58 -0
- data/lib/getch/filesystem/zfs/deps.rb +90 -0
- data/lib/getch/filesystem/zfs/device.rb +19 -0
- data/lib/getch/filesystem/zfs/encrypt.rb +15 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +67 -0
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +94 -0
- data/lib/getch/filesystem/zfs/encrypt/device.rb +21 -0
- data/lib/getch/filesystem/zfs/encrypt/format.rb +22 -0
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +67 -0
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +151 -0
- data/lib/getch/filesystem/zfs/format.rb +20 -0
- data/lib/getch/filesystem/zfs/mount.rb +67 -0
- data/lib/getch/filesystem/zfs/partition.rb +147 -0
- data/lib/getch/gentoo/boot.rb +19 -6
- data/lib/getch/gentoo/sources.rb +5 -16
- data/lib/getch/helpers.rb +4 -13
- data/lib/getch/version.rb +1 -1
- metadata +17 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 259461a4875fb46c062067c9663e211c206475aaaaa89d3066f85d1b3be2c19b
|
4
|
+
data.tar.gz: 3ab40d87e3f039ef840156cc81df8ee75e3f8f76c332ae4ba08335b04440625f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef130ea5b78dcde7f2897d16f3f74293c16da487ca029c0d47c905489d5cd4d9f32d5bffeba30fe06ab13694370f99a380aceaec6da053dece11598eb938ba4
|
7
|
+
data.tar.gz: f9f4584abb87c4287ba81e16bb0274c483627a712916728fbcc9a4667a2d91f03e09a092bdf09400bd1f92318c67ddabdf4c20217eff1eeb64f2d8d0c97a1a02
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.1.0, release 2020-10-15
|
2
|
+
* Add the (Zeta) filesystem ZFS
|
3
|
+
* `emerge --depclean` to save space.
|
4
|
+
* Add a message when getch have finish, keep /mnt/gentoo if you need to add something.
|
5
|
+
* Use systemd-detect-virt to detect a Virtual Guest.
|
6
|
+
|
1
7
|
## 0.0.9, release 2020-10-03
|
2
8
|
* Add encryption on ext4 and lvm (BIOS,UEFI)
|
3
9
|
* Correct KEYMAP="yes" with genkernel
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ BIOS system will use Grub2 and UEFI, systemd-boot. Filesystem supported by Getch
|
|
9
9
|
+ ext4
|
10
10
|
+ lvm
|
11
11
|
|
12
|
-
|
12
|
+
Encryption is also supported.
|
13
13
|
|
14
14
|
The ISO images i was able to test and that works:
|
15
15
|
+ [Archlinux](https://www.archlinux.org/download/)
|
@@ -28,24 +28,37 @@ When you boot from an `iso`, you can install `ruby`, `getch` and correct your `P
|
|
28
28
|
# source ~/.zshrc # or ~/.bashrc
|
29
29
|
|
30
30
|
## Usage
|
31
|
+
Just ensure than the script is run with a root account, not just sudo.
|
31
32
|
|
32
|
-
|
33
|
+
# getch -h
|
34
|
+
|
35
|
+
After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).
|
33
36
|
|
34
37
|
## Examples
|
35
38
|
For a french user:
|
36
39
|
|
37
|
-
# getch --
|
38
|
-
|
39
|
-
After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).
|
40
|
+
# getch --zoneinfo "Europe/Paris" --language fr_FR --keymap fr
|
40
41
|
|
41
42
|
Install Gentoo on LVM:
|
42
43
|
|
43
44
|
# getch --format lvm --disk sda
|
44
45
|
|
46
|
+
Encrypt your disk with LVM with a french keymap
|
47
|
+
|
48
|
+
# getch --format lvm --encrypt --keymap fr
|
49
|
+
|
50
|
+
Encrypt with ext4 and create a home directory /home/ninja
|
51
|
+
|
52
|
+
# getch --format ext4 --encrypt --username ninja
|
53
|
+
|
45
54
|
## Troubleshooting
|
46
55
|
|
47
56
|
#### LVM
|
48
|
-
Unless
|
57
|
+
Unless your old LVM volume group is also named `vg0`, `getch` may fail to partition your disk. You have to clean up your device before proceed with `vgremove` and `pvremove`.
|
58
|
+
|
59
|
+
#### Encryption enable on BIOS with ext4
|
60
|
+
To decrypt your disk on BIOS system, you have to enter your password two times. One time for Grub and another time for the initramfs (Genkernel). [post](https://wiki.archlinux.org/index.php/GRUB#Encrypted_/boot).
|
61
|
+
Also with GRUB, only a `us` keymap is working.
|
49
62
|
|
50
63
|
## Issues
|
51
64
|
If need more support for your hardware (network, sound card, ...), you can submit a [new issue](https://github.com/szorfein/getch/issues/new) and post the output of the following command:
|
data/bin/setup.sh
CHANGED
@@ -72,10 +72,12 @@ set_shell() {
|
|
72
72
|
[ -f ~/.zshrc ] && your_shell=~/.zshrc
|
73
73
|
|
74
74
|
[ -f "$your_shell" ] && {
|
75
|
-
if ! grep -q "
|
75
|
+
if ! grep -q "ruby" "$your_shell" ; then
|
76
76
|
echo "export PATH=\$PATH:$(ruby -e 'puts Gem.user_dir')/bin" >> "$your_shell"
|
77
77
|
fi
|
78
|
-
. "$your_shell"
|
78
|
+
if $(. "$your_shell") ; then
|
79
|
+
echo "Shell loaded"
|
80
|
+
fi
|
79
81
|
}
|
80
82
|
}
|
81
83
|
|
data/lib/getch.rb
CHANGED
@@ -33,11 +33,13 @@ module Getch
|
|
33
33
|
DEFAULT_FS = {
|
34
34
|
true => {
|
35
35
|
ext4: Getch::FileSystem::Ext4::Encrypt,
|
36
|
-
lvm: Getch::FileSystem::Lvm::Encrypt
|
36
|
+
lvm: Getch::FileSystem::Lvm::Encrypt,
|
37
|
+
zfs: Getch::FileSystem::Zfs::Encrypt
|
37
38
|
},
|
38
39
|
false => {
|
39
40
|
ext4: Getch::FileSystem::Ext4,
|
40
|
-
lvm: Getch::FileSystem::Lvm
|
41
|
+
lvm: Getch::FileSystem::Lvm,
|
42
|
+
zfs: Getch::FileSystem::Zfs,
|
41
43
|
}
|
42
44
|
}.freeze
|
43
45
|
|
data/lib/getch/command.rb
CHANGED
data/lib/getch/filesystem.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative 'zfs/device'
|
9
|
+
require_relative 'zfs/partition'
|
10
|
+
require_relative 'zfs/format'
|
11
|
+
require_relative 'zfs/mount'
|
12
|
+
require_relative 'zfs/config'
|
13
|
+
require_relative 'zfs/deps'
|
14
|
+
require_relative 'zfs/encrypt'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Config < Getch::FileSystem::Zfs::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
gen_uuid
|
8
|
+
@root_dir = MOUNTPOINT
|
9
|
+
@init = '/usr/lib/systemd/systemd'
|
10
|
+
end
|
11
|
+
|
12
|
+
def fstab
|
13
|
+
file = "#{@root_dir}/etc/fstab"
|
14
|
+
datas = data_fstab
|
15
|
+
File.write(file, datas.join("\n"))
|
16
|
+
end
|
17
|
+
|
18
|
+
def systemd_boot
|
19
|
+
return if ! Helpers::efi?
|
20
|
+
esp = '/boot/efi'
|
21
|
+
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
22
|
+
datas_gentoo = [
|
23
|
+
'title Gentoo Linux',
|
24
|
+
'linux /vmlinuz',
|
25
|
+
'initrd /initramfs',
|
26
|
+
"options resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs"
|
27
|
+
]
|
28
|
+
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
29
|
+
end
|
30
|
+
|
31
|
+
# See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
|
32
|
+
def grub
|
33
|
+
return if Helpers::efi?
|
34
|
+
file = "#{@root_dir}/etc/default/grub"
|
35
|
+
cmdline = [
|
36
|
+
"GRUB_CMDLINE_LINUX=\"resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs\""
|
37
|
+
]
|
38
|
+
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def gen_uuid
|
44
|
+
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
|
45
|
+
@uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
|
46
|
+
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
47
|
+
end
|
48
|
+
|
49
|
+
def data_fstab
|
50
|
+
boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
|
51
|
+
swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
|
52
|
+
|
53
|
+
[ boot_efi, swap ]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Deps < Getch::FileSystem::Zfs::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
install_deps
|
8
|
+
zfs_mountpoint
|
9
|
+
auto_module_rebuild
|
10
|
+
end
|
11
|
+
|
12
|
+
def make
|
13
|
+
hostid
|
14
|
+
options_make
|
15
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def install_deps
|
20
|
+
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
21
|
+
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
22
|
+
Getch::Garden.new('-a zfs').run!
|
23
|
+
Getch::Make.new("make modules_prepare").run!
|
24
|
+
Getch::Make.new("make -j$(nproc)").run!
|
25
|
+
Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
|
26
|
+
end
|
27
|
+
|
28
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
29
|
+
def zfs_mountpoint
|
30
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
31
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
32
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
33
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
34
|
+
exec("systemctl start zfs-zed.service")
|
35
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
36
|
+
exec("systemctl enable zfs-zed.service")
|
37
|
+
exec("systemctl enable zfs.target")
|
38
|
+
end
|
39
|
+
|
40
|
+
def auto_module_rebuild
|
41
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
42
|
+
Helpers::mkdir(g_dir)
|
43
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
44
|
+
content=<<EOF
|
45
|
+
post_pkg_postinst() {
|
46
|
+
# BUG: reinstalls of a source will cause errors
|
47
|
+
CURRENT_KV=$(uname -r)
|
48
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
49
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
50
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
51
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
52
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
53
|
+
else # No valid configs known
|
54
|
+
genkernel all
|
55
|
+
fi
|
56
|
+
}
|
57
|
+
EOF
|
58
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
59
|
+
end
|
60
|
+
|
61
|
+
def hostid
|
62
|
+
hostid_value=`hostid`.chomp
|
63
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
64
|
+
end
|
65
|
+
|
66
|
+
def options_make
|
67
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
68
|
+
datas = [
|
69
|
+
'',
|
70
|
+
bootloader,
|
71
|
+
'INSTALL="yes"',
|
72
|
+
'MENUCONFIG="no"',
|
73
|
+
'CLEAN="yes"',
|
74
|
+
'SAVE_CONFIG="yes"',
|
75
|
+
'MOUNTBOOT="no"',
|
76
|
+
'MRPROPER="no"',
|
77
|
+
'ZFS="yes"',
|
78
|
+
'MODULEREBUILD="yes"'
|
79
|
+
]
|
80
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
81
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
82
|
+
end
|
83
|
+
|
84
|
+
def exec(cmd)
|
85
|
+
Getch::Chroot.new(cmd).run!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Device
|
5
|
+
def initialize
|
6
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
7
|
+
@user = DEFAULT_OPTIONS[:username]
|
8
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
9
|
+
@dev_boot = Helpers::efi? ? nil : "/dev/#{@disk}2"
|
10
|
+
@dev_swap = Helpers::efi? ? "/dev/#{@disk}2" : "/dev/#{@disk}3"
|
11
|
+
@dev_root = Helpers::efi? ? "/dev/#{@disk}3" : "/dev/#{@disk}4"
|
12
|
+
@boot_pool_name = 'bpool'
|
13
|
+
@pool_name = 'zpool'
|
14
|
+
@zfs_home = @user ? true : false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative 'encrypt/device'
|
11
|
+
require_relative 'encrypt/partition'
|
12
|
+
require_relative 'encrypt/format'
|
13
|
+
require_relative 'encrypt/mount'
|
14
|
+
require_relative 'encrypt/config'
|
15
|
+
require_relative 'encrypt/deps'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Config < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
gen_uuid
|
9
|
+
@root_dir = MOUNTPOINT
|
10
|
+
@init = '/usr/lib/systemd/systemd'
|
11
|
+
crypttab
|
12
|
+
end
|
13
|
+
|
14
|
+
def fstab
|
15
|
+
file = "#{@root_dir}/etc/fstab"
|
16
|
+
datas = data_fstab
|
17
|
+
File.write(file, datas.join("\n"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def systemd_boot
|
21
|
+
return if ! Helpers::efi?
|
22
|
+
esp = '/boot/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/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}"
|
29
|
+
]
|
30
|
+
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
31
|
+
end
|
32
|
+
|
33
|
+
def crypttab
|
34
|
+
datas = [
|
35
|
+
"cryptswap UUID=#{@uuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=256"
|
36
|
+
]
|
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 Helpers::efi?
|
43
|
+
file = "#{@root_dir}/etc/default/grub"
|
44
|
+
cmdline = [
|
45
|
+
"GRUB_CMDLINE_LINUX=\"root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}\""
|
46
|
+
]
|
47
|
+
File.write("#{file}", cmdline.join("\n"), mode: 'a')
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def gen_uuid
|
53
|
+
@uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
|
54
|
+
@uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
|
55
|
+
end
|
56
|
+
|
57
|
+
def data_fstab
|
58
|
+
boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
|
59
|
+
swap = @dev_swap ? "/dev/mapper/cryptswap none swap discard 0 0" : ''
|
60
|
+
|
61
|
+
[ boot_efi, swap ]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Deps < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
install_deps
|
9
|
+
zfs_mountpoint
|
10
|
+
auto_module_rebuild
|
11
|
+
end
|
12
|
+
|
13
|
+
def make
|
14
|
+
hostid
|
15
|
+
options_make
|
16
|
+
Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def install_deps
|
21
|
+
exec("euse -E libzfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /libzfs/)
|
22
|
+
exec("euse -E rootfs") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /rootfs/)
|
23
|
+
exec("euse -E cryptsetup") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /cryptsetup/)
|
24
|
+
Getch::Garden.new('-a zfs').run!
|
25
|
+
Getch::Make.new("make modules_prepare").run!
|
26
|
+
Getch::Make.new("make -j$(nproc)").run!
|
27
|
+
Getch::Emerge.new('genkernel sys-fs/zfs sys-apps/systemd sys-fs/cryptsetup').pkg!
|
28
|
+
end
|
29
|
+
|
30
|
+
# See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
|
31
|
+
def zfs_mountpoint
|
32
|
+
Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
|
33
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
|
34
|
+
Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
|
35
|
+
exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
|
36
|
+
exec("systemctl start zfs-zed.service")
|
37
|
+
Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
|
38
|
+
exec("systemctl enable zfs-zed.service")
|
39
|
+
exec("systemctl enable zfs.target")
|
40
|
+
end
|
41
|
+
|
42
|
+
def auto_module_rebuild
|
43
|
+
g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
|
44
|
+
Helpers::mkdir(g_dir)
|
45
|
+
# See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
|
46
|
+
content=<<EOF
|
47
|
+
post_pkg_postinst() {
|
48
|
+
# BUG: reinstalls of a source will cause errors
|
49
|
+
CURRENT_KV=$(uname -r)
|
50
|
+
# Check to see if genkernel has been run previously for the running kernel and use that config
|
51
|
+
if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
|
52
|
+
genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
|
53
|
+
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
|
54
|
+
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
|
55
|
+
else # No valid configs known
|
56
|
+
genkernel all
|
57
|
+
fi
|
58
|
+
}
|
59
|
+
EOF
|
60
|
+
File.write("#{g_dir}/gentoo-sources", content)
|
61
|
+
end
|
62
|
+
|
63
|
+
def hostid
|
64
|
+
hostid_value=`hostid`.chomp
|
65
|
+
File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
|
66
|
+
end
|
67
|
+
|
68
|
+
def options_make
|
69
|
+
bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
|
70
|
+
datas = [
|
71
|
+
'',
|
72
|
+
bootloader,
|
73
|
+
'INSTALL="yes"',
|
74
|
+
'MENUCONFIG="no"',
|
75
|
+
'CLEAN="yes"',
|
76
|
+
'KEYMAP="yes"',
|
77
|
+
'SAVE_CONFIG="yes"',
|
78
|
+
'MOUNTBOOT="no"',
|
79
|
+
'MRPROPER="no"',
|
80
|
+
'ZFS="yes"',
|
81
|
+
'MODULEREBUILD="yes"'
|
82
|
+
]
|
83
|
+
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
84
|
+
File.write(file, datas.join("\n"), mode: 'a')
|
85
|
+
end
|
86
|
+
|
87
|
+
def exec(cmd)
|
88
|
+
Getch::Chroot.new(cmd).run!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Device
|
6
|
+
def initialize
|
7
|
+
@disk = DEFAULT_OPTIONS[:disk]
|
8
|
+
@user = DEFAULT_OPTIONS[:username]
|
9
|
+
@dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
|
10
|
+
@dev_boot = Helpers::efi? ? nil : "/dev/#{@disk}2"
|
11
|
+
@dev_swap = Helpers::efi? ? "/dev/#{@disk}2" : "/dev/#{@disk}3"
|
12
|
+
@dev_root = Helpers::efi? ? "/dev/#{@disk}3" : "/dev/#{@disk}4"
|
13
|
+
@boot_pool_name = 'bpool'
|
14
|
+
@pool_name = 'zpool'
|
15
|
+
@zfs_home = @user ? true : false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Format < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@state = Getch::States.new()
|
9
|
+
format
|
10
|
+
end
|
11
|
+
|
12
|
+
def format
|
13
|
+
return if STATES[:format]
|
14
|
+
system("mkfs.fat -F32 #{@dev_boot_efi}") if @dev_boot_efi
|
15
|
+
system("mkswap -f #{@dev_swap}")
|
16
|
+
@state.format
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module FileSystem
|
5
|
+
module Zfs
|
6
|
+
module Encrypt
|
7
|
+
class Mount < Getch::FileSystem::Zfs::Encrypt::Device
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@root_dir = MOUNTPOINT
|
11
|
+
@boot_dir = "#{@root_dir}/boot"
|
12
|
+
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
13
|
+
@state = Getch::States.new()
|
14
|
+
@log = Getch::Log.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
return if STATES[:mount]
|
19
|
+
exec("zpool export -a")
|
20
|
+
exec("rm -rf #{MOUNTPOINT}/*")
|
21
|
+
exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
|
22
|
+
exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
|
23
|
+
exec("zfs load-key -a")
|
24
|
+
mount_swap
|
25
|
+
mount_root
|
26
|
+
mount_boot
|
27
|
+
mount_boot_efi
|
28
|
+
exec("zfs mount -a")
|
29
|
+
@state.mount
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def mount_swap
|
35
|
+
if Helpers::grep?('/proc/swaps', /^\/dev/)
|
36
|
+
exec("swapoff #{@dev_swap}")
|
37
|
+
end
|
38
|
+
|
39
|
+
exec("swapon #{@dev_swap}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def mount_root
|
43
|
+
Helpers::mkdir(@root_dir)
|
44
|
+
exec("zfs mount #{@pool_name}/ROOT/gentoo")
|
45
|
+
end
|
46
|
+
|
47
|
+
def mount_boot_efi
|
48
|
+
return if ! @dev_boot_efi
|
49
|
+
Helpers::mkdir(@boot_efi_dir)
|
50
|
+
exec("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def mount_boot
|
54
|
+
return if ! @dev_boot
|
55
|
+
Helpers::mkdir(@boot_dir)
|
56
|
+
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
57
|
+
end
|
58
|
+
|
59
|
+
def exec(cmd)
|
60
|
+
@log.info("==> #{cmd}")
|
61
|
+
Helpers::sys(cmd)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
module Encrypt
|
5
|
+
class Partition < Getch::FileSystem::Zfs::Encrypt::Device
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
@state = Getch::States.new()
|
9
|
+
@log = Getch::Log.new()
|
10
|
+
run_partition
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_partition
|
14
|
+
return if STATES[:partition ]
|
15
|
+
clear_struct
|
16
|
+
cleaning
|
17
|
+
partition
|
18
|
+
zfs
|
19
|
+
@state.partition
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def clear_struct
|
25
|
+
oldvg = `vgdisplay | grep #{@vg}`.chomp
|
26
|
+
oldzpool = `zpool status | grep pool:`.gsub(/pool: /, '').delete(' ').split("\n")
|
27
|
+
if oldzpool[0] != "" and $?.success?
|
28
|
+
oldzpool.each { |p| exec("zpool destroy #{p}") if p }
|
29
|
+
end
|
30
|
+
exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
|
31
|
+
exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
|
32
|
+
|
33
|
+
exec("sgdisk -Z /dev/#{@disk}")
|
34
|
+
exec("wipefs -a /dev/#{@disk}")
|
35
|
+
end
|
36
|
+
|
37
|
+
# See https://wiki.archlinux.org/index.php/Solid_state_drive/Memory_cell_clearing
|
38
|
+
# for SSD
|
39
|
+
def cleaning
|
40
|
+
@bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
41
|
+
puts
|
42
|
+
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
43
|
+
case gets.chomp
|
44
|
+
when /^y|^Y/
|
45
|
+
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{@bloc} status=progress")
|
46
|
+
else
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def partition
|
52
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
53
|
+
if Helpers::efi?
|
54
|
+
exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
|
55
|
+
exec("sgdisk -n2:0:+#{mem} -t2:8200 /dev/#{@disk}")
|
56
|
+
exec("sgdisk -n3:0:+0 -t3:BF00 /dev/#{@disk}")
|
57
|
+
else
|
58
|
+
exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
59
|
+
exec("sgdisk -n2:0:+2G -t2:BE00 /dev/#{@disk}") # boot pool GRUB
|
60
|
+
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
61
|
+
exec("sgdisk -n4:0:+0 -t4:BF00 /dev/#{@disk}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def zfs
|
66
|
+
ashift = case @bloc
|
67
|
+
when 8096
|
68
|
+
13
|
69
|
+
when 4096
|
70
|
+
12
|
71
|
+
else # 512
|
72
|
+
9
|
73
|
+
end
|
74
|
+
|
75
|
+
Helpers::mkdir(MOUNTPOINT)
|
76
|
+
|
77
|
+
@log.debug("ashift found for #{@bloc} - #{ashift}")
|
78
|
+
if ! Helpers::efi?
|
79
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
80
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
81
|
+
exec("zpool create -f \\
|
82
|
+
-o ashift=#{ashift} -d \\
|
83
|
+
-o feature@async_destroy=enabled \\
|
84
|
+
-o feature@bookmarks=enabled \\
|
85
|
+
-o feature@embedded_data=enabled \\
|
86
|
+
-o feature@empty_bpobj=enabled \\
|
87
|
+
-o feature@enabled_txg=enabled \\
|
88
|
+
-o feature@extensible_dataset=enabled \\
|
89
|
+
-o feature@filesystem_limits=enabled \\
|
90
|
+
-o feature@hole_birth=enabled \\
|
91
|
+
-o feature@large_blocks=enabled \\
|
92
|
+
-o feature@lz4_compress=enabled \\
|
93
|
+
-o feature@spacemap_histogram=enabled \\
|
94
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
95
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
96
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
97
|
+
#{@boot_pool_name} #{@dev_boot}
|
98
|
+
")
|
99
|
+
end
|
100
|
+
|
101
|
+
exec("zpool create -f -o ashift=#{ashift} \\
|
102
|
+
-O encryption=aes-256-gcm \\
|
103
|
+
-O keylocation=prompt -O keyformat=passphrase \\
|
104
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
105
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
106
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
107
|
+
#{@pool_name} #{@dev_root}
|
108
|
+
")
|
109
|
+
|
110
|
+
add_datasets
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_datasets
|
114
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
115
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
116
|
+
|
117
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
118
|
+
# set bootfs
|
119
|
+
#exec("zpool set bootfs=#{@pool_name}/ROOT/gentoo #{@pool_name}")
|
120
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
121
|
+
|
122
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
123
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
124
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
125
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
126
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
127
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
128
|
+
|
129
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
130
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
131
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
132
|
+
end
|
133
|
+
|
134
|
+
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
135
|
+
# Partition_efi
|
136
|
+
# /boot/efi - EFI system partition - 260MB
|
137
|
+
# / - Root
|
138
|
+
|
139
|
+
# Partition_bios
|
140
|
+
# None - Bios Boot Partition - 1MiB
|
141
|
+
# /boot - Boot - 8300
|
142
|
+
# / - Root
|
143
|
+
|
144
|
+
def exec(cmd)
|
145
|
+
Helpers::sys(cmd)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Format < Getch::FileSystem::Zfs::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@state = Getch::States.new()
|
8
|
+
format
|
9
|
+
end
|
10
|
+
|
11
|
+
def format
|
12
|
+
return if STATES[:format]
|
13
|
+
system("mkfs.fat -F32 #{@dev_boot_efi}") if @dev_boot_efi
|
14
|
+
system("mkswap -f #{@dev_swap}")
|
15
|
+
@state.format
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Getch
|
4
|
+
module FileSystem
|
5
|
+
module Zfs
|
6
|
+
class Mount < Getch::FileSystem::Zfs::Device
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@root_dir = MOUNTPOINT
|
10
|
+
@boot_dir = "#{@root_dir}/boot"
|
11
|
+
@boot_efi_dir = "#{@root_dir}/boot/efi"
|
12
|
+
@state = Getch::States.new()
|
13
|
+
@log = Getch::Log.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
return if STATES[:mount]
|
18
|
+
exec("zpool export -a")
|
19
|
+
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
|
+
mount_swap
|
23
|
+
mount_root
|
24
|
+
mount_boot
|
25
|
+
mount_boot_efi
|
26
|
+
exec("zfs mount -a")
|
27
|
+
@state.mount
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def mount_swap
|
33
|
+
if Helpers::grep?('/proc/swaps', /^\/dev/)
|
34
|
+
exec("swapoff #{@dev_swap}")
|
35
|
+
end
|
36
|
+
|
37
|
+
exec("swapon #{@dev_swap}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def mount_root
|
41
|
+
Helpers::mkdir(@root_dir)
|
42
|
+
exec("zfs mount #{@pool_name}/ROOT/gentoo")
|
43
|
+
end
|
44
|
+
|
45
|
+
def mount_boot_efi
|
46
|
+
return if ! @dev_boot_efi
|
47
|
+
Helpers::mkdir(@boot_efi_dir)
|
48
|
+
exec("mount #{@dev_boot_efi} #{@boot_efi_dir}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def mount_boot
|
52
|
+
return if ! @dev_boot
|
53
|
+
Helpers::mkdir(@boot_dir)
|
54
|
+
exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
|
55
|
+
end
|
56
|
+
|
57
|
+
def exec(cmd)
|
58
|
+
@log.info("==> #{cmd}")
|
59
|
+
system(cmd)
|
60
|
+
unless $?.success?
|
61
|
+
raise "Error with #{cmd}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Getch
|
2
|
+
module FileSystem
|
3
|
+
module Zfs
|
4
|
+
class Partition < Getch::FileSystem::Zfs::Device
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@state = Getch::States.new()
|
8
|
+
@log = Getch::Log.new()
|
9
|
+
run_partition
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_partition
|
13
|
+
return if STATES[:partition ]
|
14
|
+
clear_struct
|
15
|
+
cleaning
|
16
|
+
partition
|
17
|
+
zfs
|
18
|
+
@state.partition
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def clear_struct
|
24
|
+
oldvg = `vgdisplay | grep #{@vg}`.chomp
|
25
|
+
oldzpool = `zpool status | grep pool:`.gsub(/pool: /, '').delete(' ').split("\n")
|
26
|
+
if oldzpool[0] != "" and $?.success?
|
27
|
+
oldzpool.each { |p| exec("zpool destroy #{p}") if p }
|
28
|
+
end
|
29
|
+
exec("vgremove -f #{@vg}") if oldvg != '' # remove older volume group
|
30
|
+
exec("pvremove -f #{@dev_root}") if oldvg != '' and File.exist? @dev_root # remove older volume group
|
31
|
+
|
32
|
+
exec("sgdisk -Z /dev/#{@disk}")
|
33
|
+
exec("wipefs -a /dev/#{@disk}")
|
34
|
+
end
|
35
|
+
|
36
|
+
# See https://wiki.archlinux.org/index.php/Solid_state_drive/Memory_cell_clearing
|
37
|
+
# for SSD
|
38
|
+
def cleaning
|
39
|
+
@bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
|
40
|
+
puts
|
41
|
+
print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
|
42
|
+
case gets.chomp
|
43
|
+
when /^y|^Y/
|
44
|
+
exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{@bloc} status=progress")
|
45
|
+
else
|
46
|
+
return
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def partition
|
51
|
+
mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
|
52
|
+
if Helpers::efi?
|
53
|
+
exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
|
54
|
+
exec("sgdisk -n2:0:+#{mem} -t2:8200 /dev/#{@disk}")
|
55
|
+
exec("sgdisk -n3:0:+0 -t3:BF00 /dev/#{@disk}")
|
56
|
+
else
|
57
|
+
exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
|
58
|
+
exec("sgdisk -n2:0:+2G -t2:BE00 /dev/#{@disk}") # boot pool GRUB
|
59
|
+
exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
|
60
|
+
exec("sgdisk -n4:0:+0 -t4:BF00 /dev/#{@disk}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def zfs
|
65
|
+
ashift = case @bloc
|
66
|
+
when 8096
|
67
|
+
13
|
68
|
+
when 4096
|
69
|
+
12
|
70
|
+
else # 512
|
71
|
+
9
|
72
|
+
end
|
73
|
+
|
74
|
+
Helpers::mkdir(MOUNTPOINT)
|
75
|
+
|
76
|
+
@log.debug("ashift found for #{@bloc} - #{ashift}")
|
77
|
+
if ! Helpers::efi?
|
78
|
+
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
|
79
|
+
@log.info("Creating boot pool on #{@pool_name}")
|
80
|
+
exec("zpool create -f \\
|
81
|
+
-o ashift=#{ashift} -d \\
|
82
|
+
-o feature@async_destroy=enabled \\
|
83
|
+
-o feature@bookmarks=enabled \\
|
84
|
+
-o feature@embedded_data=enabled \\
|
85
|
+
-o feature@empty_bpobj=enabled \\
|
86
|
+
-o feature@enabled_txg=enabled \\
|
87
|
+
-o feature@extensible_dataset=enabled \\
|
88
|
+
-o feature@filesystem_limits=enabled \\
|
89
|
+
-o feature@hole_birth=enabled \\
|
90
|
+
-o feature@large_blocks=enabled \\
|
91
|
+
-o feature@lz4_compress=enabled \\
|
92
|
+
-o feature@spacemap_histogram=enabled \\
|
93
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
94
|
+
-O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
|
95
|
+
-O mountpoint=/boot -R #{MOUNTPOINT} \\
|
96
|
+
#{@boot_pool_name} #{@dev_boot}
|
97
|
+
")
|
98
|
+
end
|
99
|
+
|
100
|
+
exec("zpool create -f -o ashift=#{ashift} \\
|
101
|
+
-O acltype=posixacl -O canmount=off -O compression=lz4 \\
|
102
|
+
-O dnodesize=auto -O normalization=formD -O atime=off \\
|
103
|
+
-O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
|
104
|
+
#{@pool_name} #{@dev_root}
|
105
|
+
")
|
106
|
+
|
107
|
+
add_datasets
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_datasets
|
111
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
|
112
|
+
exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
|
113
|
+
|
114
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
|
115
|
+
# set bootfs
|
116
|
+
#exec("zpool set bootfs=#{@pool_name}/ROOT/gentoo #{@pool_name}")
|
117
|
+
exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
|
118
|
+
|
119
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
|
120
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
|
121
|
+
exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
|
122
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
|
123
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
|
124
|
+
exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
|
125
|
+
|
126
|
+
exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
|
127
|
+
exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
|
128
|
+
exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}") if @user
|
129
|
+
end
|
130
|
+
|
131
|
+
# Follow https://wiki.archlinux.org/index.php/Partitioning
|
132
|
+
# Partition_efi
|
133
|
+
# /boot/efi - EFI system partition - 260MB
|
134
|
+
# / - Root
|
135
|
+
|
136
|
+
# Partition_bios
|
137
|
+
# None - Bios Boot Partition - 1MiB
|
138
|
+
# /boot - Boot - 8300
|
139
|
+
# / - Root
|
140
|
+
|
141
|
+
def exec(cmd)
|
142
|
+
Getch::Command.new(cmd).run!
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
data/lib/getch/gentoo/boot.rb
CHANGED
@@ -13,7 +13,8 @@ module Getch
|
|
13
13
|
@config.fstab
|
14
14
|
bootloader
|
15
15
|
password
|
16
|
-
|
16
|
+
cleanup
|
17
|
+
the_end
|
17
18
|
end
|
18
19
|
|
19
20
|
def bootloader
|
@@ -74,13 +75,25 @@ module Getch
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
private
|
79
|
+
|
80
|
+
def cleanup
|
81
|
+
Getch::Emerge.new("emerge --depclean").run!
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
def the_end
|
85
|
+
#Helpers::exec_or_die("umount -l /mnt/gentoo/dev{/shm,/pts,}")
|
86
|
+
#Helpers::exec_or_die("umount -R #{MOUNTPOINT}")
|
87
|
+
puts
|
88
|
+
puts "getch has finish, before reboot, you can:"
|
89
|
+
puts " + Chroot on your system with: chroot #{MOUNTPOINT} /bin/bash"
|
90
|
+
puts " + Install more packages like networkmanager or emacs"
|
91
|
+
puts
|
92
|
+
puts " + Add more modules for your kernel (graphic, wifi card) and recompile it with:"
|
93
|
+
puts " genkernel --kernel-config=/usr/src/linux/.config all "
|
94
|
+
puts
|
95
|
+
puts "Reboot the system when you have done !"
|
96
|
+
end
|
84
97
|
|
85
98
|
def exec_chroot(cmd)
|
86
99
|
script = "chroot #{MOUNTPOINT} /bin/bash -c \"
|
data/lib/getch/gentoo/sources.rb
CHANGED
@@ -7,7 +7,6 @@ module Getch
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def build_others
|
10
|
-
install_zfs if ismatch?('zfs')
|
11
10
|
virtualbox_guest
|
12
11
|
qemu_guest
|
13
12
|
install_wifi
|
@@ -20,10 +19,10 @@ module Getch
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def make
|
23
|
-
if DEFAULT_OPTIONS[:fs] == 'lvm'
|
22
|
+
if DEFAULT_OPTIONS[:fs] == 'lvm' || DEFAULT_OPTIONS[:fs] == 'zfs' || DEFAULT_OPTIONS[:encrypt]
|
24
23
|
@filesystem.make
|
25
24
|
else
|
26
|
-
|
25
|
+
make_kernel
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -33,11 +32,7 @@ module Getch
|
|
33
32
|
|
34
33
|
private
|
35
34
|
|
36
|
-
def
|
37
|
-
Getch::Make.new("make -j$(nproc)").run!
|
38
|
-
end
|
39
|
-
|
40
|
-
def just_make
|
35
|
+
def make_kernel
|
41
36
|
puts "Compiling kernel sources"
|
42
37
|
cmd = "make -j$(nproc) && make modules_install && make install"
|
43
38
|
Getch::Make.new(cmd).run!
|
@@ -46,7 +41,8 @@ module Getch
|
|
46
41
|
end
|
47
42
|
|
48
43
|
def virtualbox_guest
|
49
|
-
|
44
|
+
systemd=`systemd-detect-virt`.chomp
|
45
|
+
return if ! ismatch?('vmwgfx') || systemd.match(/none/)
|
50
46
|
garden("-a virtualbox-guest")
|
51
47
|
Getch::Emerge.new("app-emulation/virtualbox-guest-additions").pkg!
|
52
48
|
end
|
@@ -76,13 +72,6 @@ module Getch
|
|
76
72
|
garden("-a sound")
|
77
73
|
end
|
78
74
|
|
79
|
-
def install_zfs
|
80
|
-
return if ! DEFAULT_OPTIONS[:fs] == 'zfs'
|
81
|
-
garden("-a zfs")
|
82
|
-
only_make # a first 'make' is necessary before emerge zfs
|
83
|
-
Getch::Emerge.new("sys-fs/zfs").pkg!
|
84
|
-
end
|
85
|
-
|
86
75
|
def wifi_drivers
|
87
76
|
garden("-a ath9k-driver") if ismatch?('ath9k')
|
88
77
|
end
|
data/lib/getch/helpers.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'open3'
|
3
3
|
require 'fileutils'
|
4
|
-
require_relative 'command'
|
5
4
|
|
6
5
|
module Helpers
|
7
6
|
def self.efi?
|
@@ -31,20 +30,12 @@ module Helpers
|
|
31
30
|
File.write path, content if ! File.exist? path
|
32
31
|
end
|
33
32
|
|
34
|
-
def self.
|
35
|
-
|
36
|
-
source /etc/profile
|
37
|
-
emerge --changed-use #{pkgs}
|
38
|
-
\""
|
39
|
-
Getch::Command.new(cmd).run!
|
33
|
+
def self.mkdir(dir)
|
34
|
+
FileUtils.mkdir_p dir if ! Dir.exist? dir
|
40
35
|
end
|
41
36
|
|
42
|
-
def self.
|
43
|
-
|
44
|
-
source /etc/profile
|
45
|
-
#{cmd}
|
46
|
-
\""
|
47
|
-
Getch::Command.new(script).run!
|
37
|
+
def self.touch(file)
|
38
|
+
File.write file, '' if ! File.exist? file
|
48
39
|
end
|
49
40
|
|
50
41
|
def self.grep?(file, regex)
|
data/lib/getch/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szorfein
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
J/zT/q2Ac7BWpSLbv6p9lChBiEnD9j24x463LR5QQjDNS5SsjzRQfFuprsa9Nqf2
|
36
36
|
Tw==
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-10-
|
38
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email:
|
@@ -83,6 +83,20 @@ files:
|
|
83
83
|
- lib/getch/filesystem/lvm/format.rb
|
84
84
|
- lib/getch/filesystem/lvm/mount.rb
|
85
85
|
- lib/getch/filesystem/lvm/partition.rb
|
86
|
+
- lib/getch/filesystem/zfs.rb
|
87
|
+
- lib/getch/filesystem/zfs/config.rb
|
88
|
+
- lib/getch/filesystem/zfs/deps.rb
|
89
|
+
- lib/getch/filesystem/zfs/device.rb
|
90
|
+
- lib/getch/filesystem/zfs/encrypt.rb
|
91
|
+
- lib/getch/filesystem/zfs/encrypt/config.rb
|
92
|
+
- lib/getch/filesystem/zfs/encrypt/deps.rb
|
93
|
+
- lib/getch/filesystem/zfs/encrypt/device.rb
|
94
|
+
- lib/getch/filesystem/zfs/encrypt/format.rb
|
95
|
+
- lib/getch/filesystem/zfs/encrypt/mount.rb
|
96
|
+
- lib/getch/filesystem/zfs/encrypt/partition.rb
|
97
|
+
- lib/getch/filesystem/zfs/format.rb
|
98
|
+
- lib/getch/filesystem/zfs/mount.rb
|
99
|
+
- lib/getch/filesystem/zfs/partition.rb
|
86
100
|
- lib/getch/gentoo.rb
|
87
101
|
- lib/getch/gentoo/boot.rb
|
88
102
|
- lib/getch/gentoo/chroot.rb
|
@@ -116,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '0'
|
118
132
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.0.3
|
120
134
|
signing_key:
|
121
135
|
specification_version: 4
|
122
136
|
summary: A CLI tool to install Gentoo
|
metadata.gz.sig
CHANGED
Binary file
|