Skip to content

Instantly share code, notes, and snippets.

@bademux
Last active December 30, 2021 21:01
Show Gist options
  • Save bademux/b91cbbafa8e69ca13ff893d97ba37b2c to your computer and use it in GitHub Desktop.
Save bademux/b91cbbafa8e69ca13ff893d97ba37b2c to your computer and use it in GitHub Desktop.
install Data Disk alpine with zfs /var

Download latest Extended Alpine https://alpinelinux.org/downloads/

Copy all files from alpine iso to USB drive formatted as a single efi partition.

Setup Apline

setup-alpine
apk add util-linux nano udev zfs
setup-udev
modprobe zfs
mount -o remount,rw /media/usb
dd if=/dev/random of=/media/usb/var.key bs=1 count=32

zpool create -f -o ashift=12 -o autotrim=on \
       -O acltype=posixacl -O canmount=on -O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa -O atime=off -O mountpoint=none \
       rpool mirror \
       ata-Samsung_SSD_850_PRO_256GB_XXX ata-Patriot_XXX #ls  /dev/disk/by-id
       
zfs create -o compression=zstd -o encryption=aes-256-gcm -o keylocation=file:///media/usb/var.key -o keyformat=raw -o mountpoint=legacy rpool/alpine-var
mount -t zfs rpool/alpine-var /mnt
cp -R /var/* /mnt && touch /mnt/zsfmark
zfs set mountpoint=/var rpool/alpine-var

sed -i 's/MOUNT_EXTRA_OPTIONS=""/MOUNT_EXTRA_OPTIONS="-l"/' /etc/conf.d/zfs #load key on mount

rc-update add zfs-import sysinit
rc-update add zfs-mount sysinit

lbu ci && reboot

Install zram. Enable community repository in /etc/apk/repositories and then

apk update && apk add zram-init

sed -i 's/num_devices=2/num_devices=1/' /etc/conf.d/zram-init
sed -i 's/size0=512/size0=1024/' /etc/conf.d/zram-init
echo "vm.swappiness = 1" >> /etc/sysctl.conf
rc-service zram-init start

lbu ci && reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment