Last active
June 16, 2024 14:21
-
-
Save queckezz/667d1c7af10ba0b426b7df4db4f2c23a to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
# 1. First make sure you create a GPT disk with two partitions (with `cfdisk`): | |
# - EFI Partition (128M) | |
# - Linux partition (Rest) | |
read -p "Enter hostname: " hostname | |
read -p "Enter /dev device for EFI: " bootdev | |
read -p "Enter /dev device for root: " rootdev | |
BTRFS_OPTS="rw,noatime,compress=zstd,discard=async" | |
REPO="https://repo-de.voidlinux.org/current" | |
ARCH="x86_64" | |
# setup luks encryption | |
cryptsetup luksFormat --type luks1 -y /dev/vda2 | |
cryptsetup open /dev/vda2 cryptroot | |
# btrfs setup | |
mkfs.btrfs -L void /dev/mapper/cryptroot | |
mount -o $BTRFS_OPTS /dev/mapper/cryptroot /mnt | |
btrfs su cr /mnt/@ | |
btrfs su cr /mnt/@home | |
btrfs su cr /mnt/@snapshots | |
umount /mnt | |
mount -o $BTRFS_OPTS,subvol=@ /dev/mapper/cryptroot /mnt | |
mkdir /mnt/{home,.snapshots} | |
mount -o $BTRFS_OPTS,subvol=@home /dev/mapper/cryptroot /mnt/home | |
mount -o $BTRFS_OPTS,subvol=@snapshots /dev/mapper/cryptroot /mnt/.snapshots | |
# Certain directories that don’t need to be included in the snapshots, we will create some nested subvolumes for these specific directories | |
mkdir -p /mnt/var/cache | |
btrfs su cr /mnt/var/cache/xbps | |
btrfs su cr /mnt/var/tmp | |
btrfs su cr /mnt/srv | |
# EFI setup | |
mkfs.fat -F 32 -n EFI /dev/vda1 | |
mkdir -p /mnt/boot/efi | |
mount -o rw,noatime /dev/vda1 /mnt/boot/efi | |
# copy RSA keys | |
mkdir -p /mnt/var/db/xbps/keys | |
cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/ | |
# System install | |
XBPS_ARCH=$ARCH xbps-install -S -R "$REPO" -r /mnt base-system cryptsetup grub-x86_64-efi helix | |
xchroot /mnt chmod 755 / | |
xchroot /mnt echo "change root user password" | |
xchroot /mnt passwd root | |
xchroot /mnt echo $hostname > /etc/hostname | |
xchroot /mnt echo "LANG=en_US.UTF-8" > /etc/locale.conf | |
xchroot /mnt echo "en_US.UTF-8 UTF-8" >> /etc/default/libc-locales | |
xchroot /mnt xbps-reconfigure -f glibc-locales | |
# create new user | |
xchroot /mnt echo "create main user" | |
xchroot /mnt useradd queckezz | |
xchroot /mnt passwd queckezz | |
xchroot /mnt usermod -aG wheel queckezz | |
# setup /etc/fstab | |
EFI_UUID=$(blkid -s UUID -o value /dev/vda1) | |
ROOT_UUID=$(blkid -s UUID -o value /dev/mapper/cryptroot) | |
LUKS_UUID=$(blkid -s UUID -o value /dev/vda2) | |
cat <<EOF > /mnt/etc/fstab | |
UUID=$ROOT_UUID / btrfs $BTRFS_OPTS,subvol=@ 0 1 | |
UUID=$ROOT_UUID /home btrfs $BTRFS_OPTS,subvol=@home 0 2 | |
UUID=$ROOT_UUID /.snapshots btrfs $BTRFS_OPTS,subvol=@snapshots 0 2 | |
UUID=$EFI_UUID /boot/efi vfat defaults,noatime 0 2 | |
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0 | |
EOF | |
# grub install | |
cat <<EOF > /mnt/etc/default/grub | |
GRUB_DEFAULT=0 | |
GRUB_TIMEOUT=5 | |
GRUB_DISTRIBUTOR="Void" | |
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 rd.auto=1 rd.luks.allow-discards" | |
# GRUB_BACKGROUND=/usr/share/void-artwork/splash.png | |
GRUB_ENABLE_CRYPTODISK=y | |
EOF | |
xchroot /mnt grub-install /dev/vda --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id="void" | |
# link services for wired connection | |
xchroot /mnt ln -s /etc/sv/dhcpcd-eth0 /var/service | |
xchroot /mnt ln -s /etc/sv/dhcpcd /var/service | |
# Ensure an initramfs is generated: | |
xchroot /mnt xbps-reconfigure -fa | |
# cleanup | |
# umount -R /mnt | |
# reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
todo:
-- #%wheel ALL=(ALL) ALL