meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:fs:zfs:move_to_zfs [2021/02/14 11:30] niziaklinux:fs:zfs:move_to_zfs [2021/05/14 16:06] (current) niziak
Line 2: Line 2:
  
 Based on  [[https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Buster%20Root%20on%20ZFS.html|Debian Buster Root on ZFS]] Based on  [[https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Buster%20Root%20on%20ZFS.html|Debian Buster Root on ZFS]]
 +
 +Additional references:
 +  * [[https://www.tomica.net/blog/2019/02/moving-ubuntu-to-root-on-zfs/]]
 +  * [[https://blog.heckel.io/2016/12/31/move-existing-linux-install-zfs-root/]]
 +  * [[https://wiki.debian.org/ZFS|ZFS - Debian Wiki]]
 +
 +===== Prepare system =====
 +<code bash>
 +apt install --yes zfs-initramfs zfs-dkms
 +</code>
  
 ===== Prepare new disk ===== ===== Prepare new disk =====
Line 18: Line 28:
 <code bash> <code bash>
 zpool create \ zpool create \
-    -o ashift=12 -d \+    -o ashift=13 -d \
     -o feature@async_destroy=enabled \     -o feature@async_destroy=enabled \
     -o feature@bookmarks=enabled \     -o feature@bookmarks=enabled \
     -o feature@embedded_data=enabled \     -o feature@embedded_data=enabled \
-    -o feature@empty_bpobj=enabled \+    -o feature@empty_bpobj=enabled \rapidly and thoroughly than you'd think.
     -o feature@enabled_txg=enabled \     -o feature@enabled_txg=enabled \
     -o feature@extensible_dataset=enabled \     -o feature@extensible_dataset=enabled \
Line 37: Line 47:
 </code> </code>
  
-==== create root pool ====+==== Create root pool ====
  
 <code bash> <code bash>
 zpool create \ zpool create \
-    -o ashift=12 \+    -o ashift=13 \
     -O acltype=posixacl -O canmount=off -O compression=lz4 \     -O acltype=posixacl -O canmount=off -O compression=lz4 \
     -O dnodesize=auto -O normalization=formD -O relatime=on \     -O dnodesize=auto -O normalization=formD -O relatime=on \
Line 48: Line 58:
 </code>     </code>    
  
-=== prepare filesystem ===+===== prepare filesystem =====
  
 <code bash> <code bash>
Line 93: Line 103:
 </code> </code>
  
-=== Move filesystem ===+==== Move filesystem ====
  
 <code bash> <code bash>
Line 105: Line 115:
 </code> </code>
  
-=== update filesystem ===+==== update filesystem ====
  
 <code bash> <code bash>
-mount --rbind /dev  /mnt/dev +mount --rbind /dev  /rpool/dev 
-mount --rbind /proc /mnt/proc +mount --rbind /proc /rpool/proc 
-mount --rbind /sys  /mnt/sys +mount --rbind /sys  /rpool/sys 
-chroot /mnt /bin/bash --login+chroot /rpool /bin/bash --login
 </code> </code>
  
 +<code bash>
 +ln -s /proc/self/mounts /etc/mtab
 +mv /boot /boot.org
 +zfs set mountpoint=/boot bpool
 +zfs set mountpoint=/boot bpool/BOOT/debian
 +zfs mount bpool/BOOT/debian
 +rsync -av /boot.org/ /boot/
 +</code>
 +
 +<code bash>
 +zfs set mountpoint=/ rpool
 +zfs set mountpoint=/ rpool/ROOT/debian
 +zfs set readonly=off rpool/ROOT/debian
 +</code>
 +
 +==== Enable importing bpool ====
 +
 +<file /etc/systemd/system/zfs-import-bpool.service>
 +[Unit]
 +DefaultDependencies=no
 +Before=zfs-import-scan.service
 +Before=zfs-import-cache.service
 +
 +[Service]
 +Type=oneshot
 +RemainAfterExit=yes
 +ExecStart=/sbin/zpool import -N -o cachefile=none bpool
 +# Work-around to preserve zpool cache:
 +ExecStartPre=-/bin/mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache
 +ExecStartPost=-/bin/mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache
 +
 +[Install]
 +WantedBy=zfs-import.target
 +</file>
 +
 +<code bash>
 +systemctl enable zfs-import-bpool.service
 +</code>
 +
 +==== fstab ====
 +
 +Remove all old fstab entries related to prebvious setup!
 +
 +==== Workaround GRUB’s missing zpool-features support ====
 +
 +<file /etc/default/grub>
 +GRUB_CMDLINE_LINUX="root=ZFS=rpool/ROOT/debian boot=zfs"
 +</file>
 +
 +<code bash>update-initramfs -c -k </code>
 +
 +==== Update GRUB ====
 +
 +=== EFI boot ===
 +
 +<code bash>
 +mkdosfs -F 32 -s 1 -n EFI ${DISK}-part2
 +mkdir /boot/efi
 +echo /dev/disk/by-uuid/$(blkid -s UUID -o value ${DISK}-part2) \
 +   /boot/efi vfat noatime,nofail,x-systemd.device-timeout=1 0 0 >> /etc/fstab
 +mount /boot/efi
 +apt install --yes grub-efi-amd64 shim-signed   
 +grub-install --target=x86_64-efi --efi-directory=/boot/efi \
 +    --bootloader-id=debian --recheck --no-floppy
 +
 +</code>
 +
 +=== legacy boot ===
 +<code bash>
 +grup-probe /boot
 +# should return zfs
 +
 +
 +update-grub
 +
 +grub-install $DISK
 +</code>
 +
 +==== Fix filesystem mount ordering ====
 +
 +<code bash>
 +mkdir /etc/zfs/zfs-list.cache
 +touch /etc/zfs/zfs-list.cache/bpool
 +touch /etc/zfs/zfs-list.cache/rpool
 +ln -s /usr/lib/zfs-linux/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d
 +zed -F &
 +</code>
 +
 +Verify that zed updated the cache by making sure these are not empty:
 +
 +<code bash>
 +cat /etc/zfs/zfs-list.cache/bpool
 +cat /etc/zfs/zfs-list.cache/rpool
 +</code>
 +
 +Fix the paths to eliminate mount prefix /rpool:
 +<code bash>
 +sed -Ei "s|/rpool/?|/|" /etc/zfs/zfs-list.cache/*
 +</code>
 +
 +
 +Exit chroot: <code>exit</code>
 +
 +Unmount zfs
 +<code>
 +mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
 +    xargs -i{} umount -lf {}
 +</code>
 +
 +**DON'T FORGET TO EXPORT BEFORE REBOOT!**
 +
 +<code>
 +zpool export -a
 +
 +reboot
 +</code>
 +
 +Reboot. Choose recovery boot to verify.
 +
 +===== Add 2nd disk for mirror =====
 +
 +<code bash>
 +DISK=/dev/disk/by-id/scsi-SATA_disk2
 +sgdisk --zap-all $DISK
 +sgdisk -a8 -n1:24K:+1000K -t1:EF02 $DISK  # grub bios
 +sgdisk     -n2:1M:+256M   -t2:EF00 $DISK  # EFI
 +sgdisk     -n3:0:+512M    -t3:BF01 $DISK  # /boot
 +sgdisk     -n4:0:       -t4:BF00 $DISK  # rpool
 +</code>
 +
 +Attach boot partitiona to ''bpool'':
 +<code bash>
 +zpool list -v
 +zpool attach bpool ata-WDC_WD1003FZEX-00MK2A0_WD-WCC3F5HSP1N1-part3 $DISK-part3
 +zpool list -v
 +</code>
 +
 +Attach pool partition to ''rpool'':
 +<code bash>
 +zpool list -v
 +zpool attach rpool ata-WDC_WD1003FZEX-00MK2A0_WD-WCC3F5HSP1N1-part4 $DISK-part4
 +zpool list -v
 +</code>
 +
 +Check mirror build progresS:
 +<code>
 +zpool status
 +
 +  pool: bpool
 + state: ONLINE
 +  scan: resilvered 263M in 0 days 00:00:06 with 0 errors on Sun Feb 14 18:26:12 2021
 +
 +  pool: rpool
 + state: ONLINE
 +status: One or more devices is currently being resilvered.  The pool will
 + continue to function, possibly in a degraded state.
 +action: Wait for the resilver to complete.
 +  scan: resilver in progress since Sun Feb 14 18:27:09 2021
 + 68,9G scanned at 860M/s, 504K issued at 6,15K/s, 326G total
 + 0B resilvered, 0,00% done, no estimated completion time
 +</code>
 +
 +==== Install grub on 2nd disk ====
 +
 +
 +=== legacy  ===
 +
 +<code bash>dpkg-reconfigure grub-pc</code>
 +Hit enter until you get to the device selection screen. Select (using the space bar) all of the disks (not partitions) in your pool.
 +
 +or
 +
 +<code bash>grub-install $DISK</code>
 +
 +=== For UEFI booting ===
 +
 +<code bash>umount /boot/efi</code>
 +
 +<code bash>
 +dd if=/dev/disk/by-id/scsi-SATA_disk1-part2 \
 +   of=/dev/disk/by-id/scsi-SATA_disk2-part2
 +
 +efibootmgr -c -g -d /dev/disk/by-id/scsi-SATA_disk2 \
 +    -p 2 -L "debian-2" -l '\EFI\debian\grubx64.efi'
 +
 +mount /boot/efi
 +</code>
 +
 +==== add ZIL and L2ARC  ====
 +
 +<code bash>
 +zpool add rpool log c2980761-ed99-4af3-8519-f03ed43fbefe
 +</code>
 +
 +<code bash>
 +zpool add rpool cache 3b42df2e-2923-464c-92d6-8d629252727d
 +</code>
 +
 +===== issue: No pool imported =====
 +
 +<code>
 +No pool imported. Manually import the root pool
 +at the command prompt and then exit.
 +Hint: Try:  zpool import -R /root -N
 +</code>
 +
 +
 +Initramfs stuck because no /root found:
 +<code bash>
 +zpool import -R /root -N rpool
 +zfs mount rpool/ROOT/debian
 +exit
 +</code>
 +
 +Solution:
 +
 +<file /etc/default/grub>
 +GRUB_CMDLINE_LINUX="root=ZFS=rpool/ROOT/debian boot=zfs"
 +</file>
 +
 +<code bash>
 +update-initramfs -c -k all
 +</code>
 +
 +===== issue ? =====
 +
 +
 +
 +
 +
 +Now in recovery mode fix ''/etc/zfs/zfs-list.cache/*'' content (see above).
 +
 +<code bash>
 +update-initramfs -c -k all
 +</code>
 +
 +
 +
 +
 +
 +===== TEMP =====
  
 DONT FORGET TO ADD NEXT MIRROR DEVICE DRIVE TO ZFS POOLS: DONT FORGET TO ADD NEXT MIRROR DEVICE DRIVE TO ZFS POOLS:
Line 119: Line 370:
   * rpool   * rpool
   *    * 
 +
 +grub-install $DISK
 +
 +