Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a little confused about fdisk and mkfs.

So - here is typical USB flash drive partitioning and formatting:

umount /dev/sdb
fdisk fdisk /dev/sdb

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-960, default 1): ↵
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-960, default 960): ↵
Using default value 960 

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 6
Changed system type of partition 1 to 6 (FAT16)

Command (m for help): a
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x 
partitions, please see the fdisk manual page for additional
information.

mkfs -t vfat /dev/sdb1

My question is:

Why do we even have to use t option to specify partition type while doing fdisk step? How does it affect everything? Does it create some mark on usb drive meaning that there only supposed to be vfat partition? Or is it safe to skip t step altogether? AFAIK - partitioning is only splitting disk into areas - is it not?

Just trying to understand why it works the way it works:)

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

Because mkfs does not know or care about partition tables. You can use it on any block device you wish, including those that have nothing to do with a hard disk, and therefore partitions. The partition type code that fdisk puts in the msdos partition table is only a hint and is pretty much ignored by non Microsoft operating systems.

share|improve this answer
add comment

The partition type is less specific than the filesystem type. Most "native" Linux filesystems use partition type 83, for example: all of the ext* variants, ReiserFS, XFS, and others.

You should try switching to parted or gParted. For some filesystem types, it is able to create the partition and create a filesystem in it all within the same tool. (With some filesystems, you still have to mkfs separately, though.)

share|improve this answer
add comment

The partition type is for devices that need to know what type of filesystem you are putting on that partition. Linux seems to be clever enough to just ignore the type, and knows what the filesystem is no matter what. However, there are some devices that will only be able to read your disk if the filesystem type matches the actual filesystem that you put on the disk.

mkfs creates the actual filesystem. It doesn't know what sort of thing you are putting that filesystem on, so it can't just guess. You need to tell it exactly what sort of filesystem you are trying to create so that it knows what to do.

I found out recently why it matters what the filesystem type is. I setup a usb stick for putting songs on to use in a media player, however I didn't set the filesystem type correctly, even though the actual filesystem was vfat. The music player had no idea how to read the drive, it worked once the partition type was set correctly. I also had the same problem on a mac, a usb stick with the wrong partition type couldn't be read even though the actual filesystem was fine.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.