I use an external USB drive to hold daily file-server backups. My backup scripts mount & unmount the drive around the rsnapshot backup, which allows the drive to spin down for most of the day, plus protecting it from random finger fumbles and possible system breakage. Whether that affects the drive’s long-term reliability or not, I cannot say, but it’s been chugging along for a year so far.
In any event, hotplugging precludes the usual /dev/sd?? notation notation for disk mounting, because the drive tends to have a different device name depending on what’s plugged in. It turns out one of my printers has a USB port for memory gadgets (from whence it can print directly, not that I ever want to) which looks like an unmounted drive which may come up either before or after the USB backup drive.
Sooo, I must use the drive’s UUID (Univerally Unique ID). Or, more accurately, the filesystem’s UUID, which has some implications.
Figure out which drive it is by looking in dmesg
[ 18.436000] scsi 4:0:0:0: Direct-Access Maxtor OneTouch 0122 PQ: 0 ANSI: 4 ... snippage ... [ 18.444000] sd 4:0:0:0: [sdd] 976773168 512-byte hardware sectors (500108 MB) [ 18.444000] sd 4:0:0:0: [sdd] Write Protect is off [ 18.444000] sd 4:0:0:0: [sdd] Mode Sense: 2d 08 00 00 [ 18.444000] sd 4:0:0:0: [sdd] Assuming drive cache: write through [ 18.448000] sd 4:0:0:0: [sdd] 976773168 512-byte hardware sectors (500108 MB) [ 18.448000] sd 4:0:0:0: [sdd] Write Protect is off [ 18.448000] sd 4:0:0:0: [sdd] Mode Sense: 2d 08 00 00 [ 18.448000] sd 4:0:0:0: [sdd] Assuming drive cache: write through [ 18.448000] sdd: sdd1 sdd4 [ 18.456000] sd 4:0:0:0: [sdd] Attached SCSI disk [ 18.456000] sd 4:0:0:0: Attached scsi generic sg4 type 0
The sdd1 partition occupies nearly the entire drive and holds the backup files. The sdd4 partition is a tiny FAT thing for the Maxtor utilities that set the spin-down time and suchlike. Every now and then you do need a Windows box, alas.
Find the UUID by looking in /dev/disk/by-uuid/
lrwxrwxrwx 1 root root 10 2009-03-21 08:08 069e50dc-1994-47d2-9c7e-0b5179a89041 -> ../../sdd1 ... snippage ...
Plunk that in /etc/fstab
UUID=069e50dc-1994-47d2-9c7e-0b5179a89041 /mnt/backup ext2 defaults,noatime,noauto,nodev,noexec,nosuid 0 0
Then I (and, more importantly, my scripts) can mount the drive with a simple sudo mount /mnt/backup regardless of what drive name it sports today.
The UUID comes from the filesystem written in the partition, so rebuilding the filesystem with mke2fs gives the partition a new UUID; the old entry in /etc/fstab stops working. You can use tune2fs to copy the old UUID to the new filesystem or do as I do: just plunk the new UUID in /etc/fstab.
The system reads the partition’s UUID when it boots, so regenerate the /dev/disk/by-uuid entry using sudo udevtrigger or replugging the drive (which is awkward because it’s in the basement and I’m upstairs). That also re-jiggers all the hotpluggable devices, which shouldn’t matter, right?
The reason I use mke2fs rather than sudo rm -rf /mnt/backup is that it takes basically forever to delete a whole drive full of files.
Comments
2 responses to “UUIDs for External USB Drives”
[…] The no-create-root option prevents horrible things from happening if the USB drive wakes up dead and doesn’t mount; you don’t want to back up the drives to the /mnt/bulkdata mount point. The USB drive mounts using a UUID entry in /etc/fstab, as described there. […]
[…] More on that from the last go-round there. […]