install.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/bash -eu
  2. #
  3. # Author: Casey DeLorme
  4. #
  5. # This is used by my packer build, but is wired to work for a complete install.
  6. #
  7. # Description: Thse are the pre-installation steps for Arch, where you may have
  8. # launched the iso and have a terminal, but you're working off a live system
  9. # and still need to partition the disk.
  10. #
  11. # Warning: This installation is wired for efi mode installations. While it
  12. # may print a warning it won't stop the installation and may leave you with
  13. # a derelict system.
  14. #
  15. # Warning: This currently uses /dev/sda explicitly and may delete data or fail
  16. # if there are multiple disks connected or you are using alternative storage
  17. # such as M.2/NVME.
  18. [ ! -f /sys/firmware/efi/efivars ] && echo "efivars not mounted and this install may leave you with a derelict system..."
  19. # optionally print all commands
  20. [ -n "$DEBUG" ] && set -x
  21. # test network connection
  22. ping -c 3 archlinux.org
  23. # synchronize time (print for debug)
  24. timedatectl set-ntp true
  25. timedatectl status
  26. # @todo: future editions will intelligently check available disks,
  27. # may ask which disk to use, may detect if running on a laptop,
  28. # may automatically choose or ask if swap should be sized for
  29. # hibernation, and appropriately modify partition logic.
  30. # partition the hard drive
  31. parted /dev/sda -s 'mklabel gpt'
  32. parted /dev/sda -s 'mkpart primary fat32 1MiB 1024MiB'
  33. parted /dev/sda -s 'set 1 esp on'
  34. parted /dev/sda -s 'mkpart primary linux-swap 1024MiB 3072MiB'
  35. parted /dev/sda -s 'mkpart primary btrfs 3072MiB 100%'
  36. # format the partitions
  37. mkfs.fat -F32 -nEFI /dev/sda1
  38. mkswap -Larch /dev/sda2
  39. mkfs.btrfs -fLarch /dev/sda3
  40. # enable and mount partitions with appropriate settings
  41. swapon /dev/sda2
  42. mount -o "noatime,compress=lzo,space_cache,autodefrag,ssd" /dev/sda3 /mnt
  43. mkdir /mnt/boot
  44. mount /dev/sda1 /mnt/boot
  45. # install base and base-devel package sets, and generate the fstab
  46. pacstrap /mnt base base-devel
  47. genfstab -U -p /mnt >> /mnt/etc/fstab
  48. # this assumes that arch.sh and install/ exists and will copy them to continue
  49. # @note: would prefer to copy to `/tmp` but `/mnt/tmp` from iso is a separate tmpfs
  50. mkdir -p /mnt/srv/arch-desktop
  51. cp -r install /mnt/srv/arch-desktop/
  52. cp arch.sh /mnt/srv/arch-desktop/
  53. # proceed to automate arch-chroot installation then umount and reboot with an async delay
  54. arch-chroot /mnt /srv/arch-desktop/arch.sh
  55. umount -R /mnt
  56. (sleep 5 && systemctl reboot) &