A disk partition must be formatted and mounted before use. The formatting process can also be done for several other reasons, such as changing the file system, fixing errors, or deleting all data.
Here at Fixwebnode, as part of our Server Management Services, we regularly help our Customers to perform related Linux system Disk Partitions queries.
In this context, we shall look into how to format and mount disk partitions in Linux using ext4, FAT32, or NTFS file system.
Table of contents [Show]
Steps to format and mount a partition in Linux
1. Check the Partitions
Before formatting, locate a partition you wish to format. To do so, run the lsblk command that displays block devices:$ lsblk
Block devices are files that represent devices such as hard drives, RAM disks, USB drives, and CD/ROM drives.
The output of the above command will give a list of all block devices as well as information about them:
- NAME – Device names.
- MAJ:MIN – Major or minor device numbers.
- RM – Whether the device is removable (1 if yes, 0 if no).
- SIZE – The size of the device.
- RO – Whether the device is read-only.
- TYPE – The type of the device.
- MOUNTPOINT – Device's mount point.
For example, lets say we are dealing with the /dev/sdb1 partition, the lsblk command without additional options does not display information about the device's file systems.
To display a list containing file system information, add the -f option:$ lsblk -f
The terminal prints out the list of all block devices. The partitions that do not contain information on the file system in use are non-formatted partitions.
2. Format Disk Partition in Linux
The general syntax for formatting disk partitions in Linux is:$ mkfs [options] [-t type fs-options] device [size]
The best way to format disk partitions using the mkfs command, depending on the file system type is outlined below:
- ext4
- FAT32
- NTFS
How to Format Disk Partition with ext4 File System ?
To Format Disk Partition with ext4 File System, do the following steps:
i. Format a disk partition with the ext4 file system using the following command:$ sudo mkfs -t ext4 /dev/sdb1
ii. Next, verify the file system change using the command:$ lsblk -f
The terminal prints out a list of block devices.
iii. Locate the preferred partition and confirm that it uses the ext4 file system:$ sudo mkfs -t ext4 /dev/sdb1
How to Format Disk Partition with FAT32 File System ?
To do this, follow the below steps accordingly:
i. To format a disk with a FAT32 file system, run:
$ sudo mkfs -t vfat /dev/sdb1
ii. Next, run the lsblk command to verify the file system change and locate the preferred partition from the list:
$ lsblk -f
How to Format Disk Partition with NTFS File System ?
To do this, follow the below steps:
i. Run the mkfs command and specify the NTFS file system to format a disk:$ sudo mkfs -t ntfs /dev/sdb1
The terminal prints a confirmation message when the formatting process completes.
ii. Next, verify the file system change by executing the below command:$ lsblk -f
iii. Locate the preferred partition and confirm that it uses the NFTS file system:$ sudo mkfs -t ntfs /dev/sdb1
3. Mount the Disk Partition in Linux
Before using the disk, create a mount point and mount the partition to it. A mount point is a directory used to access data stored in disks. Follow the below steps:
i. Create a mount point by running:$ sudo mkdir -p [mountpoint]
ii. Next, mount the partition by using the following command:$ sudo mount -t auto /dev/sdb1 [mountpoint]
Note: Replace [mountpoint] with the preferred mount point (example:/usr/media).
There is no output if the process completes successfully.
iii. Verify if the partition is mounted using the following command:$ lsblk -f
[Need help in fixing Linux disk partitions issues ? We can help you. ]
This article covers how to manage disk partitions in Linux. In fact, It supports various partition tables and lets you create, delete, and modify disk partitions, so you can utilize the disk space effectively to install operating systems, back up your data, and organize your files.
Now you can manage disk partitions in Linux easily and subsequently be able to get more out of the storage, b