{"id":4790,"date":"2018-12-08T17:21:46","date_gmt":"2018-12-08T17:21:46","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=4790"},"modified":"2018-12-11T04:53:31","modified_gmt":"2018-12-11T04:53:31","slug":"how-to-use-fdisk-in-linux-linux-hint","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/08\/how-to-use-fdisk-in-linux-linux-hint\/","title":{"rendered":"How to Use fdisk in Linux \u2013 Linux Hint"},"content":{"rendered":"<p>fdisk<\/p>\n<p>is a tool for partitioning hard drives (HDDs), solid state drives (SSDs), USB thumb drives etc. The best thing about fdisk is that it is installed by default on almost every Linux distribution these days. Fdisk is also very easy to use.<\/p>\n<p>In this article, I will show you how to use fdisk to partition storage devices such as HDDs, SSDs, and USB thumb drives in Linux. So, let\u2019s get started.<\/p>\n<p>In Linux, the block devices or hard drives has unique identifiers such as sda, sdb, sdc etc. Before you start partitioning your hard drive, you must make sure that you\u2019re partitioning the right one. Otherwise, you may lose data in the process.<\/p>\n<p>You can use fdisk to list all the storage\/block devices on your Linux computer with the following command:<\/p>\n<p>As you can see, I have a hard drive (sda) and a USB thumb drive (sdb) attached to my computer. The lsblk command also lists the partitions. The raw storage device has the TYPE disk. So, make sure you don\u2019t use a partition identifier instead of raw disk identifier.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/1-4.png\" alt=\"\" width=\"979\" height=\"256\" \/><\/p>\n<p>As you can see, the hard drive (sda) is 20GB in size and the USB thumb drive (sdb) is 3.8GB in size.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/2-4.png\" alt=\"\" width=\"979\" height=\"256\" \/><\/p>\n<p>You can access the device identifier, let\u2019s say sdb, as \/dev\/sdb.<\/p>\n<p>In the next section, I will show you how to open it with fdisk.<\/p>\n<h2>Opening Storage Devices with fdisk:<\/h2>\n<p>To open a storage\/block device with fdisk, first, you have to make sure that none of its partition is mounted.<\/p>\n<p>Let\u2019s say, you want to open your USB thumb drive \/dev\/sdb with fdisk. But, it has a single partition \/dev\/sdb1, which is mounted somewhere on your computer.<\/p>\n<p>To unmount \/dev\/sdb1, run the following command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/3-4.png\" alt=\"\" width=\"995\" height=\"82\" \/><\/p>\n<p>Now, open \/dev\/sdb with fdisk with the following command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/4-4.png\" alt=\"\" width=\"985\" height=\"82\" \/><\/p>\n<p>As you can see, \/dev\/sdb storage\/block device is opened with fdisk.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/5-4.png\" alt=\"\" width=\"986\" height=\"209\" \/><\/p>\n<p>In the next sections, I will show you how to use the fdisk command line interface to do common partitioning tasks.<\/p>\n<h3>Listing Existing Partitions with fdisk:<\/h3>\n<p>You can press p and then press &lt;Enter&gt; to list all the existing partitions of the storage\/block device you opened with fdisk.<\/p>\n<p>As you can see in the screenshot below, I have a single partition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/6-4.png\" alt=\"\" width=\"1070\" height=\"266\" \/><\/p>\n<h3>Creating a New Partition Table with fdisk:<\/h3>\n<p>A partition table holds information about the partition of your hard drive, SSD or USB thumb drive. DOS and GPT are the most common types of partition table.<\/p>\n<p>DOS is an old partition table scheme. It is good for small size storage devices such as a USB thumb drive. In a DOS partition table, you can\u2019t create more than 4 primary partitions.<\/p>\n<p>GPT is the new partition table scheme. In GPT, you can have more than 4 primary partitions. It is good for big storage devices.<\/p>\n<p>With fdisk, you can create both DOS and GPT partition table.<\/p>\n<p>To create a DOS partition table, press o and then press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/7-4.png\" alt=\"\" width=\"1021\" height=\"96\" \/><\/p>\n<p>To create a GPT partition table, press g and then press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/8-4.png\" alt=\"\" width=\"1000\" height=\"92\" \/><\/p>\n<h3>Creating and Removing Partitions with fdisk:<\/h3>\n<p>To create a new partition with fdisk, press n and then press &lt;Enter&gt;.<\/p>\n<p>Now, enter the partition number and press &lt;Enter&gt;. Usually, the default partition number is okay. So, you can just leave it as it is unless you want to do something very specific.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/9-4.png\" alt=\"\" width=\"1007\" height=\"71\" \/><\/p>\n<p>Now, enter the sector number on your hard drive from which you want the partition to start from. Usually, the default value is alright. So, just press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/10-4.png\" alt=\"\" width=\"1032\" height=\"76\" \/><\/p>\n<p>The last sector number or size is the most important here. Let\u2019s say, you want to create a partition of size 100 MB, you just type in +100M here. For 1GB, you type in +1G here. The same way, for 100KB, +1K. For 2TB, +2T. For 2PT, +2P. Very simple. Don\u2019t type in fractions here, only type in real numbers. Otherwise, you will get an error.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/11-4.png\" alt=\"\" width=\"1025\" height=\"436\" \/><\/p>\n<p>As you can see, I created a 100MB partition. The partition is created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/12-4.png\" alt=\"\" width=\"1008\" height=\"182\" \/><\/p>\n<p>If you had a partition that started and ended in the same sector before, you may see something like this. Just, press y and then press &lt;Enter&gt; to remove the partition signature.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/13-4.png\" alt=\"\" width=\"1008\" height=\"182\" \/><\/p>\n<p>As you can see, fdisk tells you that when you write the changes, the signature will be removed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/14-3.png\" alt=\"\" width=\"1000\" height=\"245\" \/><\/p>\n<p>I am going to create another partition of 1GB in size.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/15-4.png\" alt=\"\" width=\"1004\" height=\"171\" \/><\/p>\n<p>I am going to create another 512MB partition just to show you how to remove partitions with fdisk.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/16-4.png\" alt=\"\" width=\"1006\" height=\"161\" \/><\/p>\n<p>Now, if you list the partitions, you should be able to see the partitions that you created. As you can see, the 100MB, 1GB and 512MB partitions that I just created are listed here.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/17-3.png\" alt=\"\" width=\"1006\" height=\"271\" \/><\/p>\n<p>Now, let\u2019s say you want to delete the third partition \/dev\/sdb3 or the 512MB partition. To do that, press d and then press &lt;Enter&gt;. Now, type in the partition number and press &lt;Enter&gt;. In my case, it is the partition number 3.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/18-2.png\" alt=\"\" width=\"1006\" height=\"63\" \/><\/p>\n<p>As you can see, partition number 3 is deleted.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/19-1.png\" alt=\"\" width=\"1019\" height=\"141\" \/><\/p>\n<p>As you can see, the 512MB partition or the 3rd partition is no more.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/20-1.png\" alt=\"\" width=\"1020\" height=\"258\" \/><\/p>\n<p>To permanently save the changes to the disk, press w and then press &lt;Enter&gt;. The partition table should be saved.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/21-1.png\" alt=\"\" width=\"997\" height=\"132\" \/><\/p>\n<h4>Formatting and Mounting Partitions:<\/h4>\n<p>Now that you\u2019ve created some partitions using fdisk, you can format it and start using them. To format the second partition, let\u2019s say \/dev\/sdb2, to ext4 filesystem, run the following command:<\/p>\n<p>$ sudo mkfs.ext4 -L MySmallPartition \/dev\/sdb2<\/p>\n<p><u>NOTE:<\/u> Here, MySmallPartition is the label for the \/dev\/sdb2 partition. You can put anything meaningful here that describes what this partition is for.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/22-1.png\" alt=\"\" width=\"993\" height=\"84\" \/><\/p>\n<p>The partition is formatted to ext4 filesystem.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/23-1.png\" alt=\"\" width=\"982\" height=\"313\" \/><\/p>\n<p>Now that the partition \/dev\/sdb2 is formatted to ext4, you can use the mount command to mount it on your computer. To mount the partition \/dev\/sdb2 to \/mnt, run the following command:<\/p>\n<p>$ sudo mount \/dev\/sdb2 \/mnt<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/24-1.png\" alt=\"\" width=\"982\" height=\"84\" \/><\/p>\n<p>As you can see, the partition \/dev\/sdb2 is mounted successfully to \/mnt mount point.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/25-1.png\" alt=\"\" width=\"996\" height=\"299\" \/><\/p>\n<p>So, that\u2019s how you use fdisk in Linux to partition disks in Linux. Thanks for reading this article.<\/p>\n<p><a href=\"https:\/\/linuxhint.com\/fdisk_in_linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>fdisk is a tool for partitioning hard drives (HDDs), solid state drives (SSDs), USB thumb drives etc. The best thing about fdisk is that it is installed by default on almost every Linux distribution these days. Fdisk is also very easy to use. In this article, I will show you how to use fdisk to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/08\/how-to-use-fdisk-in-linux-linux-hint\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Use fdisk in Linux \u2013 Linux Hint&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4790","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=4790"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4790\/revisions"}],"predecessor-version":[{"id":5528,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4790\/revisions\/5528"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=4790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=4790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=4790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}