Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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