{"id":1061,"date":"2018-07-09T07:55:35","date_gmt":"2018-07-09T02:25:35","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1061"},"modified":"2019-04-27T07:46:33","modified_gmt":"2019-04-27T02:16:33","slug":"how-to-manage-linux-disk-partitions-using-fdisk-commands","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-manage-linux-disk-partitions-using-fdisk-commands\/","title":{"rendered":"How to Manage Linux Disk Partitions using fdisk commands"},"content":{"rendered":"<p><strong>Description<\/strong><\/p>\n<p>fdisk stands (for \u201c<strong>fixed disk<\/strong> or <strong>format disk<\/strong>\u201c) is an most commonly used command-line based disk manipulation utility for a Linux\/Unix systems.<\/p>\n<p>With the help of fdisk command we can <strong>view<\/strong>, <strong>create<\/strong>, <strong>resize<\/strong>, <strong>delete<\/strong>, <strong>change<\/strong>, <strong>copy<\/strong> and <strong>move partitions<\/strong> on a hard drive using its own user friendly text based menu driven interface.<\/p>\n<p>It helps in creating space for new partitions, organising space for new drives, re-organising an old drives and copying or moving data to new disks.<\/p>\n<p>It allows you to create a maximum of four new primary partition and number of logical (extended) partitions, based on size of the hard disk you have in your system.<\/p>\n<p>You must be <strong>root<\/strong> user to run fdisk command, otherwise you will get a \u201c<strong>command not found<\/strong>\u201d error.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. View all Disk Partitions in Linux<\/strong><\/p>\n<p>Below command list all existing disk partition on your system.<\/p>\n<p>The \u2018<strong>-l<\/strong>\u2018 argument stand for (listing all partitions) is used with fdisk command to view all available partitions on Linux.<\/p>\n<p>The partitions are displayed by their device\u2019s names. For example: <strong>\/dev\/sda<\/strong>, <strong>\/dev\/sdb<\/strong> or <strong>\/dev\/sdc<\/strong>.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# fdisk -l\n\nDisk \/dev\/xvda1: 42.9 GB, 42949672960 bytes, 83886080 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 4096 bytes\nI\/O size (minimum\/optimal): 4096 bytes \/ 4096 bytes\n\n\nDisk \/dev\/xvda2: 2147 MB, 2147483648 bytes, 4194304 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 4096 bytes\nI\/O size (minimum\/optimal): 4096 bytes \/ 4096 bytes<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>2. View Specific Disk Partition in Linux<\/strong><\/p>\n<p>To view all partitions of specific hard disk use the option \u2018<strong>-l<\/strong>\u2018 with device name. For example, the following command will display all disk partitions of device \/dev\/sda.<\/p>\n<p>For different device names, simple write device name as<strong> \/dev\/sdb<\/strong> or <strong>\/dev\/sdc<\/strong>.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# fdisk -l \/dev\/sda\nDisk \/dev\/sda: 637.8 GB, 637802643456 bytes\n255 heads, 63 sectors\/track, 77541 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nDevice Boot Start End Blocks Id System\n\/dev\/sda1 * 1 13 104391 83 Linux\n\/dev\/sda2 14 2624 20972857+ 83 Linux\n\/dev\/sda3 2625 4582 15727635 83 Linux\n\/dev\/sda4 4583 77541 586043167+ 5 Extended\n\/dev\/sda5 4583 5887 10482381 83 Linux\n\/dev\/sda6 5888 7192 10482381 83 Linux\n\/dev\/sda7 7193 7845 5245191 83 Linux\n\/dev\/sda8 7846 8367 4192933+ 82 Linux swap \/ Solaris\n\/dev\/sda9 8368 77541 555640123+ 8e Linux LVM<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>3. Check all Available fdisk Commands<\/strong><\/p>\n<p>Use the following command by mentioning the hard disk name such as <strong>\/dev\/sda<\/strong> as shown below.<\/p>\n<p>The following command will give you output similar to below.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# fdisk \/dev\/sda\nWARNING: DOS-compatible mode is deprecated. It's strongly recommended to\nswitch off the mode (command 'c') and change display units to\nsectors (command 'u').\nCommand (m for help):<\/pre>\n<p>Type \u2018<strong>m<\/strong>\u2018 to see the list of all available commands of fdisk which can be operated on <strong>\/dev\/sda<\/strong> hard disk.<\/p>\n<p>After, I enter \u2018m\u2018 on the screen, you will see the all available options for <strong>fdisk<\/strong> that you can be used on the <strong>\/dev\/sda<\/strong> device.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@mail ~]# fdisk \/dev\/sda\nWARNING: DOS-compatible mode is deprecated. It's strongly recommended to\nswitch off the mode (command 'c') and change display units to\nsectors (command 'u').\nCommand (m for help): m\nCommand action\na toggle a bootable flag\nb edit bsd disklabel\nc toggle the dos compatibility flag\nd delete a partition\nl list known partition types\nm print this menu\nn add a new partition\no create a new empty DOS partition table\np print the partition table\nq quit without saving changes\ns create a new empty Sun disklabel\nt change a partition's system id\nu change display\/entry units\nv verify the partition table\nw write table to disk and exit\nx extra functionality (experts only)\nCommand (m for help):<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>4. Print all Partition Table in Linux<\/strong><\/p>\n<p>To print all partition table of hard disk, you must be on command mode of specific hard disk say <strong>\/dev\/sda<\/strong>.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# fdisk \/dev\/sda<\/pre>\n<p>&nbsp;<\/p>\n<p>From the command mode, enter \u2018p\u2018 instead of \u2018m\u2018 as we did earlier.<\/p>\n<p>As I enter \u2018p\u2018, it will print the specific <strong>\/dev\/sda<\/strong> partition table.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">Command (m for help): p\nDisk \/dev\/sda: 637.8 GB, 637802643456 bytes\n255 heads, 63 sectors\/track, 77541 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nDevice Boot Start End Blocks Id System\n\/dev\/sda1 * 1 13 104391 83 Linux\n\/dev\/sda2 14 2624 20972857+ 83 Linux\n\/dev\/sda3 2625 4582 15727635 83 Linux\n\/dev\/sda4 4583 77541 586043167+ 5 Extended\n\/dev\/sda5 4583 5887 10482381 83 Linux\n\/dev\/sda6 5888 7192 10482381 83 Linux\n\/dev\/sda7 7193 7845 5245191 83 Linux\n\/dev\/sda8 7846 8367 4192933+ 82 Linux swap \/ Solaris\n\/dev\/sda9 8368 77541 555640123+ 8e Linux LVM\nCommand (m for help):<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>5. How to Format a Partition in Linux<\/strong><\/p>\n<p>After the new partition is created, don\u2019t skip to format the newly created partition using \u2018<strong>mkfs<\/strong>\u2018 command.<\/p>\n<p>Type the following command in the terminal to format a partition.<\/p>\n<p>Here <strong>\/dev\/sda4<\/strong> is my newly created partition.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# mkfs.ext4 \/dev\/sda4<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>6.How to Check Size of a Partition in Linux<\/strong><\/p>\n<p>After formatting new partition, check the size of that partition using flag \u2018s\u2018 (<strong>displays size in blocks<\/strong>) with fdisk command.<\/p>\n<p>This way you can check size of any specific device.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">[root@mail ~]# fdisk -s \/dev\/sda2\n5194304<\/pre>\n<p>&nbsp;<\/p>\n<p>We hope you\u2019ve found this useful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description fdisk stands (for \u201cfixed disk or format disk\u201c) is an most commonly used command-line based disk manipulation utility for a Linux\/Unix systems. With the help of fdisk command we can view, create, resize, delete, change, copy and move partitions on a hard drive using its own user friendly text based menu driven interface. It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1285,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1061","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1061"}],"version-history":[{"count":1,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1061\/revisions"}],"predecessor-version":[{"id":1063,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1061\/revisions\/1063"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1285"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}