This commit is contained in:
teldra 2022-02-06 23:25:49 +01:00
parent 9e3c35b53d
commit 47e0bd6003
1 changed files with 76 additions and 5 deletions

81
main.sh
View File

@ -2,6 +2,9 @@
main="/tmp/vinstall"
target="${main}/target"
pass="oem"
mkdir -p $target
. functions
@ -12,7 +15,7 @@ target_phy_disk() {
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL,WWN|grep disk)
echo "$DISKS_DETAILS"
input "which one?" "$(echo "$DISKS_DETAILS"|awk '{print $1}'|tr '\n' ' ')" "not found."
TARGET_PHY_DISK="$output"
TARGET_PHY_DISK="/dev/${output}"
}
target_phy_id() {
@ -50,7 +53,7 @@ encryption_style() {
header "Choose encryption style"
echo "implemented:"
echo "a)keyfile in initramfs" #bios: 1 uefi: 2
echo "b)no encryption" #bios: 1 uefi: 2
echo "b)no encryption" #bios: 2 uefi: 2
echo "not implemented:"
echo "c)no keyfile (double pw enter)" #bios: 1 uefi: 2
echo "d)keyfile on usb" #bios: 1 uefi: ?
@ -59,11 +62,72 @@ encryption_style() {
ENCRYPTION_STYLE="$output"
}
partition() {
hibernation() {
ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))"
ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")"
HIBERNATE=1
if [[ "${ramsize}" -lt "2" ]]; then
SWAPSIZE="$(( ramsize * 2 ))"
SWAPSIZE="$(( ramsize * 3 ))"
elif [[ "${ramsize}" -ge "2" ]] && [[ "${ramsize}" -lt "8" ]]; then
SWAPSIZE="${ramsize}"
SWAPSIZE="$(( ramsize * 2 ))"
elif [[ "${ramsize}" -ge "8" ]] && [[ "${ramsize}" -lt "16" ]]; then
SWAPSIZE="${ramsize}"
SWAPSIZE="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")"
elif [[ "${ramsize}" -ge "16" ]]; then
SWAPSIZE="4"
echo "hibernate not recommended, turning off"
HIBERNATE="0"
SWAPSIZE="4"
fi
}
do_partition() {
header "do partition"
start=1
if [ "$EFI" == "1" ]; then
echo parted --script $TARGET_PHY_WWN 'mklabel gpt'
echo parted -a optimal $TARGET_PHY_WWN mklabel gpt
size=500
echo parted -a optimal $TARGET_PHY_WWN unit mib mkpart EFI fat32 $start $(($start+$size))
start=$(($start+$size+1))
echo parted -a optimal $TARGET_PHY_WWN unit mib mkpart root $start -1s
mkfs.vfat -F32 $TARGET_PHY_WWN-part1
TARGET_PART="2"
else
echo parted --script $TARGET_PHY_WWN 'mklabel msdos'
echo parted -a optimal $TARGET_PHY_WWN mklabel msdos
TARGET_PART="1"
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
size=2048
echo parted -a optimal $TARGET_PHY_WWN unit mib mkpart primary ext4 $start $(($start+$size))
start=$(( $start + $size + 1 ))
mkfs.btrfs $TARGET_PHY_WWN-part1
TARGET_PART="2"
fi
echo parted -a optimal $TARGET_PHY_WWN unit mib mkpart primary ext4 $start -1
fi
TARGETNAME=$(basename ${TARGET_PHY_WWN}-part${TARGET_PART})
echo -n $pass | cryptsetup luksFormat ${TARGET_PHY_WWN}-part${TARGET_PART}
#echo -n $pass | sudo cryptsetup luksOpen /dev/sdc1 sdc1 -d -
echo -n $pass | cryptsetup luksOpen ${TARGET_PHY_WWN}-part${TARGET_PART} "luks-${TARGETNAME}"
vgcreate vg-${TARGETNAME} /dev/mapper/luks-${TARGETNAME}
lvcreate --name swap -L ${SWAPSIZE}G vg-${TARGETNAME}
lvcreate --name root -l 100%FREE vg-${TARGETNAME}
mkswap /dev/mapper/vg-${TARGETNAME}-swap
mkfs.btrfs /dev/mapper/vg-${TARGETNAME}-root
mount /dev/mapper/vg-${TARGETNAME}-root $target
btrfs subvol create ${target}/root
btrfs subvol create ${target}/home
umount $target
mount /dev/mapper/vg-${TARGETNAME}-root $target -o subvol=root
if [ "$EFI" == "1" ]; then
mkdir -p ${target}/boot/efi
mount ${TARGET_PHY_WWN}-part1 ${target}/boot/efi
else
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
mkdir -p ${target}/boot
mount ${TARGET_PHY_WWN}-part1 ${target}/boot
fi
fi
}
@ -71,3 +135,10 @@ target_phy_disk
target_phy_id
use_efi
encryption_style
hibernation
do_partition