A quick note in addition to the ZFS root section article .
In the previous article, / boot was duplicated on two ext4 partitions, and in the future we planned to do it normally.
The kernel is updated quite often and each time it was necessary to mount both / boot, update the kernel, copy the contents, do update-grub, update-initramfs, etc.
It's pretty tired.
The future is now.
It is possible to make this a script, but grub2 supports booting from ZFS.
Therefore, the correct and less expensive option is to make / boot on the ZFS mirror. The conditions are assumed to be the same as those described in the previous article : Debian, root on ZFS.
It is necessary to copy partition images, for example, on a USB flash drive, so that in case of failure, it is possible to recover to the previous working state:
mount /dev/disk/by-id/usb-Corsair_Flash_Voyager-0\:0-part1 /mnt/usb/ dd if=/dev/disk/by-id/ata-Micron_1100-part2 of=/mnt/usb/micron_boot.img bs=4M dd if=/dev/disk/by-id/ata-Samsung_SSD_850_PRO-part2 of=/mnt/usb/samsung_boot.img bs=4M umount /mnt/usb
Be sure to remove the USB flash drive after this.
It is necessary to check whether the zfs module is loaded into grub:
grep -R zfs /boot/grub/grub.cfg
As a result, the line should be displayed insmod zfs
.
If it is not there, you need to add such a line in / etc / default / grub:
GRUB_PRELOAD_MODULES="zfs"
In principle, grub itself will add the necessary module when it detects a ZFS installation, but it is better to be safe.
Now you need to copy the contents of the boot partition, which will be needed in the future:
mount /dev/disk/by-id/ata-Micron_1100-part2 /boot tar -C / -cf ~/boot.tar /boot tar tf ~/boot.tar
As a result, a list of files from / boot should be displayed.
Now FS can be unmounted:
umount /boot
rm -rf /boot zpool create -f -o ashift=12 \ -O atime=off -O compression=lz4 -O normalization=formD \ -O mountpoint=none \ boot_pool mirror /dev/disk/by-id/ata-Micron_1100-part2 /dev/disk/by-id/ata-Samsung_SSD_850_PRO-part2 zfs create -o mountpoint=/boot boot_pool/boot zpool set bootfs=boot_pool/boot boot_pool zfs mount|grep /boot
ashift
- the degree to which you need to build a two to get the specified block size.
12 is a 4K block.
The block size can be blockdev --getbsz /dev/<disk>
with the blockdev --getbsz /dev/<disk>
, or from the technical specification for the device.
If as a result, the line boot_pool /boot
appears, the pool was created correctly and the dataset is mounted.
zpool list boot_pool -v
Must output something like this:
NAME SIZE ALLOC FREE EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT boot_pool 1008M 220M 788M - 7% 21% 1.00x ONLINE - mirror 1008M 220M 788M - 7% 21% /dev/disk/by-id/ata-Micron_1100-part2 - - - - - - /dev/disk/by-id/ata-Samsung_SSD_850_PRO-part2 - - - - - -
First you need to check that grub understands FS:
grub-probe /boot
The string zfs
should be displayed.
tar -C / -xf ~/boot.tar ls /boot
After unpacking is completed, the list of files in / boot will be displayed.
Next, update the initramfs and install the bootloader:
update-initramfs -k all -u grub-install --bootloader-id=debian1 --recheck --no-floppy /dev/disk/by-id/ata-Samsung_SSD_850_PRO grub-install --bootloader-id=debian2 --recheck --no-floppy /dev/disk/by-id/ata-Micron_1100 ZPOOL_VDEV_NAME_PATH=YES update-grub
The process will take some time. The bootloader, in theory, it is possible not to reinstall, but it did not work for me without it.
Now you need to reboot:
reboot
After rebooting, zfs mount|grep /boot
will print boot_pool/boot /boot
, which means: everything went right.
It is enough to boot from Live USB and copy one of the images back:
mount /dev/disk/by-id/usb-Corsair_Flash_Voyager-0\:0-part1 /mnt/usb/ dd if=micron_boot of=/dev/disk/by-id/ata-Micron_1100-part2 bs=4M umount /boot
After that, it is possible to boot from the restored boot partition.
Source: https://habr.com/ru/post/358914/
All Articles