From 97beb0a9ab5395f09790e13f3a2c2d1e99f45af9 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Thu, 11 Jun 2020 16:58:15 +0200 Subject: [PATCH] Implemented partition creation for encrypted system --- scripts/image/base.sh | 7 +++-- scripts/image/setup.sh | 71 ++++++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/scripts/image/base.sh b/scripts/image/base.sh index 43cb4d5..e734fac 100644 --- a/scripts/image/base.sh +++ b/scripts/image/base.sh @@ -22,8 +22,9 @@ echo_partition_name(){ set_partition_paths(){ info "Setting partition paths..." - root_partition_path=$(echo_partition_name "2") boot_partition_path=$(echo_partition_name "1") + root_partition_path=$(echo_partition_name "2") + encrypted_partition_path=$(echo_partition_name "3") } make_mount_folders(){ @@ -44,8 +45,8 @@ make_working_folder(){ mount_partitions(){ info "Mount boot and root partition..." && - mount "$boot_partition_path" "$boot_mount_path" && - mount "$root_partition_path" "$root_mount_path" && + mount -v "$boot_partition_path" "$boot_mount_path" && + mount -v "$root_partition_path" "$root_mount_path" && info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" || error } diff --git a/scripts/image/setup.sh b/scripts/image/setup.sh index 71b9b2e..5a8b1f7 100644 --- a/scripts/image/setup.sh +++ b/scripts/image/setup.sh @@ -89,6 +89,7 @@ os_does_not_support_raspberry_version_error () { case "$os" in "arch") + question "Should the system be encrypted?(y/N)" && read -r encrypt_system base_download_url="http://os.archlinuxarm.org/os/"; case "$version" in "1") @@ -206,29 +207,60 @@ if [ "$transfer_image" = "y" ] info "Starting image transfer..." if [ "$os" = "arch" ] then - info "Execute fdisk..." - ( 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 "" #press ENTER to accept the default first sector, - echo "+100M" #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 "" #and then press ENTER twice to accept the default first and last sector. - echo "" - 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." + 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 "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 "" #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 "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 "" #Default end sector + echo "w" #Write the partition table and exit by typing w. + )| fdisk "$device_path" || error + fi 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..." && - mkfs.ext4 "$root_partition_path" || error "Format root is not possible." + mkfs.ext4 "$root_partition_path" || error mount_partitions; @@ -373,7 +405,6 @@ if [ "$update_system" == "y" ] esac fi -question "Should the system be encrypted?(y/N)" && read -r encrypt_system if [ "$encrypt_system" == "y" ] then # @see https://gist.github.com/gea0/4fc2be0cb7a74d0e7cc4322aed710d38