Thursday, August 20, 2009

Linux format external USB hard disk Partition

SkyHi @ Thursday, August 20, 2009
Q. I have an external new hard drive connected using USB port under Red Hat Fedora Core Linux. I want to use it for backup. There are two partition /dev/sda1 and /dev/sda2. This hard disk was setup and formatted by friend under Windows XP (NTFS partition). Now I want to format and use one partition for Linux and another for Windows XP.

How do I format sda1 without losing data from /dev/sda2?

A. To format /dev/sda1 as Linux ext3 partition use command mkfs.ext3. It is used to create an ext2/ext3 filesystem

Type the command as follows:
# mkfs.ext3 /dev/sda1

Before hitting [enter] key make sure you double check partition device name (/dev/sda1). If unsure make backup of important data on USB pen or DVD disk.


nik@Januty:~$ dmesg
[ 3573.698883] usbcore: registered new interface driver usb-storage
[ 3573.698890] USB Mass Storage support registered.
[ 3573.699114] usb-storage: device found at 3
[ 3573.699117] usb-storage: waiting for device to settle before scanning
[ 3578.690390] usb-storage: device scan complete
[ 3578.691230] scsi 2:0:0:0: Direct-Access WDC WD40 0BB-23JHA1 1C06 PQ: 0 ANSI: 2 CCS
[ 3578.692345] sd 2:0:0:0: Attached scsi generic sg2 type 0
[ 3578.698932] sd 2:0:0:0: [sdb] 78156288 512-byte logical blocks: (40.0 GB/37.2 GiB)
[ 3578.701348] sd 2:0:0:0: [sdb] Write Protect is off
[ 3578.701356] sd 2:0:0:0: [sdb] Mode Sense: 00 38 00 00
[ 3578.701361] sd 2:0:0:0: [sdb] Assuming drive cache: write through
[ 3578.706594] sd 2:0:0:0: [sdb] Assuming drive cache: write through
[ 3578.706605] sdb: sdb1
[ 3578.715633] sd 2:0:0:0: [sdb] Assuming drive cache: write through
[ 3578.715642] sd 2:0:0:0: [sdb] Attached SCSI disk


Step 2:

nik@Januty:~$mkfs.ext3 /dev/sdb
mke2fs 1.41.9 (22-Aug-2009)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
mkfs.ext3: Permission denied while trying to determine filesystem size

Step 3:
nik@Januty:~$sudo mkdir /mnt/sdb
nik@Januty:~$sudo mount /dev/sdb /mnt/sdb



Ubuntu Linux format USB pen drive

Q. How do I format a USB pen drive under Ubuntu Linux for ext3 file system?
A. You can format USB pen drive with the help of following commands:

[a] fdisk : Partition table manipulator for Linux

[b] mkfs.ext3 : Create an ext2/ext3 filesystem by formatting given partition name (/dev/partition)

[c] e2label : Change the label on an ext2/ext3 filesystem

First make sure USB pen is not mounted. Click on Places > Computer > Select USB pen > Right click > Select Unmount Volume.

Let us assume that /dev/sda1 is your partition name for USB pen. To format type the following command (Open X terminal and type the command)
$ sudo mkfs.ext3 /dev/sda1
Caution: Careful while entering device/partition name; wrong name can wipe out entire hard disk!!!
Now use e2label command to change the filesystem label on the ext3 filesystem located on device /dev/sda1:
$ sudo e2label /dev/sda1 usb-pen
You can also create an MS-DOS/Windows XP file system under Linux, enter:
$ sudo mkfs.vfat /dev/sda1

Now you are ready to use USB pen.