Created
May 25, 2012 13:22
-
-
Save mig/2788138 to your computer and use it in GitHub Desktop.
Adapted from arch-by-hand, more bare bones.
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
#!/bin/bash | |
# This script is designed to be run in conjunction with a UEFI boot using Archboot intall media. | |
# prereqs: | |
# -------------------- | |
# EFI "BIOS" set to boot *only* from EFI | |
# successful EFI boot of Archboot USB | |
# mount -t vfat /dev/sdb1 /src | |
set -o nounset | |
HOSTNAME=egg | |
USERNAME=mig | |
DISK=/dev/sda | |
AURHELPER=packer | |
INSTALL_TARGET="/install" | |
HR="--------------------------------------------------------------------------------" | |
PACMAN="pacman --noconfirm --config /tmp/pacman.conf" | |
TARGET_PACMAN="pacman --noconfirm --config /tmp/pacman.conf --root "${INSTALL_TARGET}"" | |
CHROOT_PACMAN="pacman --noconfirm --cachedir /var/cache/pacman/pkg --config /tmp/pacman.conf" | |
FILE_URL="file:///packages/core-$(uname -m)/pkg" | |
FTP_URL='ftp://mirrors.kernel.org/archlinux/$repo/os/$arch' | |
HTTP_URL='http://mirrors.kernel.org/archlinux/$repo/os/$arch' | |
SetValue () { | |
# EXAMPLE: SetValue VARIABLENAME '\"Quoted Value\"' /file/path | |
VALUENAME="$1" NEWVALUE="$2" FILEPATH="$3" | |
sed -i "s+^#\?\(${VALUENAME}\)=.*$+\1=${NEWVALUE}+" "${FILEPATH}" | |
} | |
CommentOutValue () { | |
VALUENAME="$1" FILEPATH="$2" | |
sed -i "s/^\(${VALUENAME}.*\)$/#\1/" "${FILEPATH}" | |
} | |
UncommentValue () { | |
VALUENAME="$1" FILEPATH="$2" | |
sed -i "s/^#\(${VALUENAME}.*\)$/\1/" "${FILEPATH}" | |
} | |
echo "STARTING" | |
echo -n "Waiting for network address.." | |
dhcpcd -p eth0 | |
# Mount packages squashfs images | |
# ------------------------------------------------------------------------ | |
umount "/packages/core-$(uname -m)" | |
umount "/packages/core-any" | |
rm -rf "/packages/core-$(uname -m)" | |
rm -rf "/packages/core-any" | |
mkdir -p "/packages/core-$(uname -m)" | |
mkdir -p "/packages/core-any" | |
modprobe -q loop | |
modprobe -q squashfs | |
mount -o ro,loop -t squashfs "/src/packages/archboot_packages_$(uname -m).squashfs" "/packages/core-$(uname -m)" | |
mount -o ro,loop -t squashfs "/src/packages/archboot_packages_any.squashfs" "/packages/core-any" | |
# Create temporary pacman.conf file | |
# ------------------------------------------------------------------------ | |
cat << PACMANEOF > /tmp/pacman.conf | |
[options] | |
Architecture = auto | |
CacheDir = ${INSTALL_TARGET}/var/cache/pacman/pkg | |
CacheDir = /var/cache/pacman/pkg | |
CacheDir = /packages/core-$(uname -m)/pkg | |
CacheDir = /packages/core-any/pkg | |
[core] | |
Server = ${FILE_URL} | |
Server = ${FTP_URL} | |
Server = ${HTTP_URL} | |
[extra] | |
Server = ${FILE_URL} | |
Server = ${FTP_URL} | |
Server = ${HTTP_URL} | |
PACMANEOF | |
${PACMAN} -Sy | |
echo -e "\nInstalling prereqs...\n$HR" | |
echo "Server = http://mirror.ece.vt.edu/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist | |
${PACMAN} -Sy gptfdisk btrfs-progs | |
echo -e "\nFormatting disk...\n$HR" | |
# disk prep | |
sgdisk -Z ${DISK} # zap all on disk | |
sgdisk -a 2048 -o ${DISK} # new gpt disk 2048 alignment | |
# create partitions | |
sgdisk -n 1:0:+512M ${DISK} # partition 1 (UEFI SYS), default start block, 512MB | |
sgdisk -n 2:0:+400M ${DISK} # partition 2 (BOOT), default start block, 400MB | |
sgdisk -n 3:0:+16G ${DISK} # partition 3 (SWAP), default start block, 16GB | |
sgdisk -n 4:0:+20G ${DISK} # partition 4 (ROOT), default start, 20G | |
sgdisk -n 5:0:+20G ${DISK} # partition 4 (VAR), default start, 20G | |
sgdisk -n 6:0:+50G ${DISK} # partition 5 (USR), default start, 50G | |
sgdisk -n 7:0:0 ${DISK} # partition 6 (LUKS), default start, remaining | |
# set partition types | |
sgdisk -t 1:ef00 ${DISK} | |
sgdisk -t 2:8300 ${DISK} | |
sgdisk -t 3:8200 ${DISK} | |
sgdisk -t 4:8300 ${DISK} | |
sgdisk -t 5:8300 ${DISK} | |
sgdisk -t 6:8300 ${DISK} | |
sgdisk -t 7:8300 ${DISK} | |
# label partitions | |
sgdisk -c 1:"UEFISYS" ${DISK} | |
sgdisk -c 2:"BOOT" ${DISK} | |
sgdisk -c 3:"SWAP" ${DISK} | |
sgdisk -c 4:"ROOT" ${DISK} | |
sgdisk -c 5:"VAR" ${DISK} | |
sgdisk -c 6:"USR" ${DISK} | |
sgdisk -c 7:"LUKS" ${DISK} | |
# format LUKS on root | |
cryptsetup --cipher=aes-xts-plain --verify-passphrase --key-size=512 luksFormat "${DISK}7" | |
cryptsetup luksOpen "${DISK}7" root | |
# NOTE: make sure to add dm_crypt and aes_x86_64 to MODULES in rc.conf | |
# make filesystems | |
echo -e "\nCreating Filesystems...\n$HR" | |
mkfs.vfat -F32 -n "UEFISYS" "${DISK}1" | |
mkfs.ext3 -L "BOOT" "${DISK}2" | |
mkswap -L "SWAP" "${DISK}3" | |
swapon "${DISK}3" | |
mkfs.ext4 -L "ROOT" "${DISK}4" | |
mkfs.ext4 -L "VAR" "${DISK}5" | |
mkfs.ext4 -L "USR" "${DISK}6" | |
mkfs.ext4 -L "HOME" /dev/mapper/home | |
# mount target | |
mkdir "${INSTALL_TARGET}" | |
mount -t ext4 "${DISK}4" "${INSTALL_TARGET}" | |
mount -t ext4 "${DISK}5" "${INSTALL_TARGET}"/var | |
mount -t ext4 "${DISK}6" "${INSTALL_TARGET}"/usr | |
mount -t ext4 /dev/mapper/home "${INSTALL_TARGET}"/home | |
mkdir "${INSTALL_TARGET}"/boot | |
mount -t ext3 "${DISK}2" "${INSTALL_TARGET}"/boot | |
mkdir "${INSTALL_TARGET}"/boot/efi | |
mount -t vfat "${DISK}1" "${INSTALL_TARGET}"/boot/efi | |
# kernel modules for EFI install | |
# ------------------------------------------------------------------------ | |
if [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Inc.' ]] || [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Computer, Inc.' ]]; then | |
modprobe -r -q efivars || true | |
else | |
modprobe -q efivars | |
fi | |
modprobe -q dm-mod | |
# ------------------------------------------------------------------------ | |
# mount proc, sys, dev in install root | |
# ------------------------------------------------------------------------ | |
mkdir -p "${INSTALL_TARGET}"/proc | |
mkdir -p "${INSTALL_TARGET}"/sys | |
mkdir -p "${INSTALL_TARGET}"/dev | |
mount -o bind /proc "${INSTALL_TARGET}"/proc | |
mount -o bind /sys "${INSTALL_TARGET}"/sys | |
mount -o bind /dev "${INSTALL_TARGET}"/dev | |
mkdir -m 755 -p "${INSTALL_TARGET}"/tmp | |
cp /tmp/pacman.conf "${INSTALL_TARGET}"/tmp/pacman.conf | |
# ------------------------------------------------------------------------ | |
# Install base, necessary utilities | |
# ------------------------------------------------------------------------ | |
[[ ! -d "${INSTALL_TARGET}/var/cache/pacman/pkg" ]] && mkdir -m 755 -p "${INSTALL_TARGET}/var/cache/pacman/pkg" | |
[[ ! -d "${INSTALL_TARGET}/var/lib/pacman" ]] && mkdir -m 755 -p "${INSTALL_TARGET}/var/lib/pacman" | |
${TARGET_PACMAN} -Sy | |
${TARGET_PACMAN} -Su base curl | |
${TARGET_PACMAN} -R grub | |
cp -r "${INSTALL_TARGET}"/boot/grub "${INSTALL_TARGET}"/boot/grub.bak | |
rm -rf "${INSTALL_TARGET}"/boot/grub | |
${TARGET_PACMAN} -S grub2-efi-x86_64 | |
# ------------------------------------------------------------------------ | |
# Configure new system | |
# ------------------------------------------------------------------------ | |
SetValue HOSTNAME "${HOSTNAME}" "${INSTALL_TARGET}"/etc/rc.conf | |
sed -i "s/^\(127\.0\.0\.1.*\)$/\1 ${HOSTNAME}/" "${INSTALL_TARGET}"/etc/hosts | |
SetValue CONSOLEFONT Lat2-Terminus16 "${INSTALL_TARGET}"/etc/rc.conf | |
# ------------------------------------------------------------------------ | |
# write fstab | |
# ------------------------------------------------------------------------ | |
# You can use UUID's or whatever you want here, of course. This is just | |
# the simplest approach and as long as your drives aren't changing values | |
# randomly it should work fine. | |
cat > "${INSTALL_TARGET}"/etc/fstab <<FSTAB_EOF | |
/dev/sda1 /boot/efi vfat defaults 0 0 | |
/dev/sda2 /boot ext3 defaults 0 1 | |
/dev/sda3 none swap defaults 0 0 | |
/dev/sda4 / ext4 defaults 0 1 | |
/dev/sda5 /usr ext4 defaults 0 1 | |
/dev/sda6 /var ext4 defaults 0 1 | |
/dev/mapper/home /home ext4 defaults,noatime 0 1 | |
tmpfs /tmp tmpfs nodev,nosuid 0 0 | |
FSTAB_EOF | |
# ------------------------------------------------------------------------ | |
# copy configs we want to carry over to target from install environment | |
# ------------------------------------------------------------------------ | |
mv "${INSTALL_TARGET}"/etc/resolv.conf "${INSTALL_TARGET}"/etc/resolv.conf.orig | |
cp /etc/resolv.conf "${INSTALL_TARGET}"/etc/resolv.conf | |
# we have to remount /boot from inside the chroot | |
umount "${INSTALL_TARGET}"/boot/efi | |
umount "${INSTALL_TARGET}"/boot | |
# ------------------------------------------------------------------------ | |
# Create install_efi script (to be run *after* chroot /install) | |
# ------------------------------------------------------------------------ | |
touch "${INSTALL_TARGET}"/install_efi | |
chmod a+x "${INSTALL_TARGET}"/install_efi | |
cat > "${INSTALL_TARGET}"/install_efi <<EFI_EOF | |
SetValue () { VALUENAME="\$1" NEWVALUE="\$2" FILEPATH="\$3"; sed -i "s+^#\?\(\${VALUENAME}\)=.*\$+\1=\${NEWVALUE}+" "\${FILEPATH}"; } | |
CommentOutValue () { VALUENAME="\$1" FILEPATH="\$2"; sed -i "s/^\(\${VALUENAME}.*\)\$/#\1/" "\${FILEPATH}"; } | |
UncommentValue () { VALUENAME="\$1" FILEPATH="\$2"; sed -i "s/^#\(\${VALUENAME}.*\)\$/\1/" "\${FILEPATH}"; } | |
mkdir -p /boot | |
mount -t ext3 /dev/sda2 /boot | |
mkdir -p /boot/efi | |
mount -t vfat /dev/sda1 /boot/efi | |
SetValue MODULES '\\"dm_mod dm_crypt aes_x86_64 ext2 ext4 vfat intel_agp drm i915\\"' /etc/mkinitcpio.conf | |
SetValue HOOKS '\\"base udev pata scsi sata usb usbinput keymap consolefont encrypt filesystems usr\\"' /etc/mkinitcpio.conf | |
mkinitcpio -p linux | |
UncommentValue en_US /etc/locale.gen | |
locale-gen | |
SetValue GRUB_CMDLINE_LINUX '\\"root=/dev/sda4 add_efi_memmap i915.modeset=1 i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1 pcie_aspm=force quiet\\"' /etc/default/grub | |
SetValue GRUB_TERMINAL_OUTPUT gfxterm /etc/default/grub | |
SetValue GRUB_GFXMODE 960x600x32,auto /etc/default/grub | |
SetValue GRUB_GFXPAYLOAD_LINUX keep /etc/default/grub | |
mkdir -p /boot/efi/EFI | |
grub-install --directory=/usr/lib/grub/x86_64-efi --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --boot-directory=/boot --recheck --debug &>/boot/grub_uefi.log | |
if [[ "\$(cat "/sys/class/dmi/id/sys_vendor")" != 'Apple Inc.' ]] && [[ "\$(cat "/sys/class/dmi/id/sys_vendor")" != 'Apple Computer, Inc.' ]]; then | |
for _bootnum in \$(efibootmgr | grep '^Boot[0-9]' | fgrep -i 'ARCH LINUX (GRUB2)' | cut -b5-8) ; do | |
efibootmgr --bootnum "\${_bootnum}" --delete-bootnum | |
done | |
efibootmgr --verbose --create --gpt --disk /dev/sda --part 1 --write-signature --label 'ARCH LINUX (GRUB2)' --loader '\\EFI\\arch_grub\\grubx64.efi' | |
fi | |
grub-mkconfig -o /boot/grub/grub.cfg | |
exit | |
EFI_EOF | |
chroot "${INSTALL_TARGET}" /install_efi | |
touch "${INSTALL_TARGET}"/post_install | |
chmod a+x "${INSTALL_TARGET}"/post_install | |
cat > "${INSTALL_TARGET}"/post_install <<POST_EOF | |
set -o errexit | |
set -o nounset | |
SetValue () { VALUENAME="\$1" NEWVALUE="\$2" FILEPATH="\$3"; sed -i "s+^#\?\(\${VALUENAME}\)=.*\$+\1=\${NEWVALUE}+" "\${FILEPATH}"; } | |
CommentOutValue () { VALUENAME="\$1" FILEPATH="\$2"; sed -i "s/^\(\${VALUENAME}.*\)\$/#\1/" "\${FILEPATH}"; } | |
UncommentValue () { VALUENAME="\$1" FILEPATH="\$2"; sed -i "s/^#\(\${VALUENAME}.*\)\$/\1/" "\${FILEPATH}"; } | |
echo -e "${HR}\\nNew root user password\\n${HR}" | |
passwd | |
echo -e "${HR}\\nNew non-root user password (username:${USERNAME})\\n${HR}" | |
groupadd sudo | |
useradd -m -g users -G audio,lp,optical,storage,video,games,power,scanner,network,sudo,wheel -s /bin/bash ${USERNAME} | |
passwd ${USERNAME} | |
mv /etc/profile.d/locale.sh /etc/profile.d/locale.sh.preupdate || true | |
pacman --noconfirm -Syu | |
pacman --noconfirm -S base-devel | |
mkdir -p /tmp/build | |
cd /tmp/build | |
wget https://aur.archlinux.org/packages/${AURHELPER}/${AURHELPER}.tar.gz | |
tar -xzvf ${AURHELPER}.tar.gz | |
cd ${AURHELPER} | |
makepkg --asroot -si | |
cd /tmp | |
pacman --noconfirm -S sudo | |
cp /etc/sudoers /tmp/sudoers.edit | |
sed -i "s/#\s*\(%wheel\s*ALL=(ALL)\s*ALL.*$\)/\1/" /tmp/sudoers.edit | |
sed -i "s/#\s*\(%sudo\s*ALL=(ALL)\s*ALL.*$\)/\1/" /tmp/sudoers.edit | |
visudo -qcsf /tmp/sudoers.edit && cat /tmp/sudoers.edit > /etc/sudoers | |
pacman --noconfirm -S acpi acpid cpufrequtils | |
${AURHELPER} --noconfirm -S acpitool powertop2 | |
sed -i "/^DAEMONS/ s/)/ @acpid)/" /etc/rc.conf | |
sed -i "/^MODULES/ s/)/ acpi-cpufreq cpufreq_ondemand cpufreq_powersave coretemp)/" /etc/rc.conf | |
echo "/etc/acpi/handler.sh boot" > /etc/rc.local | |
pacman --noconfirm -S ntp | |
sed -i "/^DAEMONS/ s/hwclock /!hwclock @ntpd /" /etc/rc.conf | |
pacman --noconfirm -S iw wpa_supplicant rfkill | |
pacman --noconfirm -S netcfg wpa_actiond ifplugd | |
mv /etc/wpa_supplicant.conf /etc/wpa_supplicant.conf.orig | |
echo -e "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=network\nupdate_config=1" > /etc/wpa_supplicant.conf | |
sed -i "/^DAEMONS/ s/)/ @net-auto-wireless @net-auto-wired)/" /etc/rc.conf | |
sed -i "/^DAEMONS/ s/ network / /" /etc/rc.conf | |
echo "options iwlagn led_mode=2" > /etc/modprobe.d/iwlagn.conf | |
pacman --noconfirm -S alsa-utils alsa-plugins | |
sed -i "/^DAEMONS/ s/)/ @alsa)/" /etc/rc.conf | |
mv /etc/asound.conf /etc/asound.conf.orig || true | |
pacman --noconfirm -S base-devel mesa mesa-demos | |
pacman --noconfirm -S xorg xorg-server xorg-xinit xorg-utils xorg-server-utils xdotool xorg-xlsfonts | |
pacman --noconfirm -S xcompmgr xscreensaver hsetroot | |
pacman --noconfirm -S rxvt-unicode urxvt-url-select | |
pacman --noconfirm -S dbus upower | |
sed -i "/^DAEMONS/ s/)/ @dbus)/" /etc/rc.conf | |
pacman --noconfirm -S wireless_tools netcfg-vpnc | |
pacman --noconfirm -S terminus-font | |
${AURHELPER} --noconfirm -S webcore-fonts | |
${AURHELPER} --noconfirm -S libspiro | |
${AURHELPER} --noconfirm -S fontforge | |
${AURHELPER} -S freetype2-infinality fontconfig-infinality | |
pacman --noconfirm -S htop openssh keychain bash-completion git vim | |
pacman --noconfirm -S chromium flashplugin | |
${AURHELPER} -S --noconfirm terminus-font-ttf | |
POST_EOF | |
chroot "${INSTALL_TARGET}" /post_install | |
mv "${INSTALL_TARGET}"/post_install /. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment