Merge pull request #3 from suikan4github/develop

Merge Develop to main to release
This commit is contained in:
Seiichi "Suikan" Horie 2021-07-03 12:36:50 +00:00 committed by GitHub
commit 2aef4ae4a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 659 additions and 526 deletions

17
CHANGELOG.md Normal file
View file

@ -0,0 +1,17 @@
# Change log
Record of the modification in project development.
## [Unreleased] - yyyy-mm-dd
### 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/v0.0.0...develop

View file

@ -5,45 +5,43 @@ Installation requires mainly 2 steps.
- Configure the parameters in config.sh. - Configure the parameters in config.sh.
- Run the kaiten-yaki script - Run the kaiten-yaki script
Each script have to be executed as sourced style. For example : You can execute the install script without the command line parameter. For example :
```shell ```shell
source ubuntu-kaiten-yaki.sh source ubuntu-kaiten-yaki.sh
``` ```
If you execute these script as independent command style, it will show an error message and terminate the process immediately. 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.txt carefully.
The first stage of the script is preparation like : erasing disk, format partition, and encryption. This is most critical stage of the entire installation process. This part is controlled by the configuration parameter. Thus, you have to edit the config.txt 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.
In the second stage, the distribution dependent installer is invoked. That is the Ubiquity/void-installer of Ubuntu/Void linux, respectively. The third stage is easy. There is nothing the user can do. Everything is automatic.
The third stage is easy. There is nothing user can do. Everything is automatic.
# Installation # Installation
Follow the steps below. Follow the steps below.
## Shell preparation ## Shell preparation
First of all, promote the shell to root. Almost of the procedure requires root privilege. Note that the scripts requires Bash. First of all, promote the shell to root. Almost of the procedure requires root privilege. Note that the scripts require Bash.
In case of Ubuntu : In the case of Ubuntu :
```bash ```bash
# Promote to the root user # Promote to the root user
sudo -i sudo -i /bin/bash
``` ```
In case of Void-Linux : In the case of Void-Linux :
```bash ```bash
sudo -i sudo -i /bin/bash
bash
xbps-install -Su xbps nano xbps-install -Su xbps nano
``` ```
The nano is editor package to configure the config.txt. The editor choice is up to you. Kaiten-yaki script doesn't use any editor during execution. The nano is an editor package to configure the config.txt. The choice of editor is up to you. Kaiten-yaki script doesn't have a dependency on nano editor.
Then, edit the config.txt. Then, edit the config.txt.
## Configuration parameters ## Configuration parameters
This is very critical part of the installation. The configuration parameters are in the top of the config.sh. Edit these parameters before the installation. 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 set of the default settings of the parameters : Followings are the set of the default settings of the parameters :
- Install to **/dev/sda** (DEV). - Install to **/dev/sda** (DEV).
- Erase entire disk (ERASEALL). - Erase the entire disk (ERASEALL).
- In case of EFI firmware, 200MB is allocated to the EFI partition (EFISIZE). - Overwrite install is disabled.
- 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 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 swap logical volume named "swap" in the "vg1". The size is 8GB (LVSWAPNAME,LVSWAPSIZE)
- Create a logical volume named **"anko"** for / in the "vg1". The size of the **50%** of the entire free space (LVROOTNAME, LVROOTSIZE). - Create a logical volume named **"anko"** for / in the "vg1". The size of the **50%** of the entire free space (LVROOTNAME, LVROOTSIZE).
@ -55,30 +53,30 @@ Followings are set of the default settings of the parameters :
export DEV="/dev/sda" export DEV="/dev/sda"
# Whether you want to erase all contents of the storage device or not. # Whether you want to erase all contents of the storage device or not.
# 1 : Yes, I want to erase all. # 1: Yes, I want to erase all.
# 0 : No, I don't. I want to add to the existing LUKS volume. # 0: No, I don't. I want to add to the existing LUKS volume.
export ERASEALL=1 export ERASEALL=1
# Logical Volume name for your Linux installation. Keep it unique from other distribution. # Logical Volume name for your Linux installation. Keep it unique from other distributions.
export LVROOTNAME="anko" export LVROOTNAME="anko"
# Logical volume size of the Linux installation. # Logical volume size of the Linux installation.
# 30% mean, new logical volume will use 30% of the free space in the LVM volume group. # 30% means the 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. # For example, assume the free space is 100GB, and LVROOTSIZE is 30%FREE. The script will create a 30GB logical volume.
export LVROOTSIZE="50%FREE" export LVROOTSIZE="50%FREE"
# Set the size of EFI partition and swap partition. The unit is Byte. you can use M,G... notation. # Set the size of the EFI partition and swap partition. The unit is Byte. you can use M, G... notation.
export EFISIZE="200M" export EFISIZE="200M"
export LVSWAPSIZE="8G" export LVSWAPSIZE="8G"
# Usually, these names can be left untouched. # Usually, these names can be left untouched.
# If you change, keep them consistent through all instllation in your system. # If you change, keep them consistent through all installations in your system.
export CRYPTPARTNAME="luks_volume" export CRYPTPARTNAME="luks_volume"
export VGNAME="vg1" export VGNAME="vg1"
export LVSWAPNAME="swap" export LVSWAPNAME="swap"
# Do not touch this parameter, unless you understand precisely what you are doing. # Do not touch this parameter unless you understand precisely what you are doing.
# 1 : Overwrite the existing logical volume as root vlume. 0 : Create new logical volume as root volume. # 1: Overwrite the existing logical volume as root volume. 0: Create new logical volume as root volume.
export OVERWRITEINSTALL=0 export OVERWRITEINSTALL=0
# Void Linux only. Ignored in Ubuntu. # Void Linux only. Ignored in Ubuntu.
@ -87,53 +85,53 @@ export XTERMFONTSIZE=11
``` ```
There are several restrictions : There are several restrictions :
- For the first distribution installation, you must set ERASEALL to 1, to erase entire screen and create a LUKS partition. Kaiten-yaki script creates a maximum LUKS partition as possible. - For the first distribution installation, you must set ERASEALL to 1, to erase the entire screen and create a LUKS partition. Kaiten-yaki script creates a maximum LUKS partition as possible.
- The LVROOMNAME must be unique among all installations in a computer. Otherwise, Kaiten-yaki terminate at a middle. - The LVROOMNAME must be unique among all installations in a computer. Otherwise, Kaiten-yaki terminates in a middle.
- The LVSWAPNAME must be unique among all installations in a computer. Otherwise, Kaiten-yaki creates an unnecessary logical volume. This is waste of storage resource. - The LVSWAPNAME must be unique among all installations in a computer. 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 EFISIZE and the LVSWAPSIZE are refereed during the first distribution installation only.
- The LVROOTSIZE is the size of a logical volume to create. This is a relative value to the existing free space in the volume group. If you want to install 3 distributions in a computer, you may want to set 33%FREE, 50%FREE, and 100%FREE for the first, second, and third distribution installation, respectively. - The LVROOTSIZE is the size of a logical volume to create. This is a relative value to the existing free space in the volume group. If you want to install 3 distributions in a computer, you may want to set 33%FREE, 50%FREE, and 100%FREE for the first, second, and third distribution installation, respectively.
- The name with "-" is not allowed for the VGNAME, LVROOTNAME, and LVSWAPNAME. I saw some installed doesn't work if "-" in in the name. - The name with "-" is not allowed for the VGNAME, LVROOTNAME, and LVSWAPNAME. I saw some installer doesn't work if "-" in in the name.
## About overwrite install ## About the overwrite-install
The OVERWRITEINSTALL parameter allow you to use an existing logical volume as root volume of the new installation. The OVERWRITEINSTALL parameter allows you to use an existing logical volume as the root volume of the new installation.
This is very danger because of the several aspect like, destroying wrong volume and security. But sometimes it is This is very dangerous because of several aspects like destroying the wrong volume and the risk of security. But sometimes it is
very useful. very useful.
For example, if you reboot the system at the end of GUI/TUI installer by mistake, your system will never boot again. 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 will never boot again.
In this case, the overwrite install recycle this "bad" logical volume and let your system 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 the as following : To use the overwrite-install, you have to set some parameters as follows:
- ERASEALL : 0 - ERASEALL : 0
- OVERWRITEINSTALL : 1 - OVERWRITEINSTALL : 1
And set following parameters as same as previous installation. And set the following parameters as same as the previous installation.
- LVROOTNAME - LVROOTNAME
- VGNAME - VGNAME
- CRYPTPARTNAME - CRYPTPARTNAME
So, Kaitenyaki will leave the "bad" logical volume and allow you to overwrite it by GUI/TUI installer. So, Kaiten-yaki will leave the "bad" logical volume and allow you to overwrite it by GUI/TUI installer.
## First stage : Setting up the volumes ## 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 root user, and you have to use Bash. 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 case of Ubuntu : In the case of Ubuntu :
```bash ```bash
source ubuntu-kaiten-yaki.sh source ubuntu-kaiten-yaki.sh
``` ```
In case of Void Linux In the case of Void Linux
```bash ```bash
source void-kaiten-yaki.sh source void-kaiten-yaki.sh
``` ```
After the several interactive confirmations, Kaiten-yaki will ask you to input a passphrase. This passphrase will be applied to the encryption of the LUKS volume. Make sure you use identical passphrase between all installation of the distributions in a computer. Otherwise, install process terminates with error. After several interactive confirmations, Kaiten-yaki will ask 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.
## Second stage : GUI/TUI installer ## 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 followings correctly. 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 Target Directory | Host Volume | Comment
-----------------|------------------------|--------------------------------------------------------------- -----------------|------------------------|---------------------------------------------------------------
/boot/efi | /dev/sda1 | BIOS system doesn't need this mapping /boot/efi | /dev/sda1 | BIOS system doesn't need this mapping
/ | /dev/mapper/vg1-ubuntu | Host volume name is up to your configuration parameter. / | /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. 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 target system. This is pretty dirty way. But if we don't modify this file, GUI/TUI installer fails at last. During the GUI/TUI installer copying files, Kaiten-yaki modifies the /etc/default/grub of the target system. This is the pretty dirty way. But if we don't modify this file, GUI/TUI installer fails at last.
![Ubuntu Partitioning](image/ubuntu_partitioning.png) ![Ubuntu Partitioning](image/ubuntu_partitioning.png)
![Void Partitioning](image/void_partitioning.png) ![Void Partitioning](image/void_partitioning.png)
@ -144,6 +142,10 @@ At the end of the GUI/TUI installing, do not reboot the system. Click "Continue"
![Ubuntu done](image/ubuntu_done.png) ![Ubuntu done](image/ubuntu_done.png)
![Void done](image/void_done.png) ![Void done](image/void_done.png)
## Third stage : Finalizing ## Third stage: Finalizing
After GUI/TUI installer quit without rebooting, final part of the install process automatically starts. You can reboot the system, if you see the "Ready to reboot" message on the console. 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 ramfs initial stage to allow the Linux kernel to decrypt the LUKS partition which contains root logical volume. So, the system will ask you passphrase only once when GRUB starts.
You can reboot the system if you see the "Ready to reboot" message on the console.

