Skip to content

Commit 5b8c163

Browse files
Maurice Zhougmelikov
authored andcommitted
NixOS, Alpine Linux: mount datasets in Root on ZFS guide; immutable
root; GRUB update Acknowledgement: @bjornstromberg Closes openzfs#398 NixOS: remove NetworkManager by default, add note for enable Signed-off-by: Maurice Zhou <[email protected]>
1 parent 9017215 commit 5b8c163

File tree

10 files changed

+35
-50
lines changed

10 files changed

+35
-50
lines changed

docs/Getting Started/Alpine Linux/Root on ZFS/2-system-installation.rst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ System Installation
8080
limited to only those that GRUB supports, allowing the root pool to use
8181
any/all features.
8282

83-
Features enabled with ``-o compatibility=grub2`` can be seen
84-
`here <https://github.com/openzfs/zfs/blob/master/cmd/zpool/compatibility.d/grub2>`__.
85-
8683
#. Create root pool::
8784

8885
zpool create \
@@ -158,7 +155,7 @@ System Installation
158155
done
159156

160157
mkdir -p /mnt/boot/efi
161-
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
158+
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi
162159

163160
#. By default ``setup-disk`` command does not support zfs and will refuse to run,
164161
add zfs support::
@@ -186,14 +183,6 @@ System Installation
186183

187184
chroot /mnt /usr/bin/env DISK="$DISK" sh
188185

189-
#. Rebuild initrd::
190-
191-
sed -i 's|zfs|nvme zfs|' /etc/mkinitfs/mkinitfs.conf
192-
for directory in /lib/modules/*; do
193-
kernel_version=$(basename $directory)
194-
mkinitfs $kernel_version
195-
done
196-
197186
#. Apply GRUB workaround::
198187

199188
echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
@@ -206,10 +195,11 @@ System Installation
206195
sed -i 's|stat -f -c %T /|echo zfs|' /usr/sbin/grub-mkconfig
207196

208197
# grub-probe fails to identify fs mounted at /boot
209-
sed -i "s|GRUB_DEVICE_BOOT=.*|GRUB_DEVICE_BOOT=$(echo $DISK | cut -f1 -d\ )-part2|" /usr/sbin/grub-mkconfig
198+
BOOT_DEVICE=$(zpool status -P bpool | grep -- -part2 | head -n1 | sed "s|.*/dev*|/dev|" | sed "s|part2.*|part2|")
199+
sed -i "s|GRUB_DEVICE_BOOT=.*|GRUB_DEVICE_BOOT=${BOOT_DEVICE}|" /usr/sbin/grub-mkconfig
210200

211-
This workaround needs to be applied for every GRUB update, as the
212-
update will overwrite the changes.
201+
The ``sed`` workaround for ``grub-mkconfig`` needs to be applied
202+
for every GRUB update, as the update will overwrite the changes.
213203

214204
#. Install GRUB::
215205

@@ -227,6 +217,8 @@ System Installation
227217

228218
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/x86_64-efi/grub/grub.cfg
229219
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/i386-pc/grub/grub.cfg
220+
mkdir -p /boot/grub
221+
grub-mkconfig -o /boot/grub/grub.cfg
230222

231223
#. For both legacy and EFI booting: mirror ESP content::
232224

@@ -243,7 +235,7 @@ System Installation
243235

244236
#. Unmount filesystems::
245237

246-
cut -f2 -d\ /proc/mounts | grep ^/mnt | tac | while read i; do umount -l $i; done
238+
umount -Rl /mnt
247239
zpool export -a
248240

249241
#. Reboot::

docs/Getting Started/Arch Linux/Root on ZFS/2-system-installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ System Installation
148148
done
149149

150150
mkdir -p /mnt/boot/efi
151-
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
151+
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi

docs/Getting Started/Arch Linux/Root on ZFS/5-bootloader.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Bootloader
3030
/boot/efi --bootloader-id arch --removable
3131
grub-mkconfig -o /boot/efi/arch/grub-bootdir/x86_64-efi/grub/grub.cfg
3232
grub-mkconfig -o /boot/efi/arch/grub-bootdir/i386-pc/grub/grub.cfg
33+
mkdir -p /boot/grub
34+
grub-mkconfig -o /boot/grub/grub.cfg
3335

3436
#. For both legacy and EFI booting: mirror ESP content::
3537

docs/Getting Started/Fedora/Root on ZFS/2-system-installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ System Installation
148148
done
149149

150150
mkdir -p /mnt/boot/efi
151-
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
151+
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi

docs/Getting Started/Fedora/Root on ZFS/5-bootloader.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Bootloader
3030
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/fedora/
3131
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
3232
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
33+
mkdir -p /boot/grub2
34+
grub2-mkconfig -o /boot/grub2/grub.cfg
3335

3436
#. For both legacy and EFI booting: mirror ESP content::
3537

@@ -47,6 +49,7 @@ Bootloader
4749

4850
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
4951
grub2-mkconfig -o /boot/efi/fedora/grub-bootdir/i386-pc/grub2/grub.cfg
52+
grub2-mkconfig -o /boot/grub2/grub.cfg
5053

5154
Finish Installation
5255
~~~~~~~~~~~~~~~~~~~~

docs/Getting Started/NixOS/Root on ZFS/1-preparation.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ Preparation
66
.. contents:: Table of Contents
77
:local:
88

9-
This guide supports x86_64 and arm64-efi architectures.
9+
**Note for arm64**
1010

11-
**Note for Tow-Boot**
11+
Currently there is a bug with the grub installation script. See `here
12+
<https://github.com/NixOS/nixpkgs/issues/222491>`__ for details.
1213

