Linux create disk partitions

8 Linux ‘Parted’ Commands to Create, Resize and Rescue Disk Partitions

Parted is a famous command line tool that allows you to easily manage hard disk partitions. It can help you add, delete, shrink and extend disk partitions along with the file systems located on them. Parted has gone a long way from when it first came out. Some of it’s functions have been removed, others have been added.

Parted Command to Manage Linux Disk Partitions

In this tutorial you will learn the basics of parted and we will show you some practical examples. If you don’t have any previous experience with parted, please be aware that parted writes the changes immediately to your disk, so be careful if you try to modify your disk partitions.

If you plan on testing parted, the better option would be to simply use a virtual machine or old computer/laptop without any valuable information on it. To make modifications on a disk partition it must not be in use. If you need to work on primary partition, you may boot into rescue mode.

Note: You will need to have root access to the machine you will be working on in order to use parted.

How to Install Parted on Linux

On many Linux distributions, parted comes pre-installed. If it is not included in your distro, you can install it with:

Once you have make sure that parted is installed, you can proceed further to check out some real world examples of parted command in the rest of this article.

1. Check Parted Version

Run the following command, you see message similar to the one shown on the image below. Don’t worry if your parted version is different. Unless specified otherwise, parted will use your primary drive, which in most cases will be /dev/sda .

Check Parted Command Version

If you want to exit parted, simply type:

2. List Linux Disk Partitions

Now that parted is started, let’s list the partitions of the selected hard disk. As mentioned earlier, parted chooses your first drive by default. To see the disk partitions run print .

Check Linux Partitions

When running print , it will also display the hard disk information and model. Here is example from a real hard disk (not virtual as shown on the image above) :

In the example above, you can see the disk model, capacity sector size and partition table.

3. List or Switch to Different Disk

If you have more than one hard disk, you can easily switch between disks, by using the “ select ” command. In the example below, I will switch from /dev/sda to /dev/sdb which is a secondary drive on my system.

To easily switch between disks you can use:

Select Different Disk

Change «X» with the letter of the disk to which you wish to switch.

Читайте также:  Mac os monterey список устройств

4. Create Primary or Logical Partition in Linux

Parted can be used to create primary and logical disk partitions. In this example, I will show you how to create primary partition, but the steps are the same for logical partitions.

To create new partition, parted uses “ mkpart “. You can give it additional parameters like «primary» or «logical» depending on the partition type that you wish to create.

Before you start creating partitions, it’s important to make sure that you are using (you have selected) the right disk.

Start by using print:

Show Current Linux Disk

As shown on the above image, we are using a virtual drive of 34 GB. First we will give the new disk a label and then create a partition and set a file system on it.

Now the first step is to give the new disk a label name with:

Now create the new partition with mkpart . The listed units are in megabytes (MB). We will create a 10 GB partition starting from 1 to 10000:

Create Primary or Logical Linux Partitions

Next, exit parted with «quit» command. We will format our new partition in ext4 file system using mkfs . To make this happen run the following command:

Note: It’s important to select the right disk and partition when executing the above command!

Now let’s verify our results, by printing the partition table on our secondary disk. Under file system column, you should see ext4 or the file system type that you have decided to use for your partition:

Verify Disk Partition Filesystem

5. Resize Linux Disk Partition

Parted includes multiple useful functions and one of them is «resizepart» . As you have probably figured this out by now, «resizepart» helps you resize a partition.

In the example below, you will see how to resize an existing partition. For the purpose of this example, we will be using the earlier created partition.

First you will need to know the number of the partition that you will be resizing. This can be easily found by using «print» :

Find Linux Partition Number

In our example, the partition number is «1» . Now run the resizepart command:

You will be asked for the number of the partition that you will resize. Enter it’s number. After that, you will be asked to set the new ending point for this partition. Remember that by default the units are in MB. In our example, we have set the new partition size to 15 GB:

Now verify the results with «print» :

Verify Linux Resize Partition

6. Delete Linux Partition

The next thing you will learn is how to delete a partition from your hard drive. To do this, you will need to use the «rm» command within parted. To delete a disk partition you will need to know it’s number.

As mentioned earlier, you can easily obtain this number by using «print» . In our example, we will delete the partition with number 1 from our secondary drive /dev/sdb1 :

Verify the results by printing the partitions table:

Delete a Linux Partition

7. Rescue Linux Disk Partition

Parted supports a “ rescue» utility that helps you recover a lost partition between a starting and ending point. If a partition is found within that range, it will attempt to restore it.

Here is an example:

8 Change Linux Partition Flag

Using parted, you can change the state of a flag for disk partitions. The supported flags are:

The states can be either «on» or «off» . To change a flag simply run «set» command within parted:

The above command sets lba flag to on for second partition. Verify the results with print :

Читайте также:  Чем редактировать файл linux

Change Partition Flag

Conclusion

Parted is a useful and powerful utility that can help you manage your disk partitions in Linux systems. As always, when working with disk partitions you need to be extra careful. It is strongly recommend to go through parted man pages to learn how you can customize it’s output and find more information about its capabilities.

If you have any questions or comments, please do not hesitate to use the comment section below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Creating a disk partition in Linux

Disk Partitioning in Linux

Creating and deleting partitions in Linux is a regular practice because storage devices (such as hard drives and USB drives) must be structured in some way before they can be used. In most cases, large storage devices are divided into separate sections called partitions. Partitioning also allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive. Partitioning is particularly useful if you run multiple operating systems.

Creating a Disk Partition in Linux

This procedure describes how to partition a storage disk in Linux using the parted command.

Procedure

List the partitions using the parted -l command to identify the storage device you want to partition. Typically, the first hard disk ( /dev/sda or /dev/vda ) will contain the operating system, so look for another disk to find the one you want. For example:

Open the storage device. Use the parted command to begin working with the selected storage device. For example:

Be sure to indicate the specific device you want to partition. If you just enter parted without a device name, it will randomly select a storage device to modify.

Set the partition table type to gpt , then enter Yes to accept it.

The mklabel and mktable commands are both used for making a partition table on a storage device. At the time of writing, the supported partition tables are: aix , amiga , bsd , dvh , gpt , mac , ms-dos , pc98 , sun , atari , and loop . Use help mklabel to get a list of supported partition tables. Remember mklabel will not make a partition, rather it will make a partition table.

Review the partition table of the storage device.

Create a new partition using the following command. For example, 1396 MB on partition 0:

Providing a partition name under GPT is a must; in the above example, primary is the name, not the partition type. In a GPT partition table, the partition type is used as partition name.

Quit using the quit command. Changes are automatically saved when you quit parted .

Help command for creating a new partition

To get help on how to make a new partition, type: help mkpart .

Setting filesystem type ( FS-TYPE ) will not create an ext4 filesystem on /dev/vdc1. You still have to create the ext4 filesystem with mkfs.ext4 .

A DOS partition table’s partition types are primary, logical, and extended.

Providing a partition name under GPT is a must. In a GPT partition table, the partition type is used as the partition name.

All Fedora Documentation content available under CC BY-SA 4.0 or, when specifically noted, under another accepted free and open content license.

Читайте также:  Windows для широкоформатных экранов

Источник

How to Create a Disk Partitions in Linux

In order to effectively use storage devices such as hard drives and USB drives on your computer, you need to understand and know how to structure them before using in Linux. In most cases, big storage devices are split into separate portions called partitions.

Partitioning enables you to split your hard drive into multiple parts, where each part acts as its own hard drive and this is useful when you are installing multiple operating systems in the same machine.

In this article, we will explain how to partition a storage disk in Linux systems such as CentOS, RHEL, Fedora, Debian and Ubuntu distributions.

Creating a Disk Partition in Linux

In this section, we will explain how to partition a storage disk in Linux using the parted command.

The first step is to view the partition table or layout on all block devices. This helps you identify the storage device you want to partition. You can do this using parted or fdisk command. We will use the former for purposes of demonstration, as follows, where the -l flag means list partition layout on all block devices.

List Partitions in Linux

From the output of the above command, there are two hard disks attached to the test system, the first is /dev/sda and the second is /dev/sdb .

In this case, we want to partition hard disk /dev/sdb . To manipulate disk partitions, open the hard disk to start working on it, as shown.

At the parted prompt, make a partition table by running mklabel msdos or gpt, then enter Y/es to accept it.

Make Disk Label

Important: Make sure to specify the correct device for partition in the command. If you run parted command without a partition device name, it will randomly pick a storage device to modify.

Next, create a new primary partition on the hard disk and print the partition table as shown.

Create Partition in Linux

You can create another partition for the reaming space as shown.

Create Another Partition

To quit, issue the quit command and all changes are automatically saved.

Next, create the file system type on each partition, you can use the mkfs utility (replace ext4 with the file system type you wish to use).

Create Filesystem Type on Partition

Last but not least, to access the storage space on the partitions, you need to mount them by creating the mount points and mount the partitions as follows.

To check if the partitions are actually mounted, run the df command to report file system disk space usage.

Check Partitions Disk Space Usage

Important: You may need to update /etc/fstab file to mount newly created partitions automatically at boot time.

You might also like to read these following related articles:

That’s all! In this article, we have shown how to partition a storage disk, create a file system type on a partition and mount it in Linux systems. You can ask questions or share you thoughts with us via the comment form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Оцените статью