View file

@ -1,19 +1,20 @@
# Kaiten-yaki : Yet another Full Disk Encryption for GRUB/Linux # Kaiten-yaki: Full disk encryption install script for Linux
Kaiten-yaki is a script set to help you to make a full disk encryption install to your desktop system. Kaiten-yaki is a script set to install to your desktop system. With these scripts, you can install Ubuntu/Void Linux to an encrypted partition easily.
Followings are the list of functionality. The followings are the list of functionalities:
- Support Ubuntu and Void Linux. - Ubuntu and Void Linux.
- Install from LiveCD/USB. - Install from LiveCD/USB.
- Invoke GUI/TUI installer at the middle of script execution, for the ease of installation. - Invoke GUI/TUI installer automatically at the middle of script execution, for the ease of installation.
- Automatic detection of BIOS/EFI firmware and create MBR/GPT, respectively. - Automatic detection of BIOS/EFI firmware and create MBR/GPT, respectively.
- Support to install multiple distributions in a LUKS partition. - Create an EFI partition, if needed.
- The "/boot" is located in the same logical volume with the "/". - Support multiple boot in a LUKS partition.
- The swap logical volume is located inside encrypted volume. - The "/boot" is located in the same logical volume as the "/".
- The swap logical volume is located inside the encrypted volume.
- You need to type a passphrase only once in the boot sequence. - You need to type a passphrase only once in the boot sequence.
With the configuration parameters, you can customize each installation. For example, you can configure the system to have 2, 3 or 4,... distributions in a HDD/SSD, as you want. 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 case of BIOS, the disk has MBR and doesn't have EFI partition, while it is depicted here). 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, while it is depicted here).
![Partition Diagram](image/partition_diagram_0.png) ![Partition Diagram](image/partition_diagram_0.png)
@ -22,30 +23,30 @@ The logical volume size of each Linux distribution (LVROOTSIZE) can be customize
As depicted above, the LVM volume group has only one physical volume. As depicted above, the LVM volume group has only one physical volume.
# Tested environment # Tested environment
These scripts are tested with following environment. These scripts are tested with the following environment.
- VMWare Workstation 15.5.7 ( EFI/BIOS ) - VMWare Workstation 15.5.7 ( EFI/BIOS )
- ThinkPad X200 (BIOS)
- Ubuntu 20.04.2 amd64 desktop - Ubuntu 20.04.2 amd64 desktop
- Ubuntu Mate 20.04.2 amd64 desktop - Ubuntu Mate 20.04.2 amd64 desktop
- void-live-x86_64-20210218-mate.iso - void-live-x86_64-20210218-mate.iso
- void-live-x86_64-musl-20210218-mate.iso - void-live-x86_64-musl-20210218-mate.iso
- void-live-x86_64-20210218.iso
# Installation # Installation
Start the PC with the LiveCD/LiveUSB of the distribution to install. Download this repository from github, and expand it. Start the PC with the LiveCD/LiveUSB of the distribution to install. Download this repository from GitHub, and expand it.
Then, go to script directory and follow the procedure in the [INSTALL.md](INSTALL.md) Then, go to the script directory and follow the procedure in the [INSTALL.md](INSTALL.md)
# Known issues # Known issues
If you install two or more Void Linux in to the EFI system, only the last one can boot without trouble. This is not the problem of Kaiten-yaki. If you install two or more Void Linux into the EFI system, only the last one can boot without trouble. This is not the problem of Kaiten-yaki.
# Variants considerations # Variants considerations
Ubuntu has several variants ( flavors ). While I have tested only MATE flavor, other flavor may work correctly as far as it uses Ubiquity installer. Ubuntu has several variants ( flavors ). While I have tested only MATE flavor, other flavors may work correctly as far as it uses Ubiquity installer.
Void Linux has "base" variant which doesn't have GUI. Kaiten-yaki can't run correctly without GUI.
# Acknowledgments # Acknowledgments
These scripts are based on the script shared on the [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. 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, following documents were very important to study how Void Linux installation works. 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. - [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) - [Install LVM LUKS](https://wiki.voidlinux.org/Install_LVM_LUKS) (deprecated)
# Kaiten-yaki # Kaiten-yaki

View file

@ -1,3 +1,5 @@
#!/bin/bash
# Configuration parameters for Kaiten-Yaki # Configuration parameters for Kaiten-Yaki
# Storage device to install the linux. # Storage device to install the linux.
@ -44,7 +46,7 @@ export ISEFI=0 # No, BIOS
fi # is EFI firmaare? fi # is EFI firmaare?
# Set partition number based on the firmware type # Set partition number based on the firmware type
if [ ${ISEFI} -eq 1 ] ; then if [ ${ISEFI} -ne 0 ] ; then
# EFI firmware # EFI firmware
export EFIPARTITION=1 export EFIPARTITION=1
export CRYPTPARTITION=2 export CRYPTPARTITION=2

318
script/lib.sh Normal file
View file

@ -0,0 +1,318 @@
#!/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 *****
...ERASEALL = ${ERASEALL}
...OVERWRITEINSTALL = ${OVERWRITEINSTALL}
...Check configuration in your config.sh
...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}" *****
..."-" 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 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}" *****
..."-" 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 name.
# 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}" *****
..."-" 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 name.
# For surre ask the your config.sh is edited
cat <<- HEREDOC
The destination logical volume label is "${LVROOTNAME}"
"${LVROOTNAME}" uses ${LVROOTSIZE} of the LVM volume group.
Are you sure to install? [Y/N]
HEREDOC
read -r YESNO
if [ "${YESNO}" != "Y" ] && [ "${YESNO}" != "y" ] ; then
cat <<- HEREDOC
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
# For sure ask to be sure to erase.
if [ "${ERASEALL}" -ne 0 ] ; then
echo "Are you sure you want to erase entire ${DEV}? [Y/N]"
read -r YESNO
if [ "${YESNO}" != "Y" ] && [ "${YESNO}" != "y" ] ; then
cat <<-HEREDOC
...Check your config.sh. The variable ERASEALL is ${ERASEALL}.
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
fi # if erase all
# ----- Set Passphrase -----
# Input passphrase
echo ""
echo "Type passphrase for the disk encryption."
read -sr PASSPHRASE
export PASSPHRASE
echo "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 *****
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # passphrase validation
# succesfull return
return 0
}
# *******************************************************************************
# Pre-install stage
# *******************************************************************************
function pre_install() {
# ----- 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 "...Initializing \"${DEV}\" with GPT."
sgdisk --zap-all "${DEV}"
# Create EFI partition and format it
echo "...Creating an EFI partition on \"${DEV}\"."
# shellcheck disable=SC2140
sgdisk --new="${EFIPARTITION}":0:+"${EFISIZE}" --change-name="${EFIPARTITION}":"EFI System" --typecode="${EFIPARTITION}":ef00 "${DEV}"
echo "...Formatting the EFI parttion."
mkfs.vfat -F 32 -n EFI-SP "${DEV}${EFIPARTITION}"
# Create Linux partition
echo "...Creating a Linux partition on ${DEV}."
# shellcheck disable=SC2140
sgdisk --new="${CRYPTPARTITION}":0:0 --change-name="${CRYPTPARTITION}":"Linux LUKS" --typecode="${CRYPTPARTITION}":8309 "${DEV}"
# Then print them
sgdisk --print "${DEV}"
else # BIOS
# Zap existing partition table
echo "...Erasing partition table of \"${DEV}\"."
dd if=/dev/zero of="${DEV}" bs=512 count=1
# Create MBR and allocate max storage for Linux partition
echo "...Creating a Linux partition on ${DEV} with MBR."
sfdisk "${DEV}" <<- HEREDOC
2M,,L
HEREDOC
fi # if EFI firmware
# Encrypt the partition to install Linux
echo "...Initializing \"${DEV}${CRYPTPARTITION}\" as crypt partition"
printf %s "${PASSPHRASE}" | cryptsetup luksFormat --type=luks1 --key-file - --batch-mode "${DEV}${CRYPTPARTITION}"
fi # if erase all
# ----- Open the LUKS partition -----
# Open the crypt partition.
echo "...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}". *****
...Check passphrase and your config.txt
...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 "...Volume group \"${VGNAME}\" already exist. Skipped to create. No problem."
echo "...Activating all logical volumes in volume group \"${VGNAME}\"."
vgchange -ay
echo "...Scanning all logical volumes."
lvscan
else
echo "...Initializing a physical volume on \"${CRYPTPARTNAME}\""
pvcreate /dev/mapper/"${CRYPTPARTNAME}"
echo "...And then creating Volume group \"${VGNAME}\"."
vgcreate "${VGNAME}" /dev/mapper/"${CRYPTPARTNAME}"
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 "...Swap volume already exist. Skipped to create. No problem."
else
echo "...Creating logical volume \"${LVSWAPNAME}\" on \"${VGNAME}\"."
lvcreate -L "${LVSWAPSIZE}" -n "${LVSWAPNAME}" "${VGNAME}"
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 "...Logical volume \"${VGNAME}-${LVROOTNAME}\" already exists. OK."
else # exist and not overwriteinstall
cat <<- HEREDOC
***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" already exists. *****
...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
cat <<- HEREDOC
***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" doesn't exist while overwrite install. *****
...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 "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"."
lvcreate -l "${LVROOTSIZE}" -n "${LVROOTNAME}" "${VGNAME}"
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}"
# In case of erased storage, add this mapping
if [ "${ERASEALL}" -ne 0 ] ; then
echo "swap : /dev/mapper/${VGNAME}-${LVSWAPNAME}"
fi
return 0
}
# *******************************************************************************
# Deactivate all LV in the VG and close LUKS volume
# *******************************************************************************
function 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 on_unexpected_installer_quit(){
echo "***** ERROR : The GUI/TUI installer terminated unexpectedly. *****"
if [ "${OVERWRITEINSTALL}" -eq 0 ] ; then # If not over install, volume is new. So delete it
echo "...Deleting the new logical volume \"${VGNAME}-${LVROOTNAME}\"."
lvremove -f /dev/mapper/"${VGNAME}"-"${LVROOTNAME}"
fi
# Deactivate all lg and close the LUKS volume
deactivate_and_close
echo "...The new logical volume has been deleted. 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
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
fi # Distribution check
# no error
return 0
}

