diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 720fbbe..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,112 +0,0 @@ -# Change log -Record of the modification in project development. - -## [Unreleased] - yyyy-mm-dd -### Added -### Changed -### Deprecated -### Removed -### Fixed -### Known Issue - -## [1.3.1] - 2023-04-15 -### Added -### Changed -### Deprecated -### Removed -### Fixed -- [Issue 43 : Partition names should be prefixed by "p" for NVMe](https://github.com/suikan4github/kaiten-yaki/pull/43). Thank you Uraza for your contribution. -### Known Issue - -## [1.3.0] - 2022-05-15 -### Added -- [Issue 31 : Add extra partition functionality.](https://github.com/suikan4github/kaiten-yaki/issues/31) -- [Issue 33 : Support "M/G/T" as size prefix.](https://github.com/suikan4github/kaiten-yaki/issues/33) - -### Changed -- [Issue 38 : "Ready to reboot" message should be changed](https://github.com/suikan4github/kaiten-yaki/issues/38) -- [Issue 39 : Change message style](https://github.com/suikan4github/kaiten-yaki/issues/39) - -### Deprecated -- [Issue 34 : BIOS support should be obsoleted ](https://github.com/suikan4github/kaiten-yaki/issues/34) - -### Removed -- [Issue 35 : Remove XTERMFONTSIZE variable.](https://github.com/suikan4github/kaiten-yaki/issues/35) - -### Fixed -- [Issue 32 : Ubuntu 22.04 fails to deactivate the swap](https://github.com/suikan4github/kaiten-yaki/issues/32) -- [Issue 36 : Clear the PASSPHRASE variable at the end of installation](https://github.com/suikan4github/kaiten-yaki/issues/36) - -### Known Issue - -## [1.2.0] - 2021-10-16 -### Added -### Changed -- [Issue 25 : Refactoring: Sourcing config.sys is not needed in the chrooted_job](https://github.com/suikan4github/kaiten-yaki/issues/25) -- [Issue 26 : Update AN01 for btrfs](https://github.com/suikan4github/kaiten-yaki/issues/26) -- [Issue 27 : Eliminates the confirmation dialog](https://github.com/suikan4github/kaiten-yaki/issues/27) - -### Deprecated -### Removed -- [Issue 28 : Move application notes to Wiki](https://github.com/suikan4github/kaiten-yaki/issues/28) - -### Fixed -- [Issue 24 : Fail to install the ubuntu when the / volume is btrfs](https://github.com/suikan4github/kaiten-yaki/issues/24) -- [Issue 29 : Item should be added to /etc/dracut.conf.d/10-crypt.conf , rather than be overwritten](https://github.com/suikan4github/kaiten-yaki/issues/29) - -### Known Issue - -## [1.1.0] - 2021-07-11 -Added ITERTIME parameter and corrected other small issues. Application notes AN01 - AN04 are added. -The Followings are tested distributions -- Ubuntu 20.04.2 -- Ubuntu MATE 20.04.2 -- Ubuntu 21.04 -- Void Linux glibc 20210218 mate -- Void Linux musl 20210218 mate -- Void Linux glibc 20210218 base - -See [Testing before release v1.1.0](https://github.com/suikan4github/kaiten-yaki/issues/16). -### Added -- [Issue 13 : Add ITERTIME configuration parameter to config.txt](https://github.com/suikan4github/kaiten-yaki/issues/13) -- [Issue 18 : Add a consideration of the number of key slot](https://github.com/suikan4github/kaiten-yaki/issues/18) -- [Issue 19 : Add a consideration of more flexible partitioning](https://github.com/suikan4github/kaiten-yaki/issues/19) -- [Issue 20 : Add a consideration of LUKS stretching](https://github.com/suikan4github/kaiten-yaki/issues/20) -- [Issue 21 : Add a document of how to recover from the mistyping of passphrase](https://github.com/suikan4github/kaiten-yaki/issues/21) - -### Changed -- [Issue 5 : OVERWRITEINSTALL confirmation is missing](https://github.com/suikan4github/kaiten-yaki/issues/5) -- [Issue 6 : Remove loglevel dependency from the void-kaiten-yaki.sh ](https://github.com/suikan4github/kaiten-yaki/6) -- [Issue 7 : Add the return status validation ](https://github.com/suikan4github/kaiten-yaki/7) -- [Issue 11 : Make chroot'ed job independent script file ](https://github.com/suikan4github/kaiten-yaki/11) -- [Issue 12 : change ERASEALL=0 as default ](https://github.com/suikan4github/kaiten-yaki/12) -- [Issue 14 : Change config.sh description ](https://github.com/suikan4github/kaiten-yaki/14) - -### Deprecated -### Removed -### Fixed -- [Issue 8 : Wrong message after cancellation ](https://github.com/suikan4github/kaiten-yaki/8) -- [Issue 15 : CITERTIME parameter is not passed to the chrooted_job ](https://github.com/suikan4github/kaiten-yaki/15) -- [Issue 17 : Unmount fails ](https://github.com/suikan4github/kaiten-yaki/17) - -### Known Issue - -## [1.0.0] - 2021-07-03 - -### Added -- [Issue 1 : Support non-GUI install for Void Linux.](https://github.com/suikan4github/kaiten-yaki/issues/1) - -### Changed -### Deprecated -### Removed -### Fixed -### Security -### Known Issue - - -[Unreleased]: https://github.com/suikan4github/kaiten-yaki/compare/v1.3.0...develop -[1.3.1]: https://github.com/suikan4github/kaiten-yaki/compare/v1.3.0...v1.3.1 -[1.3.0]: https://github.com/suikan4github/kaiten-yaki/compare/v1.2.0...v1.3.0 -[1.2.0]: https://github.com/suikan4github/kaiten-yaki/compare/v1.1.0...v1.2.0 -[1.1.0]: https://github.com/suikan4github/kaiten-yaki/compare/v1.0.0...v1.1.0 -[1.0.0]: https://github.com/suikan4github/kaiten-yaki/compare/v0.0.0...v1.0.0 diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index 8fe6591..0000000 --- a/INSTALL.md +++ /dev/null @@ -1,236 +0,0 @@ -# Ubuntu/Void-Linux installation into the LVM on the LUKS volume - -Installation requires mainly 2 steps. - -- Configure the parameters in config.sh. -- Run the kaiten-yaki script - -You can execute the install script without the command line parameter. For example : -```sh -source ubuntu-kaiten-yaki.sh -``` -The first stage of the script is preparation like: erasing a disk, format partition, and encryption. This is the most critical stage of the entire installation process. This part is controlled by the configuration parameter. Thus, you have to edit the config.sh carefully. - -In the second stage, the distribution-dependent GUI/TUI installer is invoked from the running script. That is the Ubiquity/void-installer of Ubuntu/Void Linux, respectively. - -The third stage configures the target Linux system to decrypt the encrypted volume automatically, without prompting user to type passphrase. In this stage, Everything is automatic. -# Installation -Follow the steps below. - -## Shell preparation -First of all, promote the shell to root. Kaiten-yaki script requires root permission to edit the storage device. Note that the scripts require Bash as shell. - -In the case of Ubuntu installation: -```sh -# Promote to the root user -sudo -i /bin/bash -``` -In the case of Void Linux installation: -```sh -# Promote to the root user -sudo -i /bin/bash -xbps-install -Su xbps nano -``` -The nano is an editor package to configure the config.sh. The choice of editor is up to you. Kaiten-yaki script doesn't have a dependency on nano editor. - -And then, go to the kaiten-yaki/script directory. -```sh -cd /the/downloaded/directory/kaiten-yaki/script -``` -Now, ready to configure. -## Configuration parameters -This is a very critical part of the installation. The configuration parameters are in the config.sh. Edit these parameters before the installation. - -Followings are the set of the default settings of the parameters : -- Install to **/dev/sda** (DEV). -- Do not erase the entire disk (ERASEALL). -- Do not overwrite the existing logical volume (OVERWRITEINSTALL). -- In the case of EFI firmware, 200MB is allocated to the EFI partition (EFISIZE). -- Create a logical volume group named "vg1" in the encrypted volume (VGNAME) -- Create a swap logical volume named "swap" in the "vg1". The size is 8GB (LVSWAPNAME,LVSWAPSIZE) -- Create a logical volume named **"anko"** as root volume, in the "vg1". The size of the new volume is the **10GB** (LVROOTNAME, LVROOTSIZE). -- No Extra volumes will be created (USELVEXT1, LVEXT1SUFFIX, LVEXT1SIZE, USELVEXT2, LVEXT2SUFFIX, LVEXT2SIZE). - -```sh -# Configuration parameters for Kaiten-Yaki - -# Storage device to install the linux. -export DEV="/dev/sda" - -# 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=0 - -# 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=0 -export LVEXT1SUFFIX="_home" -export USELVEXT2=0 -export LVEXT2SUFFIX="_var" - - -# Volume size parameters. -# 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 - -# Set the size of EFI partition and swap partition. -# The unit is Byte. You can use M,G... notation. -# You CANNOT use the % notation. -export EFISIZE="200M" - -# Logical volume size of the swap volumes. -export LVSWAPSIZE="8G" - -# Logical volume size of the Linux installation. -# There are four posibble way to specify the volume. -# nnnM, nnnG, nnnT : Absolute size speicification. nnnMbyte, nnnGByte, nnnT byte. -# mm%VG : Use mm% of the entire volume group. -# mm%FREE : Use mm% of the avairable storage are in the volume group. -export LVROOTSIZE="10G" - -# Logical volume size of the optional volumes. -export LVEXT1SIZE="30G" -export LVEXT2SIZE="10G" - - -# Usually, these names can be left untouched. -# If you change, keep them consistent through all installation in your system. -export CRYPTPARTNAME="luks_volume" -export VGNAME="vg1" -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 - - -``` - -There are several restrictions : -- For the first distribution installation, you must set ERASEALL to 1, to erase the entire storage device and create a LUKS partition. Kaiten-yaki script creates a maximum LUKS partition as possible. -- The CRYPTPARTNAME and VGNAME must be unique among all installations in a physical disk. Otherwise, Kaiten-yaki terminates in a middle. -- The LVSWAPNAME must be identical among all installations in a physical disk. Otherwise, Kaiten-yaki creates an unnecessary logical volume. This is a waste of storage resources. -- The EFISIZE and the LVSWAPSIZE are refereed during the first distribution installation only. -- The LVROOTSIZE, LVEXT1SIZE, LVEXT2SIZE are the size of a logical volumes to create. There are several way to specify the size ( where n is number) : - - nnnM : New logical volume size is nnn**MByte**. - - nnnG : New logical volume size is nnn**GByte**. - - nnnT : New logical volume size is nnn**TByte**. - - nn%VG : New logical volume size is nn% of the **entire volume group**. - - nn%FREE : New logical volume size is nn% of the **free space** in the volume group. -- The name with "-" is not allowed for the VGNAME, LVROOTNAME, and LVSWAPNAME. I saw some distribution installer doesn't work if "-" in in the name. - -### About the overwrite-install -The OVERWRITEINSTALL parameter allows you to use an existing logical volume as the root volume of the new installation. -This is very dangerous because of several aspects like destroying the wrong volume and the risk of security. But sometimes it is -very useful. - -For example, assume you are installing a distribution by Kaiten-yaki. If you reboot the system at the end of GUI/TUI installer by mistake, your system may never boot again. -In this case, the overwrite-install can recycle this "bad" logical volume and let your system boot again. - -To use the overwrite-install, you have to set some parameters as follows: -- ERASEALL : 0 -- OVERWRITEINSTALL : 1 - -And set the following parameters as same as the previous installation. -- LVROOTNAME -- VGNAME -- CRYPTPARTNAME - -Kaiten-yaki will leave the LUKS encrypted partition and allow you to overwrite the "bad" logical volume by GUI/TUI installer. -### About ITERTIME parameter -This parameter is recommended to left as default value (=0), unless you understand what it mean well. - -The ITERTIME parameter is passed as --iter-time parameter to the [cryptosetup command](https://man7.org/linux/man-pages/man8/cryptsetup.8.html), when script setup the LUKS crypto volume. See [AN03](https://github.com/suikan4github/kaiten-yaki/wiki/AN03:-The-ITERTIME-parameter-and-vulnerability) - -The unit of value is milliseconds. The target linux kernel may take this duration, to calculate a hash value from the given passphrase. You can change this duration through this parameter. - -The smaller value gives the weaker security. - -### About the extra logical volume -From ver 1.3.0, Kaiten-yaki support two extra volume in addition to LVROOT and LVSWAP. -- LVEXT1 -- LVEXT2 - -The usage of the extra logical volume is up to the user. Typically, user may want to use it for example separated /home partition. - -The name of the extra volume is the concatenation of the LVROOTNAME and LVEXTnSUFFIX ( where n is 1 or 2 ). For example, let's assume following configuration : -- LVROOTNAME="FOO" -- LVEXT1SUFFIX="_BAR" - -Thus, the name of the LVEXT1 is "FOO_BAR". - -### Partition and logical volume creation order. -Kaiten-yaki creates the partition/volume in the following order : -1. EFI partition -1. LUKS partition -1. LVSWAP -1. LVROOT -1. LVEXT1 -1. LVEXT2 - -## First stage: Setting up the volumes -After you set the configuration parameters correctly, execute the following command from the shell. Again, you have to be promoted as the root user, and you have to use Bash. - -In the case of Ubuntu : -```sh -source ubuntu-kaiten-yaki.sh -``` - -In the case of Void Linux -```sh -source void-kaiten-yaki.sh -``` -After printing the configuration parameters, Kaiten-yaki will prompt you to input a passphrase. This passphrase will be applied to the encryption of the LUKS volume. Make sure you use identical passphrases between all installations of the distributions in a computer. Otherwise, the install process terminates with an error, except the case of the ERASEALL configuration parameter is 1. - -## Second stage : GUI/TUI installer -After the first script finishes, the GUI/TUI installer starts automatically. Configure it as usual and run it. Ensure you map the following correctly. -Target Directory | Host Volume | Comment ------------------|------------------------|--------------------------------------------------------------- -/boot/efi | /dev/sda1 | BIOS system doesn't need this mapping -/ | /dev/mapper/vg1-ubuntu | Host volume name is up to your configuration parameter. -swap | /dev/mapper/swap | Only the first distribution installation requires this mapping. - -During the GUI/TUI installer copying files, Kaiten-yaki modifies the /etc/default/grub of the target system. This is a pretty dirty way. But if we don't modify this file, GUI/TUI installer fails at last. - -![Ubuntu Partitioning](image/ubuntu_partitioning.png) -![Void Partitioning](image/void_partitioning.png) - -### Do not reboot -At the end of the GUI/TUI installing, do not reboot the system. Click "Continue" and just exit the GUI/TUI installer without rebooting. Otherwise, we cannot finalize the entire installation process. - -![Ubuntu done](image/ubuntu_done.png) -![Void done](image/void_done.png) - -## Third stage: Finalizing -After GUI/TUI installer quits without rebooting, the final part of the install process automatically starts. - -In this section, Kaiten-yaki put the encryption key of the LUKS volume into the initramfs image to allow the Linux kernel decrypting the LUKS partition which contains root logical volume. Thus, the system will ask you the passphrase only once when GRUB starts. - -You can reboot the system if you see the "Ready to reboot" message on the console. - diff --git a/README.md b/README.md index bb95640..64eba1a 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,2 @@ -# Kaiten-yaki: Full disk encryption install script for Linux -Kaiten-yaki v1.3.0 is a script set to install Linux to your AMD64 desktop system. With these scripts, you can install Ubuntu/Void Linux to an encrypted partition easily. - -The followings are the list of functionalities: -- Ubuntu and Void Linux support. -- Help to install from LiveCD/USB. -- Invoke GUI/TUI installer automatically at the middle of script execution, for the ease of installation. -- Automatic detection of EFI firmware and create GPT (The BIOS detection and MBR creation function exist. But they are not test from v1.3.0). -- Create an EFI partition, if needed. -- Support multiple boot in a LUKS partition. -- Support btrfs in addition to the major file systems. -- The "/boot" is located in the same encrypted logical volume with the "/". -- The swap is located in the same encrypted logical volume with the "/". -- You need to type a passphrase only once in the boot sequence of the installed system. - -With the configuration parameters, you can customize each installation. For example, you can configure the system to have 2, 3, or 4,... distributions in an HDD/SSD, as you want. - -Following is the HDD/SSD partitioning plan of these scripts ( In the case of BIOS, the disk has MBR and doesn't have an EFI partition). - -![Partition Diagram](image/partition_diagram_0.png) - -The logical volume size of each Linux distribution (LVROOTSIZE) can be customized from a configuration parameter. Also, the swap volume size is customizable. - -As depicted above, the LVM volume group has only one physical volume. - -# Tested environment -These scripts are tested with the following environment. -- VMVare Workstation 15.5.7 ( EFI ) -- Ubuntu 22.04 amd64 desktop -- void-live-x86_64-20210930-xfce.iso -- void-live-x86_64-20210930.iso -- Followings are the tested environment of the Kaiten-Yaki v1.2.0 - - VMWare Workstation 15.5.7 ( EFI/BIOS ) - - ThinkPad X220 (BIOS) - - Ubuntu 20.04.3 amd64 desktop - - Ubuntu 21.04 amd64 desktop - - Ubuntu 21.10 amd64 desktop - - Ubuntu Mate 20.04.3 amd64 desktop - - void-live-x86_64-20210218-mate.iso - - void-live-x86_64-musl-20210218-mate.iso - - void-live-x86_64-20210218.iso - -# Installation -Rough procedure of the installation is as followings : -1. Start the PC with the LiveCD/LiveUSB of the distribution to install -1. Download this repository from GitHub -3. Run the script. - -The detail procedure is explained in the [INSTALL.md](INSTALL.md). - -# Variants considerations -Ubuntu has several variants ( flavors ). While while only the Ubuntu desktop is tested, other flavors may work correctly as far as it uses Ubiquity installer. - -# Other resources -See [Wiki](https://github.com/suikan4github/kaiten-yaki/wiki) for the application notes and the useful links. - -# Acknowledgments -These scripts are based on the script by [myn's diary](https://myn.hatenablog.jp/entry/install-ubuntu-focal-with-lvm-on-luks). That page contains rich information, hint, and techniques around the encrypted volume and Ubiquity installer. - -Also, the following documents were very important to study how Void Linux installation works. -- [Full Disk Encryption](https://docs.voidlinux.org/installation/guides/fde.html) in the Void Handbook. -- [Install LVM LUKS](https://wiki.voidlinux.org/Install_LVM_LUKS) (deprecated) -# Kaiten-yaki -![](image/i-like-kaiten-yaki.jpg) - +# linux_fulldisk_encryption +Helpful scripts of the full disk encryption for the Linux distribution diff --git a/image/i-like-kaiten-yaki.jpg b/image/i-like-kaiten-yaki.jpg deleted file mode 100755 index a3db0f6..0000000 Binary files a/image/i-like-kaiten-yaki.jpg and /dev/null differ diff --git a/image/partition_diagram_0.png b/image/partition_diagram_0.png deleted file mode 100755 index 7f98e1d..0000000 Binary files a/image/partition_diagram_0.png and /dev/null differ diff --git a/image/ubuntu_done.png b/image/ubuntu_done.png deleted file mode 100755 index 7999037..0000000 Binary files a/image/ubuntu_done.png and /dev/null differ diff --git a/image/ubuntu_partitioning.png b/image/ubuntu_partitioning.png deleted file mode 100755 index 4379793..0000000 Binary files a/image/ubuntu_partitioning.png and /dev/null differ diff --git a/image/void_done.png b/image/void_done.png deleted file mode 100755 index 214ca96..0000000 Binary files a/image/void_done.png and /dev/null differ diff --git a/image/void_partitioning.png b/image/void_partitioning.png deleted file mode 100755 index 2e3a376..0000000 Binary files a/image/void_partitioning.png and /dev/null differ diff --git a/script/config.sh b/script/config.sh deleted file mode 100644 index b73ab5b..0000000 --- a/script/config.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -# Configuration parameters for Kaiten-Yaki - -# Storage device to install the linux. -export DEV="/dev/sda" - -# 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=0 - -# 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=0 -export LVEXT1SUFFIX="_home" -export USELVEXT2=0 -export LVEXT2SUFFIX="_var" - - -# Volume size parameters. -# 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 - -# Set the size of EFI partition and swap partition. -# The unit is Byte. You can use M,G[Kaiten-Yaki] notation. -# You CANNOT use the % notation. -export EFISIZE="200M" - -# Logical volume size of the swap volumes. -export LVSWAPSIZE="8G" - -# Logical volume size of the Linux installation. -# There are four posibble way to specify the volume. -# nnnM, nnnG, nnnT : Absolute size speicification. nnnMbyte, nnnGByte, nnnT byte. -# mm%VG : Use mm% of the entire volume group. -# mm%FREE : Use mm% of the avairable storage are in the volume group. -export LVROOTSIZE="10G" - -# Logical volume size of the optional volumes. -export LVEXT1SIZE="30G" -export LVEXT2SIZE="10G" - - -# Usually, these names can be left untouched. -# If you change, keep them consistent through all installation in your system. -export CRYPTPARTNAME="luks_volume" -export VGNAME="vg1" -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 - - -# !!!!!!!!!!!!!! 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? - -# Detect drive type. -# For NVME drives, partition names should be prefixed by p. -if [[ ${DEV} == *"nvme"* ]] ; then -export PARTPREFIX="p" # Yes, NVME -else -export PARTPREFIX="" # No, regular -fi - -# Set partition number based on the firmware type -if [ ${ISEFI} -ne 0 ] ; then -# EFI firmware -export EFIPARTITION=${PARTPREFIX}1 -export CRYPTPARTITION=${PARTPREFIX}2 -else -# BIOS firmware -export CRYPTPARTITION=${PARTPREFIX}1 -fi # EFI firmware diff --git a/script/lib/chrooted_job_ubuntu.sh b/script/lib/chrooted_job_ubuntu.sh deleted file mode 100644 index 2470a61..0000000 --- a/script/lib/chrooted_job_ubuntu.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# Create a key file for LUKS and register it as contents of the initramfs image -function chrooted_job() { - # Mount the rest of partitions by target /etc/fstab - mount -a - - # Prepare the crypto tool in the install target - echo "[Kaiten-Yaki] Installing cryptsetup-initramfs package." - apt -qq install -y cryptsetup-initramfs - - # Prepare a new key file to embed in to the ramfs. - # This new file contains a new key to open the LUKS volume. - # The new key is 4096byte length binary value. - # Because this key is sotred as "cleartext", in the target file sysmte, - # only root is allowed to access this key file. - echo "[Kaiten-Yaki] Prepairing key file." - mkdir /etc/luks - dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=4096 count=1 status=none - chmod u=rx,go-rwx /etc/luks - chmod u=r,go-rwx /etc/luks/boot_os.keyfile - - # Add the new key to the LUKS 2nd key slot. The passphrase is required to modify the LUKS keyslot. - echo "[Kaiten-Yaki] Adding a key to the key file." - printf %s "${PASSPHRASE}" | cryptsetup luksAddKey --iter-time "${ITERTIME}" -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile - - # Register the LUKS voluem to /etc/crypttab to tell "This volume is encrypted" - echo "[Kaiten-Yaki] Adding LUKS volume info to /etc/crypttab." - echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab - - # Add key file to the list of the intems in initramfs. - # See https://cryptsetup-team.pages.debian.net/cryptsetup/README.initramfs.html for detail - echo "[Kaiten-Yaki] Directing to include keyfile into the initramfs" - echo "KEYFILE_PATTERN=/etc/luks/*.keyfile" >> /etc/cryptsetup-initramfs/conf-hook - echo "UMASK=0077" >> /etc/initramfs-tools/initramfs.conf - - # Finally, update the ramfs initial image with the key file. - echo "[Kaiten-Yaki] Upadting initramfs." - update-initramfs -uk all - - # Leave chroot -} - -# Execute job -chrooted_job diff --git a/script/lib/chrooted_job_void.sh b/script/lib/chrooted_job_void.sh deleted file mode 100644 index a908bbb..0000000 --- a/script/lib/chrooted_job_void.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Create a key file for LUKS and register it as contents of the initramfs image -function chrooted_job() { - # Mount the rest of partitions by target /etc/fstab - mount -a - - # Prepare the crypto tool in the install target - echo "[Kaiten-Yaki] Installing cryptsetup-initramfs package." - xbps-install -y lvm2 cryptsetup - - # Prepare a new key file to embed in to the ramfs. - # This new file contains a new key to open the LUKS volume. - # The new key is 4096byte length binary value. - # Because this key is sotred as "cleartext", in the target file sysmte, - # only root is allowed to access this key file. - echo "[Kaiten-Yaki] Prepairing key file." - mkdir /etc/luks - dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=4096 count=1 status=none - chmod u=rx,go-rwx /etc/luks - chmod u=r,go-rwx /etc/luks/boot_os.keyfile - - # Add the new key to the LUKS 2nd key slot. The passphrase is required to modify the LUKS keyslot. - echo "[Kaiten-Yaki] Adding a key to the key file." - printf %s "${PASSPHRASE}" | cryptsetup luksAddKey --iter-time "${ITERTIME}" -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile - - # Register the LUKS voluem to /etc/crypttab to tell "This volume is encrypted" - echo "[Kaiten-Yaki] Adding LUKS volume info to /etc/crypttab." - echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab - - # Add key file to the list of the intems in initramfs. - # See https://man7.org/linux/man-pages/man5/dracut.conf.5.html for details. - echo "[Kaiten-Yaki] Directing to include keyfile into the initramfs" - echo 'install_items+=" /etc/luks/boot_os.keyfile /etc/crypttab " ' >> /etc/dracut.conf.d/10-crypt.conf - - # Finally, update the ramfs initial image with the key file. - echo "[Kaiten-Yaki] Upadting initramfs." - xbps-reconfigure -fa - echo "[Kaiten-Yaki] grub-mkconfig." - grub-mkconfig -o /boot/grub/grub.cfg - - # Leave chroot -} - -# Execute job -chrooted_job diff --git a/script/lib/common.sh b/script/lib/common.sh deleted file mode 100644 index ddd4fa0..0000000 --- a/script/lib/common.sh +++ /dev/null @@ -1,565 +0,0 @@ -#!/bin/bash -u -# ******************************************************************************* -# Confirmation and Passphrase setting -# ******************************************************************************* - -function confirmation(){ - - # Consistency check for the OVERWRITEINSTALL and ERASEALL - if [ "${ERASEALL}" -ne 0 ] && [ "${OVERWRITEINSTALL}" -ne 0 ] ; then - cat <<- HEREDOC - ***** ERROR : Confliction between ERASEALL and OVERWRITEINSTALL ***** - [Kaiten-Yaki] ERASEALL = ${ERASEALL} - [Kaiten-Yaki] OVERWRITEINSTALL = ${OVERWRITEINSTALL} - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - fi - - # Sanity check for volume group name - if echo "${VGNAME}" | grep "-" -i > /dev/null ; then # "-" is found in the volume group name. - cat <<- HEREDOC - ***** ERROR : VGNAME is "${VGNAME}" ***** - [Kaiten-Yaki] "-" is not allowed in the volume name. - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - fi # "-" is found in the volume group name. - - # Sanity check for root volume name - if echo "${LVROOTNAME}" | grep "-" -i > /dev/null ; then # "-" is found in the volume name. - cat <<- HEREDOC - ***** ERROR : LVROOTNAME is "${LVROOTNAME}" ***** - [Kaiten-Yaki] "-" is not allowed in the volume name. - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - 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}" ***** - [Kaiten-Yaki] "-" is not allowed in the volume name. - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] 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}" ***** - [Kaiten-Yaki] "-" is not allowed in the volume name. - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] 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 - ***** ERROR : LVSWAPNAME is "${LVSWAPNAME}" ***** - [Kaiten-Yaki] "-" is not allowed in the volume name. - [Kaiten-Yaki] Check configuration in your config.sh - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - fi # "-" is found in the volume name. - - # For surre ask the your config.sh is edited - cat <<- HEREDOC - - LUKS volume partition : ${DEV}${CRYPTPARTITION} - LUKS volume name : "${CRYPTPARTNAME}" - 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} - HEREDOC - - if [ "${ERASEALL}" -ne 0 ] ; then - echo "[Kaiten-Yaki] Going to erase entire disk ${DEV}." - elif [ "${OVERWRITEINSTALL}" -ne 0 ] ; then - echo "[Kaiten-Yaki] Going to overwrite the logical volume \"${VGNAME}-${LVROOTNAME}\"." - else - echo "[Kaiten-Yaki] Going to create a new logical volume \"${VGNAME}-${LVROOTNAME}\"." - fi - - - # ----- Set Passphrase ----- - # Input passphrase - echo "" - echo "[Kaiten-Yaki] Type passphrase for the disk encryption." - read -sr PASSPHRASE - export PASSPHRASE - - echo "[Kaiten-Yaki] Type passphrase again, to confirm." - read -sr PASSPHRASE_C - - # Validate whether both are indentical or not - if [ "${PASSPHRASE}" != "${PASSPHRASE_C}" ] ; then - cat <<-HEREDOC - ***** ERROR : Passphrase doesn't match ***** - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - else - # Clear the PASSPHRASE for checking because we don't use it anymore. - PASSPHRASE_C="" - fi # passphrase validation - - - # Add -l or -L parameter to the size. The lvcreate command have two size parameter. - # -l ###%[FREE|VG|PVS|ORIGIN] : Size by relative value. - # -L ###[M|G|T|m|g|t] : Size by absolute value. - # Too preven the duplicated match, awk exists the process after it match the /%/ pattern. - # If Unit is not specified, installation will fail. - - LVSWAPSIZE=$(echo "${LVSWAPSIZE}" | awk '/%/{print "-l", $0; exit} /M|G|T|m|g|t/{print "-L", $0}') - export LVSWAPSIZE - - LVROOTSIZE=$(echo "${LVROOTSIZE}" | awk '/%/{print "-l", $0; exit} /M|G|T|m|g|t/{print "-L", $0}') - export LVROOTSIZE - - LVEXT1SIZE=$(echo "${LVEXT1SIZE}" | awk '/%/{print "-l", $0; exit} /M|G|T|m|g|t/{print "-L", $0}') - export LVEXT1SIZE - - LVEXT2SIZE=$(echo "${LVEXT2SIZE}" | awk '/%/{print "-l", $0; exit} /M|G|T|m|g|t/{print "-L", $0}') - export LVEXT2SIZE - - # succesfull return - return 0 -} - - -# ******************************************************************************* -# Common Pre-install stage -# ******************************************************************************* - -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 - - # Assign specified space and rest of disk to the EFI and LUKS partition, respectively. - if [ "${ISEFI}" -ne 0 ] ; then # EFI - # Zap existing partition table and create new GPT - echo "[Kaiten-Yaki] Initializing \"${DEV}\" with GPT." - sgdisk --zap-all "${DEV}" - if is_error ; then return 1 ; fi; # If error, terminate - # Create EFI partition and format it - echo "[Kaiten-Yaki] Creating an EFI partition on \"${DEV}\"." - # shellcheck disable=SC2140 - sgdisk --new="${EFIPARTITION}":0:+"${EFISIZE}" --change-name="${EFIPARTITION}":"EFI System" --typecode="${EFIPARTITION}":ef00 "${DEV}" - if is_error ; then return 1 ; fi; # If error, terminate - echo "[Kaiten-Yaki] Formatting the EFI parttion." - mkfs.vfat -F 32 -n EFI-SP "${DEV}${EFIPARTITION}" - if is_error ; then return 1 ; fi; # If error, terminate - # Create Linux partition - echo "[Kaiten-Yaki] Creating a Linux partition on ${DEV}." - # shellcheck disable=SC2140 - sgdisk --new="${CRYPTPARTITION}":0:0 --change-name="${CRYPTPARTITION}":"Linux LUKS" --typecode="${CRYPTPARTITION}":8309 "${DEV}" - if is_error ; then return 1 ; fi; # If error, terminate - # Then print them - sgdisk --print "${DEV}" - else # BIOS - # Zap existing partition table - echo "[Kaiten-Yaki] Erasing partition table of \"${DEV}\"." - dd if=/dev/zero of="${DEV}" bs=512 count=1 - if is_error ; then return 1 ; fi; # If error, terminate - # Create MBR and allocate max storage for Linux partition - echo "[Kaiten-Yaki] Creating a Linux partition on ${DEV} with MBR." - sfdisk "${DEV}" <<- HEREDOC - 2M,,L - HEREDOC - if is_error ; then return 1 ; fi; # If error, terminate - fi # if EFI firmware - - # Encrypt the partition to install Linux - echo "[Kaiten-Yaki] Initializing \"${DEV}${CRYPTPARTITION}\" as crypt partition" - printf %s "${PASSPHRASE}" | cryptsetup luksFormat --iter-time "${ITERTIME}" --type=luks1 --key-file - --batch-mode "${DEV}${CRYPTPARTITION}" - - fi # if erase all - - # ----- Open the LUKS partition ----- - # Open the crypt partition. - echo "[Kaiten-Yaki] Opening a crypt partition \"${DEV}${CRYPTPARTITION}\" as \"${CRYPTPARTNAME}\"" - printf %s "${PASSPHRASE}" | cryptsetup open -d - "${DEV}${CRYPTPARTITION}" "${CRYPTPARTNAME}" - - # Check whether successful open. If mapped, it is successful. - if [ ! -e /dev/mapper/"${CRYPTPARTNAME}" ] ; then - cat <<- HEREDOC - ***** ERROR : Cannot open LUKS volume "${CRYPTPARTNAME}" on "${DEV}${CRYPTPARTITION}". ***** - [Kaiten-Yaki] Check passphrase and your config.txt - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - fi # if crypt volume is unable to open - - # ----- Configure the LVM in LUKS volume ----- - # Check volume group ${VGNAME} exist or not - if vgdisplay -s "${VGNAME}" &> /dev/null ; then # if exist - echo "[Kaiten-Yaki] Volume group \"${VGNAME}\" already exist. Skipped to create. No problem." - echo "[Kaiten-Yaki] Activating all logical volumes in volume group \"${VGNAME}\"." - vgchange -ay - echo "[Kaiten-Yaki] Scanning all logical volumes." - lvscan - else - echo "[Kaiten-Yaki] Initializing a physical volume on \"${CRYPTPARTNAME}\"" - pvcreate /dev/mapper/"${CRYPTPARTNAME}" - if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; - echo "[Kaiten-Yaki] And then creating Volume group \"${VGNAME}\"." - vgcreate "${VGNAME}" /dev/mapper/"${CRYPTPARTNAME}" - if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; - fi # if /dev/volume-groupt exist - - # Create a SWAP Logical Volume on VG, if it doesn't exist - if [ -e /dev/mapper/"${VGNAME}"-"${LVSWAPNAME}" ] ; then - echo "[Kaiten-Yaki] Swap volume already exist. Skipped to create. No problem." - else - echo "[Kaiten-Yaki] Creating logical volume \"${LVSWAPNAME}\" on \"${VGNAME}\"." - # Too use the bash IFS, first parameter is not quoted. - lvcreate ${LVSWAPSIZE} -n "${LVSWAPNAME}" "${VGNAME}" - if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; - fi # if /dev/mapper/swap volume already exit. - - # Create a ROOT Logical Volume on VG. - if [ -e /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" ] ; then # exist - if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then # exist and overwrite install - echo "[Kaiten-Yaki] 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. ***** - [Kaiten-Yaki] Check LVROOTNAME environment variable in your config.txt. - HEREDOC - # Deactivate all lg and close the LUKS volume - deactivate_and_close - return 1 # with error status - fi - else # not exsit - if [ "${OVERWRITEINSTALL}" -ne 0 ] ; then # not exist and overwrite install - cat <<- HEREDOC - ***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" doesn't exist while overwrite install. ***** - [Kaiten-Yaki] Check consistency of your config.txt. - HEREDOC - # Deactivate all lg and close the LUKS volume - deactivate_and_close - return 1 # with error status - else # not exist and not overwrite install - echo "[Kaiten-Yaki] Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"." - # Too use the bash IFS, first parameter is not quoted. - lvcreate ${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 - if [ $? -ne 0 ] ; then deactivate_and_close; return 1 ; fi; - - fi - fi - - - # successful return - return 0 -} - - -# ******************************************************************************* -# Common message in para-install stage -# ******************************************************************************* - -function para_install_msg() { - - cat <<- HEREDOC - ****************************************************************************** - The pre-install process is done. We are ready to install the Linux to the - target storage device. By pressing return key, GUI/TUI installer starts. - - Please pay attention to the partition/logical volume mapping configuration. - In this installation, you have to map the previously created partitions/logical - volumes to the appropriate directories of the target system as followings : - - HEREDOC - - # In the EFI system, add this mapping - if [ "${ISEFI}" -ne 0 ] ; then - echo "/boot/efi : ${DEV}${EFIPARTITION}" - fi - - # Root volume mapping - echo "/ : /dev/mapper/${VGNAME}-${LVROOTNAME}" - - # If USELVEXT1 exist. - if [ "${USELVEXT1}" -ne 0 ] ; then - echo "LVEXT1 : /dev/mapper/${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" - fi - - # If USELVEXT2 exist. - if [ "${USELVEXT2}" -ne 0 ] ; then - echo "LVEXT2 : /dev/mapper/${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}" - fi - - # In case of erased storage, add this mapping - if [ "${ERASEALL}" -ne 0 ] ; then - echo "swap : /dev/mapper/${VGNAME}-${LVSWAPNAME}" - fi - - return 0 -} - - -# ******************************************************************************* -# Common post-install stage -# ******************************************************************************* -# In side this script, the chrooted job is parameterrized as by evn variable TARGETCHROOTEDJOB -function post_install() { - ## Mount the target file system - # ${TARGETMOUNTPOINT} is created by the GUI/TUI installer - # ${BTRFSOPTION} is defined by the caller of this function for BTRFS formated volume. - # ${BTRFSOPTION} have to be NOT quoted. Otherwise, mount will receive an empty - # string as first option, when the veraible is empty. - echo "[Kaiten-Yaki] Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}." - mount ${BTRFSOPTION} /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" "${TARGETMOUNTPOINT}" - - # And mount other directories - echo "[Kaiten-Yaki] Mounting all other dirs." - for n in proc sys dev tmp etc/resolv.conf; do mount --rbind "/$n" "${TARGETMOUNTPOINT}/$n"; done - - # Copy all scripts to the target /tmp for using in chroot session. - echo "[Kaiten-Yaki] Copying files in current dir to ${TARGETMOUNTPOINT}/tmp." - mkdir "${TARGETMOUNTPOINT}/tmp/kaiten-yaki" - cp -r ./* -t "${TARGETMOUNTPOINT}/tmp/kaiten-yaki" - - # Change root and create the keyfile and ramfs image for Linux kernel. - # The here-document is script executed under chroot. At here we call - # the distribution dependent script "lib/chrooted_job_${DISTRIBUTIONSIGNATURE}.sh", - # which was copied to /temp at previous code. - echo "[Kaiten-Yaki] Chroot to ${TARGETMOUNTPOINT}. and execute chrooted_job_${DISTRIBUTIONSIGNATURE}.sh" - # shellcheck disable=SC2086 - cat <<- HEREDOC | chroot "${TARGETMOUNTPOINT}" /bin/bash - cd /tmp/kaiten-yaki - # Execute copied script - source "lib/chrooted_job_${DISTRIBUTIONSIGNATURE}.sh" - HEREDOC - - # Unmount all. -l ( lazy ) option is added to supress the busy error. - echo "[Kaiten-Yaki] Unmounting all." - umount -R -l "${TARGETMOUNTPOINT}" - - echo "[Kaiten-Yaki] Post install process finished." - - # Free LUKS volume as swap volume. - echo "[Kaiten-Yaki] Disabling swap to release the LUKS volume." - swapoff -a - - # Close LUKS - echo "[Kaiten-Yaki] Deactivating all logical volumes in volume group \"${VGNAME}\"." - vgchange -a n "${VGNAME}" - echo "[Kaiten-Yaki] Closing LUKS volume \"${CRYPTPARTNAME}\"." - cryptsetup close "${CRYPTPARTNAME}" - - # Deleting the passphrase information. - echo "[Kaiten-Yaki] Deleting passphrase information." - PASSPHRASE="" - export PASSPHRASE - - # Finishing message - cat <<- HEREDOC - ****************** Install process finished ****************** - - [Kaiten-Yaki] Ready to reboot. - HEREDOC - - return 0 - -} # End of post_install_local() - - -# ******************************************************************************* -# Deactivate all LV in the VG and close LUKS volume -# ******************************************************************************* - -function deactivate_and_close(){ - - - if [ "${IS_ROOT_CREATED}" -ne 0 ] ; then # if extra volume 1 created - # Remove newly created root volume - echo "[Kaiten-Yaki] 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 "[Kaiten-Yaki] 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 "[Kaiten-Yaki] Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\"." - lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}${LVEXT2SUFFIX}" - fi - - - - echo "[Kaiten-Yaki] Deactivating all logical volumes in volume group \"${VGNAME}\"." - vgchange -a n "${VGNAME}" - echo "[Kaiten-Yaki] Closing LUKS volume \"${CRYPTPARTNAME}\"." - cryptsetup close "${CRYPTPARTNAME}" - cat <<- HEREDOC - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - -} - -# ******************************************************************************* -# Delete the nwe volume if overwrite install, and close all -# ******************************************************************************* -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 "[Kaiten-Yaki] Keep logical volume \"${VGNAME}-${LVROOTNAME}\" untouched." - fi - # Deactivate all lg and close the LUKS volume - deactivate_and_close - echo "[Kaiten-Yaki] You can retry Kaiten-yaki again." -} - - -# ******************************************************************************* -# Check whether given signaure is in the system information -# ******************************************************************************* -function distribution_check(){ - if ! uname -a | grep "${DISTRIBUTIONSIGNATURE}" -i > /dev/null ; then # Signature is not found in the OS name. - echo "*******************************************************************************" - uname -a - cat <<- HEREDOC - ******************************************************************************* - This system seems to be not $DISTRIBUTIONNAME, while this script is dediated to the $DISTRIBUTIONNAME. - Are you sure you want to run this script? [Y/N] - HEREDOC - read -r YESNO - if [ "${YESNO}" != "Y" ] && [ "${YESNO}" != "y" ] ; then - cat <<- HEREDOC - - [Kaiten-Yaki] Installation process terminated.. - HEREDOC - return 1 # with error status - fi # if YES - - fi # Distribution check - - # no error - 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 "[Kaiten-Yaki] Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}\" already exists. OK." - else - echo "[Kaiten-Yaki] Creating logical volume \"${LVROOTNAME}${LVEXT1SUFFIX}\" on \"${VGNAME}\"." - # Too use the bash IFS, first parameter is not quoted. - lvcreate ${LVEXT1SIZE} -n "${LVROOTNAME}${LVEXT1SUFFIX}" "${VGNAME}" - if [ $? -ne 0 ] ; then # if fail - echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" - return 1 ; - else # if success - IS_LVEXT1_CREATED=1 # Mark this volume is created - 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 "[Kaiten-Yaki] Logical volume \"${VGNAME}-${LVROOTNAME}${LVEXT2SUFFIX}\" already exists. OK." - else - echo "[Kaiten-Yaki] Creating logical volume \"${LVROOTNAME}${LVEXT2SUFFIX}\" on \"${VGNAME}\"." - # Too use the bash IFS, first parameter is not quoted. - lvcreate ${LVEXT2SIZE} -n "${LVROOTNAME}${LVEXT2SUFFIX}" "${VGNAME}" - if [ $? -ne 0 ] ; then # if fail - echo "***** ERROR : failed to create "${VGNAME}-${LVROOTNAME}${LVEXT1SUFFIX}" . *****" - return 1 ; - else # if success - IS_LVEXT2_CREATED=1 # Mark this volume is created - fi; - fi - fi - - # no error - return 0 - - -} - -# ******************************************************************************* -# Error report and return revsers status. -# ******************************************************************************* -function is_error() { - if [ $? -eq 0 ] ; then # Is previous job OK? - return 1 # If OK, return error ( because it was not error ) - else - cat <<- HEREDOC - **** ERROR ! **** - - Installation process terminated. - HEREDOC - return 0 # If error, return OK ( because it was error ) - fi; -} \ No newline at end of file diff --git a/script/ubuntu-kaiten-yaki.sh b/script/ubuntu-kaiten-yaki.sh deleted file mode 100644 index 0691f7b..0000000 --- a/script/ubuntu-kaiten-yaki.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/bash -u - - # shellcheck disable=SC1091 - # Load configuration parameter - source ./config.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 - - - # ******************************************************************************* - # Para-install stage - # ******************************************************************************* - - # Start the GUI installer and modify the target /etc/default/grub in parallel - if ! para_install_local ; then - return 1 # with error status - fi - - # ******************************************************************************* - # Post-install stage - # ******************************************************************************* - - # If the target volume is formated by btrfs, Ubiquity install the root into the - # @ sub-volume. Thus, mount command inside post_install have to use special option - # to specify @ as mount target. - if lsblk -o NAME,FSTYPE | grep -i "${VGNAME}-${LVROOTNAME}" | grep -i "btrfs" > /dev/null ; then - export BTRFSOPTION="-o subvol=@" - else - export BTRFSOPTION="" - fi - - # Distribution dependent finalizing. Embedd encryption key into the ramfs image. - # The script is parameterized by env-variable to fit to the distribution - post_install - - # Normal end - return 0 - -} # End of main() - - -# ******************************************************************************* -# Ubuntu dependent para-installation process -function para_install_local() { - # Show common message to let the operator focus on the critical part - para_install_msg - - # Distrobution dependent message - cat <<- HEREDOC - - **************** CAUTION! CAUTION! CAUTION! ******************** - [Kaiten-Yaki] - [Kaiten-Yaki] Make sure to click "Continue Testing", at the end of - [Kaiten-Yaki] the Ubiquity installer. Just exit the installer without - [Kaiten-Yaki] rebooting. Otherwise, your system becomes unable to boot. - [Kaiten-Yaki] - [Kaiten-Yaki] Type return key to start Ubiquity. - HEREDOC - - # waiting for a console input - read -r - - # Start Ubiquity installer - ubiquity & - - # Record the PID of the installer. - export INSTALLER_PID=$! - - - # Record the install PID, modify the /etc/default/grub of the target, - # and then, wait for the end of the intaller. - if ! grub_check_and_modify_local ; then - return 1 # with error status - fi - - return 0 -} - - - -# ******************************************************************************* -# This function will be executed in the foreguround context, to watch the GUI installer. -function grub_check_and_modify_local() { - - # While the /etc/default/grub in the install target is NOT existing, keep sleeping. - # If installer terminated without file copy, this script also terminates. - while [ ! -e ${TARGETMOUNTPOINT}/etc/default/grub ] - do - sleep 1 # 1sec. - - # Check if installer quit unexpectedly - if ! ps $INSTALLER_PID > /dev/null ; then # If not exists - # Delete the nwe volume if overwrite install, and close all - on_unexpected_installer_quit - return 1 # with error status - fi - done # while - - # Perhaps, too neuvous. Wait 1 more sectond to avoid the rece condition. - sleep 1 # 1sec. - - # Make target GRUB aware to the crypt partition - # This must do it after start of the file copy by installer, but before the end of the file copy. - echo "[Kaiten-Yaki] Adding GRUB_ENABLE_CRYPTODISK entry to ${TARGETMOUNTPOINT}/etc/default/grub " - echo "GRUB_ENABLE_CRYPTODISK=y" >> ${TARGETMOUNTPOINT}/etc/default/grub - - # And then, wait for the end of installer process - echo "[Kaiten-Yaki] Waiting for the end of GUI/TUI installer." - echo "[Kaiten-Yaki] Again, DO NOT reboot/restart here. Just exit the GUI/TUI installer." - wait $INSTALLER_PID - - # succesfull return - return 0 - -} # grub_check_and_modify_local() - -# ******************************************************************************* -# Execute -main \ No newline at end of file diff --git a/script/void-kaiten-yaki.sh b/script/void-kaiten-yaki.sh deleted file mode 100644 index 4276811..0000000 --- a/script/void-kaiten-yaki.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash -u - - # shellcheck disable=SC1091 - # Load configuration parameter - source ./config.sh - - # Load common functions - source ./lib/common.sh - -function main() { - - # This is the mount point of the install target. - export TARGETMOUNTPOINT="/mnt/target" - - # ******************************************************************************* - # Confirmation before installation - # ******************************************************************************* - - # parameters for distribution check - export DISTRIBUTIONSIGNATURE="void" - export DISTRIBUTIONNAME="Void Linux" - - # 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 - # ******************************************************************************* - - # Install essential packages. - xbps-install -y -Su xbps gptfdisk - - # ADD "rd.auto=1 cryptdevice=/dev/sda2:${CRYPTPARTNAME} root=/dev/mapper/${VGNAME}-${ROOTNAME}" to GRUB. - # This is magical part. I have not understood why this is required. - # Anyway, without this modification, Void Linux doesn't boot. - # Refer https://wiki.voidlinux.org/Install_LVM_LUKS#Installation_using_void-installer - # This modification is guaratnteed once only. To allow re-trying the installation after unexpected GUI/TUI installer quit. - export GRUB_ADDITIONAL_PARAMETERS="rd.auto=1 cryptdevice=${DEV}${CRYPTPARTITION}:${CRYPTPARTNAME} root=/dev/mapper/${VGNAME}-${LVROOTNAME}" - if grep "$GRUB_ADDITIONAL_PARAMETERS" /etc/default/grub ; then # Is additonal parameter already added? - # Yes - echo "[Kaiten-Yaki] /etc/default/grub already modified. OK, skipping to modiy." - else - # Not yet. Let's add. - echo "[Kaiten-Yaki] Modify /etc/default/grub." - sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT/{s#\"# ${GRUB_ADDITIONAL_PARAMETERS}\"#2}" /etc/default/grub - fi - - # Common part of the pre-install stage - if ! pre_install ; then - # If error, restore the modification. - echo "[Kaiten-Yaki] restoring /etc/default/grub, if needed" - sed -i -e "s#${GRUB_ADDITIONAL_PARAMETERS}##" /etc/default/grub - return 1 # with error status - fi - - - # ******************************************************************************* - # Para-install stage - # ******************************************************************************* - - # Start the TUI installer and modify the target /etc/default/grub in background - if ! para_install_local ; then - return 1 # with error status - fi - - # ******************************************************************************* - # Post-install stage - # ******************************************************************************* - - # We don't need special option for BTRFSOPTION. - export BTRFSOPTION="" - - # Distribution dependent finalizing. Embedd encryption key into the ramfs image. - # The script is parameterized by env-variable to fit to the distribution - post_install - - # Normal end - return 0 - -} # End of main() - - -# ******************************************************************************* -# Void Linux dependent post-installation process -function para_install_local() { - # Show common message to let the operator focus on the critical part - para_install_msg - - # Distrobution dependent message - cat <<- HEREDOC - - ******************** CAUTION! CAUTION! CAUTION! ************************ - [Kaiten-Yaki] - [Kaiten-Yaki] Make sure to click "NO", if the void-installer ask you to - [Kaiten-Yaki] reboot.Just exit the installer without rebooting. Otherwise, - [Kaiten-Yaki] your system becomes unable to boot. - [Kaiten-Yaki] - [Kaiten-Yaki] Type return key to start void-installer. - HEREDOC - - # waiting for a console input - read -r - - # Start the background target/etc/default/grub cheker. - # The definition of this function is down below. - grub_check_and_modify_local & - - # Record the PID of the background checker. - grub_check_and_modify_id=$! - - # Start void-installer - void-installer - - # Check if background checker still exist - if ps $grub_check_and_modify_id > /dev/null ; then # If exists - # If exist, the grub was not modifyed -> void-installer termianted unexpectedly - # Delete the nwe volume if overwrite install, and close all - on_unexpected_installer_quit - echo "[Kaiten-Yaki] restoring modified /etc/default/grub." - sed -i "s#loglevel=4 ${GRUB_ADDITIONAL_PARAMETERS}#loglevel=4#" /etc/default/grub - return 1 # with error status - fi - - return 0 -} - - - -# ******************************************************************************* -# This function will be executed in the background context, to watch the TUI installer. -function grub_check_and_modify_local() { - - # While the /etc/default/grub in the install target is NOT existing, keep sleeping. - # If installer terminated without file copy, this script also terminates. - while [ ! -e ${TARGETMOUNTPOINT}/etc/default/grub ] - do - sleep 1 # 1sec. - done # while - - # Perhaps, too neuvous. Wait 1 more sectond to avoid the rece condition. - sleep 1 # 1sec. - - # Make target GRUB aware to the crypt partition - # This must do it after start of the file copy by installer, but before the end of the file copy. - echo "[Kaiten-Yaki] Adding GRUB_ENABLE_CRYPTODISK entry to ${TARGETMOUNTPOINT}/etc/default/grub " - echo "GRUB_ENABLE_CRYPTODISK=y" >> ${TARGETMOUNTPOINT}/etc/default/grub - - # succesfull return - return 0 - -} # grub_check_and_modify_local() - -# ******************************************************************************* -# Execute -main \ No newline at end of file