Add some tools
This commit is contained in:
parent
0bcabc58db
commit
7d4603da21
77
tools/arch_do_partition.sh
Executable file
77
tools/arch_do_partition.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DISK=NOTFOUND
|
||||
|
||||
# read arguments
|
||||
opts=$(getopt \
|
||||
--longoptions "disk:" \
|
||||
--options "d:" \
|
||||
-- "$@"
|
||||
)
|
||||
|
||||
eval set --$opts
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--disk | -d)
|
||||
DISK="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
PART_BOOT="${DISK}p1"
|
||||
PART_LVM="${DISK}p2"
|
||||
VG_NAME="vg0"
|
||||
|
||||
function assert() (
|
||||
set +euo pipefail
|
||||
"${@:2}" &> /dev/null
|
||||
if [[ "$?" -ne 0 ]]; then
|
||||
echo "$1"
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
|
||||
function clean() (
|
||||
set +euo pipefail
|
||||
swapoff "/dev/${VG_NAME}/swap"
|
||||
umount "/mnt/boot"
|
||||
umount "/mnt/"
|
||||
cryptsetup close "${VG_NAME}-root"
|
||||
cryptsetup close "${VG_NAME}-swap"
|
||||
cryptsetup close "${VG_NAME}"
|
||||
cryptsetup close cryptlvm
|
||||
true
|
||||
)
|
||||
|
||||
assert "EFI Variables not set: Are you booted into UEFI?" ls /sys/firmware/efi/efivars
|
||||
|
||||
clean
|
||||
|
||||
echo -e 'size=512M, type=U\n size=+, type=L\n' | sfdisk "${DISK}"
|
||||
sync
|
||||
|
||||
mkfs.fat -F32 "${PART_BOOT}"
|
||||
|
||||
cryptsetup luksFormat "${PART_LVM}"
|
||||
cryptsetup open "${PART_LVM}" cryptlvm
|
||||
|
||||
pvcreate /dev/mapper/cryptlvm
|
||||
pvcreate /dev/mapper/cryptlvm
|
||||
vgcreate "${VG_NAME}" /dev/mapper/cryptlvm
|
||||
lvcreate -L 8G "${VG_NAME}" -n swap
|
||||
lvcreate -l 100%FREE "${VG_NAME}" -n root
|
||||
lvreduce -L -256M "${VG_NAME}/root"
|
||||
|
||||
mkfs.ext4 "/dev/${VG_NAME}/root"
|
||||
mkswap "/dev/${VG_NAME}/swap"
|
||||
|
||||
mount "/dev/${VG_NAME}/root" /mnt
|
||||
mount --mkdir "${PART_BOOT}" /mnt/boot
|
||||
swapon "/dev/${VG_NAME}/swap"
|
8
tools/arch_fix_boot.sh
Normal file
8
tools/arch_fix_boot.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(dirname -- "${BASH_SOURCE[0]}" )"
|
||||
|
||||
"${script_dir}/mount.sh"
|
||||
|
||||
sudo arch-chroot /mnt pacman -Suy
|
45
tools/mount.sh
Normal file
45
tools/mount.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
reset=0
|
||||
disk=/dev/nvme0n1p2
|
||||
volume_group="OkesVG"
|
||||
|
||||
reset() {
|
||||
swapon -s | grep "$(realpath /dev/mapper/${volume_group}-swap)" &> /dev/null && \
|
||||
swapoff "$(realpath /dev/mapper/${volume_group}-swap)"
|
||||
df | grep /mnt/boot &> /dev/null && umount /mnt/boot
|
||||
df | grep /mnt &> /dev/null && umount /mnt
|
||||
[[ -e /dev/mapper/${volume_group}-root ]] && cryptsetup close ${volume_group}-root
|
||||
[[ -e /dev/mapper/${volume_group}-swap ]] && cryptsetup close ${volume_group}-swap
|
||||
[[ -e /dev/mapper/root ]] && cryptsetup close root
|
||||
}
|
||||
|
||||
# read arguments
|
||||
opts=$(getopt \
|
||||
--longoptions "reset" \
|
||||
--options "r" \
|
||||
-- "$@"
|
||||
)
|
||||
eval set --$opts
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--reset | -r)
|
||||
reset=1
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ "${reset}" -eq 1 ]] && reset
|
||||
[[ -e /dev/mapper/root ]] || cryptsetup open "${disk}" root
|
||||
vgchange -ay ${volume_group}
|
||||
# sleep 2
|
||||
df | grep /mnt &> /dev/null || mount /dev/mapper/${volume_group}-root /mnt
|
||||
df | grep /mnt/boot &> /dev/null || mount /dev/nvme0n1p1 /mnt/boot
|
||||
swapon -s | grep "$(realpath /dev/mapper/${volume_group}-swap)" &> /dev/null || \
|
||||
swapon /dev/mapper/${volume_group}-swap
|
Loading…
x
Reference in New Issue
Block a user