View file

@ -1,109 +0,0 @@
#!/bin/bash -u
# *******************************************************************************
# Confirmation and Passphrase setting
# *******************************************************************************
function confirmation(){
# Consistency check for the OVERWRITEINSTALL and ERASEALL
if [ ${ERASEALL} -eq 1 -a ${OVERWRITEINSTALL} -eq 1 ] ; then
cat <<- HEREDOC 1>&2
***** ERROR : Confliction between ERASEALL and OVERWRITEINSTALL *****
...ERASEALL = ${ERASEALL}
...OVERWRITEINSTALL = ${OVERWRITEINSTALL}
...Check configuration in your config.sh
...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 1>&2
***** ERROR : VGNAME is "${VGNAME}" *****
..."-" 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 group name.
# Sanity check for root volume name
if echo ${LVROOTNAME} | grep "-" -i > /dev/null ; then # "-" is found in the volume name.
cat <<- HEREDOC 1>&2
***** ERROR : LVROOTNAME is "${LVROOTNAME}" *****
..."-" 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 name.
# Sanity check for swap volume name
if echo ${LVSWAPNAME} | grep "-" -i > /dev/null ; then # "-" is found in the volume name.
cat <<- HEREDOC 1>&2
***** ERROR : LVSWAPNAME is "${LVSWAPNAME}" *****
..."-" 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 name.
# For surre ask the your config.sh is edited
cat <<- HEREDOC
The destination logical volume label is "${LVROOTNAME}"
"${LVROOTNAME}" uses ${LVROOTSIZE} of the LVM volume group.
Are you sure to install? [Y/N]
HEREDOC
read YESNO
if [ ${YESNO} != "Y" -a ${YESNO} != "y" ] ; then
cat <<- HEREDOC 1>&2
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
# For sure ask to be sure to erase.
if [ ${ERASEALL} -eq 1 ] ; then
echo "Are you sure you want to erase entire ${DEV}? [Y/N]"
read YESNO
if [ ${YESNO} != "Y" -a ${YESNO} != "y" ] ; then
cat <<-HEREDOC 1>&2
...Check your config.sh. The variable ERASEALL is ${ERASEALL}.
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
fi # if erase all
# ----- Set Passphrase -----
# Input passphrase
echo ""
echo "Type passphrase for the disk encryption."
read -sr PASSPHRASE
export PASSPHRASE
echo "Type passphrase again, to confirm."
read -sr PASSPHRASE_C
# Validate whether both are indentical or not
if [ ${PASSPHRASE} != ${PASSPHRASE_C} ] ; then
cat <<-HEREDOC 1>&2
***** ERROR : Passphrase doesn't match *****
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # passphrase validation
# succesfull return
return 0
}

