Compare commits
10 Commits
3903498d40
...
47321313a9
Author | SHA1 | Date | |
---|---|---|---|
47321313a9 | |||
c344aac77a | |||
fd2c08a18a | |||
d74fc097eb | |||
acc6b2c721 | |||
d380fc4b6d | |||
d95d43a22b | |||
557db12e8d | |||
eaf83163b6 | |||
257648c99d |
42
README.md
42
README.md
@@ -109,6 +109,30 @@ In cases where a variable is both exported prior to script execution and specifi
|
||||
|
||||
Known options are as follows.
|
||||
|
||||
### Kernel downgrade
|
||||
|
||||
By default we install newest `linux` and `linux-headers` packages into a `chroot`. Once we're in that `chroot` we then install newest [AUR zfs-dkms package](https://aur.archlinux.org/packages/zfs-dkms). You may want to override `linux` and `linux-headers` versions we're installing to ensure you end up with a compatible mix between them and `zfs-dkms`.
|
||||
|
||||
For example:
|
||||
```
|
||||
export ARCHZBM_KERNEL_VER=6.5.9.arch2
|
||||
```
|
||||
|
||||
In our `chroot` this will trigger execution of:
|
||||
```
|
||||
downgrade --ala-only 'linux=6.5.9.arch2' 'linux-headers=6.5.9.arch2' --ignore always
|
||||
```
|
||||
|
||||
Where `downgrade` is the [AUR downgrade package](https://aur.archlinux.org/packages/downgrade). This will downgrade `linux` and `linux-headers` and will add a setting to your `/etc/pacman.conf`:
|
||||
```
|
||||
[options]
|
||||
IgnorePkg = linux linux-headers
|
||||
```
|
||||
|
||||
Setting `ARCHZBM_KERNEL_VER` to an empty string `''` or keeping it undefined are both valid and will retain newest versions instead of downgrading.
|
||||
|
||||
Also read [Kernel selection](#kernel-selection) for details.
|
||||
|
||||
### Compression
|
||||
|
||||
By default we create a zpool with ZFS property `compression=on`. If the `lz4_compress` pool feature is active this will by default enable `compression=lz4`. See `man 7 zfsprops` for example in ZFS 2.1.9 for details. See `zpool get feature@lz4_compress <pool>` to check this feature's status on your `<pool>`.
|
||||
@@ -296,6 +320,24 @@ When it comes to the point that your SSH client sends an are-your-still-there me
|
||||
|
||||
This effectively configures your SSH client to remain connected even through somewhat lossy hops to the Dropbear daemon; and to cleanly disconnect 3 seconds and some change after you've executed whatever you needed to do in ZFSBootMenu.
|
||||
|
||||
# Kernel selection
|
||||
|
||||
This script compiles ZFS via Arch Linux' [Dynamic Kernel Module Support](https://wiki.archlinux.org/title/Dynamic_Kernel_Module_Support) (DKMS). Not all kernels allow for successful compilation, in some instances a particularly recent kernel version may change APIs to such a degree that ZFS compilation simply fails.
|
||||
|
||||
We strongly suggest to that you:
|
||||
|
||||
- Firstly, refer to a resource such as the [Arch Linux Archive package version list](https://archive.archlinux.org/packages/l/linux/) to find out what newest kernel version this script will install.
|
||||
- Secondly, research if newest [AUR zfs-dkms package](https://aur.archlinux.org/packages/zfs-dkms) is compatible with that kernel. Two reasonable points of contact are AUR and its comments section for `zfs-dkms` where users quickly report issues; and the [github.com/openzfs/zfs issues list](https://github.com/openzfs/zfs/issues).
|
||||
|
||||
An example for this is that `linux-6.6.1.arch1-1-x86_64` released on Wednesday, November 8, 2023 at a time when newest `zfs-dkms` package version [was 2.2.0](https://aur.archlinux.org/cgit/aur.git/commit/?h=zfs-dkms&id=da1b6372c57b16f2781a7fda2b95971bb392c5ee) which did not compile against `linux` 6.6.x.
|
||||
|
||||
You'd then set for example:
|
||||
```
|
||||
export ARCHZBM_KERNEL_VER=6.5.9.arch2
|
||||
```
|
||||
|
||||
Where any 6.5.x version is known to work well with `zfs-dkms`. See also [Kernel downgrade](#kernel-downgrade) for details on how to configure this.
|
||||
|
||||
# Flavor choices
|
||||
|
||||
We make the following opinionated flavor choices. Feel free to change them to your liking.
|
||||
|
167
setup.sh
167
setup.sh
@@ -68,6 +68,10 @@ function setup_env_vars () {
|
||||
echo '----------------------------------------'
|
||||
echo
|
||||
|
||||
read -u3 -p 'Please type kernel version to use, leave empty for latest, confirm with <Enter>: ' -s ARCHZBM_KERNEL_VER
|
||||
echo
|
||||
echo
|
||||
|
||||
echo 'Do you want compressed datasets?'
|
||||
select arg_compressed in "Compressed" "Uncompressed"; do
|
||||
case "${arg_compressed}" in
|
||||
@@ -278,6 +282,48 @@ function setup_env_vars () {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${want_ssh_in_zbm}" ]]; then
|
||||
echo 'Do you want to define OS root user'"'"'s SSH pub key?'
|
||||
select arg_root_pub_keys in 'Yes (let me specify)' 'Yes (use ZBM pub keys)' 'No (don'"'"'t enable sshd.service)'; do
|
||||
case "${arg_root_pub_keys}" in
|
||||
'Yes (let me specify)')
|
||||
want_custom_pub_keys_in_os='true'
|
||||
break
|
||||
;;
|
||||
'Yes (use ZBM pub keys)')
|
||||
ARCHZBM_OS_SSH_AUTH_KEYS="${ARCHZBM_SSH_AUTH_KEYS}"
|
||||
break
|
||||
;;
|
||||
'No (don'"'"'t enable sshd.service)')
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done <&3 && echo
|
||||
|
||||
if [[ "${want_custom_pub_keys_in_os}" ]]; then
|
||||
read -u3 -p 'Please type SSH pub keys on one line separated by double-commas (,,) and confirm with <Enter>: ' ARCHZBM_OS_SSH_AUTH_KEYS
|
||||
echo
|
||||
fi
|
||||
else
|
||||
echo 'Do you want to define OS root user'"'"'s SSH pub key?'
|
||||
select arg_root_pub_keys in 'Yes (let me specify)' 'No (don'"'"'t enable sshd.service)'; do
|
||||
case "${arg_root_pub_keys}" in
|
||||
'Yes (let me specify)')
|
||||
want_own_pub_key_in_os='true'
|
||||
break
|
||||
;;
|
||||
'No (don'"'"'t enable sshd.service)')
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done <&3 && echo
|
||||
|
||||
if [[ "${want_own_pub_key_in_os}" ]]; then
|
||||
read -u3 -p 'Please type SSH pub keys on one line separated by double-commas (,,) and confirm with <Enter>: ' ARCHZBM_OS_SSH_AUTH_KEYS
|
||||
echo
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${want_dns_and_ntp}" ]]; then
|
||||
read -u3 -p 'Specify one or more comma-separated DNS IPs: ' ARCHZBM_OS_DNS_IP
|
||||
echo
|
||||
@@ -301,7 +347,7 @@ function setup_env_vars () {
|
||||
fi
|
||||
fi
|
||||
|
||||
for env_var in 'ARCHZBM_ZFSPROPS_NO_COMPRESSION' 'ARCHZBM_ZFSPROPS_NO_ENCRYPTION' 'ARCHZBM_ZPOOL_PASSWORD' 'ARCHZBM_ROOT_PASSWORD' 'ARCHZBM_NET_AUTOCONF' 'ARCHZBM_NET_DEVICE' 'ARCHZBM_NET_CLIENT_IP' 'ARCHZBM_NET_NETMASK' 'ARCHZBM_NET_GATEWAY_IP' 'ARCHZBM_SSH_PORT' 'ARCHZBM_SSH_KEEPALIVE_INTVL' 'ARCHZBM_SSH_AUTH_KEYS' 'ARCHZBM_OS_CLIENT_IP' 'ARCHZBM_OS_GATEWAY_IP' 'ARCHZBM_OS_DNS_IP' 'ARCHZBM_OS_NTP_IP'; do
|
||||
for env_var in 'ARCHZBM_KERNEL_VER' 'ARCHZBM_ZFSPROPS_NO_COMPRESSION' 'ARCHZBM_ZFSPROPS_NO_ENCRYPTION' 'ARCHZBM_ZPOOL_PASSWORD' 'ARCHZBM_ROOT_PASSWORD' 'ARCHZBM_NET_AUTOCONF' 'ARCHZBM_NET_DEVICE' 'ARCHZBM_NET_CLIENT_IP' 'ARCHZBM_NET_NETMASK' 'ARCHZBM_NET_GATEWAY_IP' 'ARCHZBM_SSH_PORT' 'ARCHZBM_SSH_KEEPALIVE_INTVL' 'ARCHZBM_SSH_AUTH_KEYS' 'ARCHZBM_OS_CLIENT_IP' 'ARCHZBM_OS_GATEWAY_IP' 'ARCHZBM_OS_SSH_AUTH_KEYS' 'ARCHZBM_OS_DNS_IP' 'ARCHZBM_OS_NTP_IP'; do
|
||||
if [[ "${!env_var}" ]]; then
|
||||
printf -- '%s='"'"'%s'"'"'\n' \
|
||||
"${env_var}" "${!env_var}" \
|
||||
@@ -312,7 +358,7 @@ function setup_env_vars () {
|
||||
printf -- '%s\n' \
|
||||
'Done, please rerun script now with just' \
|
||||
'... | bash' \
|
||||
'so without the '"'"'setup'"'"' argument's
|
||||
'so without the '"'"'setup'"'"' argument'
|
||||
exit 77
|
||||
}
|
||||
|
||||
@@ -1047,7 +1093,6 @@ EFI:
|
||||
ImageDir: /efi/EFI/ZBM
|
||||
Versions: false
|
||||
Enabled: true
|
||||
Stub: /usr/share/zfsbootmenu/stubs/linuxx64.efi.stub/linuxx64.efi.stub # workaround: https://github.com/zbm-dev/zfsbootmenu/discussions/501
|
||||
Kernel:
|
||||
CommandLine: ro loglevel=0 zbm.import_policy=hostid
|
||||
Prefix: vmlinuz
|
||||
@@ -1261,6 +1306,13 @@ function install_os_in_chroot () {
|
||||
unleash_makepkg #2.5
|
||||
add_motd_getting_started_msg #2.6
|
||||
get_aur_helper #2.7
|
||||
if [[ "${ARCHZBM_KERNEL_VER}" ]]; then
|
||||
paru_install 'downgrade'
|
||||
yes | downgrade --ala-only \
|
||||
'linux='"${ARCHZBM_KERNEL_VER}" \
|
||||
'linux-headers='"${ARCHZBM_KERNEL_VER}" \
|
||||
--ignore always
|
||||
fi
|
||||
paru_install 'zfs-dkms' 'zfs-utils' 'jq'
|
||||
hwclock --systohc
|
||||
mkinitcpio -P
|
||||
@@ -1312,8 +1364,8 @@ EOF
|
||||
[[ "${ARCHZBM_OS_NTP_IP}" ]]; then
|
||||
|
||||
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||
Address="${ARCHZBM_OS_CLIENT_IP}"
|
||||
Gateway="${ARCHZBM_OS_GATEWAY_IP}"
|
||||
Address=${ARCHZBM_OS_CLIENT_IP}
|
||||
Gateway=${ARCHZBM_OS_GATEWAY_IP}
|
||||
EOF
|
||||
|
||||
if [[ "${ARCHZBM_OS_DNS_IP}" ]]; then
|
||||
@@ -1324,7 +1376,7 @@ EOF
|
||||
fi
|
||||
for dns_addr in "${dns_addresses[@]}"; do
|
||||
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||
DNS="${dns_addr}"
|
||||
DNS=${dns_addr}
|
||||
EOF
|
||||
done
|
||||
|
||||
@@ -1332,7 +1384,7 @@ EOF
|
||||
mapfile -t ntp_addresses < <(<<<"${ARCHZBM_OS_NTP_IP}" tr ',' '\n' | sed '/^$/d')
|
||||
for ntp_addr in "${ntp_addresses[@]}"; do
|
||||
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||
NTP="${ntp_addr}"
|
||||
NTP=${ntp_addr}
|
||||
EOF
|
||||
done
|
||||
fi
|
||||
@@ -1356,29 +1408,50 @@ EOF
|
||||
systemctl disable 'systemd-networkd-wait-online' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_dns () {
|
||||
function configure_sshd () {
|
||||
#3.4
|
||||
local pub_key_line
|
||||
|
||||
cat >> '/mnt/etc/ssh/sshd_config.d/40-defaults.conf' <<"EOF"
|
||||
PasswordAuthentication no
|
||||
PermitRootLogin yes
|
||||
EOF
|
||||
|
||||
while IFS= read -r pub_key_line; do
|
||||
printf -- '%s\n' "${pub_key_line}" >> '/mnt/root/.ssh/authorized_keys'
|
||||
done < <(<<<"${ARCHZBM_OS_SSH_AUTH_KEYS}" sed -r -e 's/,,/\n/g')
|
||||
|
||||
systemctl enable 'sshd.service' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_dns () {
|
||||
#3.5
|
||||
rm '/mnt/etc/resolv.conf'
|
||||
ln -s '/run/systemd/resolve/stub-resolv.conf' '/mnt/etc/resolv.conf'
|
||||
|
||||
# Optionally you may want /etc/systemd/network/50-wired.network to use
|
||||
# UseDNS=no and hardcode DNS server(s) here:
|
||||
# sed -i 's/^#DNS=.*/DNS=1.1.1.1/' /mnt/etc/systemd/resolved.conf
|
||||
systemctl enable 'systemd-resolved' --root='/mnt'
|
||||
systemctl enable 'systemd-resolved.service' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_ntp () {
|
||||
#3.6
|
||||
systemctl enable 'systemd-timesyncd.service' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_reflector () {
|
||||
#3.5
|
||||
#3.7
|
||||
systemctl enable 'reflector.service' 'reflector.timer' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_zfs () {
|
||||
#3.6
|
||||
systemctl enable 'zfs-import-cache' 'zfs-mount' 'zfs-import.target' 'zfs.target' --root='/mnt'
|
||||
#3.8
|
||||
systemctl enable 'zfs-import-cache.service' 'zfs-mount.service' 'zfs-import.target' 'zfs.target' --root='/mnt'
|
||||
}
|
||||
|
||||
function configure_zfs_mount_gen () {
|
||||
#3.7
|
||||
#3.9
|
||||
mkdir -p '/mnt/etc/zfs/zfs-list.cache'
|
||||
touch '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}"
|
||||
zfs list -H -o name,mountpoint,canmount,atime,relatime,devices,exec,readonly,setuid,nbmand | sed 's/\/mnt//' > '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}"
|
||||
@@ -1386,7 +1459,7 @@ function configure_zfs_mount_gen () {
|
||||
}
|
||||
|
||||
function set_new_uefi_boot_entries () {
|
||||
#3.8
|
||||
#3.10
|
||||
declare -a uefi_images
|
||||
mapfile -t uefi_images < \
|
||||
<(find '/mnt/efi/EFI/ZBM' -type f -iname '*.efi' -print0 | \
|
||||
@@ -1429,7 +1502,7 @@ function set_new_uefi_boot_entries () {
|
||||
}
|
||||
|
||||
function umount_all () {
|
||||
#3.9
|
||||
#3.11
|
||||
if [[ "${part_schema}" = 'mbr' ]]; then
|
||||
umount '/mnt/boot/syslinux'
|
||||
else
|
||||
@@ -1441,16 +1514,20 @@ function umount_all () {
|
||||
|
||||
function finalize_os_setup () {
|
||||
#3.1
|
||||
set_root_pw #3.2
|
||||
configure_networking #3.3
|
||||
configure_dns #3.4
|
||||
configure_reflector #3.5
|
||||
configure_zfs #3.6
|
||||
configure_zfs_mount_gen #3.7
|
||||
if [[ "${part_schema}" = 'gpt' ]]; then
|
||||
set_new_uefi_boot_entries #3.8
|
||||
set_root_pw #3.2
|
||||
configure_networking #3.3
|
||||
if [[ "${ARCHZBM_OS_SSH_AUTH_KEYS}" ]]; then
|
||||
configure_sshd #3.4
|
||||
fi
|
||||
umount_all #3.9
|
||||
configure_dns #3.5
|
||||
configure_ntp #3.6
|
||||
configure_reflector #3.7
|
||||
configure_zfs #3.8
|
||||
configure_zfs_mount_gen #3.9
|
||||
if [[ "${part_schema}" = 'gpt' ]]; then
|
||||
set_new_uefi_boot_entries #3.10
|
||||
fi
|
||||
umount_all #3.11
|
||||
}
|
||||
|
||||
function main () {
|
||||
@@ -1458,29 +1535,29 @@ function main () {
|
||||
arg_parse "${@}"
|
||||
fi
|
||||
if we_are_changerooted; then
|
||||
install_os_in_chroot #2.2
|
||||
install_os_in_chroot #2.2
|
||||
else
|
||||
no_kernel_update_in_iso #1.1
|
||||
set_ntp #1.2
|
||||
resize_cow_space #1.3
|
||||
update_pacman_db #1.4
|
||||
install_pkgs 'jq' #1.5
|
||||
install_zfs #1.6
|
||||
uefi_or_bios #1.7
|
||||
load_settings_file #1.8
|
||||
setup_zpool #1.9
|
||||
mount_system #1.10
|
||||
copy_zpool_cache #1.11
|
||||
install_archlinux #1.12
|
||||
gen_fstab #1.13
|
||||
set_hostname #1.14
|
||||
set_locale #1.15
|
||||
add_zfs_hook_to_initramfs #1.16
|
||||
set_initramfs_build_list #1.17
|
||||
add_zfs_files_to_new_os #1.18
|
||||
enter_chroot #2.1
|
||||
no_kernel_update_in_iso #1.1
|
||||
set_ntp #1.2
|
||||
resize_cow_space #1.3
|
||||
update_pacman_db #1.4
|
||||
install_pkgs 'jq' #1.5
|
||||
install_zfs #1.6
|
||||
uefi_or_bios #1.7
|
||||
load_settings_file #1.8
|
||||
setup_zpool #1.9
|
||||
mount_system #1.10
|
||||
copy_zpool_cache #1.11
|
||||
install_archlinux #1.12
|
||||
gen_fstab #1.13
|
||||
set_hostname #1.14
|
||||
set_locale #1.15
|
||||
add_zfs_hook_to_initramfs #1.16
|
||||
set_initramfs_build_list #1.17
|
||||
add_zfs_files_to_new_os #1.18
|
||||
enter_chroot #2.1
|
||||
# We're done in chroot
|
||||
finalize_os_setup #3.1
|
||||
finalize_os_setup #3.1
|
||||
fi
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user