Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a few Debian 5 systems that are still using /dev/hda in the fstab. We'd like to covert them to using UUIDs. This is supposed to be done automatically via the "linux-base" package (postinst), but for some reason it's not kicking in (perhaps someone already ran it and it saved some state somewhere to not do it).

While it's certainly possible to change over to UUIDs by manually editing a bunch of files, it'd be useful to script it somehow. Various incantations of debconf and debconf-set-selections don't seem to work.

So basically, how can one invoke the Debian-provided script/s that do/es all the UUID conversions?

share|improve this question
    
While I do not know about debian provided script, you might want to look at this script: ubuntuforums.org/showthread.php?t=1508991 –  Gabor Vincze Oct 26 '12 at 17:54
add comment

2 Answers

Per Gabor Vincze, the script from Ubuntu forums seems to do a decent code:

#!/bin/bash
# This script will change all entries of the form /dev/sd* in /etc/fstab to their appropriate UUID names
# You must have root privelages to run this script (use sudo)
if [ `id -u` -ne 0 ]; then                                              # Checks to see if script is run as root
        echo "This script must be run as root" >&2                      # If it isn't, exit with error
        exit 1
fi

cp /etc/fstab /etc/fstab.backup
sed -n 's|^/dev/\([sh]d[a-z][0-9]\).*|\1|p' </etc/fstab >/tmp/devices   # Stores all /dev entries from fstab into a file
while read LINE; do                                                     # For each line in /tmp/devices
        UUID=`ls -l /dev/disk/by-uuid | grep "$LINE" | sed -n 's/^.* \([^ ]*\) -> .*$/\1/p'` # Sets the UUID name for that device
        sed -i "s|^/dev/${LINE}|UUID=${UUID}|" /etc/fstab               # Changes the entry in fstab to UUID form
done </tmp/devices
cat /etc/fstab                                                          # Outputs the new fstab file
printf "\n\nWrite changes to /etc/fstab? (y/n) "
read RESPONSE;
case "$RESPONSE" in
        [yY]|[yY][eE][sS])                                              # If answer is yes, keep the changes to /etc/fstab
                echo "Writing changes to /etc/fstab..."
                ;;
        [nN]|[nN][oO]|"")                                               # If answer is no, or if the user just pressed Enter
                echo "Aborting: Not saving changes..."                  # don't save the new fstab file
                cp /etc/fstab.backup /etc/fstab
                rm /etc/fstab.backup
                ;;
        *)                                                              # If answer is anything else, exit and don't save changes
                echo "Invalid Response"                                 # to fstab
                echo "Exiting"
                cp /etc/fstab.backup /etc/fstab
                rm /etc/fstab.backup
                exit 1
                ;;
esac
rm /tmp/devices
echo "DONE!"
share|improve this answer
add comment

The script would have been in /var/lib/dpkg/info/linux-base.postinst . You could launch it manually, or look for a "migrated" flag that you could clear before calling dpkg-reconfigure.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.