View file

@ -1,50 +0,0 @@
#!/bin/bash -u
# *******************************************************************************
# Common part of para-install
# *******************************************************************************
function parainstall() {
# 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 still exist
if ! ps $INSTALLER_PID > /dev/null ; then # If not exists
cat <<-HEREDOC 1>&2
***** ERROR : The GUI/TUI installer terminated unexpectedly. *****
...Deleting the new logical volume "${VGNAME}-${LVROOTNAME}".
HEREDOC
lvremove -f /dev/mapper/${VGNAME}-${LVROOTNAME}
echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"."
vgchange -a n ${VGNAME}
echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"."
cryptsetup close ${CRYPTPARTNAME}
cat <<-HEREDOC 1>&2
...The new logical volume has been deleted. You can retry Kaiten-yaki again.
...Installation process terminated.
HEREDOC
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 "...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 "...Waiting for the end of GUI/TUI installer."
echo "...Again, DO NOT reboot/restart here. Just exit the GUI/TUI installer."
wait $INSTALLER_PID
# succesfull return
return 0
} # para install

View file

@ -1,30 +0,0 @@
#!/bin/bash -u
function parainstall_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} -eq 1 ] ; then
echo "/boot/efi : ${DEV}${EFIPARTITION}"
fi
# Root volume mapping
echo "/ : /dev/mapper/${VGNAME}-${LVROOTNAME}"
# In case of erased storage, add this mapping
if [ ${ERASEALL} -eq 1 ] ; then
echo "swap : /dev/mapper/${VGNAME}-${LVSWAPNAME}"
fi
return 0
}

