External USB Hard Drive under Linux


“640 kilobytes ought to be enough for anybody.”
— unknown source (often misattributed to Bill Gates)

Yesterday, I had to replace a one-terabyte external USB hard drive attached to my home file server with a larger one…

Oh, I wasn’t going to ramble about these days’ lack of disk space, I just wanted to document what I did to get the drive up and running: maybe someone could use this article as a quick start for their own configuration. (Mine was a two-terabyte Hitachi SimpleDrive under Fedora Core Linux.)

Please note that this is not a complete newbie manual on all aspects of the procedure, so don’t expect to find detailed explanations on things like which shell command does what or why this filesystem is better than that one or why I am sudo-ing when switching to root seems to be much easier an approach.

Here we go now. (Skip steps marked with ** if you are not replacing a drive but installing a new one.)

  • First of all, connect the USB drive to your running Linux machine and power the former up.
  • Find out if and how the system recognized it.
$> sudo dmesg | tail
usb 4-6: new high speed USB device using ehci_hcd and address 3
usb 4-6: configuration #1 chosen from 1 choice
scsi3 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 3
usb-storage: waiting for device to settle before scanning
usb-storage: device scan complete
scsi 3:0:0:0: Direct-Access     Hitachi  HDS722020ALA330       PQ: 0 ANSI: 2 CCS
sd 3:0:0:0: [sdc] 3907029168 512-byte hardware sectors (2000399 MB)
sd 3:0:0:0: [sdc] Write Protect is off
sd 3:0:0:0: [sdc] Mode Sense: 34 00 00 00
sd 3:0:0:0: [sdc] Assuming drive cache: write through
sd 3:0:0:0: [sdc] 3907029168 512-byte hardware sectors (2000399 MB)
sd 3:0:0:0: [sdc] Write Protect is off
sd 3:0:0:0: [sdc] Mode Sense: 34 00 00 00
sd 3:0:0:0: [sdc] Assuming drive cache: write through sdc: sdc1
sd 3:0:0:0: [sdc] Attached SCSI disk
sd 3:0:0:0: Attached scsi generic sg3 type 0
VFS: Can't find ext3 filesystem on dev sdc1.

From this output you can see that the drive was recognized as device /dev/sdc with a single partition /dev/sdc1.

The partition’s filesystem is not ext3. (Factory-preformatted FAT32, most likely.) Since the drive will remain attached to a Linux machine, it would make sense to reformat it into something native.

  • Partition the drive.
$> sudo /sbin/fdisk /dev/sdc

Choose the appropriate options from the menu. I went this way:
p — print current partition table;
l — list known partition types (filesystems);
d — delete current partition;
n — create new partition.

For this new partition, specify:
p — primary partition;
1 — partition number;
default values for first/last cylinder;
Linux — partition type (which is etx3 on this system; ID 83 in the list of known partition types mentioned above).

And finally:
w — write table to disk and exit.

  • Create filesystem (format partition).
$> sudo /sbin/mkfs.ext3 -j /dev/sdc1
  • Create mount point.
$> sudo mkdir /mnt/mynewdrive
  • Mount the new drive’s partition for file transfer.**
$> sudo mount -t ext3 /dev/sdc1 /mnt/mynewdrive
  • Transfer files from the old drive.**
$> sudo cp -Rvp /mnt/myolddrive/ /mnt/mynewdrive

Don’t forget the -p option to preserve file ownership and permissions. Mind the slash after myolddrive/.

This will take some time. (14 hours for approximately 800 GB in my case.)

  • Unmount both drives.**

Prior to that, stop any processes/services which might still be using the drives. (In my case, for instance, it was a Samba fileserver daemon holding shared folders on the old drive.)

$> sudo umount /mnt/mynewdrive
$> sudo umount /mnt/myolddrive

Notice that the command is umount, not unmount.

  • Disconnect the old drive. Reposition and/or reconnect the new one, if necessary.**
  • Check if the new drive is still recognized under its original name.**

In my case, it wasn’t: it took place of the old one, which went under /dev/sdb (with partition /dev/sdb1).

For this check, look through latest system messages like you did in the beginning:

$> sudo dmesg | tail
  • Adjust fstab.

Open fstab for editing:

$> sudo vi /etc/fstab

Remove old drive’s mapping**:

/dev/sdb1     /mnt/myolddrive     ext3     defaults     0 0

Add new drive’s mount options:

/dev/sdb1     /mnt/mynewdrive     ext3     defaults     0 0

Make sure to specify the correct partition name.

Save changes.

  • Re-mount the new drive.
$> sudo mount /dev/sdc1
  • Enjoy your new large-capacity storage.

Two terabytes ought to be enough for anybody, right?

Share

Posted

in

by

Tags:

Comments

2 responses to “External USB Hard Drive under Linux”

  1. […] External USB Hard Drive under Linux [zeyaLabs] […]

  2. Hurrah! At last I got a web site from where
    I can actually get useful information regarding my study and knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.