How to format a new Linux partition with the command line.

Posted: March 26, 2016. At: 12:26 PM. This was 1 year ago. Post ID: 8820

This is how to format a hard disk partition that will hold data for your Linux system. The partition must be unmounted before formatting, but this is the ideal way to create a file-system on a new partition that has been created with fdisk.

[email protected]:~# mkfs.ext4
mkfs.ext4     mkfs.ext4dev  
[email protected]:~# mkfs.ext4 /dev/sdd3 
mke2fs 1.42.13 (17-May-2015)
/dev/sdd3 contains a xfs file system
Proceed anyway? (y,n) y
Creating filesystem with 57308349 4k blocks and 14327808 inodes
Filesystem UUID: 3c9ff4b7-0a4d-46bd-8499-238f66e1b840
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872
 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Now I can list all of the partitions on the hard disk and see the one I have recently formatted.

[email protected]:~# fdisk -l /dev/sdd
Disk /dev/sdd: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa8a8a8a8
 
Device     Boot     Start       End   Sectors   Size Id Type
/dev/sdd1            2048 390625279 390623232 186.3G 83 Linux
/dev/sdd2       450562048 518146032  67583985  32.2G 83 Linux
/dev/sdd3       518305792 976772588 458466797 218.6G 83 Linux
/dev/sdd4       390627326 450562047  59934722  28.6G  5 Extended
/dev/sdd5       390627328 406249471  15622144   7.5G 82 Linux swap / Solaris
/dev/sdd6       406251520 450562047  44310528  21.1G 83 Linux
 
Partition table entries are not in disk order.

Here I am mounting the new partition and it works.

root@jason-desktop:/mnt# mount /dev/sdd3 /mnt/lfsdisk/
root@jason-desktop:/mnt# cd lfsdisk/
root@jason-desktop:/mnt/lfsdisk# ls -huila
total 24K
      2 drwxr-xr-x 3 root root 4.0K Mar 26 12:27 .
8257537 drwxr-xr-x 4 root root 4.0K Mar 26 12:27 ..
     11 drwx------ 2 root root  16K Mar 26 12:09 lost+found

This is another way to list all block devices on the system.

[email protected]:~# lsblk 
NAME   MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
sda      8:0    0    1.8T  0 disk 
└─sda1   8:1    0    1.8T  0 part /media/jason/Seagate Backup Plus Drive
sdb      8:16   0    1.8T  0 disk 
├─sdb1   8:17   0    100M  0 part 
└─sdb2   8:18   0    1.8T  0 part 
sdc      8:32   0    1.8T  0 disk 
├─sdc1   8:33   0 1002.3G  0 part 
├─sdc2   8:34   0  683.4G  0 part 
└─sdc3   8:35   0  177.3G  0 part 
sdd      8:48   0  465.8G  0 disk 
├─sdd1   8:49   0  186.3G  0 part 
├─sdd2   8:50   0   32.2G  0 part 
├─sdd3   8:51   0  218.6G  0 part 
├─sdd4   8:52   0      1K  0 part 
├─sdd5   8:53   0    7.5G  0 part 
└─sdd6   8:54   0   21.1G  0 part 
sde      8:64   0  298.1G  0 disk 
├─sde1   8:65   0  292.2G  0 part /
├─sde2   8:66   0      1K  0 part 
└─sde5   8:69   0      6G  0 part [SWAP]
sr0     11:0    1    4.2G  0 rom

No comments have been made. Use this form to start the conversation :)

Leave a Reply