Updated April 20, 2023
Introduction of Linux Format
In the Linux operating system, we are using the Linux format to format the disk or any external storage device. There are different types like btrfs, ext2, ext4, xfs, cramfs, ext3, minix. This format is compatible with the Linux operating system. As per the compatibility in terms of the application or the job status, we can choose the respective Linux format. It is mainly used to format the external block storage. There are lots of different utility available in this format the internal and external disk like fdisk, etc. In the fdisk, the FDISK_DEBUG variable was enabled to debug the output. The value for the same variable is “0xffff”.
Syntax
[Format Method] [Options] [Device Name]fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
- fdisk: We can use the “fdisk” keyword in the syntax or command. It will take different arguments like sector information, header, different options, etc. As per the provided arguments, it will format the input storage.
- options: We can provide the different flags as the option that is compatible with the “fdisk” command.
- device or device path: As per the condition, we can provide the path of the device or device reference to the fdisk command.
How Linux Format Works?
In the Linux environment, we are having multiple tools and utilities to format the external and internal storage. For formatting the storage disk, generally we are using the fdisk utility. It will take the inputs like sector information, cylinder, format type or any manual inputs. As per the input arguments, the fdisk command will format the input disk.
Below is the list of option, we can use it while formatting the disk.
Option | Description |
-b sectorsize | It will help to specify the sector size of the input disk. This option will accept the values like 512, 1024, 2048 and 4096. In the older kernel, we need to use these values otherwise in the kernel there is no need to define the values. |
-c[=mode] | It will help to define the compatibility mode i.e. dos or nondos. The default value is the non-DOS mode. It is possible to use the mode with option (in the backward compatibility) |
-C cyls | It will help to specify the number of cylinders of the input disk. But in the newer versions, this option is DEPRECATED. |
-H heads | It will help to specify the number of heads on the input disk. Basically is not highlighting the physical number but the number of used partition tables, etc. the compatible values are 16 and 255. |
-S sects | It will help to specify the number of sectors per track on the input disk. Basically is not highlighting the physical number but the number of used partition tables, etc. the compatible value is 63 |
-h | It will help to print the number of compatible option and exit it |
-l | It will list the partition tables of the input disk and exit it. |
-s partition… | It will display the size of the input partition. The size will display in terms of blocks |
-u[=unit] | It will help to list the partition tables and display the sector and cylinder information. By default, it will show the size in sectors. |
-v | It will print the version information of the fdisk command or program and exit it |
Examples
Following are the examples are given below:
Linux Format – List of Disk
In the Linux environment, we are able to list down the number of disk associated with the environment. We need to use the “-l” option with the command.
Command:
fdisk -l
Output:
Explanation: As per the above command, we are able to list out the number of storage device information of the Linux environment.
Linux Format – View with Specific Disk
In Linux, there are multiple disks may present but we can choose the appropriate disk on which we need to work.
Command:
fdisk -l /dev/sda
Output:
Explanation: As per the above command, we are finding the sub storage information associated with the “/dev/sda” storage.
Linux Format – Print List of Available Option
While working with the Linux format, we need to choose any storage. Once, we will choose the storage. We can explore different option available with the same functionality.
Command:
fdisk /dev/sda
Output:
Explanation: If we are using the fdisk utility to format the Linux storage, we will get the number of option with it. In below screenshot, you will get the list of option available with it.
Linux Format – Format the Linux Disk or Storage with MKFS
In Linux, we are having the functionality to format any type of storage. While formatting we need to take care of the format type.
Note: Once the data will be formatted, it would be different to recover the data (as per the option we have used while doing formatting the storage). Hence, we will be very careful while formatting any storage device.
Command:
umount /mount_dir/
mkfs.ext4 /dev/sdb
Output:
Screenshot 1 (a)
Screenshot 1 (b)
Explanation: In the screenshot 1 (a), we are seeing the “/dev/sdb” storage is mounted with “/mount_dir” directory and consumed the 4.1 GB of data. With the help of mkfs utility, we are formatting the storage device “/dev/sdb” with ext4 format (refer screenshot 1 (b)).
Linux Format – Format the Linux Disk or Storage with FDISK
In Linux, we are able to format or delete the storage with the help of fdisk also.
Command:
fdisk /dev/sdb
choose the partition number user the “d” option
Output:
Explanation: As per the above command, we are deleting or formatting the “/dev/sdb1” partition.
Conclusion
We have seen the uncut concept of “Linux Format” with the proper example, explanation and command with different outputs. As per the requirement, we are able to format the different storage devices in the Linux environment. As per the application or job compatibility, we need to choose the format type.
Recommended Articles
We hope that this EDUCBA information on “Linux Format” was beneficial to you. You can view EDUCBA’s recommended articles for more information.