-
-
Save gntlmnoffice/8cdc219286688ceeef6188c90569b210 to your computer and use it in GitHub Desktop.
Archlinux EFI install script https://git.io/alx86_efi and https://git.io/alx86_legacy
This file contains hidden or 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/sh | |
| ############################################################################## | |
| # ARCH LINUX INSTALL SCRIPT: | |
| # btrfs, lvm, luks, hibernate, trim | |
| # | |
| # PARTITION LAYOUT: | |
| # /dev/<disk>1 = grub boot partition | |
| # /dev/<disk>2 = luks encrypted root | |
| # | |
| # ROOT LAYOUT: | |
| # /dev/mapper/lvm = lvm physical volume | |
| # /dev/mapper/vg-swap = swap partition | |
| # /dev/mapper/vg-root = btrfs filesystem | |
| # | |
| # BTRFS SUBVOLUMES: | |
| # / = main system files | |
| # /var = logs, cache, etc | |
| # /home = user home directories | |
| # /.snapshots = btrfs snapshots | |
| # | |
| # based on xengi's setup guide: | |
| # https://xengi.de/posts/2015/12/28/archlinux_setup_guide/ | |
| # and on jmcantrell's awesome work: | |
| # https://gist.github.com/jmcantrell/95b6992af97ec1b625480200d6641a37 | |
| # | |
| # install from archiso: | |
| # curl -L https://git.io/alx86_efi | sh | |
| ############################################################################## | |
| set -e | |
| lang=en_US | |
| keymap=us | |
| live_install() { | |
| loadkeys $keymap | |
| # choose install disk | |
| local disk=${1:-`choose_disk`} | |
| local bootpart=${disk}1 | |
| local rootpart=${disk}2 | |
| # detect trim support | |
| is_ssd $disk && local ssd=1 | |
| # create disk partitions | |
| parted -s -a optimal $disk \ | |
| mklabel gpt unit MiB \ | |
| mkpart fat32 0% 256 set 1 boot on \ | |
| mkpart root 256 100% set 2 lvm on | |
| # describe lvm layout | |
| lvm=/dev/mapper/lvm | |
| root=/dev/mapper/vg-root | |
| swap=/dev/mapper/vg-swap | |
| # impossible to get a sane memory size, | |
| # so confirm closest guess with user | |
| swapsize=`get_swapsize` | |
| # encrypt root partition | |
| # GRUB only supports luks1 at writing this | |
| cryptsetup --key-size 512 luksFormat --type luks1 $rootpart | |
| cryptsetup open --type luks \ | |
| ${ssd:+--allow-discards} $rootpart lvm | |
| # create lvm volumes | |
| pvcreate $lvm | |
| vgcreate vg $lvm | |
| lvcreate -L $swapsize vg -n swap | |
| lvcreate -l +100%FREE vg -n root | |
| # create filesystems | |
| mkswap -L SWAP $swap | |
| mkfs.btrfs -L ROOT $root | |
| mount $root /mnt | |
| btrfs subvolume create /mnt/@ | |
| btrfs subvolume create /mnt/@var | |
| btrfs subvolume create /mnt/@home | |
| btrfs subvolume create /mnt/@snapshots | |
| umount /mnt | |
| # mount filesystems | |
| swapon -d $swap | |
| mount_btrfs $root @ /mnt | |
| mkdir /mnt/{var,home,.snapshots} | |
| mount_btrfs $root @var /mnt/var | |
| mount_btrfs $root @home /mnt/home | |
| mount_btrfs $root @snapshots /mnt/.snapshots | |
| # initialize system | |
| pacstrap /mnt base base-devel grub efibootmgr \ | |
| linux-headers intel-ucode btrfs-progs snapper \ | |
| linux-lts linux-lts-headers linux-zen linux-zen-headers | |
| # add file system mount points | |
| genfstab -U -p /mnt >>/mnt/etc/fstab | |
| test $ssd && sed -i \ | |
| -e '/swap/s:defaults:defaults,discard:' \ | |
| /mnt/etc/fstab | |
| # configure boot entry | |
| local cryptdevice="PARTUUID=`blkid -s PARTUUID -o value $rootpart`:lvm" | |
| test $ssd && cryptdevice+=":allow-discards" | |
| { | |
| echo "GRUB_ENABLE_CRYPTODISK=y" | |
| echo "GRUB_CMDLINE_LINUX=\"cryptdevice=$cryptdevice resume=$swap\"" | |
| } >>/mnt/etc/default/grub | |
| # create and mount bootloader efi directory | |
| mkdir /mnt/boot/efi | |
| mount $bootpart /mnt/boot/efi | |
| # install bootloader to disk | |
| arch-chroot /mnt grub-install \ | |
| --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch --recheck | |
| # create keyfile to avoid entering passphrase twice | |
| local keyfile=/mnt/crypto_keyfile.bin | |
| mkkeyfile $keyfile | |
| cryptsetup luksAddKey $rootpart $keyfile | |
| # configure mkinitcpio | |
| sed -i \ | |
| -e "/^MODULES=/s:():(crc32c-intel intel_agp i915):" \ | |
| -e "/^BINARIES=/s:():(/usr/bin/btrfs):" \ | |
| -e "/^FILES=/s:():(/${keyfile##*/}):" \ | |
| -e "/^HOOKS=/s:filesystems:keyboard keymap encrypt resume lvm2 filesystems:" \ | |
| -e "/^HOOKS=/s:)$: btrfs usr shutdown):" \ | |
| /mnt/etc/mkinitcpio.conf | |
| # create initial ramdisk | |
| arch-chroot /mnt mkinitcpio -p linux | |
| arch-chroot /mnt mkinitcpio -p linux-zen | |
| # generate grub config | |
| arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg | |
| # run chroot install | |
| cp $0 /mnt && arch-chroot /mnt sh /${0##*/} chroot | |
| # unmount everything | |
| umount /mnt/{boot/efi,home,var,.snapshots} /mnt | |
| swapoff $swap | |
| lvchange -a n /dev/mapper/vg-swap | |
| lvchange -a n /dev/mapper/vg-root | |
| vgchange -a n vg | |
| dmsetup remove /dev/mapper/lvm | |
| cryptsetup close lvm | |
| } | |
| chroot_install() { | |
| pacman -Sy --noconfirm \ | |
| networkmanager vim git wget lynx bash-completion | |
| # set hostname | |
| hostname=`get hostname` | |
| echo "$hostname" >/etc/hostname | |
| echo "127.0.1.1 $hostname.localdomain $hostname" >>/etc/hosts | |
| # set keymap | |
| echo "KEYMAP=$keymap" >>/etc/vconsole.conf | |
| # set locale | |
| echo "LANG=$lang.UTF-8" >/etc/locale.conf | |
| sed -i "/#$lang/s/^#//" /etc/locale.gen | |
| locale-gen | |
| # set time zone | |
| timezone=`tzselect` | |
| ln -sf /usr/share/zoneinfo/$timezone /etc/localtime | |
| # update hardware clock | |
| hwclock --systohc --utc | |
| # create priviledged user | |
| username=`get username` | |
| useradd -m $username -G users,wheel | |
| passwd $username | |
| # enable sudo group | |
| pacman -Sy --noconfirm sudo | |
| echo "%wheel ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/wheel | |
| # change root login | |
| passwd root | |
| } | |
| get_swapsize() { | |
| local free=` | |
| free -h | grep '^Mem:' | | |
| sed 's:\s\+: :g' | cut -d' ' -f2 | |
| ` | |
| { | |
| echo "total memory \`free -h\` = $free" | |
| echo "\`free\` reports less than the actual value" | |
| echo "hibernate needs swap (at least) equal to memory" | |
| echo "example swapsize: 16G 512M" | |
| } >&2 | |
| get swapsize # reply to stdout | |
| } | |
| choose_disk() { | |
| # show summary of connected disks | |
| local columns=NAME,SIZE,TYPE,STATE,VENDOR,MODEL | |
| lsblk -pd -o $columns | egrep '(NAME|disk)' >&2 | |
| # prompt for selection | |
| local disks=` | |
| lsblk -pld -o NAME,TYPE | tail -n+2 | | |
| grep '\bdisk\b' | awk '{print $1}' | |
| ` | |
| choose disk $disks # reply to stdout | |
| } | |
| is_ssd() { | |
| # non-zero values indicate trim support | |
| lsblk -pD -o NAME,DISC-GRAN,DISC-MAX | | |
| grep ${1:?missing disk} | grep -q '[1-9]' | |
| } | |
| mkkeyfile() { | |
| local keyfile=${1:?missing keyfile} | |
| dd bs=512 count=8 if=/dev/urandom of=$keyfile | |
| chmod 000 $keyfile | |
| } | |
| mount_btrfs() { | |
| local part=${1:?missing partition} | |
| local subvol=${2:?missing subvolume} | |
| local mnt=${3:?missing mountpoint} | |
| local mntopts=noatime,autodefrag,compress=lzo,space_cache | |
| test $ssd && mntopts+=",discard,ssd" | |
| mount -o $mntopts,subvol=$subvol $part $mnt | |
| } | |
| get() { | |
| local reply | |
| read -p "enter ${1:-value}: " reply | |
| echo $reply; test $reply | |
| } | |
| choose() { | |
| local reply | |
| echo "choose ${1:-value}:" >&2; shift | |
| select reply in "$@"; do | |
| echo $reply; break | |
| done | |
| test $reply | |
| } | |
| ${1:-live}_install |
This file contains hidden or 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/sh | |
| ############################################################################## | |
| # ARCH LINUX INSTALL SCRIPT: | |
| # ext4, lvm, luks, hibernate, trim | |
| # | |
| # PARTITION LAYOUT: | |
| # /dev/<disk>1 = grub boot partition | |
| # /dev/<disk>2 = luks encrypted root | |
| # | |
| # ROOT LAYOUT: | |
| # /dev/mapper/lvm = lvm physical volume | |
| # /dev/mapper/vg-swap = swap partition | |
| # /dev/mapper/vg-root = ext4 filesystem | |
| # | |
| # based on xengi's setup guide: | |
| # https://xengi.de/posts/2015/12/28/archlinux_setup_guide/ | |
| # and on jmcantrell's awesome work: | |
| # https://gist.github.com/jmcantrell/95b6992af97ec1b625480200d6641a37 | |
| # | |
| # install from archiso: | |
| # curl -L TO_BE_FILLED | sh | |
| ############################################################################## | |
| set -e | |
| lang=en_US | |
| keymap=us | |
| live_install() { | |
| loadkeys $keymap | |
| # choose install disk | |
| local disk=${1:-`choose_disk`} | |
| local bootpart=${disk}1 | |
| local rootpart=${disk}2 | |
| # detect trim support | |
| is_ssd $disk && local ssd=1 | |
| # create disk partitions | |
| parted -s -a optimal $disk \ | |
| mklabel gpt unit MiB \ | |
| mkpart fat32 0% 256 set 1 boot on \ | |
| mkpart root 256 100% set 2 lvm on | |
| mkfs.vfat -F 32 $bootpart | |
| fatlabel $bootpart BOOT | |
| # describe lvm layout | |
| lvm=/dev/mapper/lvm | |
| root=/dev/mapper/vg-root | |
| swap=/dev/mapper/vg-swap | |
| # impossible to get a sane memory size, | |
| # so confirm closest guess with user | |
| swapsize=`get_swapsize` | |
| # encrypt root partition | |
| # GRUB only supports luks1 at writing this | |
| cryptsetup --key-size 512 luksFormat --type luks1 $rootpart | |
| cryptsetup open --type luks \ | |
| ${ssd:+--allow-discards} $rootpart lvm | |
| # create lvm volumes | |
| pvcreate $lvm | |
| vgcreate vg $lvm | |
| lvcreate -L $swapsize vg -n swap | |
| lvcreate -l +100%FREE vg -n root | |
| # create filesystems | |
| mkswap -L SWAP $swap | |
| mkfs.ext4 -L ROOT $root | |
| mount $root /mnt | |
| # mount filesystems | |
| swapon -d $swap | |
| # initialize system | |
| pacstrap /mnt base base-devel grub efibootmgr linux linux-headers intel-ucode lvm2 | |
| # add file system mount points | |
| genfstab -U -p /mnt >>/mnt/etc/fstab | |
| test $ssd && sed -i \ | |
| -e '/swap/s:defaults:defaults,discard:' \ | |
| /mnt/etc/fstab | |
| # configure boot entry | |
| local cryptdevice="PARTUUID=`blkid -s PARTUUID -o value $rootpart`:lvm" | |
| test $ssd && cryptdevice+=":allow-discards" | |
| { | |
| echo "GRUB_ENABLE_CRYPTODISK=y" | |
| echo "GRUB_CMDLINE_LINUX=\"cryptdevice=$cryptdevice resume=$swap\"" | |
| } >>/mnt/etc/default/grub | |
| # create and mount bootloader efi directory | |
| mkdir /mnt/boot/efi | |
| mount $bootpart /mnt/boot/efi | |
| # install bootloader to disk | |
| arch-chroot /mnt grub-install \ | |
| --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch --recheck | |
| # create keyfile to avoid entering passphrase twice | |
| local keyfile=/mnt/crypto_keyfile.bin | |
| mkkeyfile $keyfile | |
| cryptsetup luksAddKey $rootpart $keyfile | |
| # configure mkinitcpio | |
| sed -i \ | |
| -e "/^MODULES=/s:():(crc32c-intel intel_agp i915):" \ | |
| -e "/^FILES=/s:():(/${keyfile##*/}):" \ | |
| -e "/^HOOKS=/s:filesystems:keyboard keymap encrypt resume lvm2 filesystems:" \ | |
| -e "/^HOOKS=/s:)$: usr shutdown):" \ | |
| /mnt/etc/mkinitcpio.conf | |
| # create initial ramdisk | |
| arch-chroot /mnt mkinitcpio -p linux | |
| # generate grub config | |
| arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg | |
| # run chroot install | |
| cp $0 /mnt && arch-chroot /mnt sh /${0##*/} chroot | |
| # unmount everything | |
| umount /mnt/{boot/efi,home,var,.snapshots} /mnt | |
| swapoff $swap | |
| lvchange -a n /dev/mapper/vg-swap | |
| lvchange -a n /dev/mapper/vg-root | |
| vgchange -a n vg | |
| dmsetup remove /dev/mapper/lvm | |
| cryptsetup close lvm | |
| } | |
| chroot_install() { | |
| pacman -Sy --noconfirm \ | |
| networkmanager vim git wget lynx bash-completion | |
| # set hostname | |
| hostname=`get hostname` | |
| echo "$hostname" >/etc/hostname | |
| echo "127.0.1.1 $hostname.localdomain $hostname" >>/etc/hosts | |
| # set keymap | |
| echo "KEYMAP=$keymap" >>/etc/vconsole.conf | |
| # set locale | |
| echo "LANG=$lang.UTF-8" >/etc/locale.conf | |
| sed -i "/#$lang/s/^#//" /etc/locale.gen | |
| locale-gen | |
| # set time zone | |
| timezone=`tzselect` | |
| ln -sf /usr/share/zoneinfo/$timezone /etc/localtime | |
| # update hardware clock | |
| hwclock --systohc --utc | |
| # create priviledged user | |
| username=`get username` | |
| useradd -m $username -G users,wheel | |
| passwd $username | |
| # enable sudo group | |
| pacman -Sy --noconfirm sudo | |
| echo "%wheel ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/wheel | |
| # change root login | |
| passwd root | |
| } | |
| get_swapsize() { | |
| local free=` | |
| free -h | grep '^Mem:' | | |
| sed 's:\s\+: :g' | cut -d' ' -f2 | |
| ` | |
| { | |
| echo "total memory \`free -h\` = $free" | |
| echo "\`free\` reports less than the actual value" | |
| echo "hibernate needs swap (at least) equal to memory" | |
| echo "example swapsize: 16G 512M" | |
| } >&2 | |
| get swapsize # reply to stdout | |
| } | |
| choose_disk() { | |
| # show summary of connected disks | |
| local columns=NAME,SIZE,TYPE,STATE,VENDOR,MODEL | |
| lsblk -pd -o $columns | egrep '(NAME|disk)' >&2 | |
| # prompt for selection | |
| local disks=` | |
| lsblk -pld -o NAME,TYPE | tail -n+2 | | |
| grep '\bdisk\b' | awk '{print $1}' | |
| ` | |
| choose disk $disks # reply to stdout | |
| } | |
| is_ssd() { | |
| # non-zero values indicate trim support | |
| lsblk -pD -o NAME,DISC-GRAN,DISC-MAX | | |
| grep ${1:?missing disk} | grep -q '[1-9]' | |
| } | |
| mkkeyfile() { | |
| local keyfile=${1:?missing keyfile} | |
| dd bs=512 count=8 if=/dev/urandom of=$keyfile | |
| chmod 000 $keyfile | |
| } | |
| get() { | |
| local reply | |
| read -p "enter ${1:-value}: " reply | |
| echo $reply; test $reply | |
| } | |
| choose() { | |
| local reply | |
| echo "choose ${1:-value}:" >&2; shift | |
| select reply in "$@"; do | |
| echo $reply; break | |
| done | |
| test $reply | |
| } | |
| ${1:-live}_install |
This file contains hidden or 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/sh | |
| ############################################################################## | |
| # ARCH LINUX INSTALL SCRIPT: | |
| # btrfs, lvm, luks, hibernate, trim | |
| # | |
| # PARTITION LAYOUT: | |
| # /dev/<disk>1 = luks encrypted root | |
| # | |
| # ROOT LAYOUT: | |
| # /dev/mapper/lvm = lvm physical volume | |
| # /dev/mapper/vg-swap = swap partition | |
| # /dev/mapper/vg-root = btrfs filesystem | |
| # | |
| # BTRFS SUBVOLUMES: | |
| # / = main system files | |
| # /var = logs, cache, etc | |
| # /home = user home directories | |
| # /.snapshots = btrfs snapshots | |
| # | |
| # based on xengi's setup guide: | |
| # https://xengi.de/posts/2015/12/28/archlinux_setup_guide/ | |
| # and on jmcantrell's awesome work: | |
| # https://gist.github.com/jmcantrell/95b6992af97ec1b625480200d6641a37 | |
| # | |
| # install from archiso: | |
| # curl -L https://git.io/alx86_legacy | sh | |
| ############################################################################## | |
| set -e | |
| lang=en_US | |
| keymap=us | |
| live_install() { | |
| loadkeys $keymap | |
| # choose install disk | |
| local disk=${1:-`choose_disk`} | |
| local rootpart=${disk}1 | |
| # detect trim support | |
| is_ssd $disk && local ssd=1 | |
| # create disk partitions | |
| parted -s -a optimal $disk \ | |
| mklabel msdos unit MiB \ | |
| mkpart primary 2048s 100% set 1 lvm on | |
| # describe lvm layout | |
| lvm=/dev/mapper/lvm | |
| root=/dev/mapper/vg-root | |
| swap=/dev/mapper/vg-swap | |
| # impossible to get a sane memory size, | |
| # so confirm closest guess with user | |
| swapsize=`get_swapsize` | |
| # encrypt root partition | |
| # GRUB only supports luks1 at writing this | |
| cryptsetup --key-size 512 luksFormat --type luks1 $rootpart | |
| cryptsetup open --type luks \ | |
| ${ssd:+--allow-discards} $rootpart lvm | |
| # create lvm volumes | |
| pvcreate $lvm | |
| vgcreate vg $lvm | |
| lvcreate -L $swapsize vg -n swap | |
| lvcreate -l +100%FREE vg -n root | |
| # create filesystems | |
| mkswap -L SWAP $swap | |
| mkfs.btrfs -L ROOT $root | |
| mount $root /mnt | |
| btrfs subvolume create /mnt/@ | |
| btrfs subvolume create /mnt/@var | |
| btrfs subvolume create /mnt/@home | |
| btrfs subvolume create /mnt/@snapshots | |
| umount /mnt | |
| # mount filesystems | |
| swapon -d $swap | |
| mount_btrfs $root @ /mnt | |
| mkdir /mnt/{var,home,.snapshots} | |
| mount_btrfs $root @var /mnt/var | |
| mount_btrfs $root @home /mnt/home | |
| mount_btrfs $root @snapshots /mnt/.snapshots | |
| # initialize system | |
| pacstrap /mnt base base-devel grub \ | |
| linux-headers intel-ucode btrfs-progs snapper \ | |
| linux-lts linux-lts-headers linux-zen linux-zen-headers | |
| # add file system mount points | |
| genfstab -U -p /mnt >>/mnt/etc/fstab | |
| test $ssd && sed -i \ | |
| -e '/swap/s:defaults:defaults,discard:' \ | |
| /mnt/etc/fstab | |
| # configure boot entry | |
| local cryptdevice="PARTUUID=`blkid -s PARTUUID -o value $rootpart`:lvm" | |
| test $ssd && cryptdevice+=":allow-discards" | |
| { | |
| echo "GRUB_ENABLE_CRYPTODISK=y" | |
| echo "GRUB_CMDLINE_LINUX=\"cryptdevice=$cryptdevice resume=$swap\"" | |
| } >>/mnt/etc/default/grub | |
| # install bootloader to disk | |
| arch-chroot /mnt grub-install \ | |
| --target=i386-pc --recheck ${disk} | |
| # create keyfile to avoid entering passphrase twice | |
| local keyfile=/mnt/crypto_keyfile.bin | |
| mkkeyfile $keyfile | |
| cryptsetup luksAddKey $rootpart $keyfile | |
| # configure mkinitcpio | |
| sed -i \ | |
| -e "/^MODULES=/s:():(crc32c-intel intel_agp i915):" \ | |
| -e "/^BINARIES=/s:():(/usr/bin/btrfs):" \ | |
| -e "/^FILES=/s:():(/${keyfile##*/}):" \ | |
| -e "/^HOOKS=/s:filesystems:keyboard keymap encrypt resume lvm2 filesystems:" \ | |
| -e "/^HOOKS=/s:)$: btrfs usr shutdown):" \ | |
| /mnt/etc/mkinitcpio.conf | |
| # create initial ramdisk | |
| arch-chroot /mnt mkinitcpio -p linux | |
| arch-chroot /mnt mkinitcpio -p linux-lts | |
| arch-chroot /mnt mkinitcpio -p linux-zen | |
| # generate grub config | |
| arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg | |
| # run chroot install | |
| cp $0 /mnt && arch-chroot /mnt sh /${0##*/} chroot | |
| # unmount everything | |
| umount /mnt/{home,var,.snapshots} /mnt | |
| swapoff $swap | |
| lvchange -a n /dev/mapper/vg-swap | |
| lvchange -a n /dev/mapper/vg-root | |
| vgchange -a n vg | |
| dmsetup remove /dev/mapper/lvm | |
| cryptsetup close lvm | |
| } | |
| chroot_install() { | |
| pacman -Sy --noconfirm \ | |
| networkmanager vim git wget lynx bash-completion | |
| # set hostname | |
| hostname=`get hostname` | |
| echo "$hostname" >/etc/hostname | |
| echo "127.0.1.1 $hostname.localdomain $hostname" >>/etc/hosts | |
| # set keymap | |
| echo "KEYMAP=$keymap" >>/etc/vconsole.conf | |
| # set locale | |
| echo "LANG=$lang.UTF-8" >/etc/locale.conf | |
| sed -i "/#$lang/s/^#//" /etc/locale.gen | |
| locale-gen | |
| # set time zone | |
| timezone=`tzselect` | |
| ln -sf /usr/share/zoneinfo/$timezone /etc/localtime | |
| # update hardware clock | |
| hwclock --systohc --utc | |
| # create priviledged user | |
| username=`get username` | |
| useradd -m $username -G users,wheel | |
| passwd $username | |
| # enable sudo group | |
| pacman -Sy --noconfirm sudo | |
| echo "%wheel ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/wheel | |
| # change root login | |
| passwd root | |
| } | |
| get_swapsize() { | |
| local free=` | |
| free -h | grep '^Mem:' | | |
| sed 's:\s\+: :g' | cut -d' ' -f2 | |
| ` | |
| { | |
| echo "total memory \`free -h\` = $free" | |
| echo "\`free\` reports less than the actual value" | |
| echo "hibernate needs swap (at least) equal to memory" | |
| echo "example swapsize: 16G 512M" | |
| } >&2 | |
| get swapsize # reply to stdout | |
| } | |
| choose_disk() { | |
| # show summary of connected disks | |
| local columns=NAME,SIZE,TYPE,STATE,VENDOR,MODEL | |
| lsblk -pd -o $columns | egrep '(NAME|disk)' >&2 | |
| # prompt for selection | |
| local disks=` | |
| lsblk -pld -o NAME,TYPE | tail -n+2 | | |
| grep '\bdisk\b' | awk '{print $1}' | |
| ` | |
| choose disk $disks # reply to stdout | |
| } | |
| is_ssd() { | |
| # non-zero values indicate trim support | |
| lsblk -pD -o NAME,DISC-GRAN,DISC-MAX | | |
| grep ${1:?missing disk} | grep -q '[1-9]' | |
| } | |
| mkkeyfile() { | |
| local keyfile=${1:?missing keyfile} | |
| dd bs=512 count=8 if=/dev/urandom of=$keyfile | |
| chmod 000 $keyfile | |
| } | |
| mount_btrfs() { | |
| local part=${1:?missing partition} | |
| local subvol=${2:?missing subvolume} | |
| local mnt=${3:?missing mountpoint} | |
| local mntopts=noatime,autodefrag,compress=lzo,space_cache | |
| test $ssd && mntopts+=",discard,ssd" | |
| mount -o $mntopts,subvol=$subvol $part $mnt | |
| } | |
| get() { | |
| local reply | |
| read -p "enter ${1:-value}: " reply | |
| echo $reply; test $reply | |
| } | |
| choose() { | |
| local reply | |
| echo "choose ${1:-value}:" >&2; shift | |
| select reply in "$@"; do | |
| echo $reply; break | |
| done | |
| test $reply | |
| } | |
| ${1:-live}_install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment