Is it ok to mkfs without partition number?

20,120

Solution 1

Creating a filesystem on a whole disk rather than a partition is possible, but unusual. The documentation only explicitly mentions the partition because that's the most usual case (it does say usually). You can create a filesystem on anything that acts sufficiently like a fixed-size file, i.e. something where if you write data at a certain location and read back from the same location then you get back the same data. This includes whole disks, disk partitions, and other kinds of block devices, as well as regular files (disk images).

After doing mkfs.fat -n A /dev/sdb, you no longer have a partition on that disk. Beware that the kernel still thinks that the disk has a partition, because it keeps the partition table cached in memory. But you shouldn't try to use /dev/sdb1 anymore, since it no longer exists; writing to it would corrupt the filesystem you created on /dev/sdb since /dev/sdb1 is a part of /dev/sdb (everything except a few hundred bytes at the beginning). Run the command partprobe as root to tell the kernel to re-read the partition table.

While creating a filesystem on a whole disk is possible, I don't recommend it. Some operating systems may have problems with it (I think Windows would cope but some devices such as cameras might not), and you lose the possibility of creating other partitions. See also The merits of a partitionless filesystem

Solution 2

It is generally fine to put a filesystem on a whole device, rather than partitioning and formatting the partitions, if you do not intend to have more than one filesystem on your device. You will simply have to be consistent; since your put the filesystem on sda rather than sda1, you will have to mount sda as well, since sda1 will not exist at all.

The device in your question appears to be a FAT-formatted removable drive: if it is going to be used with embedded devices that may have a more or less detailed notion of how filesystems can be mounted, it may be worth testing that they do in fact support a whole-device filesystem without a partition table. (For example, cameras tend to create a single partition and format that; it's entirely possible that they would declare a partitionless memory card unusable.)

Share:
20,120

Related videos on Youtube

Alaneuler
Author by

Alaneuler

Updated on September 18, 2022

Comments

  • Alaneuler
    Alaneuler almost 2 years

    I have a pen drive and one partition:

    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda      8:0    0 931.5G  0 disk 
    └─sda1   8:1    0 931.5G  0 part /
    sdb      8:16   1   7.5G  0 disk 
    └─sdb1   8:17   1   7.5G  0 part
    

    and I have formatted with command:

       # mkfs.fat -n A /dev/sdb
    

    and it works fine.

    But after then, I skimmed though the man page for mkfs:

       mkfs is used to build a Linux filesystem on a device,  usually  a  hard
       disk  partition.   The  device argument is either the device name (e.g.
       /dev/hda1, /dev/sdb2),  or  a  regular  file  that  shall  contain  the
       filesystem.   The  size argument is the number of blocks to be used for
       the filesystem.
    

    It says mkfs should work with partition number. And my problem is why my operation works without error prompt?

    • frostschutz
      frostschutz over 7 years
      If you put it in a device that expects a partition table to exist, it might ask you to format... it's usually better to have a partition table even if it's not strictly required.
    • Toby Speight
      Toby Speight over 7 years
      The man page says the the device is usually a hard disk partition. An entire hard disk is also a suitable block device.