13-
`Tow-Boot firmware <https://tow-boot.org/>`__
14-
enables UEFI boot on many affordable arm64 based computers. If
15-
using Tow-Boot, NixOS and Tow-Boot must be on separate disks.
16-
Example, Tow-Boot is installed to an SD card. Then the SD card
17-
should not be also shared with NixOS. Install NixOS to an external
18-
disk instead.
14+
**Note for Immutable Root**
15+
16+
Immutable root can be enabled or disabled by setting
17+
``zfs-root.boot.immutable`` option inside per-host configuration.
1918

2019
#. Disable Secure Boot. ZFS modules can not be loaded if Secure Boot is enabled.
2120
#. Download `NixOS Live Image

docs/Getting Started/NixOS/Root on ZFS/2-system-installation.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,18 @@ System Installation
126126
mount -t zfs rpool/nixos/root /mnt/
127127
zfs create -o mountpoint=legacy rpool/nixos/home
128128
mkdir /mnt/home
129-
mount -t zfs rpool/nixos/home /mnt/home
129+
mount -t zfs rpool/nixos/home /mnt/home
130130
zfs create -o mountpoint=legacy rpool/nixos/var
131131
zfs create -o mountpoint=legacy rpool/nixos/var/lib
132132
zfs create -o mountpoint=legacy rpool/nixos/var/log
133133
zfs create -o mountpoint=none bpool/nixos
134134
zfs create -o mountpoint=legacy bpool/nixos/root
135135
mkdir /mnt/boot
136136
mount -t zfs bpool/nixos/root /mnt/boot
137+
mkdir -p /mnt/var/log
138+
mkdir -p /mnt/var/lib
139+
mount -t zfs rpool/nixos/var/lib /mnt/var/lib
140+
mount -t zfs rpool/nixos/var/log /mnt/var/log
137141
zfs create -o mountpoint=legacy rpool/nixos/empty
138142
zfs snapshot rpool/nixos/empty@start
139143

docs/Getting Started/NixOS/Root on ZFS/3-system-configuration.rst

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ System Configuration
3636
sed -i "s|\"bootDevices_placeholder\"|$diskNames|g" \
3737
/mnt/etc/nixos/hosts/exampleHost/default.nix
3838

39-
sed -i "s|\"hostId_placeholder\"|\"$(head -c4 /dev/urandom | od -A none -t x4| sed 's| ||g')\"|g" \
39+
sed -i "s|\"abcd1234\"|\"$(head -c4 /dev/urandom | od -A none -t x4| sed 's| ||g')\"|g" \
4040
/mnt/etc/nixos/hosts/exampleHost/default.nix
4141

42-
sed -i "s|\"systemType_placeholder\"|\"$(uname -m)-linux\"|g" \
42+
sed -i "s|\"x86_64-linux\"|\"$(uname -m)-linux\"|g" \
4343
/mnt/etc/nixos/flake.nix
4444

4545
#. Set root password::
@@ -52,8 +52,8 @@ System Configuration
5252
"s|rootHash_placeholder|${rootPwd}|" \
5353
/mnt/etc/nixos/hosts/exampleHost/default.nix
5454

55-
#. Optional: add SSH public key for root and change host name in
56-
``/mnt/etc/nixos/hosts/exampleHost/default.nix``.
55+
#. You can enable NetworkManager for wireless networks and GNOME
56+
desktop environment in ``configuration.nix``.
5757

5858
#. From now on, the complete configuration of the system will be
5959
tracked by git, set a user name and email address to continue::
@@ -76,8 +76,6 @@ System Configuration
7676

7777
nixos-install --no-root-passwd --flake "git+file:///mnt/etc/nixos#exampleHost"
7878

79-
If the host name was changed, use the new host name in this command.
80-
8179
#. Exit ephemeral nix shell with git::
8280

8381
exit
@@ -91,22 +89,6 @@ System Configuration
9189

9290
reboot
9391

94-
#. NetworkManager is enabled by default. To manage network
95-
connections, execute::
96-
97-
nmtui
98-
99-
#. Optional: immutable root filesystem can be enabled by setting
100-
``my.boot.immutable`` option to ``true``.
101-
then execute::
102-
103-
nixos-rebuild boot
104-
105-
Then reboot. You may need to make certain
106-
adjustments to where configuration files are stored,
107-
see `NixOS wiki <https://nixos.wiki/wiki/ZFS>`__ for
108-
details.
109-
11092
Replace a failed disk
11193
=====================
11294

docs/Getting Started/RHEL-based distro/RHEL-based distro Root on ZFS/2-system-installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ System Installation
148148
done
149149

150150
mkdir -p /mnt/boot/efi
151-
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi
151+
mount -t vfat $(echo $DISK | cut -f1 -d' ')-part1 /mnt/boot/efi

docs/Getting Started/RHEL-based distro/RHEL-based distro Root on ZFS/5-bootloader.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Bootloader
3030
cp -r /usr/lib/grub/x86_64-efi/ /boot/efi/EFI/almalinux/
3131
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
3232
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
33+
mkdir -p /boot/grub2
34+
grub2-mkconfig -o /boot/grub2/grub.cfg
3335

3436
#. For both legacy and EFI booting: mirror ESP content::
3537

@@ -47,6 +49,7 @@ Bootloader
4749

4850
grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg
4951
grub2-mkconfig -o /boot/efi/almalinux/grub-bootdir/i386-pc/grub2/grub.cfg
52+
grub2-mkconfig -o /boot/grub2/grub.cfg
5053

5154
Finish Installation
5255
~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)