View file

@ -1,124 +0,0 @@
#!/bin/bash -u
# *******************************************************************************
# Pre-install stage
# *******************************************************************************
function pre_install() {
# ----- Erase entire disk, create partitions, format them and encrypt the LUKS partition -----
if [ ${ERASEALL} -eq 1 ] ; then
# Assign specified space and rest of disk to the EFI and LUKS partition, respectively.
if [ ${ISEFI} -eq 1 ] ; then
# Zap existing partition table and create new GPT
echo "...Initializing ${DEV} with GPT."
sgdisk --zap-all "${DEV}"
# Create EFI partition and format it
echo "...Creating an EFI partition on ${DEV}."
sgdisk --new=${EFIPARTITION}:0:+${EFISIZE} --change-name=${EFIPARTITION}:"EFI System" --typecode=${EFIPARTITION}:ef00 "${DEV}"
echo "...Formatting the EFI parttion."
mkfs.vfat -F 32 -n EFI-SP "${DEV}${EFIPARTITION}"
# Create Linux partition
echo "...Creating a Linux partition on ${DEV}."
sgdisk --new=${CRYPTPARTITION}:0:0 --change-name=${CRYPTPARTITION}:"Linux LUKS" --typecode=${CRYPTPARTITION}:8309 "${DEV}"
# Then print them
sgdisk --print "${DEV}"
else
# Zap existing partition table
echo "...Erasing partition table of ${DEV}."
dd if=/dev/zero of=${DEV} bs=512 count=1
# Create MBR and allocate max storage for Linux partition
echo "...Creating a Linux partition on ${DEV} with MBR."
sfdisk ${DEV} <<- HEREDOC
2M,,L
HEREDOC
fi # if EFI firmware
# Encrypt the partition to install Linux
echo "...Initializing ${DEV}${CRYPTPARTITION} as crypt partition"
printf %s "${PASSPHRASE}" | cryptsetup luksFormat --type=luks1 --key-file - --batch-mode "${DEV}${CRYPTPARTITION}"
fi # if erase all
# ----- Open the LUKS partition -----
# Open the crypt partition.
echo "...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 1>&2
***** ERROR : Cannot open LUKS volume "${CRYPTPARTNAME}" on ${DEV}${CRYPTPARTITION}. *****
...Check passphrase and your config.txt
...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 "...Volume group ${VGNAME} already exist. Skipped to create. No problem."
echo "...Activating all logical volumes in volume group \"${VGNAME}\"."
vgchange -ay
else
echo "...Initializing a physical volume on \"${CRYPTPARTNAME}\""
pvcreate /dev/mapper/${CRYPTPARTNAME}
echo "...And then creating Volume group \"${VGNAME}\"."
vgcreate ${VGNAME} /dev/mapper/${CRYPTPARTNAME}
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 "...Swap volume already exist. Skipped to create. No problem."
else
echo "...Creating logical volume \"${LVSWAPNAME}\" on \"${VGNAME}\"."
lvcreate -L ${LVSWAPSIZE} -n ${LVSWAPNAME} ${VGNAME}
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} -eq 1 ] ; then # exist and overwrite install
echo "...Logical volume "${VGNAME}-${LVROOTNAME}" already exists. OK."
else # exist and not overwriteinstall
cat <<- HEREDOC 1>&2
***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" already exists. *****
...Check LVROOTNAME environment variable in your config.txt.
HEREDOC
echo "...Deactivating all logical volumes in volume group \"${VGNAME}\"."
vgchange -a n ${VGNAME}
echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"."
cryptsetup close ${CRYPTPARTNAME}
cat <<- HEREDOC 1>&2
...Installation process terminated..
HEREDOC
return 1 # with error status
fi
else # not exsit
if [ ${OVERWRITEINSTALL} -eq 1 ] ; then
cat <<- HEREDOC 1>&2
***** ERROR : Logical volume "${VGNAME}-${LVROOTNAME}" doesn't exist while overwrite install. *****
...Check consistency of your config.txt.
HEREDOC
echo "...Deactivate all logical volumes in volume group \"${VGNAME}\"."
vgchange -a n ${VGNAME}
echo "...Closing LUKS volume \"${CRYPTPARTNAME}\"."
cryptsetup close ${CRYPTPARTNAME}
cat <<- HEREDOC 1>&2
...Installation process terminated..
HEREDOC
return 1 # with error status
else # not exist and not overwrite install
echo "...Creating logical volume \"${LVROOTNAME}\" on \"${VGNAME}\"."
lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME}
fi
fi
# successful return
return 0
}

