Linux fdisk Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-fdisk-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Hi, creating and deleting partitions in linux generally done in cli which makes some user confused. Here I will look it more detail but if you prefer gui you can use gparted too

Man

In order to get more detailed help man page of fdisk can be used.

Man

Man

Help

Simple and fast way to get fdisk options with the parameters following command can be used.

Help

Help

List Disks

Disk on the Linux system can be listed with the following fdisk command. In order to get detailed information about disks fdisk need root privileges. In the recent versions of Ubuntu the special disk named ram disks also listed with -l parameter.

List Disk

List Disk

As we see from the screenshot information like disk name, path, size, sectors count, logical and physical sector sizes are provided with the command.

Fdisk Interactive Shell

Most of the features of fdisk is provided by interactive shell provided by fdisk. In order to start this shell the disk we want to operate should be provided like below.

Interactive Shell

Interactive Shell

List Partitions

We assume we are in the interactive fdisk shell with the related disk. In the fdisk shell which is shortcut of print will list partition information

OR

Disk listing command will provide partition list too

List Partitions Of Specific Disk

There are situations to only list specific disks partitions this can be accomplished by specifying disk path like below.

LEARN MORE  Awk Print Tutorial With Examples

List Partitions Of Specific Disk

List Partitions Of Specific Disk

Shell Help

Interactive shell provides a lot of operations and commands. These commands can be get with the following command.

Shell Help

Shell Help

Change Partition Type

As we now there are a lot of file system or partition type. Windows systems generally uses FAT,VFAT, NTFS on the other hand Linux/Unix systems prefer ext3,ext4,btrfs,xfs like file systems. Partition file system type can be specified with command.

Now we will select our partition number where for this example we haveonly one partition and selected by default.

To set required partition type we can get list of supported partition types with command like below.

Linux type partition is OK for us which number is 83. we enter partition type number. By default all newly created partitions types are created as Linux partition type.

Change Partition Type

Change Partition Type

Write Changes To Disk

While using fdisk interactive shell modifications are done in the ram which means they are no effective if we do not write them to the disks. We should write change to the disk with like below.

Write Changes To Disk

Write Changes To Disk

Re-Read Disk Changes

After writing disk changes to the disk because of some kernel performance mechanisms they are not directly written. So to make them effective from kernel side following command should be provided in the bash.

Format Disk Dos Partition Table

Every disks will have their own partition table to identify partitions their sizes, boot options etc. DOS is most used partition table because of the Windows popularity. DOS was default partition table for Windows operating systems. DOS partition table can only use up to 2 TB disks so use with cautiously. Because of the architectural restrictions DOS partition table can not use more than 2 TB

LEARN MORE  Qemu Tutorial

Format Disk GPT Partition Table

GPT partition table is newer than DOS and fixes DOS partition table restrictions like disk size. GPT table supports disks bigger than 2 TB. To create new GPT partition table use following command.

Format Disk GPT Partition Table

Format Disk GPT Partition Table

Create Partition

Partition are specified parts of the disks. Partitions provides logical boundaries and makes disk multi part for different usage scenarios. First we will provide new partition command .

Then provide partition type with 

Now we will provide partition number which is by default 1.

First sector of this partition. If we have no specific requirements we can use default one which is 2048

The most important part is last sector number or size. We will set end boundary for this partition. If we enter without any parameter which will use default sector number which is the last unused sector on the disk. Alternative way is specifying disk size in kilobyte,megabyte, gigabyte, terabyte, petabyte. For example to create 10 GB partitions use +10G

Create Partition

Create Partition

Delete Partition

Created partitions can be deleted easily with command 

Delete Partition

Delete Partition

If there is more than one partition the partition number is asked. In example above it is not asked because of there is only one partition.

Partition Information

Detailed information about the partitions can be get in the interactive shell with command.

Partition Information

Partition Information

List Unpartitioned Disk Space

Partitions provides segmentation of disks for different usage scenarios. Some partitions can be created later and for these partitions some free or unpartitioned space can be left. Unpartitioned space can be listed with command F.

LEARN MORE  limits.conf File To Limit Users, Process In Linux With Examples

List Unpartitioned Disk Space

List Unpartitioned Disk Space

Enable Boot Flag

Partitions those contains operating systems like Windows, Linux, Unix should be flagged as bootable. Partitions can be made bootable with command a . Actually command will toggle boot able flag which means if current flag is not bootable it will change to boot able vice versa.

Enable Boot Flag

Enable Boot Flag

Verify Partition Table

Partition tables can be simply verified like below.

Verify Partition Table

Verify Partition Table

Quit/Exit

After completing operations to quit or exit from fdisk interactive shell command can be used. Do not forget to save changes if you need them.

Quit/Exit

Quit/Exit

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-fdisk-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

1 Response

  1. 07/06/2017

    […] Linux fdisk Tutorial With Examples […]

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)