From cd27c3c70bd9d41989a64e78647c91ba45d2ad09 Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 1 Mar 2020 12:14:10 -0800 Subject: [PATCH] Add resume kernel parameter, more cowspace for live install. --- archlabs-installer | 77 +++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/archlabs-installer b/archlabs-installer index 471820c..dd7ea42 100755 --- a/archlabs-installer +++ b/archlabs-installer @@ -8,7 +8,7 @@ # check for syntax errors # set -n -VER=2.1.14 +VER=2.1.15 # default values { @@ -26,15 +26,19 @@ RUN=/run/archiso/bootmnt/arch/boot # path for live system /boot VM="$(dmesg | grep -i hypervisor)" # system running in a virtual machine EXMNTS="" # extra partitions that were mounted, used to verify mountpoint and show user USER_CMD="" # optional command(s) entered by the user to run in the chroot + export DIALOGOPTS="--cr-wrap" # dialog environment variable to hold default options, see `man dialog` -BASE_PKGS="base xorg xorg-drivers sudo git gvfs gtk3 libmad libmatroska tumbler " +# packages installed for all installation types as a baseline +BASE_PKGS="base base-devel xorg xorg-drivers sudo git gvfs gtk3 libmad libmatroska tumbler " BASE_PKGS+="playerctl pulseaudio pulseaudio-alsa pavucontrol pamixer scrot xdg-user-dirs " BASE_PKGS+="ffmpeg gstreamer gst-libav gst-plugins-base gst-plugins-good bash-completion xterm" +# packages installed specific to archlabs, installed when any session is chosen AL_BASE_PKGS="archlabs-keyring archlabs-icons archlabs-fonts archlabs-themes " AL_BASE_PKGS+="archlabs-baph archlabs-wallpapers archlabs-scripts archlabs-skel-base" +# packages installed for most window managers to provide some basic functionality WM_BASE_PKGS="arandr nitrogen polkit-gnome network-manager-applet " WM_BASE_PKGS+="volumeicon xclip exo laptop-detect xdotool picom wmctrl feh " WM_BASE_PKGS+="gnome-keyring dunst gsimplecal xfce4-power-manager xfce4-settings" @@ -56,6 +60,7 @@ declare -A BCMDS=( ) # } # sessions that provide their own super bind and set the wallpaper { +declare WM_PKG_SES='openbox|bspwm|i3-gaps|fluxbox|jwm|awesome' declare SELF_CONTAINED='plasma|gnome|cinnamon|deepin' declare SELF_CONTAINED_SES='startplasma-x11|gnome-session|startdde|cinnamon-session' # } @@ -826,7 +831,7 @@ part_cryptlv() LUKS_NAME="${part#/dev/mapper/}" for dev in $(awk '/lvm/ && /crypto_LUKS/ {print "/dev/mapper/"$1}' <<< "$devs" | uniq); do if lsblk -lno NAME "$dev" | grep -q "$LUKS_NAME"; then - LUKS_DEV="$LUKS_DEV cryptdevice=$dev:$LUKS_NAME" + LUKS_DEV="${LUKS_DEV}cryptdevice=$dev:$LUKS_NAME " LVM='logical volume' break fi @@ -834,7 +839,7 @@ part_cryptlv() for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do if lsblk -lno NAME "$dev" | grep -q "$LUKS_NAME"; then LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')" - LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME" + LUKS_DEV="${LUKS_DEV}cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME " break fi done @@ -850,7 +855,7 @@ part_cryptlv() for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do if lsblk -lno NAME "$dev" | grep -q "$LUKS_NAME"; then LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')" - LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME" + LUKS_DEV="${LUKS_DEV}cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME " LUKS='encrypted' break fi @@ -1307,7 +1312,7 @@ install_cleanup() sed '7,14d; s/xlock -mode blank/i3-lock-fancy -p/g; s/root:1/rofi_run/g' "$MNT/etc/system.jwmrc" > "$MNT/home/$user/.jwmrc" fi - # no picom (compton) or ksuperkey in dwm only installs + # no picom (compton) or ksuperkey in dwm login [[ $LOGIN_WM == 'dwm' ]] && sed -i '/super/d; /picom/d' "$MNT/home/$user/.xprofile" "$MNT/root/.xprofile" # remove some commands from ~/.xprofile when using self contained sessions @@ -1319,12 +1324,13 @@ install_cleanup() install_bootldr() { + local uuid_type="UUID" + echo "Installing $BOOTLDR" if [[ $ROOT == /dev/mapper* ]]; then ROOT_ID="$ROOT" else - local uuid_type="UUID" [[ $BOOTLDR =~ (systemd-boot|refind-efi|efistub) ]] && uuid_type="PARTUUID" ROOT_ID="$uuid_type=$(blkid -s $uuid_type -o value $ROOT)" fi @@ -1336,6 +1342,16 @@ install_bootldr() find "$MNT/boot/EFI/" -maxdepth 1 -mindepth 1 -iname 'BOOT' -type d -delete -printf "remove %p\n" fi + if [[ $SWAP ]]; then # attempt to setup swap space for suspend/resume + if [[ $SWAP == /dev/mapper* ]]; then + RESUME="resume=$SWAP " + elif [[ $SWAP == "/swapfile" ]]; then + RESUME="resume=$ROOT_ID resume_offset=$(filefrag -v "${MNT}$SWAP" | awk '{ if ($1=="0:") { gsub(/\./, ""); print $4 } }') " + else + RESUME="resume=$uuid_type=$(blkid -s $uuid_type -o value "$SWAP") " + fi + fi + prerun_$BOOTLDR chrun "${BCMDS[$BOOTLDR]}" 2> "$ERR" 2>&1 errshow 1 "chrun '${BCMDS[$BOOTLDR]}'" @@ -1367,9 +1383,7 @@ install_packages() local rmpkg="" local inpkg="$PACKAGES $USER_PKGS $AL_BASE_PKGS " - if pacman -Qq archlabs-installer > /dev/null 2>&1; then - rmpkg+="archlabs-installer " - fi + pacman -Qq archlabs-installer > /dev/null 2>&1 && rmpkg+="archlabs-installer " if [[ $MYSHELL == 'zsh' ]]; then inpkg+="zsh-completions " @@ -1377,16 +1391,12 @@ install_packages() rmpkg+="zsh " fi - if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps|fluxbox|jwm|awesome) ]]; then - inpkg+="$WM_BASE_PKGS " - elif [[ $INSTALL_WMS == 'dwm' ]]; then # dwm only needs a very limited package set - inpkg+=" " - fi + [[ $INSTALL_WMS =~ ($WM_PKG_SES) ]] && inpkg+="$WM_BASE_PKGS " # update and install crucial packages first to avoid issues al_repo "$MNT/etc/pacman.conf" - chrun "pacman -Syyu $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed" 2> "$ERR" 2>&1 - errshow 1 "chrun 'pacman -Syyu $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed'" + chrun "pacman -Syyu $BASE_PKGS ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed" 2> "$ERR" 2>&1 + errshow 1 "chrun 'pacman -Syyu $BASE_PKGS ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed'" # remove the packages we don't want on the installed system [[ $rmpkg ]] && chrun "pacman -Rnsc $rmpkg --noconfirm" @@ -1539,6 +1549,7 @@ install_mkinitcpio() [[ $LUKS ]] && add+=" encrypt" [[ $LVM ]] && add+=" lvm2" + [[ $SWAP ]] && add+=" resume" sed -i "s/block filesystems/block${add} filesystems ${HOOKS}/g" "$MNT/etc/mkinitcpio.conf" chrun "mkinitcpio -p $KERNEL" 2> "$ERR" 2>&1 errshow 1 "chrun 'mkinitcpio -p $KERNEL'" @@ -1576,7 +1587,7 @@ install_background() rsync -a /run/archiso/sfs/airootfs/ "$MNT/" && install_mirrorlist "$MNT/etc/pacman.d/mirrorlist" > /tmp/bgout 2>&1 && al_repo "$MNT/etc/pacman.conf" && - chrun "pacman -Syyu $BASE_PKGS base-devel --noconfirm --needed" > /tmp/bgout 2>&1 + chrun "pacman -Syyu $BASE_PKGS --noconfirm --needed" > /tmp/bgout 2>&1 ) & BG_PID=$! trap "kill $BG_PID 2> /dev/null" EXIT @@ -1718,7 +1729,8 @@ setup_syslinux() prerun_syslinux() { - local c="$MNT/boot/syslinux" s="/usr/lib/syslinux/bios" d=".." + local c="$MNT/boot/syslinux" s="/usr/lib/syslinux/bios" + local d=".." # for non-UEFI systems we need to use ../path if [[ $SYS == 'UEFI' ]]; then c="$MNT/boot/EFI/syslinux" s="/usr/lib/syslinux/efi64" d=''; @@ -1758,13 +1770,13 @@ prerun_syslinux() LABEL $DIST MENU LABEL $DIST Linux LINUX $d/vmlinuz-$KERNEL - APPEND root=$ROOT_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw + APPEND root=$ROOT_ID ${LUKS_DEV}${RESUME}rw INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL.img LABEL ${DIST}fallback MENU LABEL $DIST Linux Fallback LINUX $d/vmlinuz-$KERNEL - APPEND root=$ROOT_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw + APPEND root=$ROOT_ID ${LUKS_DEV}${RESUME}rw INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL-fallback.img EOF return 0 @@ -1779,11 +1791,9 @@ setup_refind-efi() prerun_refind-efi() { cat > "$MNT/boot/refind_linux.conf" <<- EOF - "$DIST Linux" "root=$ROOT_ID $([[ $LUKS_DEV ]] && - printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] && + "$DIST Linux" "root=$ROOT_ID ${LUKS_DEV}${RESUME}rw add_efi_memmap $([[ $UCODE ]] && printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-%v.img" - "$DIST Linux Fallback" "root=$ROOT_ID $([[ $LUKS_DEV ]] && - printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] && + "$DIST Linux Fallback" "root=$ROOT_ID ${LUKS_DEV}${RESUME}rw add_efi_memmap $([[ $UCODE ]] && printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-%v-fallback.img" EOF @@ -1822,14 +1832,14 @@ prerun_systemd-boot() title $DIST Linux linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img") initrd /initramfs-$KERNEL.img - options root=$ROOT_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw + options root=$ROOT_ID ${LUKS_DEV}${RESUME}rw EOF cat > "$MNT/boot/loader/entries/$DIST-fallback.conf" <<- EOF title $DIST Linux Fallback linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img") initrd /initramfs-$KERNEL-fallback.img - options root=$ROOT_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw + options root=$ROOT_ID ${LUKS_DEV}${RESUME}rw EOF mkdir -pv "$MNT/etc/pacman.d/hooks" @@ -2279,22 +2289,25 @@ live() elif ! net_connect; then msg "Not Connected" "\nRunning live requires an active internet connection to install packages.\n\nExiting..\n" 2 die 1 - elif (( $(awk '/MemTotal/ {print int($2 / 1024)}' /proc/meminfo) < 2500)); then - msg "Not Enough Memory" "\nLive session requires at least 2.5G of system memory for installing packages.\n\nExiting..\n" 2 + elif (( $(awk '/MemTotal/ {print int($2 * 1024 / 1000 / 1000)}' /proc/meminfo) < 4704)); then + msg "Not Enough Memory" "\nLive session requires at least 4.5G of system memory for installing packages.\n\nExiting..\n" 2 die 1 fi clear echo "Sorting mirrorlist" - mount /run/archiso/cowspace -o remount,size=2G + if ! mount /run/archiso/cowspace -o remount,size=4G; then + msg "Remount Fail" "\nUnable to remount root with a larger copy-on-write space, this is needed for installing packages.\n\nExiting..\n" 2 + die 1 + fi install_mirrorlist "/etc/pacman.d/mirrorlist" al_repo "/etc/pacman.conf" pacman -Syyu --noconfirm || die 1 rm -rf /var/cache/pacman/pkg/* - pacman -S $BASE_PKGS $AL_BASE_PKGS xorg-xinit --needed --noconfirm || die 1 + pacman -S ${BASE_PKGS/base-devel /} $AL_BASE_PKGS xorg-xinit --needed --noconfirm || die 1 rm -rf /var/cache/pacman/pkg/* case "$ses" in - i3-gaps|openbox|fluxbox|bspwm|awesome|xfce4|jwm) pacman -S "$ses" $WM_BASE_PKGS ${WM_EXT[$ses]} --needed --noconfirm || die 1 ;; + $WM_PKG_SES) pacman -S "$ses" $WM_BASE_PKGS ${WM_EXT[$ses]} --needed --noconfirm || die 1 ;; $SELF_CONTAINED) pacman -S "$ses" ${WM_EXT[$ses]} --needed --noconfirm || die 1 ;; dwm) { pacman -S git --needed --noconfirm || die 1; }; install_suckless "/root" nochroot ;; esac