View file

@ -1,43 +1,31 @@
#!/bin/bash -u #!/bin/bash -u
function main() { # shellcheck disable=SC1091
# Load configuration parameter # Load configuration parameter
source config.sh source ./config.sh
# Load functions # Load common functions
source lib/confirmation.sh source ./lib.sh
source lib/preinstall.sh
source lib/parainstall.sh
source lib/parainstall_msg.sh
function main() {
# This is the mount point of the install target. # This is the mount point of the install target.
export TARGETMOUNTPOINT="/target" export TARGETMOUNTPOINT="/target"
# Distribution check
if ! uname -a | grep ubuntu -i > /dev/null ; then # "Ubuntu" is not found in the OS name.
echo "*******************************************************************************"
uname -a
cat <<- HEREDOC
*******************************************************************************
This system seems to be not Ubuntu, while this script is dediated to the Ubuntu.
Are you sure you want to run this script? [Y/N]
HEREDOC
read YESNO
if [ ${YESNO} != "Y" -a ${YESNO} != "y" ] ; then
cat <<- HEREDOC 1>&2
...Installation process terminated..
HEREDOC
return 1 # with error status
fi # if YES
fi # "Ubuntu" is not found in the OS name.
# ******************************************************************************* # *******************************************************************************
# Confirmation before installation # 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 # Common part of the parameter confirmation
if ! confirmation ; then if ! confirmation ; then
return 1 # with error status return 1 # with error status
@ -57,10 +45,31 @@ function main() {
# Para-install stage # Para-install stage
# ******************************************************************************* # *******************************************************************************
# Show common message to let the operator focus on the critical part # Start the GUI installer and modify the target /etc/default/grub in parallel
parainstall_msg if ! para_install_local ; then
return 1 # with error status
fi
# Ubuntu dependent message # *******************************************************************************
# Post-install stage
# *******************************************************************************
# Distribution dependent finalizing. Embedd encryption key into the ramfs image.
post_install_local
# 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 cat <<- HEREDOC
************************ CAUTION! CAUTION! CAUTION! **************************** ************************ CAUTION! CAUTION! CAUTION! ****************************
@ -72,8 +81,8 @@ function main() {
Type return key to start Ubiquity. Type return key to start Ubiquity.
HEREDOC HEREDOC
# waitfor a console input # waiting for a console input
read dummy_var read -r
# Start Ubiquity installer # Start Ubiquity installer
ubiquity & ubiquity &
@ -81,21 +90,23 @@ function main() {
# Record the PID of the installer. # Record the PID of the installer.
export INSTALLER_PID=$! export INSTALLER_PID=$!
# Common part of the para-install.
# Record the install PID, modify the /etc/default/grub of the target, # Record the install PID, modify the /etc/default/grub of the target,
# and then, wait for the end of sintaller. # and then, wait for the end of the intaller.
if ! parainstall ; then if ! grub_check_and_modify_local ; then
return 1 # with error status return 1 # with error status
fi fi
# ******************************************************************************* return 0
# Post-install stage }
# *******************************************************************************
# *******************************************************************************
# Ubuntu dependent post-installation process
function post_install_local() {
## Mount the target file system ## Mount the target file system
# ${TARGETMOUNTPOINT} is created by the GUI/TUI installer # ${TARGETMOUNTPOINT} is created by the GUI/TUI installer
echo "...Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}." echo "...Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}."
mount /dev/mapper/${VGNAME}-${LVROOTNAME} ${TARGETMOUNTPOINT} mount /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" ${TARGETMOUNTPOINT}
# And mount other directories # And mount other directories
echo "...Mounting all other dirs." echo "...Mounting all other dirs."
@ -103,39 +114,40 @@ function main() {
# Change root and create the keyfile and ramfs image for Linux kernel. # Change root and create the keyfile and ramfs image for Linux kernel.
echo "...Chroot to ${TARGETMOUNTPOINT}." echo "...Chroot to ${TARGETMOUNTPOINT}."
# shellcheck disable=SC2086
cat <<- HEREDOC | chroot ${TARGETMOUNTPOINT} /bin/bash cat <<- HEREDOC | chroot ${TARGETMOUNTPOINT} /bin/bash
# Mount the rest of partitions by target /etc/fstab # Mount the rest of partitions by target /etc/fstab
mount -a mount -a
# Set up the kernel hook of encryption # Set up the kernel hook of encryption
echo "...Installing cryptsetup-initramfs package." echo "...Installing cryptsetup-initramfs package."
apt -qq install -y cryptsetup-initramfs apt -qq install -y cryptsetup-initramfs
# Prepare a key file to embed in to the ramfs. # Prepare a key file to embed in to the ramfs.
echo "...Prepairing key file." echo "...Prepairing key file."
mkdir /etc/luks mkdir /etc/luks
dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=4096 count=1 status=none 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=rx,go-rwx /etc/luks
chmod u=r,go-rwx /etc/luks/boot_os.keyfile chmod u=r,go-rwx /etc/luks/boot_os.keyfile
# Add a key to the key file. Use the passphrase in the environment variable. # Add a key to the key file. Use the passphrase in the environment variable.
echo "...Adding a key to the key file." echo "...Adding a key to the key file."
printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile
# Add the LUKS volume information to /etc/crypttab to decrypt by kernel. # Add the LUKS volume information to /etc/crypttab to decrypt by kernel.
echo "...Adding LUKS volume info to /etc/crypttab." echo "...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 echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab
# Putting key file into the ramfs initial image # Putting key file into the ramfs initial image
echo "...Registering key file to the ramfs" echo "...Registering key file to the ramfs"
echo "KEYFILE_PATTERN=/etc/luks/*.keyfile" >> /etc/cryptsetup-initramfs/conf-hook echo "KEYFILE_PATTERN=/etc/luks/*.keyfile" >> /etc/cryptsetup-initramfs/conf-hook
echo "UMASK=0077" >> /etc/initramfs-tools/initramfs.conf echo "UMASK=0077" >> /etc/initramfs-tools/initramfs.conf
# Finally, update the ramfs initial image with the key file. # Finally, update the ramfs initial image with the key file.
echo "...Upadting initramfs." echo "...Upadting initramfs."
update-initramfs -uk all update-initramfs -uk all
# Leave chroot # Leave chroot
HEREDOC HEREDOC
# Unmount all # Unmount all
@ -149,9 +161,47 @@ function main() {
...Ready to reboot. ...Ready to reboot.
HEREDOC HEREDOC
# Normal end
return 0 return 0
}
} # End of post_install_local()
# *******************************************************************************
# 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 "...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 "...Waiting for the end of GUI/TUI installer."
echo "...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 # Execute
main main

View file

@ -1,43 +1,31 @@
#!/bin/bash -u #!/bin/bash -u
function main() { # shellcheck disable=SC1091
# Load configuration parameter # Load configuration parameter
source config.sh source ./config.sh
# Load functions # Load common functions
source lib/confirmation.sh source ./lib.sh
source lib/preinstall.sh
source lib/parainstall.sh
source lib/parainstall_msg.sh
function main() {
# This is the mount point of the install target. # This is the mount point of the install target.
export TARGETMOUNTPOINT="/mnt/target" export TARGETMOUNTPOINT="/mnt/target"
# Distribution check
if ! uname -a | grep void -i > /dev/null ; then # "Void" is not found in the OS name.
echo "*********************************************************************************"
uname -a
cat <<- HEREDOC
*********************************************************************************
This system seems to be not Void Linux, while this script is dediated to the Void Linux.
Are you sure you want to run this script for installation? [Y/N]
HEREDOC
read YESNO
if [ ${YESNO} != "Y" -a ${YESNO} != "y" ] ; then
cat <<- HEREDOC 1>&2
...Installation process terminated..
HEREDOC
return
fi # if YES
fi # "Void" is not found in the OS name.
# ******************************************************************************* # *******************************************************************************
# Confirmation before installation # 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 # Common part of the parameter confirmation
if ! confirmation ; then if ! confirmation ; then
return 1 # with error status return 1 # with error status
@ -48,27 +36,61 @@ function main() {
# ******************************************************************************* # *******************************************************************************
# Install essential packages. # Install essential packages.
xbps-install -y -Su xbps gptfdisk xterm xbps-install -y -Su xbps gptfdisk
# Common part of the pre-install stage
if ! pre_install ; then
return 1 # with error status
fi
# ADD "rd.auto=1 cryptdevice=/dev/sda2:${CRYPTPARTNAME} root=/dev/mapper/${VGNAME}-${ROOTNAME}" to GRUB. # 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. # This is magical part. I have not understood why this is required.
# Anyway, without this modification, Void Linux doesn't boot. # Anyway, without this modification, Void Linux doesn't boot.
# Refer https://wiki.voidlinux.org/Install_LVM_LUKS#Installation_using_void-installer # Refer https://wiki.voidlinux.org/Install_LVM_LUKS#Installation_using_void-installer
echo "...Modify /etc/default/grub." # This modification is guaratnteed once only. To allow re-trying the installation after unexpected GUI/TUI installer quit.
sed -i "s#loglevel=4#loglevel=4 rd.auto=1 cryptdevice=${DEV}${CRYPTPARTITION}:${CRYPTPARTNAME} root=/dev/mapper/${VGNAME}-${LVROOTNAME}#" /etc/default/grub 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 ".../etc/default/grub already modified. OK, skipping to modiy."
else
# Not yet. Let's add.
echo "...Modify /etc/default/grub."
sed -i "s#loglevel=4#loglevel=4 ${GRUB_ADDITIONAL_PARAMETERS}#" /etc/default/grub
fi
# Common part of the pre-install stage
if ! pre_install ; then
echo "...restoring modified /etc/default/grub."
sed -i "s#loglevel=4 ${GRUB_ADDITIONAL_PARAMETERS}#loglevel=4#" /etc/default/grub
return 1 # with error status
fi
# ******************************************************************************* # *******************************************************************************
# Para-install stage # 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
# *******************************************************************************
# Distribution dependent finalizing. Embedd encryption key into the ramfs image.
post_install_local
# 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 # Show common message to let the operator focus on the critical part
parainstall_msg para_install_msg
# Ubuntu dependent message
# Distrobution dependent message
cat <<- HEREDOC cat <<- HEREDOC
************************ CAUTION! CAUTION! CAUTION! **************************** ************************ CAUTION! CAUTION! CAUTION! ****************************
@ -80,30 +102,39 @@ function main() {
Type return key to start void-installer. Type return key to start void-installer.
HEREDOC HEREDOC
# waitfor a console input # waiting for a console input
read dummy_var read -r
# Start void-installer in the separate window # Start the background target/etc/default/grub cheker.
xterm -fa monospace -fs ${XTERMFONTSIZE} -e void-installer & # The definition of this function is down below.
grub_check_and_modify_local &
# Record the PID of the installer. # Record the PID of the background checker.
export INSTALLER_PID=$! grub_check_and_modify_id=$!
# Common part of the para-install. # Start void-installer
# Record the install PID, modify the /etc/default/grub of the target, void-installer
# and then, wait for the end of sintaller.
if ! parainstall ; then # 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 "...restoring modified /etc/default/grub."
sed -i "s#loglevel=4 ${GRUB_ADDITIONAL_PARAMETERS}#loglevel=4#" /etc/default/grub
return 1 # with error status return 1 # with error status
fi fi
# ******************************************************************************* return 0
# Post-install stage }
# *******************************************************************************
# *******************************************************************************
# Void Linux dependent post-installation process
function post_install_local() {
## Mount the target file system ## Mount the target file system
# ${TARGETMOUNTPOINT} is created by the GUI/TUI installer # ${TARGETMOUNTPOINT} is created by the GUI/TUI installer
echo "...Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}." echo "...Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}."
mount /dev/mapper/${VGNAME}-${LVROOTNAME} ${TARGETMOUNTPOINT} mount /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" ${TARGETMOUNTPOINT}
# And mount other directories # And mount other directories
echo "...Mounting all other dirs." echo "...Mounting all other dirs."
@ -111,42 +142,41 @@ function main() {
# Change root and create the keyfile and ramfs image for Linux kernel. # Change root and create the keyfile and ramfs image for Linux kernel.
echo "...Chroot to ${TARGETMOUNTPOINT}." echo "...Chroot to ${TARGETMOUNTPOINT}."
# shellcheck disable=SC2086
cat <<- HEREDOC | chroot ${TARGETMOUNTPOINT} /bin/bash cat <<- HEREDOC | chroot ${TARGETMOUNTPOINT} /bin/bash
# Mount the rest of partitions by target /etc/fstab # Mount the rest of partitions by target /etc/fstab
mount -a mount -a
# Set up the kernel hook of encryption # Set up the kernel hook of encryption
echo "...Installing cryptsetup-initramfs package." echo "...Installing cryptsetup-initramfs package."
xbps-install -y lvm2 cryptsetup xbps-install -y lvm2 cryptsetup
# Prepare a key file to embed in to the ramfs. # Prepare a key file to embed in to the ramfs.
echo "...Prepairing key file." echo "...Prepairing key file."
mkdir /etc/luks mkdir /etc/luks
dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=4096 count=1 status=none 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=rx,go-rwx /etc/luks
chmod u=r,go-rwx /etc/luks/boot_os.keyfile chmod u=r,go-rwx /etc/luks/boot_os.keyfile
# Add a key to the key file. Use the passphrase in the environment variable. # Add a key to the key file. Use the passphrase in the environment variable.
echo "...Adding a key to the key file." echo "...Adding a key to the key file."
printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile printf %s "${PASSPHRASE}" | cryptsetup luksAddKey -d - "${DEV}${CRYPTPARTITION}" /etc/luks/boot_os.keyfile
# Add the LUKS volume information to /etc/crypttab to decrypt by kernel. # Add the LUKS volume information to /etc/crypttab to decrypt by kernel.
echo "...Adding LUKS volume info to /etc/crypttab." echo "...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 echo "${CRYPTPARTNAME} UUID=$(blkid -s UUID -o value ${DEV}${CRYPTPARTITION}) /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab
# Putting key file into the ramfs initial image # Putting key file into the ramfs initial image
echo "...Registering key file to the ramfs" echo "...Registering key file to the ramfs"
echo 'install_items+=" /etc/luks/boot_os.keyfile /etc/crypttab " ' > /etc/dracut.conf.d/10-crypt.conf 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. # Finally, update the ramfs initial image with the key file.
echo "...Upadting initramfs." echo "...Upadting initramfs."
xbps-reconfigure -fa xbps-reconfigure -fa
echo "...grub-mkconfig." echo "...grub-mkconfig."
grub-mkconfig -o /boot/grub/grub.cfg grub-mkconfig -o /boot/grub/grub.cfg
echo "...update-grub."
update-grub
# Leave chroot # Leave chroot
HEREDOC HEREDOC
# Unmount all # Unmount all
@ -160,9 +190,35 @@ function main() {
...Ready to reboot. ...Ready to reboot.
HEREDOC HEREDOC
# Normal end
return 0 return 0
}
} # End of post_install_local()
# *******************************************************************************
# 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 "...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 # Execute
main main