|
### Execute as `root` on Raspberry |
|
### to prepare ZFS pool. |
|
### ------------------------------ |
|
|
|
### customize: |
|
RPIHOSTNAME=spongebob |
|
### ------------------------------ |
|
|
|
|
|
set -euxo pipefail |
|
|
|
DISKNAME="$(mount | awk '$3=="/" {print $1}' | sed 's/p[0-9]*$//g' | xargs basename)" |
|
DISK_BYID="$(find /dev/disk/by-id -lname "*/${DISKNAME}")" |
|
|
|
export PART2="${DISK_BYID}-part2" |
|
export PART3="${DISK_BYID}-part3" |
|
|
|
# apt install -y pv dkms dpkg-dev "linux-headers-$(uname -r)" man-db console-setup locales |
|
apt install -y zfsutils-linux locales man-db console-setup pv |
|
|
|
# en_US.UTF-8 should always be installed |
|
dpkg-reconfigure locales tzdata keyboard-configuration console-setup |
|
|
|
apt install -y zfs-initramfs |
|
echo REMAKE_INITRD=yes > /etc/dkms/zfs.conf |
|
modprobe zfs |
|
|
|
zpool create \ |
|
-o ashift=12 \ |
|
-O acltype=posixacl \ |
|
-O atime=off \ |
|
-O canmount=off \ |
|
-O compression=lz4 \ |
|
-O dnodesize=auto \ |
|
-O encryption=aes-256-gcm \ |
|
-O keyformat=passphrase \ |
|
-O keylocation=prompt \ |
|
-O mountpoint=/ \ |
|
-O normalization=formD \ |
|
-O xattr=sa \ |
|
-R /mnt \ |
|
rpool "${PART2}" |
|
|
|
zfs create -o canmount=off -o mountpoint=none rpool/ROOT |
|
zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/debian |
|
zfs mount rpool/ROOT/debian |
|
zfs create -o canmount=off -o mountpoint=/ rpool/USERDATA |
|
zfs create rpool/USERDATA/home #+buster |
|
zfs create -o mountpoint=/root rpool/USERDATA/home/root #+buster |
|
zfs create -o canmount=off rpool/ROOT/debian/var #+buster #+ubuntu |
|
zfs create -o com.sun:auto-snapshot=false rpool/ROOT/debian/var/cache #+buster |
|
zfs create -o canmount=off rpool/ROOT/debian/var/lib #+buster #+ubuntu #+merge |
|
zfs create rpool/ROOT/debian/var/lib/apt #+ubuntu |
|
zfs create rpool/ROOT/debian/var/lib/dpkg #+ubuntu |
|
zfs create rpool/ROOT/debian/var/lib/NetworkManager #+ubuntu |
|
zfs create -o com.sun:auto-snapshot=false rpool/ROOT/debian/var/lib/docker #+buster |
|
zfs create -o com.sun:auto-snapshot=false rpool/ROOT/debian/var/lib/nfs #+buster |
|
zfs create rpool/ROOT/debian/var/lib/AccountsService #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/var/log #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/var/mail #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/var/opt |
|
zfs create rpool/ROOT/debian/var/spool #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/var/games #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/var/www #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/opt #+buster |
|
zfs create rpool/ROOT/debian/srv #+buster #+ubuntu |
|
zfs create -o canmount=off rpool/ROOT/debian/usr #+buster #+ubuntu |
|
zfs create rpool/ROOT/debian/usr/local #+buster #+ubuntu |
|
|
|
zfs create -o com.sun:auto-snapshot=false rpool/ROOT/debian/var/tmp #+buster |
|
zfs create -o com.sun:auto-snapshot=false rpool/ROOT/debian/tmp #+buster |
|
chmod 1777 /mnt/var/tmp |
|
chmod 1777 /mnt/tmp |
|
|
|
#### Install system |
|
(cd /; tar -cf - --one-file-system --warning=no-file-ignored .) | \ |
|
pv -p -bs "$(du -sxm --apparent-size / | cut -f1)m" | \ |
|
(cd /mnt ; tar -x) |
|
|
|
#### chroot prepare |
|
mount --rbind /boot/firmware /mnt/boot/firmware |
|
mount --rbind /dev /mnt/dev |
|
mount --rbind /proc /mnt/proc |
|
mount -t tmpfs tmpfs /mnt/run |
|
mount --rbind /sys /mnt/sys |
|
mkdir /mnt/run/lock |
|
|
|
echo "${RPIHOSTNAME}" > /mnt/etc/hostname |
|
echo 127.0.1.1 "${RPIHOSTNAME}" >> /mnt/etc/hosts |
|
|
|
systemctl stop zed |
|
|
|
mkdir /mnt/etc/zfs/zfs-list.cache |
|
touch /mnt/etc/zfs/zfs-list.cache/rpool |
|
|
|
|
|
#### chroot |
|
chroot /mnt bash --login <<EOF |
|
|
|
set -euxo pipefail |
|
|
|
dpkg-reconfigure locales tzdata keyboard-configuration console-setup |
|
|
|
zed -F & |
|
zfs set canmount=noauto rpool/ROOT/debian |
|
|
|
while [[ ! -s /etc/zfs/zfs-list.cache/rpool ]] ; do |
|
echo "waiting for zed to update cache" |
|
sleep 1 |
|
done |
|
sleep 1 # to be on a safe side |
|
|
|
kill %1 # kill zed |
|
|
|
EOF |
|
|
|
sed -Ei "s|/mnt/?|/|" /mnt/etc/zfs/zfs-list.cache/* |
|
|
|
sed -i '/LABEL=RASPIROOT/d' /mnt/etc/fstab |
|
sed -i "s/^LABEL=RASPIFIRM/UUID=$(lsblk -dno UUID "${DISK_BYID}-part1")/" /mnt/etc/fstab |
|
|
|
cp /boot/firmware/cmdline.txt "/boot/firmware/cmdline.txt.orig-$(date -u +%Y-%m-%d--%H-%M-%S-UTC)" |
|
|
|
sed -i "s|root=[^ ]*|root=ZFS=rpool/ROOT/debian|" /boot/firmware/cmdline.txt |
|
sed -i "s|$| init_on_alloc=0 nosplash|" /boot/firmware/cmdline.txt |
|
sed -i "s|console=ttyS1,115200 ||" /boot/firmware/cmdline.txt |
|
sed -i "s| | |" /boot/firmware/cmdline.txt |
|
|
|
reboot |