This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Move Default Home Directory to a New ZFS Pool on a Separate Drive
Ciarán O'Mara edited this page Aug 9, 2021
·
1 revision
#!/bin/bash
# Move default home directory to a new zfs pool on a separate drive.
# Modelled after the Trident install script at https://github.com/project-trident/trident-installer/blob/69fb9a59bfc3808a0890da6bd3b5ad3146d05bed/src-sh/void-install-zfs.sh
user="username"
userpass="secret"
ZPOOL="homedrive"
CURRENTPOOL="trident"
TMP_MOUNTPOINT="/usr/home2"
MOUNTPOINT="/usr/home"
HOMEDRIVE="/dev/nvme2n1"
# Create new ZFS pool with at least encryption enabled.
zpool create -f -o ashift=12 -d \
-o feature@async_destroy=enabled \
-o feature@bookmarks=enabled \
-o feature@embedded_data=enabled \
-o feature@empty_bpobj=enabled \
-o feature@enabled_txg=enabled \
-o feature@encryption=enabled \
-o feature@extensible_dataset=enabled \
-o feature@filesystem_limits=enabled \
-o feature@hole_birth=enabled \
-o feature@large_blocks=enabled \
-o feature@lz4_compress=enabled \
-o feature@spacemap_histogram=enabled \
-o feature@userobj_accounting=enabled \
-O acltype=posixacl \
-O canmount=off \
-O compression=lz4 \
-O devices=off \
-O encryption=off \
-O mountpoint=none \
-O normalization=formD \
-O relatime=on \
-O xattr=sa \
${ZPOOL} ${HOMEDRIVE}
tmpfile=$(mktemp /tmp/.XXXXXX)
echo "${userpass}" > "${tmpfile}"
# Create encrypted dataset for new home.
zfs create -o "mountpoint=${TMP_MOUNTPOINT}/${user}" -o "io.github.benkerry:zfscrypt_user=${user}" -o "setuid=off" -o "compression=on" -o "atime=off" -o "encryption=on" -o "keyformat=passphrase" -o "keylocation=file://${tmpfile}" -o "canmount=noauto" "${ZPOOL}/${user}"
zfs set "keylocation=prompt" "${ZPOOL}/${user}"
# Allow the user to create/destroy child datasets and snapshots on their home dir
zfs allow "${user}" load-key,mount,create,destroy,rollback,snapshot "${ZPOOL}/${user}"
# Copy current data into new home.
zfs mount "${ZPOOL}/${user}"
chown "${user}:${user}" "${TMP_MOUNTPOINT}/${user}"
rsync -au "${MOUNTPOINT}/${user}/" "${TMP_MOUNTPOINT}/${user}/"
zfs unmount "${ZPOOL}/${user}"
# Disable original home.
zfs set canmount=off "${CURRENTPOOL}/home/${user}"
# Set final mount point for new home.
zfs set moutpoint="${MOUNTPOINT}/${user}/" "${ZPOOL}/${user}"
- Main Website: https://project-trident.org
- Sponsorships available! https://project-trident.org/sponsors
- Void Linux Documentation
- Void Linux Rosetta Stone: Dictionary of commands between different Linux distros.
- Void Linux FAQ