-
-
Save fuad-ibrahimzade/15ef5570b4870f1112bd2f77b0f35400 to your computer and use it in GitHub Desktop.
Simple installer for ArchLinux on ZFS (tested in VirtualBox)
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/sh | |
| # prerequisites | |
| # pacman -S arch-install-scripts sgdisk rsync | |
| ZPOOL=rootfs | |
| RAIDZ=mirror | |
| 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[@]}" | |
| do | |
| sgdisk -n 2:34:2047 -t 2:EF02 "$disk" -c 2:"BIOS Boot Partition" | |
| blockdev --rereadpt "$disk" | |
| done | |
| # 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" | |
| exit | |
| EOF | |
| # 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 ...' | |
| } | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment