diff --git a/test/test.sh b/test/test.sh index 4f9a6c9..c778ec2 100755 --- a/test/test.sh +++ b/test/test.sh @@ -63,6 +63,7 @@ function execute_installer { echo "$SELF_NAME: installation with codename $CODENAME" ./ubuntu-installer.sh "$TASK" \ + --separate-home \ --username "$TEST_USERNAME" \ --hostname "$TEST_HOSTNAME" \ --codename "$CODENAME" \ diff --git a/ubuntu-installer.sh b/ubuntu-installer.sh index 1e1c73c..765825a 100755 --- a/ubuntu-installer.sh +++ b/ubuntu-installer.sh @@ -15,9 +15,10 @@ function main { SHOW_HELP=false SHELL_LOGIN=false USE_EFI=false + USE_SEPARATE_HOME=false #define long options - LONG_OPTIONS='help,login,efi' + LONG_OPTIONS='help,login,efi,separate-home' LONG_OPTIONS="$LONG_OPTIONS"',username:,hostname:,codename:,bundles:,dev-root:,dev-home:,dev-boot:' LONG_OPTIONS="$LONG_OPTIONS"',mirror:,locales:,time-zone:,user-gecos:,password:' LONG_OPTIONS="$LONG_OPTIONS"',keyboard-model:,keyboard-layout:,keyboard-variant:,keyboard-options:' @@ -25,7 +26,7 @@ function main { # parse arguments OPTIONS_PARSED=$( getopt \ - --options 'hleu:n:c:b:x:y:z:' \ + --options 'hlesu:n:c:b:x:y:z:' \ --longoptions "$LONG_OPTIONS" \ --name "$SELF_NAME" \ -- "$@" @@ -49,6 +50,10 @@ function main { USE_EFI=true shift 1 ;; + -s | --separate-home) + USE_SEPARATE_HOME=true + shift 1 + ;; -u | --username) USERNAME_NEW="$2" shift 2 @@ -335,11 +340,16 @@ function verify_mounting_root { function verify_mounting_home { - # the block device file for "/home" must exist - if [[ -z "${DEV_HOME:-}" ]] || [[ ! -b "${DEV_HOME:-}" ]]; then + # only perform checks if a separate home partition is used + if "$USE_SEPARATE_HOME"; then - echo "$SELF_NAME: require device file for /home" >&2 - exit 1 + # the block device file for "/home" must exist + if [[ -z "${DEV_HOME:-}" ]] || [[ ! -b "${DEV_HOME:-}" ]]; then + + echo "$SELF_NAME: require device file for /home" >&2 + exit 1 + + fi fi } @@ -873,7 +883,7 @@ function task_install_system { # format $DEV_ROOT mkfs.ext4 "$DEV_ROOT" - # mount "/" and "/home" + # mount root partition mounting_step_1 # execute debootstrap @@ -1346,9 +1356,8 @@ function configure_fstab { # set path for output file FILE="$CHROOT/etc/fstab" - # get UUID of system and home partition + # get UUID of system partition UUID_ROOT="$(blkid -s UUID -o value "$DEV_ROOT")" - UUID_HOME="$(blkid -s UUID -o value "$DEV_HOME")" if "$USE_EFI"; then @@ -1368,12 +1377,30 @@ function configure_fstab { fi + if "$USE_SEPARATE_HOME"; then + + # get UUID of home partition + UUID_HOME="$(blkid -s UUID -o value "$DEV_HOME")" + + # allows to write home specific entry to fstab file + FILE_HOME="$FILE" + + else + + # an UUID is not needed in this case + UUID_HOME="" + + # discard home specific entry + FILE_HOME="/dev/null" + + fi + # edit /etc/fstab echo '# /etc/fstab' > "$FILE" echo '# ' >> "$FILE" echo "UUID=$UUID_ROOT / ext4 defaults,errors=remount-ro 0 1" >> "$FILE" echo "UUID=$UUID_UEFI /boot/efi vfat defaults 0 2" >> "$FILE_UEFI" - echo "UUID=$UUID_HOME /home ext4 defaults 0 2" >> "$FILE" + echo "UUID=$UUID_HOME /home ext4 defaults 0 2" >> "$FILE_HOME" echo "proc /proc proc defaults 0 0" >> "$FILE" echo "sys /sys sysfs defaults 0 0" >> "$FILE" echo "tmpfs /tmp tmpfs defaults,size=40% 0 0" >> "$FILE" @@ -1672,26 +1699,10 @@ function mounting_step_1 { # set path to mounting point CHROOT="/mnt/ubuntu-$(cat '/proc/sys/kernel/random/uuid')" - CHHOME="$CHROOT/home" # mount $DEV_ROOT mkdir -p "$CHROOT" mount "$DEV_ROOT" "$CHROOT" - - # mount $DEV_HOME - if mount | grep -q "$DEV_HOME"; then - - HOME_PATH="$(df "$DEV_HOME" | grep -oE '(/[[:alnum:]]+)+$' | head -1)" - - mkdir -p "$CHHOME" - mount -o bind "$HOME_PATH" "$CHHOME" - - else - - mkdir -p "$CHHOME" - mount "$DEV_HOME" "$CHHOME" - - fi } function unmounting_step_1 { @@ -1703,8 +1714,7 @@ function unmounting_step_1 { stop_chroot_processes sync - # unmount home directory and directory root - umount "$CHHOME" + # unmount directory root umount "$CHROOT" rmdir "$CHROOT" @@ -1748,6 +1758,25 @@ function mounting_step_2 { fi fi + + if "$USE_SEPARATE_HOME"; then + + # mount $DEV_HOME + if mount | grep -q "$DEV_HOME"; then + + HOME_PATH="$(df "$DEV_HOME" | grep -oE '(/[[:alnum:]]+)+$' | head -1)" + + mkdir -p "$CHROOT/home" + mount -o bind "$HOME_PATH" "$CHROOT/home" + + else + + mkdir -p "$CHROOT/home" + mount "$DEV_HOME" "$CHROOT/home" + + fi + + fi } function unmounting_step_2 { @@ -1773,6 +1802,12 @@ function unmounting_step_2 { fi + if "$USE_SEPARATE_HOME"; then + + umount "$CHROOT/home" + + fi + fi }