Commit c0a24b03 authored by Ophélie Gagnard's avatar Ophélie Gagnard

installation/install.sh:

- Add function to automatically retrieve the paths of a partition (based on its type and "fdisk -l" output).
- Add a function to automatically retrieve the UUID of a partition (based on its type and the previous function's output).
dracut.module/dracut.conf.in:
- Identify the root partition with its UUID in the kernel command line parameter.
test.sh: Remove the file.
parent 1f67e310
......@@ -6,7 +6,7 @@ hostonly_cmdline=no
# model kernel command, see more in /boot/grub.cfg
#linux /boot/vmlinuz-4.19.0-17-amd64 root=UUID=c962bb70-ee0c-4561-9edd-56c269ef7e51 ro single mitigations=off console=ttyS1,57600
#kernel_cmdline="root=LABEL=ROOT ip=dhcp rd.neednet=1 ro single mitigations=off console=ttyS1,57600"
kernel_cmdline="root=LABEL=ROOT ip=dhcp rd.neednet=1 ro console=ttyS1,57600"
kernel_cmdline="root=UUID=%ROOT_PARTITION_ID% ip=dhcp rd.neednet=1 ro console=ttyS1,57600"
#kernel_cmdline="ip=dhcp rd.neednet=1"
show_modules=yes
reproducible=yes
......
......@@ -9,9 +9,40 @@ cd $GIT_ROOT
# define useful variables
source installation/env.sh
# This script assumes to be run by the root user (with /sbin in the path).
get_partition_path () {
# Return the path of the desired partition.
# Exit and display an error if it finds 0 or several results.
#
# This function should be called ith exactly one argument: the desired partition type.
# Its behavior is undefined otherwise.
desired_partitions=$(fdisk -l | grep "$1")
desired_partition_count=$(echo -e "$desired_partitions" | wc | awk '{print $1}')
if [ -z "$desired_partitions" ]; then
echo -e "No partition of type $1 (shouldbe 1)."
exit
elif [ "$desired_partition_count" -ne 1 ]; then
echo -e "$desired_partition_count partitions of type $1 (should be 1)."
exit
else
echo -e "$desired_partitions" | awk '{print $1}'
fi
}
get_partition_id () {
desired_partition_path=$(get_partition_path "$1")
echo -e "$(findmnt -fn -o UUID "$desired_partition_path")"
}
root_partition_type="Linux filesystem"
efi_partition_type="EFI System"
TARGET_EFI_PARTITION=$(get_partition_path "$efi_partition_type")
ROOT_PARTITION_ID=$(get_partition_id "$root_partition_type")
# Install the module
cd dracut.module
./configure
......@@ -21,25 +52,9 @@ cd -
# Generation of dracut.module/dracut.conf
cd dracut.module
sed "s|%PROJECT_DIR%|$PROJECT_DIR|g" dracut.conf.in > dracut.conf
sed "s|%PROJECT_DIR%|${PROJECT_DIR}|g;s|%ROOT_PARTITION_ID%|${ROOT_PARTITION_ID}|g" dracut.conf.in > dracut.conf
cd -
# note: on the capri002 (as of the time those lines are wrote):
# OS disk: 250GB, /dev/nvme1n1
# /dev/nvme1n1p1 efi partition
# /dev/nvme1n1p2 root partition
# /dev/nvme1n1p3 swap partition
# Data disk: 4TB, /dev/nvme0n1 (but with a Debian installed on it...)
# /dev/nvme0n1p1 efi partition
# /dev/nvme0n1p2 root partition
# /dev/nvme0n1p3 swap partition
TARGET_DISK=/dev/nvme1n1
TARGET_EFI_PARTITION=${TARGET_DISK}p1
TARGET_ROOT_PARTITION=${TARGET_DISK}p2
# why?
e2label $TARGET_ROOT_PARTITION ROOT
# TMP: Delete bootnum 0 so that there is only one boot option for an image created by this script
efibootmgr -b 0 -B || true
......
#!/bin/bash
get_partition () {
# Return the path of the desired partition.
# Exit and display an error if it finds 0 or several results.
#
# This function should be called with exactly one argument: the desired partition type.
# Its behavior is undefined otherwise.
#echo argument = $1 # DEBUG 100
desired_partitions=$(fdisk -l | grep "$1")
#echo desired_partitions = # DEBUG 100
#echo $desired_partitions # DEBUG 100
desired_partition_count=$(echo -e "$desired_partitions" | wc | awk '{print $1}')
#echo desired_partition_count = # DEBUG 100
#echo $desired_partition_count # DEBUG 100
if [ -z "$desired_partitions" ]; then
echo -e "No partition of type $1 (should be 1)".
exit
elif [ "$desired_partition_count" -ne 1 ] ; then
echo -e "$desired_partition_count partitions of type $1 (should be 1)."
exit
else
#desired_partition_path=$(echo -e "$desired_partitions" | awk '{print $1}')
echo -e "$desired_partitions" | awk '{print $1}'
fi
}
root_partition_path=$(get_partition "Linux filesystem")
efi_partition_path=$(get_partition "EFI System")
root_partition_id=$(findmnt -fn -o UUID $root_partition_path)
efi_partition_id=$(findmnt -fn -o UUID $efi_partition_path)
echo root_partition_path = $root_partition_path
echo efi_partition_path = $efi_partition_path
echo root_partition_id = $root_partition_id
echo efi_partition_id = $efi_partition_id
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment