Finding out which disk is which on Ubuntu

June 9, 2019

My file server often has various disks swapped in and out. It can get confusing which /dev/sd? corresponds to which drive. While reading the man page of findfs, I stumbled on this:

The complete overview about filesystems and partitions you can get for example by:
  lsblk –fs
  partx –show

These three things (along with judicious use of e2label and the other *label commands) is going to make my life a lot easier!

Setting disk labels in Linux

June 5, 2010

Back in December, I wrote about setting UUIDs so multiple disks could be mounted in the same place using /etc/fstab.

I’ve since decided that was dumb. Disks should have unique UUIDs – Linux may use that for more than just mounting the file system. Luckily, there is a better option: the disk label.

Mounting a disk using the disk label is very similar to mounting using UUIDs. First, you need to give the disk a label. I think you can do that when you mkfs, but it’s pretty cheap to do it after you’ve already bulit the file system using:

e2label /dev/sdb1 mylabel

(substituting whatever device you want for /dev/sdb1 and whatever label you want for mylabel. This will work for ext2, ext3 and ext4 – if you’re using another file system, it should have its own label utility.)

Then, rather than specifying UUID= in /etc/fstab, specify:


Your disk will mount automatically, but still have a unique ID. Sounds better to me.

Sun has a useful tutorial at:

Setting disk UUIDs

December 14, 2009

After setting up mounting by UUID as described here, I realized I had a problem.

I wanted to swap disks out (that is, have multiple versions of my backup drive). However, since the drives are being mounted by UUID, I wanted to have only one entry in /etc/fstab for all my “backup” drives.

It appears that dd would work, but that seemed inelegant, especially if future drives are different sizes. So I did a bit of searching and found the discussion here.

In short, I could use

sudo tune2fs /dev/sdb1 -U new-uuid-number

to set the UUID of a file system to whatever I want.

After I’d done that, I couldn’t figure out how to refresh the UUID in /dev/disk/by-uuid/ – even after ejecting and re-inserting the SATA disk, the old UUID still showed up. I ended up rebooting (sigh) and now I can swap drives out with abandon. I probably should have specified the UUID when I did the mkfs. This looks like this bug.

I haven’t tried it, but I would guess having two disks with the same UUID in the machine at the same time would be a Bad Thing.

In retrospect, it would probably have been better if I’d used disk labels instead of UUIDs.

Automatically mounting drives with UUIDs

December 6, 2009

Until now, I’ve always mounted drives by accessing their devices. However, I ran into a situation where this wouldn’t work. Luckily, Ubuntu has the ablility to access drives by UUID – which solved my problem.

I have a drive that holds networked data, which I mount on Ubuntu 8.04 Server as /data/. I also back that drive up to a drive which is normally read-only as /databackup/.

Both of these drives are SATA – meaning they could be unplugged at any time. If both are unplugged, whichever drive gets plugged in first becomes /dev/sda1 – and the other becomes /dev/sdb1. This means I can’t rely on mounting /dev/sda1 on /data and /dev/sdb1 on /databackup.

To get around this, I mounted the drives using UUID in /etc/fstab. First, I had to figure out what the UUIDs of the drives were. To start with, I killed Samba and unmounted both – I knew /dev/sda1 was /data and /dev/sdb1 was /databackup. Then I obtained the UUIDs of both drives:

$ sudo vol_id --uuid /dev/sda1
$ sudo vol_id --uuid /dev/sdb1

Next, I replaced the device mounts (/dev/sda1 and /dev/sdb1) in /etc/fstab with:

UUID=7b932326-717b-4ba6-bef2-fedfbafcabe6 /data ext3...
UUID=94efd7bd-8498-46f3-ab6d-cb706c413567 /databackup ext3...

Under Ubuntu 9.10, it appears that vol_id has merged into blkid – so now you would use:

$ sudo blkid /dev/sda1
/dev/sda1: UUID="f30ba2a3-9da6-48b1-8ab5-75952ef26cc4" TYPE="ext3"

to determine the UUID, and then update /etc/fstab as you’d do for 8.04.