Last active
October 22, 2019 14:00
-
-
Save satmandu/5d8e5886881b2e92c203a122f5297fa4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
# Hack to add user USERDATA zpool to an Ubuntu 19.10 system. | |
# I have this at /usr/local/bin/zfsuseradd.sh | |
user="${1}" | |
[[ -n "$user" ]] || (echo "User not specified." && exit 1) | |
zfs_user_suffix=$(mount | grep rpool/USERDATA/root_ | awk '{print $1}' | sed 's/rpool\/USERDATA\/root_//') | |
[[ -n "$zfs_user_suffix" ]] || (echo "Can't get Ubuntu ZFS user suffix." && exit 1) | |
zfs_system_suffix=$(mount | grep rpool/ROOT/ubuntu_ | awk '{print $1}' | head -1 | sed 's/rpool\/ROOT\/ubuntu_//') | |
[[ -n "$zfs_system_suffix" ]] || (echo "Can't get Ubuntu ZFS system suffix." && exit 1) | |
echo "creating rpool/USERDATA/""${user}""_""${zfs_user_suffix}""" | |
[[ -e /"${user}"_"${zfs_user_suffix}" ]] && (echo "mount point already exists" && exit 1) | |
zfs create rpool/USERDATA/"${user}"_"${zfs_user_suffix}" | |
zfs set mountpoint=/"${user}"_"${zfs_user_suffix}" \ | |
rpool/USERDATA/"${user}"_"${zfs_user_suffix}" | |
# Set local properties created by ubuntu installer for userdata zpools | |
# set canmount=on since otherwise these don't appear to get mounted at boot. | |
# canmount=on is default. In theory this can be set to on by: | |
# zfs inherit -S canmount rpool/USERDATA/$user_$zfs_user_suffix | |
# zfs set canmount=on \ | |
# rpool/USERDATA/"${user}"_"${zfs_user_suffix}" | |
zfs set com.ubuntu.zsys:bootfs-datasets=rpool/ROOT/ubuntu_"${zfs_system_suffix}" \ | |
rpool/USERDATA/"${user}"_"${zfs_user_suffix}" | |
rsync -haHAX /home/"${user}"/ /"${user}"_"${zfs_user_suffix}" | |
rm -r /home/"${user:?}" | |
chown "${user}"."${user}" /"${user}"_"${zfs_user_suffix}" | |
zfs set mountpoint=/home/"${user}" rpool/USERDATA/"${user}"_"${zfs_user_suffix}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As per discussion here: https://discourse.ubuntu.com/t/enhancing-our-zfs-support-on-ubuntu-19-10-an-introduction/12130/117