Skip to content

Instantly share code, notes, and snippets.

@monsieurp
Created January 16, 2018 10:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save monsieurp/f3be9e866bfa71430b7937a2c6c2df70 to your computer and use it in GitHub Desktop.
Save monsieurp/f3be9e866bfa71430b7937a2c6c2df70 to your computer and use it in GitHub Desktop.
Parse the blkid output and turn it into a fstab compatible file.
#!/usr/bin/env bash
tmpfile=$(mktemp /tmp/blkid2fstab.XXXXXX)
blkid -o list | while read -r l; do
[[ ! ${l} =~ (^/dev/sd) ]] && continue
IFS=" " read -a line <<< "${l}"
fs="${line[1]}"
mountpt="${line[2]}"
uuid="UUID=${line[3]}"
fsopts="defaults,noatime 1 2"
if [[ ${mountpt} == "<swap>" ]]; then
mountpt="none"
fs="swap"
fsopts="sw 0 0"
fi
if [[ ${mountpt} == "/" ]]; then
fsopts="noatime,errors=remount-ro 0 1"
fi
echo "${uuid} ${mountpt} ${fs} ${fsopts}" >> "${tmpfile}"
done
clear
cat "${tmpfile}"
echo
while true; do
read -p "Do you want to replace /etc/fstab with the output above? [yn] " yn
case $yn in
[Yy]* )
now=$(date '+%Y.%m.%d_%H.%M.%S')
cp /etc/fstab "fstab.$now"
cp "${tmpfile}" /etc/fstab
echo "Created a fstab backup in $(readlink -f "fstab.${now}")."
exit
;;
[Nn]* )
exit
;;
* )
echo "Please answer y or n."
;;
esac
done
rm "${tmpfile}"
@3intermute
Copy link

holy crap thank you so much for this!!! this script saved my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment