Linux: Creating a Filesystem
-
As with any operating system, in Linux we have block devices, create partitions, optionally apply a logical volume manager and on top of all of that we format to a filesystem which we use to store our files. In Linux we do this using the mkfs command.
In normal day to day operations, we will do nearly all work with the ETX4 and the XFS filesystems. But the mkfs command will support many options. We can use the mkfs command directly but how it is done in Linux is a bit odd, but easy. There are actually a large number of commands that start with "mkfs" and end in the name of the filesystem that we want to use. Each of these is not actually a command per se but is actually a symbolic link to one central command. But that's unnecessary to know to use it.
Using tab completion, in Linux Mint in this example, we can type in "mkfs." and hit tab and see all of the available format commands available to us on the existing system:
$ mkfs. mkfs.bfs mkfs.ext2 mkfs.ext4 mkfs.fat mkfs.hfsplus mkfs.minix mkfs.ntfs mkfs.vfat mkfs.cramfs mkfs.ext3 mkfs.ext4dev mkfs.hfs mkfs.jfs mkfs.msdos mkfs.reiserfs mkfs.xfs
That is a few, to be sure. Of those, however, we really only are going to care about a few in the "real world." For normal usage mkfs.xfs, mkfs.ext4 and mkfs.ntfs are the only ones that we are ever likely to use and the last one there would be extremely rare desktop compatibility use cases. Most of these options are legacy and would only exist for research, education or legacy compatibility purposes. The one exception would be mkfs.jfs, but with the power, support and robustness of XFS today, there is little, if any, call to use IBM's JFS filesystem. Note: BFS is not synonimous with BtrFS. The mkfs.bfs command creates an SCO BFS filesystem, not a BtrFS filesystem.
If we have created a new partition from our earlier lesson, let's say that it is
/dev/vda2
and we want to format it as XFS, this is all that we need to do:mkfs.xfs /dev/vda2
That's it. Filesystem specific format command and the block device that we want to format.
If we had a
/dev/sdb1
device and wanted to use the latest Linux Extended Filesystem (EXT4) filesystem, we would do this:mkfs.ext4 /dev/sdb1
For nearly all use cases, this is all that is needed. There are advanced flags available for individual filesystems to allow for detailed tuning such as adjusting block and cluster sizes, relocating meta data and such. But these are rarely used as the defaults are very good and require a lot of careful consideration. We will not cover them here and likely you will not need to use them. If you do, you will want to be consulting documentation at the time of doing so as these are not routine commands. For 99% of use cases, the standard command is sufficient.
Once the mkfs command completes, we now have a fully formatted disk or partition, but it is not yet mounted. So it will not be displayed by the df command at this time.
Part of a series on Linux Systems Administration by Scott Alan Miller
-
Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important
-
@thwr said in Linux: Creating a Filesystem:
Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important
mkswap will be covered separately. It's not quite a filesystem, exactly. EXT2 and vFAT have been dropped from use on /boot on current generation systems. That's a vestige now. Was still common in the RHEL 5 / CentOS 5 era, but has been some time now.
-
@thwr said in Linux: Creating a Filesystem:
Good article, just missing two things here...
If you check the main article, you can see placeholders for a lot of where content will be. Memory management doesn't have a ToC created yet, but it will be coming.
-
@scottalanmiller said in Linux: Creating a Filesystem:
@thwr said in Linux: Creating a Filesystem:
Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important
mkswap will be covered separately. It's not quite a filesystem, exactly. EXT2 and vFAT have been dropped from use on /boot on current generation systems. That's a vestige now. Was still common in the RHEL 5 / CentOS 5 era, but has been some time now.
You are right, but a popular distro using vfat on /boot is Debian-based Raspbian for example.
-
@scottalanmiller said in Linux: Creating a Filesystem:
@thwr said in Linux: Creating a Filesystem:
Good article, just missing two things here...
If you check the main article, you can see placeholders for a lot of where content will be. Memory management doesn't have a ToC created yet, but it will be coming.
great, thanks
-
I'm assuming LVM will be covered separately - I'm trying to understand what it's purpose is versus just using mkfs.
-
@Dashrender said in Linux: Creating a Filesystem:
I'm assuming LVM will be covered separately - I'm trying to understand what it's purpose is versus just using mkfs.
It will be. And it is unrelated. mkfs and lvm do totally different things. Neither replaces the other in any way.