update files

This commit is contained in:
Javier Pacheco 2024-03-04 05:27:15 +00:00
parent 0c5e605bb7
commit a9e2cd1491
2 changed files with 4 additions and 182 deletions

View File

@ -11,7 +11,7 @@ root_uuid=$(blkid -s UUID -o value $root_device)
swap_uuid=$(blkid -s UUID -o value $swap_device)
# Generate fstab content
cat << EOF > $1
cat << EOF > $(file)
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
@ -21,9 +21,7 @@ cat << EOF > $1
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=$boot_uuid /boot/efi efi defaults,noatime,nodiratime 0 2
UUID=$root_uuid / ext4 defaults,noatime,nodiratime 0 1
UUID=$swap_uuid swap swap defaults 0 0
tmpfs /tmp tmpfs defaults,nosuid,nodev,nodiratime 0 0
UUID=$root_uuid / ext4 defaults,noatime,nodiratime 0 1
UUID=$swap_uuid swap swap defaults 0 0
tmpfs /tmp tmpfs defaults,nosuid,nodev,nodiratime 0 0
EOF
echo "fstab file generated successfully."

176
gfstab
View File

@ -1,176 +0,0 @@
#!/bin/sh
# fstab generator similar in function to the Arch Linux tool that can be found
# on arch-install-scripts.
#
# Copyright (C) 2020 Cem Keylan <cem@ckyln.com>
out() { printf '%s\n' "$@" ;}
die() { out "$@" >&2; exit 1 ;}
find_tag() {
# Function to find the tag of the given device. This eliminates the
# requirement for programs such as lsblk/blkid.
#
# usage: find_tag /dev/sdx1
# If no identifiers are given, return with the plain partition name.
[ "$ident" ] || { out "$1"; return 0 ;}
[ -d "${tagdir:=/dev/disk/by-$(printf %s "$ident" | tr '[:upper:]' '[:lower:]')}" ] ||
die "Directory '$dir' doesn't exist"
for file in "$tagdir/"*; do
[ "$(_readlinkf "$file")" = "$1" ] || continue
tag="$ident=${file##*/}"
break
done
# If the tag couldn't be found for some reason, fallback to the default
# name instead of printing empty.
out "${tag:-$1}"
}
print_mnt() {
# Print fstab entry
printf '%-23s %-15s %-15s %-15s %s %s\n\n' "$@"
}
_readlinkf() {
# https://github.com/ko1nksm/readlinkf
[ "${1:-}" ] || return 1
max_symlinks=40
CDPATH='' # to avoid changing to an unexpected directory
target=$1
[ -e "${target%/}" ] || target=${1%"${1##*[!/]}"} # trim trailing slashes
[ -d "${target:-/}" ] && target="$target/"
cd -P . 2>/dev/null || return 1
while [ "$max_symlinks" -ge 0 ] && max_symlinks=$((max_symlinks - 1)); do
if [ ! "$target" = "${target%/*}" ]; then
case $target in
/*) cd -P "${target%/*}/" 2>/dev/null || break ;;
*) cd -P "./${target%/*}" 2>/dev/null || break ;;
esac
target=${target##*/}
fi
if [ ! -L "$target" ]; then
target="${PWD%/}${target:+/}${target}"
printf '%s\n' "${target:-/}"
return 0
fi
# `ls -dl` format: "%s %u %s %s %u %s %s -> %s\n",
# <file mode>, <number of links>, <owner name>, <group name>,
# <size>, <date and time>, <pathname of link>, <contents of link>
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html
link=$(ls -dl -- "$target" 2>/dev/null) || break
target=${link#*" $target -> "}
done
return 1
}
ispseudo() {
# This function checks for pseudo-filesystems and returns 0 if it is.
# There is no definitive way to know every single pseudo-filesystems,
# there might be some issues with this function.
#
# If the filesystem is not a directory or a tag, we will assume that
# it is a pseudofs. The only exception I have noticed so far are loop
# devices.
case "$fs" in /dev/loop*) return 0 ;; /*|*=*) ;; *) return 0; esac
# These are the most common types of pseudo filesystems.
case "$type" in squashfs|proc|sysfs|tmpfs|devtmpfs|devpts|debugfs) return 0; esac
# As for the last check, we will look up /proc/filesystems which are
# filesystems known by the running kernel.
while read -r ps filesystem; do
[ "$filesystem" = "$type" ] || continue
[ "$ps" ] && return 0
return 1
done < /proc/filesystems
# If we still haven't come up with an answer, let's assume that this is NOT
# a pseudo-filesystem.
return 1
}
usage() {
out "usage: ${0##*/} [-f filter] [-t tag] [-LpPU] [root]" "" \
" Options:" \
" -f <filter> Restrict output to mountpoints matching the prefix FILTER" \
" -L Use labels for source identifiers (Shortcut for -t LABEL)" \
" -p Exclude pseudofs mounts (default behaviour)" \
" -P Include pseudofs mounts" \
" -t <tag> Use tag for source identifiers (should be one of: LABEL," \
" UUID, PARTLABEL, PARTUUID)" \
" -U Use UUIDs for source identifiers (Shortcut for -t UUID)" "" \
" -h Print this help message" "" \
"${0##*/} generates output suitable for addition to an fstab file based on the" \
"devices mounted under the mountpoint specified by the given root." "" \
"This implementation of genfstab is from <https://git.ckyln.com/genfstab>"
exit "${1:-0}"
}
# Print help information
case " $* " in *' --help '*|*' -h '*) usage; esac
ident='' filter='' pseudo=0
while getopts hPpLUf:t: flag; do
case $flag in
h) usage ;;
P) pseudo=1 ;;
p) pseudo=0 ;;
L) ident=LABEL ;;
U) ident=UUID ;;
f) [ -d "$OPTARG" ] || die "Not a directory '$OPTARG'"
filter=$(_readlinkf "$OPTARG") ;;
t) case "$OPTARG" in
LABEL|UUID|PARTLABEL|PARTUUID) ident=$OPTARG ;;
*) die "Unknown identifier '$OPTARG'"; esac
;;
?) usage 1
esac
done
shift $((OPTIND - 1))
[ "$1" ] && {
[ -d "$1" ] || die "Not a directory '$1'"
root="$(_readlinkf "$1")"
}
# It's a good thing that /proc/mounts and fstab share the same syntax. We will
# always be defining dump and pass ourselves since they will always be '0 0' on
# /proc/mounts.
while read -r fs dir type options _; do
if ispseudo; then
pass=0
[ "$pseudo" != 1 ] && continue
[ "$ident" ] && out "# $fs"
else
case "$dir" in "${root:-/}"*) ;; *) continue; esac
[ "$ident" ] && out "# $fs"
fs="$(find_tag "$fs")"
[ "$root" ] && dir=/${dir#$root}
case "$dir" in /) pass=1 ;; *) pass=2; esac
fi
[ "$filter" ] && case "$dir" in ${filter%/}*) ;; *) continue; esac
print_mnt "$fs" "${dir:-/}" "$type" "$options" "${dump:=0}" "$pass"
done < /proc/mounts
# Now print out mounted swaps. I am really not quite sure how swaps work as I
# don't personally use them. If you have a better approach to this, please let
# me know.
while read -r file _; do
[ -f "/$file" ] || continue
[ "$root" ] && {
case "$file" in "$root/"*) ;; *) continue; esac
file=/${file#$root}
}
print_mnt "$file" none swap sw 0 0
done < /proc/swaps