Format an external usb disk with only a commandline (linux)

on

I’ve bought a WD 2Terrabyte external hard disk, for use in an only Linux environment. The out of factory filesystem on it mounts perfecty with any linux box, only problem is the proprietary nature of it. So let’s reformat it. I’ve connected it with a non-gui nas, so I have to use the comman-line tools. It came preformatted with some small partitions and one big one. First thing to do was to erase all partitions and make one big one. Now a little thinking came. I had to make a choise. There are two tools available on this machine to handle this. Fdisk and Parted (and even cfdisk). Hmm. Which one to choose. On this page I think I found the answer: “For basic Linux partitioning tasks, use the fdisk command / utility. However, to do more advanced Linux partitioning tasks, like resizing a partition or copying a partition, use the parted utility.” Let’s use good old fdisk.

So first thing to do to find out about my hard disks:

fdisk -l

Hey that’s funny! Somewhere in the output of this command fdisk recommends parted:

WARNING: GPT (GUID Partition Table) detected on ‘/dev/sdc’! The util fdisk doesn’t support GPT. Use GNU Parted.

So the Raid disks (dev/sdc is one of the raid disks) was partioned with parted during setup of the machine (Ubuntu serveredition).

But the information I needed is listed below:

Disk /dev/sdd: 2000.4 GB, 2000396746752 bytes

This is one line from a few dozen of lines, showing that my 2000 gig usbdisk is identified as /dev/sdd. So let’s partion this /dev/sdd:

fdisk /dev/sdd

First thing that is shown is some warning about DOS-compatible mode. I ignored this.

First I deleted all the partitions: d. Then added 1 new partition: n (and answered a few questions: primary partition, partition number 1, first sector default (enter), last sector default (enter)). Then checked this with a p:

Command (m for help): p

Disk /dev/sdd: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000bef84

 Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048  3907024895  1953511424   83  Linux

This looked fine to me, so I finaly wrote it to disk: w

Now I had to format the disk (/dev/sdd1) using:

mkfs -v -t ext3 /dev/sdd1

A long list of output will be generated (because of this -v option). Actualy the real programm called is mke2fs.

After this I added a volumelabel to this just created partition (let’s name it WD2T2):

tune2fs -L WD2T2 /dev/sdd1

Now it was time to mount this disk as /mnt/usb1

mount -t ext3 /dev/sdd1 /mnt/usb1

Or alternatively using the labelname:

mount -t ext3 -L WD2T2 /mnt/usb1

In a next blog I’ll format this disk using parted or cfdisk.