Disks and partitions need to be formatted before it can be mounted and used. Linux by default supports formatting disks and partitions to several filesystem types, which each would come with their pros and cons. Some of the popular supported filesystem types are ext4, Btrfs, and exFAT.
While various graphical tools exist for formatting disks and partitions, most Linux distributions come with the command-line tool mkfs installed by default. This tool is often the foundation for many graphical formatting tools.
Steps to format disk and partition in Linux:
- Open the terminal.
- Display the available disks and partitions on your system.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 55.4M 1 loop /snap/core18/19 loop1 7:1 0 55.4M 1 loop /snap/core18/19 loop2 7:2 0 51M 1 loop /snap/snap-stor loop3 7:3 0 219M 1 loop /snap/gnome-3-3 loop4 7:4 0 217.9M 1 loop /snap/gnome-3-3 loop5 7:5 0 31.1M 1 loop /snap/snapd/104 loop6 7:6 0 62.1M 1 loop /snap/gtk-commo loop7 7:7 0 64.8M 1 loop /snap/gtk-commo loop8 7:8 0 51M 1 loop /snap/snap-stor loop9 7:9 0 31.1M 1 loop /snap/snapd/107 sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 513M 0 part /boot/efi └─sda3 8:3 0 19.5G 0 part / sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part sr0 11:0 1 1024M 0 rom
- Ensure the disk or partition you want to format is not mounted or in use.
$ sudo umount /dev/sdb1 [sudo] password for user: umount: /dev/sdb1: not mounted.
- Verify the supported filesystems for the mkfs command.
$ sudo mkfs. mkfs.bfs mkfs.ext4 mkfs.ntfs mkfs.cramfs mkfs.fat mkfs.vfat mkfs.ext2 mkfs.minix mkfs.ext3 mkfs.msdos
Type mkfs. and press <TAB> twice for the terminal to show possible autompleted commands.
Install necessary package if your desired filestem is not listed or supported.
- Format the disk or partition using your desired filesystem type.
$ sudo mkfs.ext4 /dev/sdb1 mke2fs 1.45.6 (20-Mar-2020) Creating filesystem with 5242624 4k blocks and 1310720 inodes Filesystem UUID: ccab0f8d-3b5b-4189-9da3-23c49159c318 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
- Confirm the current filesystem type to ensure the disk or partition has been formatted successfully.
$ blkid /dev/sdb1 /dev/sdb1: UUID="ccab0f8d-3b5b-4189-9da3-23c49159c318" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c088a647-01"
- Mount the disk or partition as needed.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.