{"id":6205,"date":"2018-12-27T20:52:26","date_gmt":"2018-12-27T20:52:26","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=6205"},"modified":"2018-12-28T23:03:41","modified_gmt":"2018-12-28T23:03:41","slug":"how-to-use-parted-on-linux-linux-hint","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/27\/how-to-use-parted-on-linux-linux-hint\/","title":{"rendered":"How to use parted on Linux \u2013 Linux Hint"},"content":{"rendered":"<p>Parted is a command line tool for managing disk partitions on Linux. Parted can be used to work with both MSDOS and GPT partition tables. Parted can be used to do many low level partitioning tasks easily. In order to use parted correctly, you will need a lot of knowledge on the physical structure of the disk such as the block size of the disk. In this article, I will show you how to use parted on Linux. I will be using Ubuntu 18.04 LTS for the demonstration. So, let\u2019s get started.<\/p>\n<p>If you\u2019re using Ubuntu or any Debian based Linux distributions, then you can easily install parted as it is available in the official package repository. First, update the APT package repository cache with the following command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/1-28.png\" alt=\"\" width=\"1140\" height=\"91\" \/><\/p>\n<p>The APT package repository cache is updated.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/2-25.png\" alt=\"\" width=\"1140\" height=\"366\" \/><\/p>\n<p>Now, run the following command to install parted:<\/p>\n<p>$ sudo apt install parted<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/3-23.png\" alt=\"\" width=\"1138\" height=\"98\" \/><\/p>\n<p>Now, press y and then press &lt;Enter&gt; to continue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/4-22.png\" alt=\"\" width=\"1128\" height=\"353\" \/><\/p>\n<p>Parted should be installed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/5-23.png\" alt=\"\" width=\"1132\" height=\"352\" \/><\/p>\n<p>On CentOS\/RHEL 7, you can install parted with the following command:<\/p>\n<p>$ sudo yum install parted -y<\/p>\n<h2>Finding Storage Device Identifiers:<\/h2>\n<p>Before you can start working with parted, you have to know which storage device you need to partition.<\/p>\n<p>You can run the following command to list all the attached storage devices on your computer:<\/p>\n<p>$ sudo lshw -class disk -short<\/p>\n<p>As you can see, I have 2 storage devices on my computer, \/dev\/sda and \/dev\/sdb. Here, \/dev\/sdb is my 32GB USB thumb drive. This is the one I want to partition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/6-22.png\" alt=\"\" width=\"1139\" height=\"235\" \/><\/p>\n<h3>Opening Storage Device with parted:<\/h3>\n<p>Now that you know which storage device you want to partition, you can open parted as follows:<\/p>\n<p><u>NOTE:<\/u> Make sure you change \/dev\/sdb to the storage device that you want to partition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/7-23.png\" alt=\"\" width=\"826\" height=\"93\" \/><\/p>\n<p>Parted should be opened. Now, you can run many of the parted commands to partition your desired storage device any way you want.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/8-22.png\" alt=\"\" width=\"1126\" height=\"185\" \/><\/p>\n<h3>Switching to Different Storage Device:<\/h3>\n<p>You can also start parted without specifying which storage device to open beforehand as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/9-21.png\" alt=\"\" width=\"801\" height=\"97\" \/><\/p>\n<p>As you can see, parted is started. By default, \/dev\/sda, the first\/primary storage device is selected.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/10-22.png\" alt=\"\" width=\"1130\" height=\"187\" \/><\/p>\n<p>You can list all the storage devices on your computer with the following parted command:<\/p>\n<p>As you can see, the storage devices on my computer \/dev\/sda and \/dev\/sdb are listed along with their physical size.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/11-21.png\" alt=\"\" width=\"757\" height=\"178\" \/><\/p>\n<p>Now, you can use the select parted command to select the storage device (let\u2019s say \/dev\/sdb) that you want to partition as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/12-21.png\" alt=\"\" width=\"779\" height=\"92\" \/><\/p>\n<p>As you can see, \/dev\/sdb is selected.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/13-20.png\" alt=\"\" width=\"795\" height=\"140\" \/><\/p>\n<h3>Creating a New Partition Table:<\/h3>\n<p>You can create GPT and MSDOS partition table with parted.<\/p>\n<p>To create a GPT partition table, run the following parted command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/14-19.png\" alt=\"\" width=\"710\" height=\"95\" \/><\/p>\n<p>To create a MSDOS partition table, run the following parted command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/15-19.png\" alt=\"\" width=\"746\" height=\"92\" \/><\/p>\n<p>I will go for MSDOS partition table as I am partitioning a USB thumb drive. The procedure for the GPT partition creation is the same.<\/p>\n<p>Now, type in Ignore and press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/16-18.png\" alt=\"\" width=\"912\" height=\"137\" \/><\/p>\n<p>When you create a new partition table, all the existing partitions will be erased. If you\u2019re okay with it, type in Yes and then press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/17-15.png\" alt=\"\" width=\"1140\" height=\"220\" \/><\/p>\n<p>For some reason, the changes can\u2019t be applied immediately. But it\u2019s alright. Type in Ignore and press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/18-13.png\" alt=\"\" width=\"1132\" height=\"296\" \/><\/p>\n<p>A new partition table should be created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/19-10.png\" alt=\"\" width=\"1127\" height=\"319\" \/><\/p>\n<h3>Creating New Partitions:<\/h3>\n<p>You can create a new partition with the following parted command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/20-11.png\" alt=\"\" width=\"1139\" height=\"91\" \/><\/p>\n<p>Now, type in either primary or extended depending on whether you want to create a primary or extended partition. Once you\u2019re done, press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/21-11.png\" alt=\"\" width=\"1126\" height=\"115\" \/><\/p>\n<p>Now, type in a filesystem type that you want to use for the partition. I will go for ext4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/22-10.png\" alt=\"\" width=\"1131\" height=\"144\" \/><\/p>\n<p><u>NOTE:<\/u> You can find out what keywords you can use here with the following command:<\/p>\n<p>$ grep -v nodev \/proc\/filesystems| cut -f2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/23-10.png\" alt=\"\" width=\"933\" height=\"258\" \/><\/p>\n<p>Now, type in the location in megabyte (MB) where the partition starts. If it\u2019s the first partition, then 1 (MB) is an acceptable value. Once you\u2019re done, press &lt;Enter&gt;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/24-10.png\" alt=\"\" width=\"1140\" height=\"172\" \/><\/p>\n<p>Now, type in the location in megabyte (MB) where the partition ends. The size of the partition will be the difference between the End and Start location. For example, let\u2019s say, you want to create a 1GB\/1024MB partition. So, the end will be 1024. Once you\u2019re done, press &lt;Enter&gt;.<\/p>\n<p><u>NOTE:<\/u> You can\u2019t put 1025 here due to alignment problems. Parted don\u2019t align partitions automatically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/26-9.png\" alt=\"\" width=\"1140\" height=\"193\" \/><\/p>\n<p>The partition will be created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/27-9.png\" alt=\"\" width=\"1106\" height=\"210\" \/><\/p>\n<p>You can list all the partitions of your selected storage devices as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/28-8.png\" alt=\"\" width=\"1115\" height=\"91\" \/><\/p>\n<p>As you can see, the newly created partition is listed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/29-7.png\" alt=\"\" width=\"1125\" height=\"328\" \/><\/p>\n<p><u>NOTE:<\/u> When you create multiple partitions with parted, you have to start the new partition from at least End+1 of the last partition. For example, the partition I created earlier ended in 1024MB. So, the next partition will start from 1025MB or more.<\/p>\n<p>I created another partition to demonstrate how to remove partitions using parted in the next section.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/30-7.png\" alt=\"\" width=\"1140\" height=\"470\" \/><\/p>\n<h3>Removing Partitions:<\/h3>\n<p>First, list all the partitions of your selected storage device as follows:<\/p>\n<p>Let\u2019s say, you want to delete the partition number 2 as marked in the screenshot below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/31-6.png\" alt=\"\" width=\"1079\" height=\"456\" \/><\/p>\n<p>To do that, run the following parted command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/32-6.png\" alt=\"\" width=\"1100\" height=\"124\" \/><\/p>\n<p>As you can see, partition number 2 no longer exists.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/33-4.png\" alt=\"\" width=\"1110\" height=\"348\" \/><\/p>\n<h3>Changing the Unit:<\/h3>\n<p>When you create a new partition, you have to specify the Start and End section of your new partition. The default unit is MB. You can change it very easily in parted.<\/p>\n<p>The supported units and keywords are:<\/p>\n<table>\n<tbody>\n<tr>\n<td>Unit<\/td>\n<td>keyword<\/td>\n<\/tr>\n<tr>\n<td>Sectors<\/td>\n<td>s<\/td>\n<\/tr>\n<tr>\n<td>Bytes<\/td>\n<td>B<\/td>\n<\/tr>\n<tr>\n<td>Cylinders<\/td>\n<td>cyl<\/td>\n<\/tr>\n<tr>\n<td>cylinders, heads, sectors<\/td>\n<td>chs<\/td>\n<\/tr>\n<tr>\n<td>Kilobytes<\/td>\n<td>KB<\/td>\n<\/tr>\n<tr>\n<td>Mebibytes<\/td>\n<td>MiB<\/td>\n<\/tr>\n<tr>\n<td>Megabytes<\/td>\n<td>MB<\/td>\n<\/tr>\n<tr>\n<td>Gibibytes<\/td>\n<td>GiB<\/td>\n<\/tr>\n<tr>\n<td>Gigabytes<\/td>\n<td>GB<\/td>\n<\/tr>\n<tr>\n<td>Percentage<\/td>\n<td>%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><u>NOTE:<\/u> For more information on this, check the man page of parted with the following command:<\/p>\n<p>You can use the unit command to change the default unit.<\/p>\n<p>For example, let\u2019s say you want to change the default unit MB to sectors, then run the following command:<\/p>\n<p>As you can see, the display unit has changed as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/34-3.png\" alt=\"\" width=\"1115\" height=\"617\" \/><\/p>\n<p>Now, you can also create partitions with the newly set unit.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/35-3.png\" alt=\"\" width=\"1097\" height=\"443\" \/><\/p>\n<p>So, that\u2019s how you use parted on Linux. Thanks for reading this article.<\/p>\n<p><a href=\"https:\/\/linuxhint.com\/parted_linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Parted is a command line tool for managing disk partitions on Linux. Parted can be used to work with both MSDOS and GPT partition tables. Parted can be used to do many low level partitioning tasks easily. In order to use parted correctly, you will need a lot of knowledge on the physical structure of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/27\/how-to-use-parted-on-linux-linux-hint\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to use parted on 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-6205","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\/6205","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=6205"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6205\/revisions"}],"predecessor-version":[{"id":6824,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6205\/revisions\/6824"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=6205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=6205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=6205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}