Compare commits

..

26 Commits

Author SHA1 Message Date
15d67f2e3f Merge pull request '26-install-zfs-only-when-needed' (#27) from 26-install-zfs-only-when-needed into main
Reviewed-on: #27
2025-01-17 20:11:11 +00:00
6fb13a097c Merge remote-tracking branch 'origin/26-install-zfs-only-when-needed' into 26-install-zfs-only-when-needed 2025-01-17 21:09:40 +01:00
64c66cbd0f fix(zfs): Install ZFS only when needed (#26)
In situations where this script runs on alternative Arch Linux live
CD ISOs such as github.com/stevleibelt/arch-linux-live-cd-iso-with
-zfs we may not have to insall ZFS kernel modules. Test if the 'zfs'
module is loaded and skip installation if yes.
2025-01-17 21:09:19 +01:00
1036ce9c5b fix(zfs): Install ZFS only when needed (#26)
In situations where this script runs on alternative Arch Linux live
CD ISOs such as github.com/stevleibelt/arch-linux-live-cd-iso-with
-zfs we may not have to insall ZFS kernel modules. Test if the 'zfs'
module is loaded and skip installation if yes.
2025-01-17 21:08:44 +01:00
3ae8b53616 build(meta): Don't commit .idea JetBrains dir (#26) 2025-01-17 21:05:53 +01:00
2adac7b94b Add a 2G loop device for emergency swap 2025-01-02 01:00:06 +01:00
9525976fe2 For now no pacman upgrade in ISO 2024-12-28 18:27:29 +01:00
624d278971 For now no pacman upgrade in ISO 2024-12-28 18:21:04 +01:00
08f33c33c7 refactor(os): Retry pacman download on fail 2024-12-28 16:33:13 +01:00
eadbbea2fd Merge pull request '19-define-os-ip' (#24) from 19-define-os-ip into main
Reviewed-on: #24
2023-11-12 03:26:36 +00:00
d7d41eec5b refactor(os): Homogenous single quotes (#19) 2023-11-12 03:32:27 +01:00
6fe5d59108 refactor(os): remove unneeded line break (#19) 2023-11-12 03:31:31 +01:00
96b860e0db refactor(os): Update interactive questionnaire gif (#19) 2023-11-12 03:31:02 +01:00
d467dd6610 refactor(os): Phrasing (#19) 2023-11-11 04:35:41 +01:00
8ed5849596 refactor(os): Phrasing (#19) 2023-11-11 04:26:11 +01:00
5f6a5bfdac refactor(os): No need to hide kernel version string (#19) 2023-11-11 04:20:29 +01:00
47321313a9 refactor(os): Fix function numbering (#19) 2023-11-11 04:07:44 +01:00
c344aac77a refactor(os): Fix comment spacing (#19) 2023-11-11 04:06:30 +01:00
fd2c08a18a refactor(os): Always enable NTP (#19) 2023-11-11 04:05:21 +01:00
d74fc097eb refactor(os): Be specific with systemd unit names (#19) 2023-11-11 04:04:58 +01:00
acc6b2c721 feat(os): Reuse or set SSH pub keys in OS (#19) 2023-11-11 04:04:14 +01:00
d380fc4b6d fix(os): No need to double-quote in a heredoc (#19) 2023-11-11 04:03:09 +01:00
d95d43a22b feat(os): Downgrade kernel when requested (#19) 2023-11-11 04:02:30 +01:00
557db12e8d fix(zbm): ZBM 2.2.2 no longer needs nor has its own stub loader file (#19) 2023-11-11 04:01:59 +01:00
eaf83163b6 refactor(os): Typo (#19) 2023-11-11 04:01:28 +01:00
257648c99d feat(os): Optionally force kernel downgrade for ZFS compatibility (#19) 2023-11-11 04:01:14 +01:00
3 changed files with 230 additions and 84 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
archzbm_settings.env archzbm_settings.env
.idea

View File

@@ -109,6 +109,30 @@ In cases where a variable is both exported prior to script execution and specifi
Known options are as follows. 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 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 ### 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>`. 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>`.
@@ -243,7 +267,7 @@ This syntax crutch allows you to use the full range of Dropbear-supported `autho
An interactive questionnaire can guide you through settings and goes like this: An interactive questionnaire can guide you through settings and goes like this:
![Command line setup questionnaire](https://i.imgur.com/RhCStdu.gif) ![Command line setup questionnaire](https://i.imgur.com/OXG75GH.gif)
To do the questionnaire yourself start this script with the `setup` argument: To do the questionnaire yourself start this script with the `setup` argument:
@@ -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. 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` came out 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 # Flavor choices
We make the following opinionated flavor choices. Feel free to change them to your liking. We make the following opinionated flavor choices. Feel free to change them to your liking.

269
setup.sh
View File

@@ -68,13 +68,16 @@ function setup_env_vars () {
echo '----------------------------------------' echo '----------------------------------------'
echo echo
read -u3 -p 'Please type kernel version to use, leave empty for latest, confirm with <Enter>: ' ARCHZBM_KERNEL_VER
echo
echo 'Do you want compressed datasets?' echo 'Do you want compressed datasets?'
select arg_compressed in "Compressed" "Uncompressed"; do select arg_compressed in 'Compressed' 'Uncompressed'; do
case "${arg_compressed}" in case "${arg_compressed}" in
Compressed) 'Compressed')
break break
;; ;;
Uncompressed) 'Uncompressed')
ARCHZBM_ZFSPROPS_NO_COMPRESSION='true' ARCHZBM_ZFSPROPS_NO_COMPRESSION='true'
break break
;; ;;
@@ -82,12 +85,12 @@ function setup_env_vars () {
done <&3 && echo done <&3 && echo
echo 'Do you want encrypted datasets?' echo 'Do you want encrypted datasets?'
select arg_encrypted in "Encrypted" "Unencrypted"; do select arg_encrypted in 'Encrypted' 'Unencrypted'; do
case "${arg_encrypted}" in case "${arg_encrypted}" in
Encrypted) 'Encrypted')
break break
;; ;;
Unencrypted) 'Unencrypted')
ARCHZBM_ZFSPROPS_NO_ENCRYPTION='true' ARCHZBM_ZFSPROPS_NO_ENCRYPTION='true'
break break
;; ;;
@@ -96,13 +99,13 @@ function setup_env_vars () {
if [[ "${arg_encrypted}" = 'Encrypted' ]]; then if [[ "${arg_encrypted}" = 'Encrypted' ]]; then
echo 'Do you want a custom dataset decryption password?' echo 'Do you want a custom dataset decryption password?'
select arg_custom_dataset_pw in "Yes" "No"; do select arg_custom_dataset_pw in 'Yes' 'No (use '"'"'password'"'"')'; do
case "${arg_custom_dataset_pw}" in case "${arg_custom_dataset_pw}" in
Yes) 'Yes')
want_custom_dataset_pw='true' want_custom_dataset_pw='true'
break break
;; ;;
No) 'No (use '"'"'password'"'"')')
break break
;; ;;
esac esac
@@ -116,13 +119,13 @@ function setup_env_vars () {
fi fi
echo 'Do you want a custom '"'"'root'"'"' user password?' echo 'Do you want a custom '"'"'root'"'"' user password?'
select arg_custom_root_pw in "Yes" "No"; do select arg_custom_root_pw in 'Yes' 'No (use '"'"'password'"'"')'; do
case "${arg_custom_root_pw}" in case "${arg_custom_root_pw}" in
Yes) 'Yes')
want_custom_root_pw='true' want_custom_root_pw='true'
break break
;; ;;
No) 'No (use '"'"'password'"'"')')
break break
;; ;;
esac esac
@@ -149,7 +152,7 @@ function setup_env_vars () {
if [[ "${want_ssh_in_zbm}" ]]; then if [[ "${want_ssh_in_zbm}" ]]; then
echo 'How do you want to assign an IP address in ZFSBootMenu?' echo 'How do you want to assign an IP address in ZFSBootMenu?'
select arg_ip_autoconf_method in "Statically" "Dynamically, DHCP" "Dynamically, BOOTP" "Dynamically, RARP"; do select arg_ip_autoconf_method in 'Statically' 'Dynamically, DHCP' 'Dynamically, BOOTP' 'Dynamically, RARP'; do
case "${arg_ip_autoconf_method}" in case "${arg_ip_autoconf_method}" in
'Statically') 'Statically')
ARCHZBM_NET_AUTOCONF='none' ARCHZBM_NET_AUTOCONF='none'
@@ -185,7 +188,7 @@ function setup_env_vars () {
fi fi
echo 'Do you want a custom SSH listening port?' echo 'Do you want a custom SSH listening port?'
select arg_custom_ssh_port in "Yes (let me specify)" "No (keep port 22)"; do select arg_custom_ssh_port in 'Yes (let me specify)' 'No (keep port 22)'; do
case "${arg_custom_ssh_port}" in case "${arg_custom_ssh_port}" in
'Yes (let me specify)') 'Yes (let me specify)')
want_custom_ssh_port='true' want_custom_ssh_port='true'
@@ -203,7 +206,7 @@ function setup_env_vars () {
fi fi
echo 'Do you want the SSH daemon to use a custom keepalive send interval?' echo 'Do you want the SSH daemon to use a custom keepalive send interval?'
select arg_custom_ssh_keepalive_intvl in "Yes (let me specify)" "No (keep 1)"; do select arg_custom_ssh_keepalive_intvl in 'Yes (let me specify)' 'No (keep 1)'; do
case "${arg_custom_ssh_keepalive_intvl}" in case "${arg_custom_ssh_keepalive_intvl}" in
'Yes (let me specify)') 'Yes (let me specify)')
want_custom_keepalive_intvl='true' want_custom_keepalive_intvl='true'
@@ -278,6 +281,48 @@ function setup_env_vars () {
fi fi
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 if [[ "${want_dns_and_ntp}" ]]; then
read -u3 -p 'Specify one or more comma-separated DNS IPs: ' ARCHZBM_OS_DNS_IP read -u3 -p 'Specify one or more comma-separated DNS IPs: ' ARCHZBM_OS_DNS_IP
echo echo
@@ -301,7 +346,7 @@ function setup_env_vars () {
fi fi
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 if [[ "${!env_var}" ]]; then
printf -- '%s='"'"'%s'"'"'\n' \ printf -- '%s='"'"'%s'"'"'\n' \
"${env_var}" "${!env_var}" \ "${env_var}" "${!env_var}" \
@@ -312,7 +357,7 @@ function setup_env_vars () {
printf -- '%s\n' \ printf -- '%s\n' \
'Done, please rerun script now with just' \ 'Done, please rerun script now with just' \
'... | bash' \ '... | bash' \
'so without the '"'"'setup'"'"' argument's 'so without the '"'"'setup'"'"' argument'
exit 77 exit 77
} }
@@ -384,19 +429,34 @@ function update_pacman_db () {
systemctl start reflector systemctl start reflector
# In an ISO and for the minimal number of packages we need we do not # In an ISO and for the minimal number of packages we need we do not
# care about partial upgrades # care about partial upgrades
pacman -Syyuu --noconfirm #
# Are we better off not attempting an upgrade inside the ISO?
# Let's try and find out.
# while ! pacman -Syyuu --needed --noconfirm --downloadonly; do
# sleep 5
# done
# pacman -Syyuu --needed --noconfirm
pacman -Syy
} }
function install_pkgs () { function install_pkgs () {
#1.5 #1.5
printf -- '%s\n' 'Installing packages ...' printf -- '%s\n' 'Installing packages ...'
while ! pacman -S --needed --noconfirm --downloadonly "${@}"; do
sleep 5
done
pacman -S --needed --noconfirm "${@}" pacman -S --needed --noconfirm "${@}"
} }
function install_zfs () { function install_zfs () {
#1.6 #1.6
declare reset_colors='\033[0m' declare reset_colors='\033[0m'
curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash if modinfo 'zfs' &>/dev/null; then
>&3 printf -- '%s\n' \
'ZFS kernel module is loaded, no need to install ...'
else
curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash
fi
printf -- "${reset_colors}" printf -- "${reset_colors}"
} }
@@ -718,27 +778,29 @@ function install_archlinux () {
#1.12 #1.12
pacman_dl_parallel pacman_dl_parallel
pacman_dont_check_space pacman_dont_check_space
pacstrap /mnt \ while ! pacstrap /mnt \
base \ base \
base-devel \ base-devel \
linux \ linux \
linux-headers \ linux-headers \
linux-firmware \ linux-firmware \
amd-ucode \ amd-ucode \
efibootmgr \ efibootmgr \
vim \ vim \
git \ git \
iwd \ iwd \
networkmanager \ networkmanager \
network-manager-applet \ network-manager-applet \
dialog \ dialog \
os-prober \ os-prober \
reflector \ reflector \
bluez \ bluez \
bluez-utils \ bluez-utils \
man-db \ man-db \
xdg-utils \ xdg-utils \
xdg-user-dirs xdg-user-dirs; do
sleep 5
done
} }
function gen_fstab () { function gen_fstab () {
@@ -1047,7 +1109,6 @@ EFI:
ImageDir: /efi/EFI/ZBM ImageDir: /efi/EFI/ZBM
Versions: false Versions: false
Enabled: true Enabled: true
Stub: /usr/share/zfsbootmenu/stubs/linuxx64.efi.stub/linuxx64.efi.stub # workaround: https://github.com/zbm-dev/zfsbootmenu/discussions/501
Kernel: Kernel:
CommandLine: ro loglevel=0 zbm.import_policy=hostid CommandLine: ro loglevel=0 zbm.import_policy=hostid
Prefix: vmlinuz Prefix: vmlinuz
@@ -1244,6 +1305,10 @@ function get_disks_with_one_efipart () {
function install_os_in_chroot () { function install_os_in_chroot () {
#2.2 #2.2
dd if='/dev/zero' of='/swapfile' bs='1M' count='2048'
losetup '/dev/loop9' '/swapfile'
mkswap '/dev/loop9'
swapon '/dev/loop9'
### Reinit keyring ### Reinit keyring
# As keyring is initialized at boot, and copied to the install dir with pacstrap, and ntp is running # As keyring is initialized at boot, and copied to the install dir with pacstrap, and ntp is running
# Time changed after keyring initialization, it leads to malfunction # Time changed after keyring initialization, it leads to malfunction
@@ -1251,6 +1316,9 @@ function install_os_in_chroot () {
rm -rf '/etc/pacman.d/gnupg' rm -rf '/etc/pacman.d/gnupg'
pacman-key --init pacman-key --init
pacman-key --populate archlinux pacman-key --populate archlinux
while ! pacman -S archlinux-keyring --noconfirm --downloadonly; do
sleep 5
done
pacman -S archlinux-keyring --noconfirm pacman -S archlinux-keyring --noconfirm
locale-gen locale-gen
@@ -1261,6 +1329,13 @@ function install_os_in_chroot () {
unleash_makepkg #2.5 unleash_makepkg #2.5
add_motd_getting_started_msg #2.6 add_motd_getting_started_msg #2.6
get_aur_helper #2.7 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' paru_install 'zfs-dkms' 'zfs-utils' 'jq'
hwclock --systohc hwclock --systohc
mkinitcpio -P mkinitcpio -P
@@ -1280,6 +1355,9 @@ function install_os_in_chroot () {
add_syslinux_pacman_hook add_syslinux_pacman_hook
fi fi
add_zbm_pacman_hook add_zbm_pacman_hook
swapoff '/dev/loop9'
losetup -d '/dev/loop9'
rm '/swapfile'
} }
function set_root_pw () { function set_root_pw () {
@@ -1312,8 +1390,8 @@ EOF
[[ "${ARCHZBM_OS_NTP_IP}" ]]; then [[ "${ARCHZBM_OS_NTP_IP}" ]]; then
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
Address="${ARCHZBM_OS_CLIENT_IP}" Address=${ARCHZBM_OS_CLIENT_IP}
Gateway="${ARCHZBM_OS_GATEWAY_IP}" Gateway=${ARCHZBM_OS_GATEWAY_IP}
EOF EOF
if [[ "${ARCHZBM_OS_DNS_IP}" ]]; then if [[ "${ARCHZBM_OS_DNS_IP}" ]]; then
@@ -1324,7 +1402,7 @@ EOF
fi fi
for dns_addr in "${dns_addresses[@]}"; do for dns_addr in "${dns_addresses[@]}"; do
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
DNS="${dns_addr}" DNS=${dns_addr}
EOF EOF
done done
@@ -1332,7 +1410,7 @@ EOF
mapfile -t ntp_addresses < <(<<<"${ARCHZBM_OS_NTP_IP}" tr ',' '\n' | sed '/^$/d') mapfile -t ntp_addresses < <(<<<"${ARCHZBM_OS_NTP_IP}" tr ',' '\n' | sed '/^$/d')
for ntp_addr in "${ntp_addresses[@]}"; do for ntp_addr in "${ntp_addresses[@]}"; do
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
NTP="${ntp_addr}" NTP=${ntp_addr}
EOF EOF
done done
fi fi
@@ -1356,29 +1434,50 @@ EOF
systemctl disable 'systemd-networkd-wait-online' --root='/mnt' systemctl disable 'systemd-networkd-wait-online' --root='/mnt'
} }
function configure_dns () { function configure_sshd () {
#3.4 #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' rm '/mnt/etc/resolv.conf'
ln -s '/run/systemd/resolve/stub-resolv.conf' '/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 # Optionally you may want /etc/systemd/network/50-wired.network to use
# UseDNS=no and hardcode DNS server(s) here: # UseDNS=no and hardcode DNS server(s) here:
# sed -i 's/^#DNS=.*/DNS=1.1.1.1/' /mnt/etc/systemd/resolved.conf # 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 () { function configure_reflector () {
#3.5 #3.7
systemctl enable 'reflector.service' 'reflector.timer' --root='/mnt' systemctl enable 'reflector.service' 'reflector.timer' --root='/mnt'
} }
function configure_zfs () { function configure_zfs () {
#3.6 #3.8
systemctl enable 'zfs-import-cache' 'zfs-mount' 'zfs-import.target' 'zfs.target' --root='/mnt' systemctl enable 'zfs-import-cache.service' 'zfs-mount.service' 'zfs-import.target' 'zfs.target' --root='/mnt'
} }
function configure_zfs_mount_gen () { function configure_zfs_mount_gen () {
#3.7 #3.9
mkdir -p '/mnt/etc/zfs/zfs-list.cache' mkdir -p '/mnt/etc/zfs/zfs-list.cache'
touch '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}" 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}" 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 +1485,7 @@ function configure_zfs_mount_gen () {
} }
function set_new_uefi_boot_entries () { function set_new_uefi_boot_entries () {
#3.8 #3.10
declare -a uefi_images declare -a uefi_images
mapfile -t uefi_images < \ mapfile -t uefi_images < \
<(find '/mnt/efi/EFI/ZBM' -type f -iname '*.efi' -print0 | \ <(find '/mnt/efi/EFI/ZBM' -type f -iname '*.efi' -print0 | \
@@ -1429,7 +1528,7 @@ function set_new_uefi_boot_entries () {
} }
function umount_all () { function umount_all () {
#3.9 #3.11
if [[ "${part_schema}" = 'mbr' ]]; then if [[ "${part_schema}" = 'mbr' ]]; then
umount '/mnt/boot/syslinux' umount '/mnt/boot/syslinux'
else else
@@ -1441,16 +1540,20 @@ function umount_all () {
function finalize_os_setup () { function finalize_os_setup () {
#3.1 #3.1
set_root_pw #3.2 set_root_pw #3.2
configure_networking #3.3 configure_networking #3.3
configure_dns #3.4 if [[ "${ARCHZBM_OS_SSH_AUTH_KEYS}" ]]; then
configure_reflector #3.5 configure_sshd #3.4
configure_zfs #3.6
configure_zfs_mount_gen #3.7
if [[ "${part_schema}" = 'gpt' ]]; then
set_new_uefi_boot_entries #3.8
fi 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 () { function main () {
@@ -1458,29 +1561,29 @@ function main () {
arg_parse "${@}" arg_parse "${@}"
fi fi
if we_are_changerooted; then if we_are_changerooted; then
install_os_in_chroot #2.2 install_os_in_chroot #2.2
else else
no_kernel_update_in_iso #1.1 no_kernel_update_in_iso #1.1
set_ntp #1.2 set_ntp #1.2
resize_cow_space #1.3 resize_cow_space #1.3
update_pacman_db #1.4 update_pacman_db #1.4
install_pkgs 'jq' #1.5 install_pkgs 'jq' #1.5
install_zfs #1.6 install_zfs #1.6
uefi_or_bios #1.7 uefi_or_bios #1.7
load_settings_file #1.8 load_settings_file #1.8
setup_zpool #1.9 setup_zpool #1.9
mount_system #1.10 mount_system #1.10
copy_zpool_cache #1.11 copy_zpool_cache #1.11
install_archlinux #1.12 install_archlinux #1.12
gen_fstab #1.13 gen_fstab #1.13
set_hostname #1.14 set_hostname #1.14
set_locale #1.15 set_locale #1.15
add_zfs_hook_to_initramfs #1.16 add_zfs_hook_to_initramfs #1.16
set_initramfs_build_list #1.17 set_initramfs_build_list #1.17
add_zfs_files_to_new_os #1.18 add_zfs_files_to_new_os #1.18
enter_chroot #2.1 enter_chroot #2.1
# We're done in chroot # We're done in chroot
finalize_os_setup #3.1 finalize_os_setup #3.1
fi fi
} }