How do I move /home/user to a zfs pool?

Solution 1:

  1. YMMV. Make sure anything said below makes sense to you.

  2. Ensure that you can login, via at least one admin-enabled account (can manage ZFS), when the NAS is down.

  3. Copy, via tar or rsync (not cp) all of your old HOME directory (/home/you) to the new HOME directory, mounted some temporary place line /media/$USER/newhome.

  4. Backup, then edit /etc/fstab to NFS mount the appropriate NAS directory as /home/you. See man fstab about NFS mounts, man mount, too. Use the auto option. Do NOT mount it yet.

  5. Carefully delete most of the files/directories in your old HOME directory, just leaving enough of the structure so that you can login with the files here, in case the mount fails.

  6. logout and login to verify what you did in step 4.

  7. If all seems OK, mount the NAS HOME directory via:

    sudo mount /home/you

  8. sudo shutdown -r now to reboot your system, make all processes forget about your old $HOME, and start over with /home/you mounted.

Solution 2:

How to move /home directory into a ZFS pool on Linux Mint 19XFCE-64bit

Reference: https://freedompenguin.com/articles/how-to/move-linux-home-zfs/

This procedure has been tested on a guest Linux Mint 19XFCE 64bit inside VirtualBox V5.2.22

Host system Linux Mint 18 KDE 64 bit

  • Anything described below refers to the guest OS.

  • Procedure is not 100% step by step. Some steps are described giving their gobal meaning, not

going in deep details.

  • Every time it will be mentioned the word “user” it means YOUR user directory name (for example instead of /home/user/Documents put /home/jonathan/Documents where jonathan is an example name)

  • Following procedure is valid for one single user.

  • Last, but not less important, forgive my english. I am italian.

Procedure

installation of zfs utils by terminal

sudo apt install zfsutils-linux

By using G-Parted:

Reduce the only available partition to a reasonable value (let’s say 20-25 Gbyte).

On free space created by previous step, create a new partition NOT formatted.

By file browser, go to /dev/disk/by-id/ and take note of second partition name. Such partition is that one just created (NOT formatted) that will host ZFS pool dedicated to /home directory. In my case, second partition name was ata-VBOX_HARDDISK_VB49b2d698-41fa84b3-part2 You will see such name in the pool creation sintax here below.

Now we create the zhome pool using the partition 2 NOT formatted we just created.

By terminal

zp=zhome

sudo zpool create -o ashift=12 -o autoexpand=on -o autoreplace=on -O atime=off -O compression=lz4 $zp /dev/disk/by-id/ata-VBOX_HARDDISK_VB49b2d698-41fa84b3-part2

The detailed meaning of different parameters can be found in the reference article mentioned at the beginning.

Now we must backup directory /home/user/ into a temporary directory such as /tmp/user-bck/

By terminal

sudo rsync -avh /home/user/ /tmp/user-bck/

Now we must erase directory /home I don’t know why, but command must be given twice to succeed (first time it warns "directory is not empty"...)

By terminal

sudo rm -r -f /home
sudo rm -r -f /home

SOME NOTES

1) it is a good thing having ZFS Datasets instead of IMPORTANT directories. That because it will allow to take selective snapshots SPECIFIC for each directory. VERY useful, just to mention, in case of Each virtual machine directory...

2) Each dataset is seen by file browser as a NORMAL directory. So, inside of it, we can then create whatever subdirectories we want. BUT IT IS FORBIDDEN to create a ZFS Dataset in this way: pool/dataset1/directory/dataset2

3) Snapshots apply to datasets only, NOT to directories…

Now let’s create EVERY ZFS Datasets with EXACTLY the same name as /home/user directories (Documents, Music, etc.) Be carefull: I translated the names of directories from italian to english. Please, make sure of the sintax (Documents, Pictures, Music, etc.)

By terminal

sudo zfs create -o sharesmb=off $zp/home

sudo zfs create $zp/home/user

sudo zfs create $zp/home/user/Documents

sudo zfs create $zp/home/user/Pictures

sudo zfs create $zp/home/user/Music

sudo zfs create $zp/home/user/Video

sudo zfs create $zp/home/user/Models

sudo zfs create $zp/home/user/Download

sudo zfs create $zp/home/user/Desktop

Now we give (immediate and permanent) instruction to ZFS about mount point of the pool zhome/home. Mount is performed immediately and will be performed on every boot.

By terminal

sudo zfs set mountpoint=/home $zp/home

Now we must restore /home/user backup and place it into the new, EMPTY, just mounted, /home directory.

By terminal

cd /
sudo rsync -avh --ignore-existing /tmp/user-bck/ /home/user/

Option –ignore-existing is given to avoid overwriting of directories on the same-name ZFS Datasets (Documents, Music, etc.)

Now reboot system

By terminal

sudo reboot

Tested on 21 Novembre 2018 ore 22:30.

Regards

Michele