How to format a USB pendrive in Linux ?
Here some more recent RnD done on my end and it will help you to make out easily while you trying to do formating your usb in linux.
Type the following command to find out USB pen partition name:
[root@thiyag]# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 51606140 6148584 44933428 13% /
devtmpfs 953540 0 953540 0% /dev
tmpfs 961808 1000 960808 1% /dev/shm
tmpfs 961808 40612 921196 5% /run
/dev/sda3 51606140 6148584 44933428 13% /
tmpfs 961808 40612 921196 5% /run
tmpfs 961808 0 961808 0% /sys/fs/cgroup
tmpfs 961808 0 961808 0% /media
/dev/sda5 251747076 83478108 155480900 35% /home
/dev/sda1 495844 78680 391564 17% /boot
/dev/sdb1 7898008 4 7898004 1% /media/2E3E-D0DE
We can use fdisk as well to get to know the USB partition,
[root@thiyag]# fdisk -l
Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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: 0x9c68a144
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8759295 3866624 82 Linux swap / Solaris
/dev/sda3 8759296 113616895 52428800 83 Linux
/dev/sda4 113616896 625142447 255762776 5 Extended
/dev/sda5 113618944 625141759 255761408 83 Linux
Disk /dev/sdb: 8103 MB, 8103395328 bytes
196 heads, 32 sectors/track, 2523 cylinders, total 15826944 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: 0xc3072e18
Device Boot Start End Blocks Id System
/dev/sdb1 * 32 15826943 7913456 7 HPFS/NTFS/exFAT
Once identified the partition name type the following command to format the usb pen in Linux
(caution you must select correct usb partition name, otherwise you will loss all the data on hard disk)
[root@thiyag]# mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.12 (29 Oct 2011)
mkfs.vfat: /dev/sdb1 contains a mounted file system.
here we are getting an error as, “mkfs.vfat: /dev/sdb1 contains a mounted file system.”
So it asking us to unmount before we format the USB
here we go for unmount the mounted usb.
[root@thiyag]# umount /dev/sdb1
We havn’t get any error, so we unmounted it 😉
finally, use the following command to format your pendrive/usb drive.
# mkfs.ext3 /dev/sdb1
To format as VFAT/FAT32 file system type the following command:
[root@thiyag]# mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.12 (29 Oct 2011)
[root@thiyag]#
hope it works for you too ! 🙂
Hi,
Thanks for the blog. Be aware that the instruction you give:
# mkfs.ext3 /dev/sda1
works on the primary drive, usually the internal hard disk. It should change to
# mkfs.ext3 /dev/sdb1
the referred pendrive…
Salutacions,
Josep
Thanks Josep !
It was typo, sorry for that. It has been corrected now.
Thanks for visiting my blog !