Format an external USB drive for data back on linux

February 10, 2009

I’ve had to do this task a good many times, soI figured I should note it here for easy access.

Problem: How do I format an external USB drive for access in the linux filesytem.

First plug in the drive and power it up.
To ensure the Linux OS recognizes the new device, you can run the command


It should output something like:

 I/O error: dev 08:10, sector 0
 unable to read partition table
 I/O error: dev 08:10, sector 0
Device 08:20 not ready.
 I/O error: dev 08:20, sector 0
SCSI device sda: 625142447 512-byte hdwr sectors (320073 MB)
 /dev/scsi/host2/bus0/target0/lun0: p1

What you are looking for now is the device the OS has mapped it to.. in this case it’s sda ( it may also be sdb or sdc, depending on what other devices you have connected )

You will now be able to access this device through /dev/sda
Next I ran

cfdisk /dev/sda

This allows me to view the partition table on this device. It should show you the type of filesystem if any ( ntfs,fat or unformatted, etc )

In my case I want to make it a linux partition.
I created a [new partition], and set the type to 83 – Linux

I then chose [write] and [quit], this will create the new partition ( and WARNING!! :permanently erase everything on the device)
I could then format the device. I use ReiserFS, which I find great for devices that get jostled around and may get slight corruption, Reiser is awesome at recovering and fixing itself, even better than Ext3
I ran

mkreiserfs /dev/sda1

The 1 on sda1 now signifies the first partition on the device sda.
This will format the device and let you know the result.

At this point I did a quick check to see the health of the device with the command

fsck.reiserfs –check /dev/sda1

Which output:

Do you want to run this program?[N/Yes] (note need to type Yes if you do):Yes
reiserfsck --check started at Tue Feb 10 09:57:44 2009
Replaying journal..
Reiserfs journal '/dev/sda1' in blocks [18..8211]: 0 transactions replayed
Checking internal tree..finished
Comparing bitmaps..finished
Checking Semantic tree:
No corruptions found
There are on the filesystem:
        Leaves 1
        Internal nodes 0
        Directories 1
        Other files 0
        Data block pointers 0 (0 of them are zero)
        Safe links 0
reiserfsck finished at Tue Feb 10 09:58:06 2009

the key info there is the line : No corruptions found
Which means there are no Bad blocks on the device.
So now I proceed to mount the device and then access it like any other folder on the system
mount -t auto /dev/sda1 /mnt/BACKUP-DRIVE/
in this case I had already made a folder called BACKUP-DRIVE in my /mnt directory.
now If I run:


I get

/dev/sda1            312559096     32840 312526256   1% /mnt/BACKUP-DRIVE

That tells me the drive is ready to go, I can cd /mnt//BACKUP-DRIVE and start writing files.
it my case I was to rsync my work files into the backup device I use this command

rsync -vbruz /work /mnt/BACKUP-DRIVE

This will check any only update the files that have changed since the last backup, and go recursively.. in this case, it will copy everything over and may take awhile.
When this is complete.. I run
umount /dev/sda1

and I can safely unplug the device until the next backup.
For the next backup I simply

  1. Plug device in and turn on
  2. mount -auto /dev/sda1 /mnt/BACKUP-DRIVE
  3. rsync -vbruz /work  /mnt/BACKUP-DRIVE ( where /work is the source of the files I want to backup )

ReiserFs comes with a whole bunch of great tools, in case the drive does become corrupted.. or it’s starts to age and gets bad blocks.

You can also automate alot of this ( I have yet to do this ) so that when you plugin the device it automatically calls your backup scripts or something.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: