You must create a file system before you can use a data storage device attached to a Linux computer. Learn how to use
mkfs and other utilities to do just that for all types of file systems. We show you how.
mkfs Creates file systems
mkfs creates file systems. On other operating systems, creating a file system is called formatting. Regardless of its name, a partition is prepared to store data. The partition needs a way to save files, yes. However, it also requires a mechanism to store the names and locations of these files along with their metadata such as the file creation timestamp, the timestamp for changing the file, the size of the file, and so on. Once
mkfs has created the required framework for processing and storing file metadata, you can add files to the partition.
The syntax is very simple. All you have to do is tell
mkfs which device partition the file system should be created on and what type of file system you want to be. That's obvious. Behind the scenes it looks a bit different. For some time, mkfs has been a wrapper for
mke2fs on most Linux distributions. The command
mkfs calls the command
mke2fs and gives it the options you have specified. Poor old
mke2fs does all the work, but gets nothing of the honor.
The syntax of
mkfs has been updated, and the old format has been deprecated. Both forms will work, but we will use the modern style in this article.
The Choice of File Systems
The modern way of using
mkfs is to enter "mkfs" and then "." Name of the file system to be created.
To display the file systems that can create
mkfs type "mkfs" and press the Tab key twice. There is no space after "mkfs". Just press the Tab key twice.
The list of available file systems is displayed in the terminal window. The screenshot comes from Ubuntu 18.04 LTS. Other distributions may offer more or fewer options. We will go over these and briefly describe them. After a short word about journaling.
Journaling is an important concept in file systems. The file system records the pending file descriptions in a journal. As each file is written, the journal is updated and the pending write records are updated. In this way, the file system can repair damaged, partially written files that have occurred due to a catastrophic event, such as a power failure. Some older file systems do not support journaling. Those who do not write less frequently to the hard drive because they do not need to update the journal. They may work faster but are more prone to corruption due to interrupted file writes.
- Ext2 : The very first file system for Linux was the MINIX file system. It was later replaced by the first file system written specifically for Linux, Ext. Ext2 was the successor to Ext. Ext2 is not a journaling file system.
- Ext3 : This was the successor of Ext2 and can be considered Ext2 with journaling, protecting your file system from data corruption due to crashes and sudden power outages.  Ext4 : Ext4 is the standard file system for Linux distributions. It's a solid, proven and trusted file system. It has features that reduce file fragmentation and can be used with Ext3 to drive larger volumes, partitions, and files.
- BFS : This is the boot file system developed for a job and a single job: for processing files in the boot partition. It is rare for you to create a startup file system by hand. Your Linux installation process does it for you.
- FAT : The File Allocation Table file system was developed by a consortium of computer industry heavyweights for diskettes. It was introduced in 1977. The only reason you use this non-journaling file system is compatibility with non-Linux operating systems.
- NTFS : The New Technology File System is a Microsoft Windows NT journaling file system. It was the successor to FAT. You should only use this file system for compatibility with non-Linux operating systems.
- MINIX : MINIX was originally created by Andrew S. Tanenbaum as a learning aid and is a "mini Unix" operating system. Today, it aims to provide a self-healing and fault-tolerant operating system . The file system MINIX was developed as a simplified version of the Unix file system. If you are cross-developing on a Linux computer and targeting a MINIX platform, you can use this file system. Or you might need compatibility with a MINIX computer for other reasons. Use Cases for this file system on a Linux computer do not jump me out of the way, but it is available.
- VFAT : The virtual file mapping table was introduced in Windows 95, removing the restriction to eight filename characters. File names up to 255 characters were possible. You should only use this file system for compatibility with non-Linux operating systems.
- CRAMFS : The Compressed ROM File System is a read-only file system designed for embedded systems and special read-only applications B. when booting Linux computers. It is common practice to first load a small, temporary file system so bootstrap processes can be started to prepare the "real" boot system for mounting.
- MSDOS : The file system of the Microsoft Disk Operating System. It was released in 1981 and is a basic file system. The first version did not even have directories. It has a prominent position in computer history, but there is little reason to use it today except for compatibility with older systems.
RELATED: Which Linux file system should you use?  A safe way to experiment with file systems
Creating a file system on a partition destroys any data that may already be on that partition. Using a replacement hard drive – or even a replacement computer – is the perfect way to experiment with creating and using different file systems. But of course, many people do not have spare hardware waiting to be experimented.
However, we can create an image file and create file systems within it. Once we have it mounted, we can use it as if it were a regular partition. We can explore file systems and experiment with them without the need for additional hardware. We will use the command
dd to create our image file.
The image file is created by taking source data and pasting it into an image. We have to tell
dd where the source data should come from. With the option
if (inputfile), we assign
dd to use / dev / zero as the input data source. This will be a stream of zeros.
With the option
of (output file) we can specify a name for the image file. We call it "howtogeek.img".
The size of the image file is determined by the size and number of blocks added. We use the option
bs (block size) to request a block size of 1 MB, and the option
count to request 250 blocks. This gives us a file system of 250 MB. When you issue this command, adjust the number of blocks to suit your needs and the available free space on your Linux computer.
dd if = / dev / zero of = ~ / howtogeek.img bs = 1M count = 250  dd if = / dev / zero of = ~ / howtogeek.img bs = 1M count = 250 " width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>  The file was created for us and
ddindicates that 250 blocks were created for us, as requested.
We can look at our image file with
ls:ls -hl  ls -hl in a terminal window " width="646" height="97" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
It is expected to be 250 MB, which is encouraging.
Creating the file system
Select a file system to use. We go back in time and use Ext2, the earliest version of Ext, that can be created with this implementation of
mkfs. This is a non-journal file system. Do not save important data in it without making backup copies elsewhere. We use the
mkfs.ext2variant of the
-mkfscommand and instruct them to target our image file.mkfs.ext2 ~ / howtogeek.img  mkfs.ext2 ~ / howtogeek.img in a terminal window " width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
The file system is created and some details of the file system are displayed.
As you can see in the highlighted text,
Now we have a container for the file system - the image file - for which there is a disk in this scenario. In this container we have created a file system. Now we have to deploy the file system so that we can use it.
This is a temporary setup, so we create a mount point in / mnt named "geek". We will remove it when we & # 39; re finished.sudo mkdir / mnt / geek [19659050[mkfsext2~/howtogeekimgineeinterminalwindow" width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
Now we can mount our image file.sudo mount ~ / howtogeek. img / mnt / geek [19659053<mkfsext2~/howtogeekimgineinaterminalwindow" width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>
We need to change the file-location of the mountpoint so that we have read and write access to it.sudo chown dave: user / mnt / geek /
And now we should be able to use our new file system. Let's go to the file system and copy some files to it.cd / mnt / geekcp ~ / Documents / Code / *.? ,
This will copy all files with a one-letter extension from the ~ / Documents / Code directory to our new file system. Let's check if they have been copied.ls
The files were copied so our file system was created, mounted and used. At least we think. Let's check it again. In our home directory, we will unmount the file system. Note that umount has only one "n".sudo umount / mnt / geek
Well, if we return to / mnt / geek and search for files, we should not find any since they are in our image file and it was not mounted.cd / mnt / geekls
RELATED: Mounting and Unhinging Storage Devices from the Linux Terminal
Now we have worked out the process and another tried file system should be simple. We will use the MINIX file system this time. In our home directory, we can create a new file system in our existing image file.
Be careful! If important files are in the file system in the image file, mount the image file. and call it before you create a new file system.mkfs.minix ~ / howtogeek.image
None When asked if you are sure, the new file system will be created over the old one , We can mount our image file with exactly the same command as before:sudo mount ~ / howtogeek.img / mnt / geek
 Jump we in the new file system under / mnt / geek and check if we can create a file.Touch geek.txt
ls -ahl geek.txt
And So easy and fast, we have created a new file system, have it mounted and can use it.
Remove mount point
When you're done, you can remove the geek mount point. To do this, we use rmdir:cd / mntsudo rmdir geek
Under Linux, as with most things, you learn by doing. The problem with some commands is that they are potentially destructive. The dilemma is how you can practice using them without jeopardizing your system or data.
mkfsyou can now easily create and test file systems without affecting your computer.