Additional changes

This commit is contained in:
Suikan 2021-07-06 07:41:56 +09:00
parent 3ce805c5ca
commit 7b91fbd9f4
5 changed files with 96 additions and 497 deletions

View file

@ -5,14 +5,13 @@
source ./config.sh
# Load common functions
source ./lib.sh
source ./lib/common.sh
function main() {
# This is the mount point of the install target.
export TARGETMOUNTPOINT="/mnt/target"
# *******************************************************************************
# Confirmation before installation
# *******************************************************************************
@ -76,7 +75,8 @@ function main() {
# *******************************************************************************
# Distribution dependent finalizing. Embedd encryption key into the ramfs image.
post_install_local
# The script is parameterized by env-variable to fit to the distribution
post_install
# Normal end
return 0
@ -128,71 +128,6 @@ function para_install_local() {
return 0
}
# *******************************************************************************
# Void Linux dependent post-installation process
function post_install_local() {
## Mount the target file system
# ${TARGETMOUNTPOINT} is created by the GUI/TUI installer
echo "...Mounting /dev/mapper/${VGNAME}-${LVROOTNAME} on ${TARGETMOUNTPOINT}."
mount /dev/mapper/"${VGNAME}"-"${LVROOTNAME}" ${TARGETMOUNTPOINT}
# And mount other directories
echo "...Mounting all other dirs."
for n in proc sys dev etc/resolv.conf; do mount --rbind "/$n" "${TARGETMOUNTPOINT}/$n"; done
# Change root and create the keyfile and ramfs image for Linux kernel.
echo "...Chroot to ${TARGETMOUNTPOINT}."
# shellcheck disable=SC2086
cat <<- HEREDOC | chroot ${TARGETMOUNTPOINT} /bin/bash
# Mount the rest of partitions by target /etc/fstab
mount -a
# Set up the kernel hook of encryption
echo "...Installing cryptsetup-initramfs package."
xbps-install -y lvm2 cryptsetup
# Prepare a key file to embed in to the ramfs.
echo "...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 a key to the key file. Use the passphrase in the environment variable.
echo "...Adding a key to the key file."
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.
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
# Putting key file into the ramfs initial image
echo "...Registering key file to the ramfs"
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 "...Upadting initramfs."
xbps-reconfigure -fa
echo "...grub-mkconfig."
grub-mkconfig -o /boot/grub/grub.cfg
# Leave chroot
HEREDOC
# Unmount all
echo "...Unmounting all."
umount -R ${TARGETMOUNTPOINT}
# Finishing message
cat <<- HEREDOC
****************** Post-install process finished ******************
...Ready to reboot.
HEREDOC
return 0
} # End of post_install_local()
# *******************************************************************************