NixOS, Alpine Linux: mount datasets in Root on ZFS guide; immutable
root; GRUB update Acknowledgement: @bjornstromberg Closes #398 NixOS: remove NetworkManager by default, add note for enable Signed-off-by: Maurice Zhou <jasper@apvc.uk>
This commit is contained in:
committed by
George Melikov
parent
90172151d5
commit
5b8c163e24
@@ -80,9 +80,6 @@ System Installation
|
|||||||
limited to only those that GRUB supports, allowing the root pool to use
|
limited to only those that GRUB supports, allowing the root pool to use
|
||||||
any/all features.
|
any/all features.
|
||||||
|
|
||||||
Features enabled with ``-o compatibility=grub2`` can be seen
|
|
||||||
`here <https://github.com/openzfs/zfs/blob/master/cmd/zpool/compatibility.d/grub2>`__.
|
|
||||||
|
|
||||||
#. Create root pool::
|
#. Create root pool::
|
||||||
|
|
||||||
zpool create \
|
zpool create \
|
||||||
@@ -158,7 +155,7 @@ System Installation
|
|||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p /mnt/boot/efi
|
mkdir -p /mnt/boot/efi
|
||||||
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
|
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi
|
||||||
|
|
||||||
#. By default ``setup-disk`` command does not support zfs and will refuse to run,
|
#. By default ``setup-disk`` command does not support zfs and will refuse to run,
|
||||||
add zfs support::
|
add zfs support::
|
||||||
@@ -186,14 +183,6 @@ System Installation
|
|||||||
|
|
||||||
chroot /mnt /usr/bin/env DISK="$DISK" sh
|
chroot /mnt /usr/bin/env DISK="$DISK" sh
|
||||||
|
|
||||||
#. Rebuild initrd::
|
|
||||||
|
|
||||||
sed -i 's|zfs|nvme zfs|' /etc/mkinitfs/mkinitfs.conf
|
|
||||||
for directory in /lib/modules/*; do
|
|
||||||
kernel_version=$(basename $directory)
|
|
||||||
mkinitfs $kernel_version
|
|
||||||
done
|
|
||||||
|
|
||||||
#. Apply GRUB workaround::
|
#. Apply GRUB workaround::
|
||||||
|
|
||||||
echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
|
echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
|
||||||
@@ -206,10 +195,11 @@ System Installation
|
|||||||
sed -i 's|stat -f -c %T /|echo zfs|' /usr/sbin/grub-mkconfig
|
sed -i 's|stat -f -c %T /|echo zfs|' /usr/sbin/grub-mkconfig
|
||||||
|
|
||||||
# grub-probe fails to identify fs mounted at /boot
|
# grub-probe fails to identify fs mounted at /boot
|
||||||
sed -i "s|GRUB_DEVICE_BOOT=.*|GRUB_DEVICE_BOOT=$(echo $DISK | cut -f1 -d\ )-part2|" /usr/sbin/grub-mkconfig
|
BOOT_DEVICE=$(zpool status -P bpool | grep -- -part2 | head -n1 | sed "s|.*/dev*|/dev|" | sed "s|part2.*|part2|")
|
||||||
|
sed -i "s|GRUB_DEVICE_BOOT=.*|GRUB_DEVICE_BOOT=${BOOT_DEVICE}|" /usr/sbin/grub-mkconfig
|
||||||
|
|
||||||
This workaround needs to be applied for every GRUB update, as the
|
The ``sed`` workaround for ``grub-mkconfig`` needs to be applied
|
||||||
update will overwrite the changes.
|
for every GRUB update, as the update will overwrite the changes.
|
||||||
|
|
||||||
#. Install GRUB::
|
#. Install GRUB::
|
||||||
|
|
||||||
@@ -227,6 +217,8 @@ System Installation
|
|||||||
|
|
||||||
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/x86_64-efi/grub/grub.cfg
|
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/x86_64-efi/grub/grub.cfg
|
||||||
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/i386-pc/grub/grub.cfg
|
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/i386-pc/grub/grub.cfg
|
||||||
|
mkdir -p /boot/grub
|
||||||
|
grub-mkconfig -o /boot/grub/grub.cfg
|
||||||
|
|
||||||
#. For both legacy and EFI booting: mirror ESP content::
|
#. For both legacy and EFI booting: mirror ESP content::
|
||||||
|
|
||||||
@@ -243,7 +235,7 @@ System Installation
|
|||||||
|
|
||||||
#. Unmount filesystems::
|
#. Unmount filesystems::
|
||||||
|
|
||||||
cut -f2 -d\ /proc/mounts | grep ^/mnt | tac | while read i; do umount -l $i; done
|
umount -Rl /mnt
|
||||||
zpool export -a
|
zpool export -a
|
||||||
|
|
||||||
#. Reboot::
|
#. Reboot::
|
||||||
|
|||||||
@@ -148,4 +148,4 @@ System Installation
|
|||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p /mnt/boot/efi
|
mkdir -p /mnt/boot/efi
|
||||||
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
|
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ Bootloader
|
|||||||
/boot/efi --bootloader-id arch --removable
|
/boot/efi --bootloader-id arch --removable
|
||||||
grub-mkconfig -o /boot/efi/arch/grub-bootdir/x86_64-efi/grub/grub.cfg
|
grub-mkconfig -o /boot/efi/arch/grub-bootdir/x86_64-efi/grub/grub.cfg
|
||||||
grub-mkconfig -o /boot/efi/arch/grub-bootdir/i386-pc/grub/grub.cfg
|
grub-mkconfig -o /boot/efi/arch/grub-bootdir/i386-pc/grub/grub.cfg
|
||||||
|
mkdir -p /boot/grub
|
||||||
|
grub-mkconfig -o /boot/grub/grub.cfg
|
||||||
|
|
||||||
#. For both legacy and EFI booting: mirror ESP content::
|
#. For both legacy and EFI booting: mirror ESP content::
|
||||||
|
|
||||||
|
|||||||
@@ -148,4 +148,4 @@ System Installation
|
|||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p /mnt/boot/efi
|
mkdir -p /mnt/boot/efi
|
||||||
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
|
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ Bootloader
|
|||||||
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/fedora/
|
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/fedora/
|
||||||
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
|
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
|
||||||
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
|
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
|
||||||
|
mkdir -p /boot/grub2
|
||||||
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
|
||||||
#. For both legacy and EFI booting: mirror ESP content::
|
#. For both legacy and EFI booting: mirror ESP content::
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ Bootloader
|
|||||||
|
|
||||||
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
|
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
|
||||||
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
|
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
|
||||||
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
|
||||||
Finish Installation
|
Finish Installation
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ Preparation
|
|||||||
.. contents:: Table of Contents
|
.. contents:: Table of Contents
|
||||||
:local:
|
:local:
|
||||||
|
|
||||||
This guide supports x86_64 and arm64-efi architectures.
|
**Note for arm64**
|
||||||
|
|
||||||
**Note for Tow-Boot**
|
Currently there is a bug with the grub installation script. See `here
|
||||||
|
<https://github.com/NixOS/nixpkgs/issues/222491>`__ for details.
|
||||||
|
|
||||||
`Tow-Boot firmware <https://tow-boot.org/>`__
|
**Note for Immutable Root**
|
||||||
enables UEFI boot on many affordable arm64 based computers. If
|
|
||||||
using Tow-Boot, NixOS and Tow-Boot must be on separate disks.
|
Immutable root can be enabled or disabled by setting
|
||||||
Example, Tow-Boot is installed to an SD card. Then the SD card
|
``zfs-root.boot.immutable`` option inside per-host configuration.
|
||||||
should not be also shared with NixOS. Install NixOS to an external
|
|
||||||
disk instead.
|
|
||||||
|
|
||||||
#. Disable Secure Boot. ZFS modules can not be loaded if Secure Boot is enabled.
|
#. Disable Secure Boot. ZFS modules can not be loaded if Secure Boot is enabled.
|
||||||
#. Download `NixOS Live Image
|
#. Download `NixOS Live Image
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ System Installation
|
|||||||
mount -t zfs rpool/nixos/root /mnt/
|
mount -t zfs rpool/nixos/root /mnt/
|
||||||
zfs create -o mountpoint=legacy rpool/nixos/home
|
zfs create -o mountpoint=legacy rpool/nixos/home
|
||||||
mkdir /mnt/home
|
mkdir /mnt/home
|
||||||
mount -t zfs rpool/nixos/home /mnt/home
|
mount -t zfs rpool/nixos/home /mnt/home
|
||||||
zfs create -o mountpoint=legacy rpool/nixos/var
|
zfs create -o mountpoint=legacy rpool/nixos/var
|
||||||
zfs create -o mountpoint=legacy rpool/nixos/var/lib
|
zfs create -o mountpoint=legacy rpool/nixos/var/lib
|
||||||
zfs create -o mountpoint=legacy rpool/nixos/var/log
|
zfs create -o mountpoint=legacy rpool/nixos/var/log
|
||||||
@@ -134,6 +134,10 @@ System Installation
|
|||||||
zfs create -o mountpoint=legacy bpool/nixos/root
|
zfs create -o mountpoint=legacy bpool/nixos/root
|
||||||
mkdir /mnt/boot
|
mkdir /mnt/boot
|
||||||
mount -t zfs bpool/nixos/root /mnt/boot
|
mount -t zfs bpool/nixos/root /mnt/boot
|
||||||
|
mkdir -p /mnt/var/log
|
||||||
|
mkdir -p /mnt/var/lib
|
||||||
|
mount -t zfs rpool/nixos/var/lib /mnt/var/lib
|
||||||
|
mount -t zfs rpool/nixos/var/log /mnt/var/log
|
||||||
zfs create -o mountpoint=legacy rpool/nixos/empty
|
zfs create -o mountpoint=legacy rpool/nixos/empty
|
||||||
zfs snapshot rpool/nixos/empty@start
|
zfs snapshot rpool/nixos/empty@start
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ System Configuration
|
|||||||
sed -i "s|\"bootDevices_placeholder\"|$diskNames|g" \
|
sed -i "s|\"bootDevices_placeholder\"|$diskNames|g" \
|
||||||
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
||||||
|
|
||||||
sed -i "s|\"hostId_placeholder\"|\"$(head -c4 /dev/urandom | od -A none -t x4| sed 's| ||g')\"|g" \
|
sed -i "s|\"abcd1234\"|\"$(head -c4 /dev/urandom | od -A none -t x4| sed 's| ||g')\"|g" \
|
||||||
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
||||||
|
|
||||||
sed -i "s|\"systemType_placeholder\"|\"$(uname -m)-linux\"|g" \
|
sed -i "s|\"x86_64-linux\"|\"$(uname -m)-linux\"|g" \
|
||||||
/mnt/etc/nixos/flake.nix
|
/mnt/etc/nixos/flake.nix
|
||||||
|
|
||||||
#. Set root password::
|
#. Set root password::
|
||||||
@@ -52,8 +52,8 @@ System Configuration
|
|||||||
"s|rootHash_placeholder|${rootPwd}|" \
|
"s|rootHash_placeholder|${rootPwd}|" \
|
||||||
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
/mnt/etc/nixos/hosts/exampleHost/default.nix
|
||||||
|
|
||||||
#. Optional: add SSH public key for root and change host name in
|
#. You can enable NetworkManager for wireless networks and GNOME
|
||||||
``/mnt/etc/nixos/hosts/exampleHost/default.nix``.
|
desktop environment in ``configuration.nix``.
|
||||||
|
|
||||||
#. From now on, the complete configuration of the system will be
|
#. From now on, the complete configuration of the system will be
|
||||||
tracked by git, set a user name and email address to continue::
|
tracked by git, set a user name and email address to continue::
|
||||||
@@ -76,8 +76,6 @@ System Configuration
|
|||||||
|
|
||||||
nixos-install --no-root-passwd --flake "git+file:///mnt/etc/nixos#exampleHost"
|
nixos-install --no-root-passwd --flake "git+file:///mnt/etc/nixos#exampleHost"
|
||||||
|
|
||||||
If the host name was changed, use the new host name in this command.
|
|
||||||
|
|
||||||
#. Exit ephemeral nix shell with git::
|
#. Exit ephemeral nix shell with git::
|
||||||
|
|
||||||
exit
|
exit
|
||||||
@@ -91,22 +89,6 @@ System Configuration
|
|||||||
|
|
||||||
reboot
|
reboot
|
||||||
|
|
||||||
#. NetworkManager is enabled by default. To manage network
|
|
||||||
connections, execute::
|
|
||||||
|
|
||||||
nmtui
|
|
||||||
|
|
||||||
#. Optional: immutable root filesystem can be enabled by setting
|
|
||||||
``my.boot.immutable`` option to ``true``.
|
|
||||||
then execute::
|
|
||||||
|
|
||||||
nixos-rebuild boot
|
|
||||||
|
|
||||||
Then reboot. You may need to make certain
|
|
||||||
adjustments to where configuration files are stored,
|
|
||||||
see `NixOS wiki <https://nixos.wiki/wiki/ZFS>`__ for
|
|
||||||
details.
|
|
||||||
|
|
||||||
Replace a failed disk
|
Replace a failed disk
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
|
|||||||
@@ -148,4 +148,4 @@ System Installation
|
|||||||
done
|
done
|
||||||
|
|
||||||
mkdir -p /mnt/boot/efi
|
mkdir -p /mnt/boot/efi
|
||||||
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
|
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ Bootloader
|
|||||||
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/almalinux/
|
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/almalinux/
|
||||||
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
|
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
|
||||||
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
|
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
|
||||||
|
mkdir -p /boot/grub2
|
||||||
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
|
||||||
#. For both legacy and EFI booting: mirror ESP content::
|
#. For both legacy and EFI booting: mirror ESP content::
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ Bootloader
|
|||||||
|
|
||||||
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
|
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
|
||||||
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
|
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
|
||||||
|
grub2-mkconfig -o /boot/grub2/grub.cfg
|
||||||
|
|
||||||
Finish Installation
|
Finish Installation
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
Reference in New Issue
Block a user