I created a zpool, called zstorage, on two mirrored drives, on Ubuntu 18.04. The OS is installed on an SSD, with the /home directory on its own partition on that same SSD. I want to migrate /home to the ZFS pool. As you can see, the pool has been set up and ready - as far as I know. Where do I go from here?
Ordinarily, when moving /home to another drive, one can edit fstab, but ZFS doesn't use fstab. I'm rather stuck at knowing how to move my existing /home to /zstorage/home and how to mount /zstorage/home. The command
sudo zfs set mountpoint=/home zstorage/home
gives me the error
cannot mount '/home': directory is not empty
property may be set but unable to remount filesystem
.
First you need to the
zstorage/home
filesystem to a different mountpoint like /zstorage/home to transfer the files from /home to /zstorage/home.To transfer the data, best would be to do this while no user is logged in and you are logged in as root directly to not have any operations in the home directory. To copy the data, use either of the two commands as follows, whereas
rsync
is better if the copy process is interrupted and has to be rerun.After the copy process, you can mount the ZFS filesystem to /home, but as you already mentioned ZFS by default rejects mount points that contain something. You can alter that with the command as follows.
The property is normally inherited to child filesystems, but you can check it with
zfs get overlay zstorage
. Now you should be able to mount the ZFS filesystem on/home
.To do that, you may want to change the mount point in ZFS as follows.
It also might be that
/home
is a separate mount point, in that case you need to remove, comment or alter the corresponding entry in /etc/fstab.You also might want to keep the original data and overmount /home while testing your new setup and delete it later when everything is as expected. Just in case something goes wrong or you want to go back.
During boot, the ZFS filesystems should be mounted automatically without the need to configure /etc/fstab.