Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple installer for ArchLinux on ZFS (tested in VirtualBox)
# prerequisites
# pacman -S arch-install-scripts sgdisk rsync
DISKS=( /dev/disk/by-id/ata-VBOX_HARDDISK_VB{5f2d4170-647f16b7,f38966d8-57bff7df} )
# Ensure zpool offline
zpool list "$ZPOOL" &> /dev/null && zpool export "$ZPOOL" && zpool destroy "$ZPOOL"
# Zap disk partition tables
echo ${DISKS[@]} | xargs -n 1 sgdisk -Z
# Create a new zpool
zpool create -m none "$ZPOOL" "$RAIDZ" "${DISKS[@]}"
# Create a dataset
zfs create -p "$ZPOOL"/ROOT/archlinux
zfs set xattr=sa "$ZPOOL"/ROOT/archlinux
# Take the zpool offline so we can re-online it with an altroot
zpool export "$ZPOOL"
# Whilst offline, add BIOS boot partition to the disks (required by Grub)
for disk in "${DISKS[@]}"
sgdisk -n 2:34:2047 -t 2:EF02 "$disk" -c 2:"BIOS Boot Partition"
blockdev --rereadpt "$disk"
# Import the zpool to a tempoary "altroot" mount point
zpool import "$ZPOOL" -d /dev/disk/by-id -o altroot=/"$ZPOOL"
# Set the real mount point to be the root
zfs set mountpoint=/ "$ZPOOL"/ROOT/archlinux
# Install OS to the zpool
[[ -d /"$ZPOOL" ]] && rsync -avxHAWXS --numeric-ids --info=progress2 --exclude /"$ZPOOL" / /"$ZPOOL"
# Add ZFS support to the initramfs, install Grub and remove fstab entries for the root fs
arch-chroot /"$ZPOOL" << EOF
sed -i -e '/^HOOKS=/s/filesystems.*)/keyboard zfs filesystems)/' /etc/mkinitcpio.conf
mkinitcpio -p linux
echo ${DISKS[@]} | ZPOOL_VDEV_NAME_PATH=1 xargs -n 1 grub-install
sed -i -e '/\s\/\s/s/^/#/' /etc/fstab
zpool set cachefile=/etc/zfs/zpool.cache "$ZPOOL"
# Write basic grub configuration to boot the zpool
cat > /"$ZPOOL"/boot/grub/grub.cfg << EOF
insmod part_gpt
menuentry 'Arch Linux ZFS' {
insmod part_gpt
echo 'Searching ...'
search --set --label "$ZPOOL"
echo 'Loading kernel ...'
linux /ROOT/archlinux@/boot/vmlinuz-linux zfs="$ZPOOL" rw
echo 'Loading initramfs ...'
initrd /ROOT/archlinux@/boot/initramfs-linux.img
echo 'Booting ...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.