Skip to content

Instantly share code, notes, and snippets.

@dalehamel
Last active March 10, 2020 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dalehamel/782cbbb9f343c48a112f to your computer and use it in GitHub Desktop.
Save dalehamel/782cbbb9f343c48a112f to your computer and use it in GitHub Desktop.
Convert /etc/fstab to use UUID's for any matching /dev/sd* device.
#!/bin/bash
cp /etc/fstab /etc/fstab.bak
while read line; do
drive=$(echo $line | awk '{print $1}')
if [[ $drive =~ /dev/sd.* ]];then
uuid=$(blkid | grep $drive | sed 's/.*\sUUID="\([a-zA-Z0-9-]*\)".*/\1/g')
sed -i "s:$drive:UUID=$uuid:g" /etc/fstab
fi
done < /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment