3

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?

enter image description 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.

Kelley
  • 33,062
  • 1
    Please don't use screenshots for terminal output. Instead paste the text into your question, select it with your mouse, and press the {} button in the editor to format it properly. – Chai T. Rex Oct 07 '18 at 14:02

1 Answers1

2

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.

cp -a /home/* /zstorage/home/
rsync -axHAX --delete /home/ /zstorage/home/

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.

zfs set overlay=on zstorage

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.

zfs set mountpoint=/home zstorage/home

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.

Thomas
  • 6,223
  • You say that first I need to mount the filesystem to something like /zstorage/home, but that's exactly what I tried to do and it wouldn't let me. What am I missing? – Kelley Oct 08 '18 at 19:50
  • 1
    From your df output, it is mounted top /zstorage/home. – Thomas Oct 09 '18 at 04:07
  • Right! And that's what I thought, too, but then I got that error message: "cannot mount '/home': directory is not empty" and then "property may be set but unable to remount filesystem." – Kelley Oct 09 '18 at 14:47
  • Just updated the answer and included the part to move the mountpoint to /home after the copy has been done. – Thomas Oct 09 '18 at 14:59
  • Thanks for your help! I went ahead and made the attempt, but then was unable to login: it gets as far as having me click on my userid and enter my password, but doesn't accept it. I figure I'll need to wipe out my zpool and start over again. I must have made a mistake somewhere. – Kelley Oct 10 '18 at 14:51
  • 1
    I never could get it to work. I booted from the Cosmic beta and used that to restore my previous fstab, and then format the drives to ext4 and thus remove ZFS, and then I was able to reboot into my 18.04 installation. I tried it all again a couple more times, but each time with the same result: I never could get Ubuntu to recognize and boot from /home on the ZFS drive. There must be something critical I'm missing, but I don't know where else to look. – Kelley Oct 12 '18 at 13:41
  • The wildcard * in cp -a /home/* /zstorage/home/ does not copy hidden files and directories (files starting with a .) by default, which may contain important settings and data for your user. Before issuing that command, run shopt -s dotglob as described in this post. – sshow Feb 05 '23 at 13:08