Update createFstab function

This commit is contained in:
Krizsán Péter 2024-11-22 18:51:08 +01:00
parent 23bb8a747d
commit 1e85600b9d

View File

@ -31,39 +31,52 @@ patchKernelVersion()
createFstab() createFstab()
{( {(
# Get mount info from lsblk output # Get mount info from lsblk output
local DIR_ROOT
local DIR_BOOT
local LSBLK_INFO local LSBLK_INFO
LSBLK_INFO=$(lsblk -l -o MOUNTPOINT,PATH,NAME,PKNAME,PARTUUID,FSTYPE,PTTYPE | sed "/^ /d") LSBLK_INFO=$(lsblk -l -o MOUNTPOINT,PATH,NAME,PKNAME,PARTUUID,FSTYPE,PTTYPE | sed "/^ /d")
# Check if we got a mount point as a parameter
if [ -n "$1" ] ; then
# In case of an invalid mount point (not existing folder) we return here
if [ ! -d "$1" ] ; then
echo "The given mount point is invalid: $1"
return 1
fi
# If a mount point is given then we generate fstab based on that mount point.
DIR_ROOT="^$1 "
DIR_BOOT="^$1/boot "
else
# No mount point is given. We generate fstab for the current running system.
DIR_ROOT="^/ "
DIR_BOOT="^/boot "
fi
# Print out the header part of our fstab
printf "# Begin /etc/fstab\n\n" printf "# Begin /etc/fstab\n\n"
printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "# File system (PARTUUID)" "mount-point" "type" "options" "dump" "fsck" printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "# File system (PARTUUID)" "mount-point" "type" "options" "dump" "fsck"
printf '#%104s\n\n' "order" printf '#%104s\n\n' "order"
# Find the root mount point # Find the root mount point and print out if found
local DIR_ROOT DIR_ROOT=$(grep "$DIR_ROOT" <<< "$LSBLK_INFO")
DIR_ROOT=$(grep "^$1 " <<< "$LSBLK_INFO")
if [ -z "$DIR_ROOT" ] ; then
DIR_ROOT=$(grep "^/ " <<< "$LSBLK_INFO")
fi
if [ -n "$DIR_ROOT" ] ; then if [ -n "$DIR_ROOT" ] ; then
printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_ROOT")" / "$(awk '{print $6}' <<< "$DIR_ROOT")" defaults 1 1 printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_ROOT")" / "$(awk '{print $6}' <<< "$DIR_ROOT")" defaults 1 1
fi fi
# Find if there is a separate boot drive # Find the boot mount point and print out if found
local DIR_BOOT DIR_BOOT=$(grep "$DIR_BOOT" <<< "$LSBLK_INFO")
DIR_BOOT=$(grep "^$1/boot " <<< "$LSBLK_INFO")
if [ -z "$DIR_BOOT" ] && [ -z "$1" ]; then
DIR_BOOT=$(grep "^/boot " <<< "$LSBLK_INFO")
fi
if [ -n "$DIR_BOOT" ] ; then if [ -n "$DIR_BOOT" ] ; then
printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_BOOT")" /boot "$(awk '{print $6}' <<< "$DIR_BOOT")" noauto,defaults 0 0 printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_BOOT")" /boot "$(awk '{print $6}' <<< "$DIR_BOOT")" noauto,defaults 0 0
fi fi
# Find if there is a swap partition # Find the swap partition and print out if found
local DIR_SWAP local DIR_SWAP
DIR_SWAP=$(grep "^\[SWAP\] " <<< "$LSBLK_INFO") DIR_SWAP=$(grep "^\[SWAP\] " <<< "$LSBLK_INFO")
if [ -n "$DIR_SWAP" ] ; then if [ -n "$DIR_SWAP" ] ; then
printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_SWAP")" swap "$(awk '{print $6}' <<< "$DIR_SWAP")" pri=1 0 0 printf '%-45s %-11s %-4s %-16s %-4s %-10s\n' "PARTUUID=$(awk '{print $5}' <<< "$DIR_SWAP")" swap "$(awk '{print $6}' <<< "$DIR_SWAP")" pri=1 0 0
fi fi
# Print out the closing line of out fstab
printf "\n# End /etc/fstab\n" printf "\n# End /etc/fstab\n"
)} )}