Created
January 16, 2018 10:41
-
-
Save monsieurp/f3be9e866bfa71430b7937a2c6c2df70 to your computer and use it in GitHub Desktop.
Parse the blkid output and turn it into a fstab compatible file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
holy crap thank you so much for this!!! this script saved my life