USB drive changes name from /dev/sdb to /dev/sdc (and back again) when copying?

I have a usb drive mounted to a folder in an Ubuntu 9.04 server installation. The mount options are stored in /etc/fstab for easy mounting/dismounting:

# <file system> <mount point>   <type>  <options>          <dump>  <pass>   
/dev/sdb1       /media/backup   ntfs    nouser,auto,sync    0      3 

(I've since changed the portion to a UUID to see if it would help with the problem). A backup has been copying files to the disk every morning without issue. Just now I tried to copy one of the files to another folder, and ended up with the error:

cp: reading `ts01-even.tgz': Input/output error

I discovered that the problem occured because /dev/sdb had changed to /dev/sdc. If I mount /dev/sdc and try to copy the file again, the drive will change back to /dev/sdb. After changing the fstab file system from /dev/sdX1 to a UUID there was no difference in behavior. Also, I used to be able to list the file contents of the tarball, but attempting to do so now results in the above behavior. Any ideas?

UPDATE:

running the backup script and storing the backup on the usb HD does not produce the problem, but listing the files in the tarball does. Here is the output of the syslog during the tarball command "tar -ztf FILENAME":

Jul  3 15:09:14 ts01 kernel: [308398.446893] Buffer I/O error on device sdc1, logical block 786433
Jul  3 15:09:28 ts01 ntfs-3g[7468]: ntfs_attr_pread_i: ntfs_pread failed: Input/output error
Jul  3 15:09:28 ts01 ntfs-3g[7468]: Failed to read of MFT, mft=5 count=1 br=-1: Input/output error
Jul  3 15:09:28 ts01 kernel: [308412.404579] Buffer I/O error on device sdc1, logical block 786433
Jul  3 15:09:29 ts01 ntfs-3g[7468]: Unmounting /dev/sdc1 (FreeAgent Drive)
Jul  3 15:09:32 ts01 ntfs-3g[29176]: Version 2009.2.1 external FUSE 27
Jul  3 15:09:32 ts01 ntfs-3g[29176]: Mounted /dev/sdb1 (Read-Write, label "FreeAgent Drive", NTFS 3.1)
Jul  3 15:09:32 ts01 ntfs-3g[29176]: Cmdline options: rw,sync
Jul  3 15:09:32 ts01 ntfs-3g[29176]: Mount options: rw,sync,silent,allow_other,nonempty,relatime,fsname=/dev/sdb1,blkdev,blksize=4096
Jul  3 15:10:01 ts01 /USR/SBIN/CRON[29630]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Jul  3 15:11:35 ts01 kernel: [308539.310031] usb 1-1: reset high speed USB device using ehci_hcd and address 38
... (log repeated with a different address)
Jul  3 15:12:47 ts01 kernel: [308611.790038] usb 1-1: reset high speed USB device using ehci_hcd and address 38
Jul  3 15:12:49 ts01 kernel: [308613.148837] end_request: I/O error, dev sdb, sector 84779391
Jul  3 15:12:49 ts01 kernel: [308613.148871] Buffer I/O error on device sdb1, logical block 10597416
... (log repeated with a different address, with the logical block incrementing by 1 each time)
Jul  3 15:12:49 ts01 kernel: [308613.149090] Buffer I/O error on device sdb1, logical block 10597425
Jul  3 15:12:49 ts01 ntfs-3g[29176]: ntfs_attr_pread_i: ntfs_pread failed: Input/output error
Jul  3 15:12:49 ts01 ntfs-3g[29176]: ntfs_attr_pread error reading '/TS01_Backup/ts01-even.tgz' at offset 177012736: 131072 <> -1: Input/output error
Jul  3 15:12:49 ts01 ntfs-3g[29176]: ntfs_attr_pread_i: ntfs_pread failed: Input/output error
Jul  3 15:12:49 ts01 ntfs-3g[29176]: ntfs_attr_pread error reading '/TS01_Backup/ts01-even.tgz' at offset 177012736: 4096 <> -1: Input/output error

I found something that seemed relevant, but following the instructions has not proven fruitful: FreeAgent Drives


Solution 1:

There are many things that seem wrong with your configuration.

  1. It doesn't make sense to put USB drives in fstab. Fstab is a mostly static listing of system storage devices and their mount points. You assign a static drive/partition identification (based on controller/device address) to a static mount point. Neither of these are really static for USB drives. In your first example, you'd have problems if you install a second hard-disk to the system: it would become /dev/sdb, moving your current USB drive to /dev/sdc, thus breaking your configuration at boot time.

  2. Also, having your drive in fstab and with "auto" option tells the system that the drive is to be mounted at boot time. If for any reason the drive is disconnected at boot time, you'll have your server failing at the boot procedure, which is a really undesirable situation. If the drive is not essential for the system to function, it at least should not have the "auto" option.

  3. The "nouser" option is unnecessary, it is the default. The "sync" option is a really bad idea unless you really know what you are doing. Not only it severely impacts performance, it also causes additional wearing of the drive, specially flash media.

  4. fs_passno = 3 (sixth column of fstab) causes undefined behavior. Valid values are 0, 1 or 2 only.

  5. Using NTFS with a drive intended for backup of a Linux server. Why are you doing that? All Linux NTFS implementations are suboptimal, and inadequate to run any Linux subsystem upon. You should use a native Linux filesystem, like Ext3.

From your kernel log, I could predict that one or more of these may be valid:

  1. You have a malpartitioned disk, i.e. the filesystem was formatted with the wrong parameters, bigger than the actual partition; or the partition in the partition table (the logical size) is bigger than the physical size of the drive. This is from the "Buffer I/O errors" you are seeing. You should consider resetting this disk completely, including the partition table, and repartitioning and reformatting it from scratch.

  2. You have a bad sector in your disk ("end_request: I/O errors"). You should consider running badblocks over the disk to check.

  3. Your USB enclosure is not functioning properly (from "usb resets"). If it is an external hard drive, it should use an independent power supply. The 5V 500mA that is (sometimes) available from the USB port is not enough to keep the mechanics of a hard drive running. It may also be overheating, specially cheap USB flash drives.

  4. The NTFS filesystem is corrupted. Fixing it may be possible with ntfsfix, but you should remember, again, that NTFS is not a native Linux filesystem. For best results, you'd need a Windows system to properly check this partition (using Scandisk).

Other suggestions include: stop using NTFS and choose a native Linux filesystem, remove that entry from fstab, manually mount the disk as part of the backup script, umounting it after finished and use UUID or filesystem labels to refer to the disk.

Solution 2:

You want to investigate udev. This is responsible for naming the device node under /dev and you can set up rules to give your USB key a unique name.

Solution 3:

It sounds to me as if your device is either amlfunctioning half way through copying, or it doesn't get enough power from the computer.

What USB port is it connected to? If you have an externally powered USB hub, use that.

Else, go as close as you can to the motherboard - some computers have less power available at the front/top ports, or at the extra usb ports at the extension slots.

Solution 4:

I've seen cheap USB devices do all kinds of stupid things during massive copying.

(Where I work we have a USB evaluation version of our software and I dd a 4Gb stick to produce them.) I've probably handled dozens of sticks in the last year.

I'm pretty sure I've seen the state machine at the USB stick get jammed under heavy use in cheap models. Again, Ubuntu, but 8.04LTS.

Again, echoing a previous poster, try a different port; I found a using USB port on the powered docking station fro the laptop I was using helped.

Bulk advice is to stick to name brand drives.