Mounting USB HDDs
From Unconscious
Contents |
Mounting USB HDDs
In the desktop edition of Ubuntu Linux, USB HDDs are handled quite elegantly; You plug it in, and it appears. Not so with the server version. On the server version, it has to be mounted. Fortunately, mounting filesystems under linux is not that hard, but there are certain things to be aware of.
First I did lsusb to see whether the system even saw the drive.
Then I used fdisk -l to see what the drive looked like to the system.
fdisk -l
Disk /dev/hda: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/hda1 * 1 4664 37463548+ 83 Linux /dev/hda2 4665 4865 1614532+ 5 Extended /dev/hda5 4665 4865 1614501 82 Linux swap / Solaris
Disk /dev/sda: 200.0 GB, 200049647616 bytes 255 heads, 63 sectors/track, 24321 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 * 1 24321 195358401 c W95 FAT32 (LBA)
Since I don't understand much about the meaning of the output of fdisk, I assumed that the USB HDD was /dev/sda. When purchased this device was formatted with fat32, and was setup for use with windows. I reformatted them (I bought 2) with ext3 under Fedora Core 2, using mkfs.ext3. So, I was puzzled to see /dev/sda1 with a file system of W95 FAT32. I tried to mount it using /dev/sda, and that didn't work. Eventually I tried using /dev/sda1, as shown in my /etc/fstab, below, and that worked.
$ cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1 /dev/hda5 none swap sw 0 0 /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0 /dev/sda1 /media/usbdisk ext3 defaults 0 0 #
20070116: The 300gb Seagates went on sale last week at buy.com, so I bought another one. It's only slightly different form the previous two. When I plugged it into my edgy desktop box it mounted as /media/SEA_DISK, under /dev/sdf. I formatted it like the previous two...
mkfs.ext3 /dev/sdf
Then I copied a whole bunch of data to it from the other 300gb disk. I forgot about it and, after a forced reboot due to a power failure, found that it was empty. WTF?!? Now, it mounts as /media/Backup, which is fine, I just have no idea how I did that.
20071207: Started using the USB disks again, as duplicates/backups for data stored on the bigger eSata disks. So, I decided to document my adventures somewhat better this time. See below...
fdisk
This is the utility I used to partition my USB disks. Assuming the dev is designated as /dev/sdx, and I want a single large partition. To partition the disk I enter
sudo fdisk /dev/sdx
p to display any partitions, and d to delete them, one at a time.
1 to delete the first partition.
n to create a new partition.
p to make it a primary partition.
1 to make it the first partition.
Enter to use the default first cylinder.
Enter again to use the default last cylinder.
a to make the partition active.
1 to select the first partition.
w to write the new partition table.
I read somewhere that I must then reboot for the new partition table to take effect, but that seems like a huge nuisance. I just recently did a repartition of a little 80gb external drive, and found that unmounting the drive worked just fine. Note, however, that the drive was originally mounted on the fly via HotPlug, and I'm not sure how all that stuff works.
mkfs
This is what I use to build the file system on my newly partitioned disk. Since I want the disk to use the ext3 journaling file system, I use mkfs.ext3, and, since I want this file system to reside in my newly created partition, which is designated as /dev/sdx1, I use the following command:
sudo mkfs.ext3 /dev/sdx1
there are a number of options for mkfs. I tried dir_index, but that failed. I thought that I could specify a volume label using -L <label>, but that didn't work.
e2label
This is the command I used to change the volume label on my new disk, like so...
sudo e2label /dev/sdx1 Label
Mounting eSATA disks
The usbdisks are kinda of slow. Well, they're actually not that slow, it's just that if you haven't accessed them for several minutes, there's a delay before they're accessible again. So, when my USB disk pair started to get pretty full, I ordered a pair of Seagate 500gb eSATA disks. eSATA is supposed to be 8 times as fast as USB 2.0, and the disks were actually less expensive than their USB counterparts.
I made the mistake of buying a eSATA interface card, without realizing that the Seagate disk package includes a card. Since I bought two disks, I now have three eSATA cards. Anybody need one?
The eSATA disks aren't hotplug devices like the USB disks are. They must be on when the system comes up, otherwise it does not recognize them. To find out where they are, so I can add an entry to /etc/fstab, I use fdisk.
scott@dystopia:~$ sudo fdisk -l Password:
Disk /dev/sda: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 * 1 4664 37463548+ 83 Linux /dev/sda2 4665 4865 1614532+ 5 Extended /dev/sda5 4665 4865 1614501 82 Linux swap / Solaris
Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdb1 1 60801 488384001 83 Linux
Disk /dev/sdc: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdc1 1 60801 488384001 83 Linux
Disk /dev/sdh: 300.0 GB, 300069052416 bytes 255 heads, 63 sectors/track, 36481 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdh1 * 1 36481 293033601 c W95 FAT32 (LBA)
Disk /dev/sdi: 300.0 GB, 300069052416 bytes 255 heads, 63 sectors/track, 36481 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdi doesn't contain a valid partition table scott@dystopia:~$
I actually think I may have found a better way to make sure that the same disk is always mounted at the same mount point. This is my new /etc/fstab
scott@dystopia:~$ cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/hda1 UUID=25d364e5-7cfc-46d0-8a5d-fe80a44338bb / ext3 defaults,errors=remount-ro 0 1 # /dev/hda5 UUID=d187a596-78b8-4a39-ae38-7ce75cba24e9 none swap sw 0 0 /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/ /media/floppy0 auto rw,user,noauto 0 0 # /dev/sdb1 /media/eSataDisk1 ext3 defaults 0 0 UUID=79079be6-2451-433b-ae28-62029ca0e637 /media/eSataDisk1 ext3 defaults 0 0 # /dev/sdc1 /media/eSataDisk2 ext3 defaults 0 0 UUID=8e171710-fe16-40ce-842c-d938f2fa4987 /media/eSataDisk2 ext3 defaults 0 0 scott@dystopia:~$
I got the UUIDs for each disk using ls
scott@dystopia:~$ ls -l /dev/disk/by-uuid/ total 0 lrwxrwxrwx 1 root root 10 2007-07-05 08:03 25d364e5-7cfc-46d0-8a5d-fe80a44338bb -> ../../sda1 lrwxrwxrwx 1 root root 9 2007-07-05 08:03 4ca8e5f5-6dfb-4a15-a7bd-6e2d2f8d77e2 -> ../../sdi lrwxrwxrwx 1 root root 9 2007-07-05 08:03 5cd09c4e-bed4-491a-a858-75783221c85e -> ../../sdc lrwxrwxrwx 1 root root 10 2007-07-05 08:03 70b0670f-c363-46d4-8972-343bbbb1b6b0 -> ../../sdh1 lrwxrwxrwx 1 root root 10 2007-07-05 08:03 79079be6-2451-433b-ae28-62029ca0e637 -> ../../sdb1 lrwxrwxrwx 1 root root 10 2007-07-05 08:03 8e171710-fe16-40ce-842c-d938f2fa4987 -> ../../sdc1 lrwxrwxrwx 1 root root 10 2007-07-05 08:03 d187a596-78b8-4a39-ae38-7ce75cba24e9 -> ../../sda5 scott@dystopia:~$
After reboot the disks are mounted in the same mount point. However, there is also an initial latency on accessing eSata disks, similar to that exhibited by USB disks. What up wi dat?
