/ boot on ZFS mirror


    A small note, in addition to the article on the root partition on ZFS .


    In the previous article, / boot was duplicated on two ext4 partitions, and in the future it was planned to do fine.


    The kernel is updated often enough and each time it was necessary to mount both / boot, update the kernel, copy the contents, do update-grub, update-initramfs, etc.


    This is tired of the order.


    The future has come.


    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.


    Preliminary steps


    It is necessary to copy the images of partitions, for example, to a USB flash drive, so that in case of failure, it would be possible to restore 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 that.


    It is necessary to check whether the zfs module is loaded into grub:


    grep -R zfs /boot/grub/grub.cfg 

    As a result, a string should be displayed insmod zfs.
    If it is not there, you need to add the following line to / etc / default / grub:


    GRUB_PRELOAD_MODULES="zfs"

    In principle, grub itself will add the necessary module when it detects the installation on ZFS, but it is better to play it 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 unmount:


    umount /boot

    Creating ZFS pool and boot FS


    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

    A note about the ashift parameter

    ashift- the degree to which you need to raise a deuce to get the specified block size.
    12 is a 4K block.
    It is possible to get the block size using a command , or from the technical specification for the device.blockdev --getbsz /dev/


    If as a result, a row appears boot_pool /boot, the pool was created correctly, and the dataset is mounted.


    zpool list boot_pool  -v

    Should 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      -      -      -         -      -      -

    Bootloader installation


    You must first verify that grub understands the FS:


    grub-probe /boot

    A string should be displayed zfs.


    tar -C / -xf ~/boot.tar
    ls /boot

    After unpacking is completed, a list of files in / boot will be displayed.


    Next, update 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 loader, in theory, it is possible not to reinstall, but it did not work without it.


    Now you need to reboot:


    reboot

    After a reboot , it zfs mount|grep /bootwill output boot_pool/boot /boot, which means: everything went correctly.


    If something went wrong


    Just 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.


    Also popular now: