Arch-Linux-Installer/partition.sh

57 lines
1.0 KiB
Bash
Raw Normal View History

2022-02-12 16:29:17 +01:00
#!/bin/bash
#PS3="Please select a disk to partition:"
echo "Please select a disk to partition:"
# Don't separate values by space.
IFS=$'\n'
# Set variable containing name and size of all disks.
disks=( $(lsblk -d | tail -n+2 | awk '{print $1" "$4}') )
# Declare the array.
declare -a disks
# Select value on array.
select disk in ${disks[*]}
do
2022-02-12 16:35:38 +01:00
# Separate values by spaces.
2022-02-12 16:29:17 +01:00
IFS=' '
2022-02-12 16:35:38 +01:00
# Create new variable of selection.
2022-02-12 16:29:17 +01:00
array=($disk)
dev="${array[0]}"
2022-02-12 16:35:38 +01:00
echo -e
2022-02-12 16:29:17 +01:00
2022-02-12 16:35:38 +01:00
# Starting partitioning.
echo "Partitioning /dev/$dev.."
echo -e
# Clearing partition table of selected disk.
2022-02-12 16:29:17 +01:00
echo "Clearing existing partitioning table."
sgdisk -Z /dev/$dev &&
echo -e
2022-02-12 16:35:38 +01:00
# Creating boot partition.
2022-02-12 16:29:17 +01:00
size="${array[1]%?}"
echo "Creating boot partition of 256 MB."
sgdisk -n 1:0:+256M /dev/$dev &&
2022-02-12 16:53:11 +01:00
# Setting type for EFI.
sgdisk -t 1:ef00 /dev/$dev &&
2022-02-12 16:29:17 +01:00
echo -e
2022-02-12 16:35:38 +01:00
# Creating system partition.
2022-02-12 16:29:17 +01:00
echo "Creating system partition of $size GB."
sgdisk -n 2:0:0 /dev/$dev
2022-02-12 16:35:38 +01:00
echo -e
2022-02-12 16:29:17 +01:00
2022-02-12 16:35:38 +01:00
# Print partitions.
2022-02-12 16:29:17 +01:00
echo "This is your new partition table:"
2022-02-12 16:35:38 +01:00
lsblk | grep "$dev"
# Exit.
2022-02-12 16:29:17 +01:00
break
done