Skip to content

Instantly share code, notes, and snippets.

@dragan
Created August 8, 2015 19:01
Show Gist options
  • Save dragan/3702f91b840780ddbb6c to your computer and use it in GitHub Desktop.
Save dragan/3702f91b840780ddbb6c to your computer and use it in GitHub Desktop.
Bootstrap a new X1 Carbon with Arch Linux
#!/usr/bin/env zsh
# ----------------------------------------------------------------------
# Setting font to something more readable
# ----------------------------------------------------------------------
echo "Set font to something more readable"
setfont sun12x22
# ----------------------------------------------------------------------
# Partitioning
# ----------------------------------------------------------------------
echo "Scorched earth - erase all GPT and MBR structures"
sgdisk -zog /dev/sda
echo "Make EFI system partition"
sgdisk --new=1:0:+512M -c 1:"EFI System Partition" -t 1:ef00 /dev/sda
echo "Make swap partition"
sgdisk --new=2:0:+8G -c 2:"Swap Partition" -t 2:8200 /dev/sda
echo "Make system partition"
sgdisk --new=3:0:0 -c 3:"Linux System Partition" -t 3:8304 /dev/sda
echo "Write random numbers to the partition"
dd if='/dev/urandom' of='/dev/sda3' bs=1M
echo "Create LUKS device"
cryptsetup --cipher aes-xts-plain64 --key-size 512 --hash sha512 \
--iter-time 5000 --use-random --verify-passphrase luksFormat /dev/sda3
echo "Mount LUKS device"
cryptsetup open /dev/sda3 encrypted
echo "Format EFI system partition"
mkfs.fat -F32 -n EFI /dev/sda1
echo "Format swap partition"
mkswap -L Swap /dev/sda2
echo "Format encrypted system partition"
mkfs.btrfs --force --label System /dev/mapper/encrypted
echo "Activate swap"
swapon -d -L Swap
echo "Mount filesystem"
o=defaults,x-mount.mkdir
o_btrfs=$o,compress=lzo,space_cache,autodefrag,ssd,discard,noatime
mount -o $o_btrfs -L System /mnt
mount -o $o -L EFI /mnt/boot
echo "Install base system"
pacstrap /mnt base base-devel
echo "Write to crypttab"
# note: only /dev/disk/by-partuuid, /dev/disk/by-partlabel and
# /dev/sda2 formats work here
cat > /mnt/etc/crypttab <<CRYPTTAB_EOF
encryptedswap /dev/disk/by-partlabel/swap /dev/urandom swap,allow-discards
CRYPTTAB_EOF
echo "Generate fstab"
genfstab -U -p /mnt >> /mnt/etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment