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

We have a small box with external drives attached for backing up configuration sets. I found out the problem is simply that on reboot or whatever unknown event the drive switches from /dev/sda1 to /dev/sdb1.

How can I circumvent this or configure fstab to try both locations?

/dev/sda1       /stor           ext4    defaults,noatime,noexec  0       0

You can see I did quite some debugging:

root@nsa:~# mount /stor
mount: special device /dev/sda1 does not exist

As you can see below I did quite some debugging while writing the question.

syslog:

Jul 16 09:48:48 nsa kernel: [167416.395274] EXT4-fs warning (device sda1): 
         __ext4_read_dirblock:908: error reading directory block (ino 2, block 0)

#df -h before umount:

/dev/sda1       1.4T  185G  1.1T  15% /stor

#dmesg:

[   170.431715] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[119366.019470] usb 1-1.2: USB disconnect, device number 4
[119366.297601] usb 1-1.2: new high-speed USB device number 6 using dwc_otg
[119366.398979] usb 1-1.2: New USB device found, idVendor=1058, idProduct=1021
[119366.399013] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[119366.399029] usb 1-1.2: Product: Ext HDD 1021
[119366.399047] usb 1-1.2: Manufacturer: Western Digital
[119366.399063] usb 1-1.2: SerialNumber: 5743415A4132343133343334
[119366.400719] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[119366.403826] scsi1 : usb-storage 1-1.2:1.0
[119367.398875] scsi 1:0:0:0: Direct-Access     WD       Ext HDD 1021     2002 PQ: 0 ANSI: 4
[119367.401608] sd 1:0:0:0: Attached scsi generic sg0 type 0
[119367.402505] sd 1:0:0:0: [sdb] 2930272256 512-byte logical blocks: (1.50 TB/1.36 TiB)
[119367.403524] sd 1:0:0:0: [sdb] Test WP failed, assume Write Enabled
[119367.404593] sd 1:0:0:0: [sdb] Asking for cache data failed
[119367.404623] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[119367.407157] sd 1:0:0:0: [sdb] Test WP failed, assume Write Enabled
[119367.410142] sd 1:0:0:0: [sdb] Asking for cache data failed
[119367.410185] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[119374.143786]  sdb: sdb1
[119374.146995] sd 1:0:0:0: [sdb] Test WP failed, assume Write Enabled
[119374.149166] sd 1:0:0:0: [sdb] Asking for cache data failed
[119374.149203] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[119374.149231] sd 1:0:0:0: [sdb] Attached SCSI disk
[153689.349544] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #2: comm rsync: reading directory lblock 0

#lsusb:

Bus 001 Device 006: ID 1058:1021 Western Digital Technologies, Inc. Elements 2TB
share|improve this question
1  
You'd be better off using UUIDs rather than the device node. Can you run grub-probe --target=drive --device /dev/sda to see what the UUID is and use that for fstab instead ? –  Lawrence Jul 16 at 10:21
    
@Lawrence Nice! Feel free to post this as an answer (using UUID) it works well! I don't have grub bootloader and used ls /dev/disk/by-uuid instead. –  DanFromGermany Jul 16 at 10:30
    
What is assigned to sda then? –  Thorbjørn Ravn Andersen Jul 16 at 16:54
    
@ThorbjørnRavnAndersen nothing –  DanFromGermany Jul 16 at 17:01
    
Sure? Looked at your log again, the first line refers to sda1. –  Thorbjørn Ravn Andersen Jul 16 at 17:50

1 Answer 1

up vote 7 down vote accepted

As has been mentioned in the comments, grab the disk's UUID and stick this in your fstab;

UUID=66a7ba58-b1e2-4d91-9b5e-085064a954ab /stor ext4 defaults 0 0

(replace the UUID value with that of your own). As simple ls -la /dev/disk/by-uuid (which is just a collection of symlinks named the UUID of the disk which point to the real device's identifer (sda, sdb, etc). In my case;

lrwxrwxrwx 1 root root 9 Jul 7 08:45 66a7ba58-b1e2-4d91-9b5e-085064a954ab -> ../../sdf

The disk with that UUID is /dev/sdf, but I don't have to know that. The device's location could, will, and does change. It's UUID is baked into the filesystem's table of contents, which will never change unless you format it clean.

share|improve this answer
5  
The direct way to retrieve the UUID is with the blkid command –  HBruijn Jul 16 at 10:46
    
Ah cool, didn't know that one! –  dannosaur Jul 16 at 10:47

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.