From 4699f87cc7f04d005667b47ee186df52d66e9d82 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Wed, 2 Mar 2022 07:24:56 +0900 Subject: [PATCH 1/6] Add test script for development --- script/config.sh | 30 +++++++++- script/lib/common.sh | 123 +++++++++++++++++++++++++++++++++++++++- script/test/config01.sh | 112 ++++++++++++++++++++++++++++++++++++ script/test/test01.sh | 45 +++++++++++++++ script/test/testutil.sh | 38 +++++++++++++ 5 files changed, 346 insertions(+), 2 deletions(-) create mode 100755 script/test/config01.sh create mode 100755 script/test/test01.sh create mode 100644 script/test/testutil.sh diff --git a/script/config.sh b/script/config.sh index bb378c0..22f448f 100644 --- a/script/config.sh +++ b/script/config.sh @@ -14,11 +14,39 @@ export ERASEALL=0 # Keep it unique from other distribution. export LVROOTNAME="anko" +# Suffix of the optional logical volumes. +# If you want to have optional OVs, set USELVEXT# to 1. +# Then, the suffix will be added to the LVROOTNAME. +# For example, Assume you have setting below : +# LVROOTNAME="anko" +# USELVEXT1=1 +# LVEXT1SUFFIX="_home" +# USELVEXT2=0 +# LVEXT2SUFFIX="_var" +# You will have +# anko +# anko_home +# You will not have anko_var because the USELVEXT2=0. +export USELVEXT1=0 +export LVEXT1SUFFIX="_home" +export USELVEXT2=0 +export LVEXT2SUFFIX="_var" + # Logical volume size of the Linux installation. # 30% mean, new logical volume will use 30% of the free space # in the LVM volume group. For example, assume the free space is 100GB, # and LVROOTSIZE is 30%FREE. Script will create 30GB logical volume. -export LVROOTSIZE="50%FREE" +# Note that the order of the volume creation is : +# 1. EFI if needed +# 2. SWAP +# 3. LVROOT +# 4. LVEXT1 if needed +# 5. LVEXT2 if needed +export LVROOTSIZE="10%FREE" + +# Logical volume size of the optional volumes. +export LVEXT1SIZE="90%FREE" +export LVEXT2SIZE="100%FREE" # Set the size of EFI partition and swap partition. # The unit is Byte. You can use M,G... notation. diff --git a/script/lib/common.sh b/script/lib/common.sh index cd0365c..43803d4 100644 --- a/script/lib/common.sh +++ b/script/lib/common.sh @@ -42,6 +42,34 @@ function confirmation(){ return 1 # with error status fi # "-" is found in the volume name. + # Sanity check for lvext1 volume suffix + if [ "${USELVEXT1}" -ne 0 ] ; then + if echo "${LVEXT1SUFFIX}" | grep "-" -i > /dev/null ; then # "-" is found in the volume name. + cat <<- HEREDOC + ***** ERROR : LVEXT1SUFFIX is "${LVEXT1SUFFIX}" ***** + ..."-" is not allowed in the volume name. + ...Check configuration in your config.sh + + ...Installation process terminated.. + HEREDOC + return 1 # with error status + fi # "-" is found in the volume suffix. + fi # USELVEXT1 + + # Sanity check for lvext2 volume suffix + if [ "${USELVEXT2}" -ne 0 ] ; then + if echo "${LVEXT2SUFFIX}" | grep "-" -i > /dev/null ; then # "-" is found in the volume name. + cat <<- HEREDOC + ***** ERROR : LVEXT2SUFFIX is "${LVEXT2SUFFIX}" ***** + ..."-" is not allowed in the volume name. + ...Check configuration in your config.sh + + ...Installation process terminated.. + HEREDOC + return 1 # with error status + fi # "-" is found in the volume suffix. + fi # USELVEXT2 + # Sanity check for swap volume name if echo "${LVSWAPNAME}" | grep "-" -i > /dev/null ; then # "-" is found in the volume name. cat <<- HEREDOC @@ -62,6 +90,23 @@ function confirmation(){ Volume group name : "${VGNAME}" Root volume name : "${VGNAME}-${LVROOTNAME}" Root volume size : "${LVROOTSIZE}" + HEREDOC + + if [ "${USELVEXT1}" -ne 0 ] ; then + cat <<- HEREDOC + Extra volume name 1 : "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" + Extra volume size 1 : "${LVEXT1SIZE}" + HEREDOC + fi # USELVEXT1 + + if [ "${USELVEXT2}" -ne 0 ] ; then + cat <<- HEREDOC + Extra volume name 2 : "${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" + Extra volume size 2 : "${LVEXT2SIZE}" + HEREDOC + fi # USELVEXT2 + + cat <<- HEREDOC Swap volume name : "${VGNAME}-${LVSWAPNAME}" Swap volume size : "${LVSWAPSIZE}" --iter-time parameter : ${ITERTIME} @@ -207,7 +252,7 @@ function pre_install() { return 1 # with error status fi else # not exsit - if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then + if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then # not exist and overwrite install cat <<- HEREDOC ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" doesn't exist while overwrite install. ***** ...Check consistency of your config.txt. @@ -219,6 +264,69 @@ function pre_install() { echo "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." lvcreate -l "${LVROOTSIZE}" -n "${LVROOTNAME}" "${VGNAME}" if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; + + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" ] ; then # if extra volume 1 exist + cat <<- HEREDOC + ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" exists while non-overwrite install. ***** + ...Check consistency of your config.txt. + HEREDOC + # Remove newly created root volume + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + # Deactivate all lg and close the LUKS volume + deactivate_and_close + return 1 # with error status + else + echo "...Creating logical volume \"${LVROOTNAME}${LVEXT1SUFFIX}\" on \"${VGNAME}\"." + lvcreate -l "${LVEXT1SIZE}" -n "${LVROOTNAME}${LVEXT1SUFFIX}" "${VGNAME}" + if [ $? -ne 0 ] ; then # if fail + # Remove newly created root volume + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + # Deactivate all lg and close the LUKS volume + deactivate_and_close; + return 1 ; + fi; + fi + fi + + if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 + if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" ] ; then # if extra volume 2 exist + cat <<- HEREDOC + ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" exists while non-overwrite install. ***** + ...Check consistency of your config.txt. + HEREDOC + # Remove newly created root volume + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + # Deactivate all lg and close the LUKS volume + deactivate_and_close + return 1 # with error status + else + echo "...Creating logical volume \"${LVROOTNAME}${LVEXT2SUFFIX}\" on \"${VGNAME}\"." + lvcreate -l "${LVEXT2SIZE}" -n "${LVROOTNAME}${LVEXT2SUFFIX}" "${VGNAME}" + if [ $? -ne 0 ] ; then # if fail + # Remove newly created root volume + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + # Deactivate all lg and close the LUKS volume + deactivate_and_close; + return 1 ; + fi; + fi + fi + fi fi @@ -338,6 +446,19 @@ function on_unexpected_installer_quit(){ else # if not overwrite istall, delete the new volume echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + + if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 + # Remove newly created extra volume 2 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT2SUFFIX}" + fi + fi # Deactivate all lg and close the LUKS volume deactivate_and_close diff --git a/script/test/config01.sh b/script/test/config01.sh new file mode 100755 index 0000000..cfa8614 --- /dev/null +++ b/script/test/config01.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# ##################################### + +# Test setup. +# /dev/sdb/ +# ERASEALL +# LVROOT 10% +# LVEXT1 90% +# LVEXT2 10% + +# ##################################### + +# Configuration parameters for Kaiten-Yaki + +# Storage device to install the linux. +export DEV="/dev/sdb" + +# Whether you want to erase all contents of the storage device or not. +# 1 : Yes, I want to erase all. +# 0 : No, I don't. I want to add to the existing LUKS volume. +export ERASEALL=1 + +# Logical Volume name for your Linux installation. +# Keep it unique from other distribution. +export LVROOTNAME="anko" + +# Suffix of the optional logical volumes. +# If you want to have optional OVs, set USELVEXT# to 1. +# Then, the suffix will be added to the LVROOTNAME. +# For example, Assume you have setting below : +# LVROOTNAME="anko" +# USELVEXT1=1 +# LVEXT1SUFFIX="_home" +# USELVEXT2=0 +# LVEXT2SUFFIX="_var" +# You will have +# anko +# anko_home +# You will not have anko_var because the USELVEXT2=0. +export USELVEXT1=1 +export LVEXT1SUFFIX="_home" +export USELVEXT2=1 +export LVEXT2SUFFIX="_var" + +# Logical volume size of the Linux installation. +# 30% mean, new logical volume will use 30% of the free space +# in the LVM volume group. For example, assume the free space is 100GB, +# and LVROOTSIZE is 30%FREE. Script will create 30GB logical volume. +# Note that the order of the volume creation is : +# 1. EFI if needed +# 2. SWAP +# 3. LVROOT +# 4. LVEXT1 if needed +# 5. LVEXT2 if needed +export LVROOTSIZE="10%FREE" + +# Logical volume size of the optional volumes. +export LVEXT1SIZE="90%FREE" +export LVEXT2SIZE="100%FREE" + +# Set the size of EFI partition and swap partition. +# The unit is Byte. You can use M,G... notation. +export EFISIZE="200M" +export LVSWAPSIZE="8G" + +# Usually, these names can be left untouched. +# If you change, keep them consistent through all installation in your system. +export CRYPTPARTNAME="luks_test" +export VGNAME="vg_test" +export LVSWAPNAME="swap" + +# Do not touch this parameter, unless you understand what you are doing. +# 1 : Overwrite the existing logical volume as root volume. +# 0 : Create new logical volume as root volume. +export OVERWRITEINSTALL=0 + +# Do not touch this parameter, unless you understand what you are doing. +# This is a paameter value of the --iter-time option for cyrptsetup command. +# If you specify 1000, that means 1000mSec. 0 means compile default. +export ITERTIME=0 + +# Void Linux only. Ignored in Ubuntu. +# The font size of the void-installer +export XTERMFONTSIZE=11 + +# !!!!!!!!!!!!!! DO NOT EDIT FOLLOWING LINES. !!!!!!!!!!!!!! + +# Detect firmware type. 1 : EFI, 0 : BIOS +if [ -d /sys/firmware/efi ]; then +export ISEFI=1 # Yes, EFI +else +export ISEFI=0 # No, BIOS +fi # is EFI firmaare? + +# Set partition number based on the firmware type +if [ ${ISEFI} -ne 0 ] ; then +# EFI firmware +export EFIPARTITION=1 +export CRYPTPARTITION=2 +else +# BIOS firmware +export CRYPTPARTITION=1 +fi # EFI firmware + +# Detect the GUI environment +# This code is not efered. Just left because it is interestintg code. +if env | grep -w -e XDG_SESSION_TYPE -e DISPLAY -e WAYLAND_DISPLAY > /dev/null ; then + export GUIENV=1 # set 1 if GUI env. +else + export GUIENV=0 # set 0 if not GUI env. +fi \ No newline at end of file diff --git a/script/test/test01.sh b/script/test/test01.sh new file mode 100755 index 0000000..a5a2de5 --- /dev/null +++ b/script/test/test01.sh @@ -0,0 +1,45 @@ +#!/bin/bash -u + + # shellcheck disable=SC1091 + # Load configuration parameter + source ./config01.sh + + # Load common functions + source ../lib/common.sh + +function main() { + + # This is the mount point of the install target. + export TARGETMOUNTPOINT="/target" + + # ******************************************************************************* + # Confirmation before installation + # ******************************************************************************* + + # parameters for distribution check + export DISTRIBUTIONSIGNATURE="ubuntu" + export DISTRIBUTIONNAME="Ubuntu" + + # Check whetehr given signature exist or not + if ! distribution_check ; then + return 1 # with error status + fi + + # Common part of the parameter confirmation + if ! confirmation ; then + return 1 # with error status + fi + + # ******************************************************************************* + # Pre-install stage + # ******************************************************************************* + + # Common part of the pre-install stage + if ! pre_install ; then + return 1 # with error status + fi +} + +# main routine +main + diff --git a/script/test/testutil.sh b/script/test/testutil.sh new file mode 100644 index 0000000..a4889d2 --- /dev/null +++ b/script/test/testutil.sh @@ -0,0 +1,38 @@ + + +# ******************************************************************************* +# Deactivate all LV in the VG and close LUKS volume +# ******************************************************************************* + +function util_deactivate_and_close(){ + echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"." + vgchange -a n "${VGNAME}" + echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"." + cryptsetup close "${CRYPTPARTNAME}" + cat <<- HEREDOC + + ...Installation process terminated.. + HEREDOC + +} + +# ******************************************************************************* +# Delete the nwe volume if overwrite install, and close all +# ******************************************************************************* +function util_cleanup(){ + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + + if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 + # Remove newly created extra volume 2 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT2SUFFIX}" + fi + +} From ed48590821722d21b5fd890b06885ed6c41a5146 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Thu, 5 May 2022 23:20:30 +0900 Subject: [PATCH 2/6] Test update. --- script/test/trial.sh | 11 ++++++++++ script/test/{testutil.sh => util_cleanup.sh} | 22 +++++-------------- script/test/util_deactivate_and_close.sh | 23 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) create mode 100755 script/test/trial.sh rename script/test/{testutil.sh => util_cleanup.sh} (65%) mode change 100644 => 100755 create mode 100755 script/test/util_deactivate_and_close.sh diff --git a/script/test/trial.sh b/script/test/trial.sh new file mode 100755 index 0000000..5106da8 --- /dev/null +++ b/script/test/trial.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +DISK=/dev/sdb + +DISKSIZE=$(blockdev --report ${DISK} | awk /${DISK}/'{print $6}') +VOLSIZE=$(lvdisplay --units B /dev/vg_test/anko | awk '/Size/{print $3}') + +echo $DISKSIZE +echo $VOLSIZE + +echo "scale=3; $VOLSIZE/$DISKSIZE" | bc \ No newline at end of file diff --git a/script/test/testutil.sh b/script/test/util_cleanup.sh old mode 100644 new mode 100755 similarity index 65% rename from script/test/testutil.sh rename to script/test/util_cleanup.sh index a4889d2..0701bb9 --- a/script/test/testutil.sh +++ b/script/test/util_cleanup.sh @@ -1,20 +1,8 @@ +#!/bin/bash -u - -# ******************************************************************************* -# Deactivate all LV in the VG and close LUKS volume -# ******************************************************************************* - -function util_deactivate_and_close(){ - echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"." - vgchange -a n "${VGNAME}" - echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"." - cryptsetup close "${CRYPTPARTNAME}" - cat <<- HEREDOC - - ...Installation process terminated.. - HEREDOC - -} + # shellcheck disable=SC1091 + # Load configuration parameter + source ./config01.sh # ******************************************************************************* # Delete the nwe volume if overwrite install, and close all @@ -36,3 +24,5 @@ function util_cleanup(){ fi } + +util_cleanup diff --git a/script/test/util_deactivate_and_close.sh b/script/test/util_deactivate_and_close.sh new file mode 100755 index 0000000..2da7bb4 --- /dev/null +++ b/script/test/util_deactivate_and_close.sh @@ -0,0 +1,23 @@ +#!/bin/bash -u + + # shellcheck disable=SC1091 + # Load configuration parameter + source ./config01.sh + +# ******************************************************************************* +# Deactivate all LV in the VG and close LUKS volume +# ******************************************************************************* + +function util_deactivate_and_close(){ + echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"." + vgchange -a n "${VGNAME}" + echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"." + cryptsetup close "${CRYPTPARTNAME}" + cat <<- HEREDOC + + ...Installation process terminated.. + HEREDOC + +} + +util_deactivate_and_close From 9ef15cc1f122c100c29e7d298cac70de747fb376 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Thu, 5 May 2022 23:32:48 +0900 Subject: [PATCH 3/6] Add display of the additional volumes. The user --- script/lib/common.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script/lib/common.sh b/script/lib/common.sh index 43803d4..355e869 100644 --- a/script/lib/common.sh +++ b/script/lib/common.sh @@ -359,7 +359,17 @@ function para_install_msg() { fi # Root volume mapping - echo "/ : /dev/mapper/${VGNAME}-${LVROOTNAME}" + echo "/ : /dev/mapper/${VGNAME}-${LVROOTNAME}" + + # If USELVEXT1 exist. + if [ "${USELVEXT1}" -ne 0 ] ; then + echo "LVEXT1 : /dev/mapper/${VGNAME}${LVEXT1SUFFIX}" + fi + + # If USELVEXT2 exist. + if [ "${USELVEXT2}" -ne 0 ] ; then + echo "LVEXT2 : /dev/mapper/${VGNAME}${LVEXT2SUFFIX}" + fi # In case of erased storage, add this mapping if [ "${ERASEALL}" -ne 0 ] ; then From a21470f594af43afd4e4efdce2a45b98dbe95925 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Thu, 5 May 2022 23:47:17 +0900 Subject: [PATCH 4/6] Correct the display of the LVEXT1,2 --- script/lib/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/lib/common.sh b/script/lib/common.sh index 355e869..b3b4bb4 100644 --- a/script/lib/common.sh +++ b/script/lib/common.sh @@ -363,12 +363,12 @@ function para_install_msg() { # If USELVEXT1 exist. if [ "${USELVEXT1}" -ne 0 ] ; then - echo "LVEXT1 : /dev/mapper/${VGNAME}${LVEXT1SUFFIX}" + echo "LVEXT1 : /dev/mapper/${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" fi # If USELVEXT2 exist. if [ "${USELVEXT2}" -ne 0 ] ; then - echo "LVEXT2 : /dev/mapper/${VGNAME}${LVEXT2SUFFIX}" + echo "LVEXT2 : /dev/mapper/${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" fi # In case of erased storage, add this mapping From 8cd947c91232f07fc435cf633562cc7299a4095c Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Fri, 6 May 2022 08:44:16 +0900 Subject: [PATCH 5/6] fixed behavior of lvext When overwrite installing, the lvext# were not created. The detection of the error processing was refactored to use the global variable to see the newly created or not. --- script/lib/common.sh | 129 +++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 61 deletions(-) diff --git a/script/lib/common.sh b/script/lib/common.sh index b3b4bb4..8524a69 100644 --- a/script/lib/common.sh +++ b/script/lib/common.sh @@ -152,6 +152,11 @@ function confirmation(){ function pre_install() { + # Internal variables. + # These variables displays whether the volumes are created in this installation. + IS_ROOT_CREATED=0 + IS_LVEXT1_CREATED=0 + IS_LVEXT2_CREATED=0 # ----- Erase entire disk, create partitions, format them and encrypt the LUKS partition ----- if [ "${ERASEALL}" -ne 0 ] ; then @@ -242,6 +247,11 @@ function pre_install() { if [ -e /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" ] ; then # exist if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then # exist and overwrite install echo "...Logical volume \"${VGNAME}-${LVROOTNAME}\" already exists. OK." + + # Create extended volumes if needed + create_ext_lv + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; + else # exist and not overwriteinstall cat <<- HEREDOC ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" already exists. ***** @@ -262,70 +272,13 @@ function pre_install() { return 1 # with error status else # not exist and not overwrite install echo "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." + IS_ROOT_CREATED=1 lvcreate -l "${LVROOTSIZE}" -n "${LVROOTNAME}" "${VGNAME}" if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; - if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 - if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" ] ; then # if extra volume 1 exist - cat <<- HEREDOC - ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" exists while non-overwrite install. ***** - ...Check consistency of your config.txt. - HEREDOC - # Remove newly created root volume - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - # Deactivate all lg and close the LUKS volume - deactivate_and_close - return 1 # with error status - else - echo "...Creating logical volume \"${LVROOTNAME}${LVEXT1SUFFIX}\" on \"${VGNAME}\"." - lvcreate -l "${LVEXT1SIZE}" -n "${LVROOTNAME}${LVEXT1SUFFIX}" "${VGNAME}" - if [ $? -ne 0 ] ; then # if fail - # Remove newly created root volume - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - # Deactivate all lg and close the LUKS volume - deactivate_and_close; - return 1 ; - fi; - fi - fi - - if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 - if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" ] ; then # if extra volume 2 exist - cat <<- HEREDOC - ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" exists while non-overwrite install. ***** - ...Check consistency of your config.txt. - HEREDOC - # Remove newly created root volume - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 - # Remove newly created extra volume 1 - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" - fi - # Deactivate all lg and close the LUKS volume - deactivate_and_close - return 1 # with error status - else - echo "...Creating logical volume \"${LVROOTNAME}${LVEXT2SUFFIX}\" on \"${VGNAME}\"." - lvcreate -l "${LVEXT2SIZE}" -n "${LVROOTNAME}${LVEXT2SUFFIX}" "${VGNAME}" - if [ $? -ne 0 ] ; then # if fail - # Remove newly created root volume - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 - # Remove newly created extra volume 1 - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" - fi - # Deactivate all lg and close the LUKS volume - deactivate_and_close; - return 1 ; - fi; - fi - fi + # Create extended volumes if needed + create_ext_lv + if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; fi fi @@ -503,6 +456,60 @@ function distribution_check(){ return 0 } +# ******************************************************************************* +# Create extended volume, if needed. +# ******************************************************************************* + + +function create_ext_lv() { + if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 + if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" ] ; then # if extra volume 1 exist + echo "...Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\" already exists. OK." + else + echo "...Creating logical volume \"${LVROOTNAME}${LVEXT1SUFFIX}\" on \"${VGNAME}\"." + IS_LVEXT1_CREATED=1 + lvcreate -l "${LVEXT1SIZE}" -n "${LVROOTNAME}${LVEXT1SUFFIX}" "${VGNAME}" + if [ $? -ne 0 ] ; then # if fail + echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" + # Remove newly created root volume + if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # Is root created in this installation? + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + fi + return 1 ; + fi; + fi + fi + + if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 + if [ -e /dev/mapper/"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" ] ; then # if extra volume 2 exist + echo "...Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\" already exists. OK." + else + echo "...Creating logical volume \"${LVROOTNAME}${LVEXT2SUFFIX}\" on \"${VGNAME}\"." + IS_LVEXT2_CREATED=1 + lvcreate -l "${LVEXT2SIZE}" -n "${LVROOTNAME}${LVEXT2SUFFIX}" "${VGNAME}" + if [ $? -ne 0 ] ; then # if fail + echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" + # Remove newly created root volume + if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # newly created root must be deleted + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + fi + if [ "${IS_LVEXT1_CREATED}" -ne 0 ] ; then # Is LV EXT1 created in this volue? + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + return 1 ; + fi; + fi + fi + + # no error + return 0 + + +} # ******************************************************************************* # Error report and return revsers status. From f6d43382fecf3948dc66b37c0d42a76b3efdc2e5 Mon Sep 17 00:00:00 2001 From: Suikan <26223147+suikan4github@users.noreply.github.com> Date: Sat, 7 May 2022 08:41:18 +0900 Subject: [PATCH 6/6] Move lvremove. To simplify, removing new voluves are gathered to deactivate_and remove. --- script/lib/common.sh | 62 ++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/script/lib/common.sh b/script/lib/common.sh index 8524a69..c2a26e0 100644 --- a/script/lib/common.sh +++ b/script/lib/common.sh @@ -272,9 +272,9 @@ function pre_install() { return 1 # with error status else # not exist and not overwrite install echo "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." - IS_ROOT_CREATED=1 lvcreate -l "${LVROOTSIZE}" -n "${LVROOTNAME}" "${VGNAME}" if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; + IS_ROOT_CREATED=1 # Create extended volumes if needed create_ext_lv @@ -388,6 +388,29 @@ function post_install() { # ******************************************************************************* function deactivate_and_close(){ + + + if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # if extra volume 1 created + # Remove newly created root volume + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" + fi + + + if [ "${IS_LVEXT1_CREATED}" -ne 0 ] ; then # if extra volume 1 created + # Remove newly created extra volume 1 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" + fi + + if [ "${IS_LVEXT2_CREATED}" -ne 0 ] ; then # if extra volume 2 created + # Remove newly created extra volume 2 + echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\"." + lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT2SUFFIX}" + fi + + + echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"." vgchange -a n "${VGNAME}" echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"." @@ -406,22 +429,6 @@ function on_unexpected_installer_quit(){ echo "***** ERROR : The GUI/TUI installer terminated unexpectedly. *****" if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then # If overwrite install, keep the volume echo "...Keep logical volume \"${VGNAME}-${LVROOTNAME}\" untouched." - else # if not overwrite istall, delete the new volume - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - - if [ "${USELVEXT1}" -ne 0 ] ; then # if using extra volume 1 - # Remove newly created extra volume 1 - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" - fi - - if [ "${USELVEXT2}" -ne 0 ] ; then # if using extra volume 2 - # Remove newly created extra volume 2 - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT2SUFFIX}" - fi - fi # Deactivate all lg and close the LUKS volume deactivate_and_close @@ -467,16 +474,12 @@ function create_ext_lv() { echo "...Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\" already exists. OK." else echo "...Creating logical volume \"${LVROOTNAME}${LVEXT1SUFFIX}\" on \"${VGNAME}\"." - IS_LVEXT1_CREATED=1 lvcreate -l "${LVEXT1SIZE}" -n "${LVROOTNAME}${LVEXT1SUFFIX}" "${VGNAME}" if [ $? -ne 0 ] ; then # if fail echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" - # Remove newly created root volume - if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # Is root created in this installation? - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - fi return 1 ; + else # if success + IS_LVEXT1_CREATED=1 # Mark this volume is created fi; fi fi @@ -486,21 +489,12 @@ function create_ext_lv() { echo "...Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\" already exists. OK." else echo "...Creating logical volume \"${LVROOTNAME}${LVEXT2SUFFIX}\" on \"${VGNAME}\"." - IS_LVEXT2_CREATED=1 lvcreate -l "${LVEXT2SIZE}" -n "${LVROOTNAME}${LVEXT2SUFFIX}" "${VGNAME}" if [ $? -ne 0 ] ; then # if fail echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" - # Remove newly created root volume - if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # newly created root must be deleted - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" - fi - if [ "${IS_LVEXT1_CREATED}" -ne 0 ] ; then # Is LV EXT1 created in this volue? - # Remove newly created extra volume 1 - echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT1SUFFIX}" - fi return 1 ; + else # if success + IS_LVEXT2_CREATED=1 # Mark this volume is created fi; fi fi