UUID confusion revisited

NoOp glgxg at sbcglobal.net
Mon Mar 24 21:25:50 UTC 2008

On 03/21/2008 06:53 AM, JosephK wrote:
> Following the recent posts regarding UUIDs I thought I'd take a look at
> mine as I'm forever installing and deleting different Linux distros. I
> have 3 drives with Gutsy on sda as my main distro for the moment.
> However, if I instal another distro on sdb or sdc and after a few months
> use I decide I like it then it may be that my main distro is on sdc and
> at a later date sda could house something else.
> The upshot of this is that when I checked my /etc/fstab against
> /dev/disk/by-uuid I found that none of the 3 swap partitions (one on
> each drive) were labelled correctly so I was using no swap space.
> I've knocked together a quick script to compare the UUIDs in
> /dev/disk/by-uuid with the mounted disks in /etc/fstab. If it of any use
> to you please feel free to use, modify or what you will. Any
> constructive criticism is welcomed as I am just starting to learn bash
> shell scripting.
> #!/bin/sh
> ls -l /dev/disk/by-uuid/ |\
> awk '{print $10, "UUID="$8}' | sort |\
> awk -F"/" '{print $3}' > drives.tmp
> cat /etc/fstab |\
> sed -e '/.*\/dev.*$/N;s/\n */ /' |\
> sed -e 's;^# *;;' |\
> sed -e 's/\(^\/dev\/[a-z0-9]* UUID=[a-z0-9]\{8\}-[a-z0-9]\{4\}-[a-z0-9]\{4\}-[a-z0-9]\{4\}-[a-z0-9]\{12\}\).*/\1/' |\
> sed -e '/^\/dev\/.*UUID.*/!d' |\
> sed -e 's/^\/dev\///' > mounts.tmp
> join -a 1 drives.tmp mounts.tmp

Cool! I just saved as uuidcompare and:

sh uuidcomare

Works great, thanks.


More information about the ubuntu-users mailing list