Posted: . At: 8:08 AM. This was 3 months ago. Post ID: 19083
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Using fdisk to list and create partitions on a hard drive.


Using fdisk to create and list partitions on a hard drive is very easy. This is a very useful skill.

To list free space on a hard disk, load fdisk.

[root@localhost jcartwright]# fdisk /dev/sdf

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Then press F and hit ENTER.

Command (m for help): F
Unpartitioned space /dev/sdf: 292.45 GiB, 314017800192 bytes, 613316016 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

    Start       End   Sectors   Size
     2048 613312511 613310464 292.4G
703277056 703282607      5552   2.7M

Command (m for help):

This shows that we have 292 GiB of free space to create a disk partition.

Then, press n and hit ENTER to create a new partition.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-703282607, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-613312511, default 613312511): +285G

This sets the partition type as primary, it is a partition starting at the sector 2048 and is 285 Gigabytes in size.

Now, press p and hit ENTER, this will list all the partitions in the partition table.

Command (m for help): p

Disk /dev/sdf: 335.35 GiB, 360080695296 bytes, 703282608 sectors
Disk model: 0AS             
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xea334b06

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdf1  *    613312512 703277055  89964544 42.9G  7 HPFS/NTFS/exFAT
/dev/sdf2            2048 597690367 597688320  285G 83 Linux

Partition table entries are not in disk order.

Press w and hit ENTER to save and exit.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost jcartwright]#

To format the new partition, use mkfs to create a filesystem.

[root@localhost jcartwright]# mkfs.ext4 /dev/sdf2 
mke2fs 1.46.5 (30-Dec-2021)
/dev/sdf2 contains a LVM2_member file system
Proceed anyway? (y,N) y
Creating filesystem with 74711040 4k blocks and 18677760 inodes
Filesystem UUID: 165368c4-1ad7-43a4-b70c-80fabe5e8838
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

After this, the filesystem will be mountable in the file manager. This is very easy to do, this makes it simple to create a new partition on a HDD.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.