Implemented partition creation for encrypted system

This commit is contained in:
Kevin Veen-Birkenbach 2020-06-11 16:58:15 +02:00
parent b4774f9b12
commit 97beb0a9ab
2 changed files with 55 additions and 23 deletions

View File

@ -22,8 +22,9 @@ echo_partition_name(){
set_partition_paths(){ set_partition_paths(){
info "Setting partition paths..." info "Setting partition paths..."
root_partition_path=$(echo_partition_name "2")
boot_partition_path=$(echo_partition_name "1") boot_partition_path=$(echo_partition_name "1")
root_partition_path=$(echo_partition_name "2")
encrypted_partition_path=$(echo_partition_name "3")
} }
make_mount_folders(){ make_mount_folders(){
@ -44,8 +45,8 @@ make_working_folder(){
mount_partitions(){ mount_partitions(){
info "Mount boot and root partition..." && info "Mount boot and root partition..." &&
mount "$boot_partition_path" "$boot_mount_path" && mount -v "$boot_partition_path" "$boot_mount_path" &&
mount "$root_partition_path" "$root_mount_path" && mount -v "$root_partition_path" "$root_mount_path" &&
info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" || info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" ||
error error
} }

View File

@ -89,6 +89,7 @@ os_does_not_support_raspberry_version_error () {
case "$os" in case "$os" in
"arch") "arch")
question "Should the system be encrypted?(y/N)" && read -r encrypt_system
base_download_url="http://os.archlinuxarm.org/os/"; base_download_url="http://os.archlinuxarm.org/os/";
case "$version" in case "$version" in
"1") "1")
@ -206,29 +207,60 @@ if [ "$transfer_image" = "y" ]
info "Starting image transfer..." info "Starting image transfer..."
if [ "$os" = "arch" ] if [ "$os" = "arch" ]
then then
info "Execute fdisk..." info "Deleting partition tables..." &&
wipefs -a "$device_path" || error
if [ "$encrypt_system" == "y" ]
then
info "Creating partitions for encrypted system..." &&
( echo "o" #Type o. This will clear out any partitions on the drive. ( echo "o" #Type o. This will clear out any partitions on the drive.
echo "p" #Type p to list partitions. There should be no partitions left echo "p" #Type p to list partitions. There should be no partitions left
echo "n" #Type n, echo "n" #Type n,
echo "p" #then p for primary, echo "p" #then p for primary,
echo "1" #1 for the first partition on the drive, echo "1" #1 for the first partition on the drive,
echo "" #press ENTER to accept the default first sector, echo "" #press ENTER to accept the default first sector,
echo "+300M" #then type +100M for the last sector.
echo "t" #Type t,
echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
echo "n" #Type n,
echo "p" #then p for primary,
echo "2" #2 for the second partition on the drive,
echo "" #Default start sector
echo "+3G" #Endsector
echo "n" #Type n,
echo "p" #then p for primary,
echo "3" #2 for the second partition on the drive,
echo "" #Default start sector
echo "" #Default end sector
echo "w" #Write the partition table and exit by typing w.
)| fdisk "$device_path" || error
info "Format encrypted partition..." &&
mkfs.ext4 "$encrypted_partition_path" || error
else
info "Creating partitions..." &&
( echo "o" #Type o. This will clear out any partitions on the drive.
echo "p" #Type p to list partitions. There should be no partitions left
echo "n" #Type n,
echo "p" #then p for primary,
echo "1" #1 for the first partition on the drive,
echo "" #Default start sector
echo "+100M" #then type +100M for the last sector. echo "+100M" #then type +100M for the last sector.
echo "t" #Type t, echo "t" #Type t,
echo "c" #then c to set the first partition to type W95 FAT32 (LBA). echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
echo "n" #Type n, echo "n" #Type n,
echo "p" #then p for primary, echo "p" #then p for primary,
echo "2" #2 for the second partition on the drive, echo "2" #2 for the second partition on the drive,
echo "" #and then press ENTER twice to accept the default first and last sector. echo "" #Default start sector
echo "" echo "" #Default end sector
echo "w" #Write the partition table and exit by typing w. echo "w" #Write the partition table and exit by typing w.
)| fdisk "$device_path" || error "Creating partitions failed. Try to execute this script with the overwritting parameter." )| fdisk "$device_path" || error
fi
info "Format boot partition..." && info "Format boot partition..." &&
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible." mkfs.vfat "$boot_partition_path" || error
info "Format root partition..." && info "Format root partition..." &&
mkfs.ext4 "$root_partition_path" || error "Format root is not possible." mkfs.ext4 "$root_partition_path" || error
mount_partitions; mount_partitions;
@ -373,7 +405,6 @@ if [ "$update_system" == "y" ]
esac esac
fi fi
question "Should the system be encrypted?(y/N)" && read -r encrypt_system
if [ "$encrypt_system" == "y" ] if [ "$encrypt_system" == "y" ]
then then
# @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38 # @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38