Science and technology

Partition a drive on Linux with GNU Parted

In the 21st century, we are inclined to take knowledge storage with no consideration. We have plenty of it, it is comparatively reasonably priced, and there are a lot of several types of storage out there. No matter how a lot cloud cupboard space you are given totally free, there’s nothing fairly like having a bodily onerous drive to your actually essential (or actually huge, once you stay on a sluggish community) knowledge. However, few onerous drives are offered proper off the shelf, prepared to make use of—in a super configuration, a minimum of. Whether you are shopping for a brand new drive or establishing a system with a unique configuration, you’ll want to know the way to partition a drive on Linux.

This article demonstrates GNU Parted, top-of-the-line instruments for partitioning drives. If you like to make use of a graphical software as an alternative of a terminal command, learn my article on formatting drives for Linux.

Disk labels, partitions, and filesystems

A tough drive would not technically require a lot software program to function a storage system. However, utilizing a drive with out fashionable conventions like a partition desk and filesystem is troublesome, impractical, and unsafe to your knowledge.

There are three essential ideas you’ll want to learn about onerous drives:

  • A disk label or partition desk is metadata positioned at first of a drive, serving as a clue for the pc studying it about what sort of storage is obtainable and the place it is positioned on the drive.
  • A partition is a boundary figuring out the place a filesystem is positioned. For occasion, in case you have a 512GB drive, you may have a partition on that system that takes up all the drive (512GB), or two partitions that every take 256GB every, or three partitions taking over another variation of sizes, and so forth.
  • A filesystem is a storage scheme agreed upon by a tough drive and a pc. A pc should know the way to learn a filesystem to piece collectively all the information saved on the drive, and it should know the way to write knowledge again to the filesystem to keep up the information’s integrity.

The GNU Parted software manages the primary two ideas: disk labels and partitions. Parted has some consciousness of filesystems, however it leaves the main points of filesystem implementation to different instruments like mkfs.

[Download the GNU Parted cheat sheet]

Locating the drive

Before utilizing GNU Parted, you have to be sure the place your drive is positioned in your system. First, connect the onerous drive you need to format to your system, after which use the parted command to see what’s hooked up to your laptop:

$ parted /dev/sda print gadgets
/dev/sda (2000GB)
/dev/sdb (1000GB)
/dev/sdc (1940MB)

The system you most just lately hooked up will get a reputation later within the alphabet than gadgets which were hooked up longer. In this instance, /dev/sdc is more than likely the drive I simply hooked up. I can verify that by its measurement as a result of I do know that the USB thumb drive I hooked up is just 2GB (1940MB is shut sufficient), in comparison with my workstation’s important drives, that are terabytes in measurement. If you are undecided, then you will get extra details about the drive you assume is the one you need to partition:

$ parted /dev/sdc print
Model: Yoyodyne Tiny Drive (scsi)    
Disk /dev/sdc: 1940MB
Sector measurement (logical/bodily): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2048kB  1024kB  BS           Bloat  Hidden
 2      2049kB  1939MB  1937MB  FAT32        MyDrive

Some drives present extra metadata than others. This one identifies itself as a drive from Yoyodyne, which is precisely the branding on the bodily drive. Furthermore, it incorporates a small hidden partition on the entrance of the drive with some bloatware adopted by a Windows-compatible FAT32 partition. This is certainly the drive I intend to reformat.

Before persevering with, be sure you have got recognized the proper drive you need to partition. Repartitioning the incorrect drive leads to misplaced knowledge. For security, all doubtlessly damaging instructions on this article reference the /dev/sdX system, which you might be unlikely to have in your system.

Creating a disk label or partition desk

To create a partition on a drive, the drive will need to have a disk label. A disk label can also be known as a partition desk, so Parted accepts both time period.

To create a disk label, use the mklabel or mktable subcommand:

$ parted /dev/sdX mklabel gpt

This command creates a gpt label on the entrance of the drive positioned at /dev/sdX, erasing any label which will exist. This is a fast course of as a result of all that is being changed is metadata about partitions.

Creating a partition

To create a partition on a drive, use the mkpart subcommand, adopted by an optionally available title to your partition, adopted by the partition’s begin and finish factors. If you solely want one partition in your drive, then sizing is straightforward: begin at 1 and finish at 100%. Use the --align choose choice to permit Parted to regulate the place of the partition boundaries for greatest efficiency:

$ parted /dev/sdX --align choose
mkpart instance 1 100%

View your new partition with the print subcommand:

$ parted /dev/sdX print
Model: Yoyodyne Tiny Drive (scsi)
Disk /dev/sdi: 1940MB
Sector measurement (logical/bodily): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size  
 1      1049kB  1939MB  1938MB

You do not have to make use of the entire disk for one partition. The benefit to a partition is that multiple filesystem can exist on a drive with out interfering with the opposite partition(s). When sizing partitions, you need to use the unit subcommand to set what sort of measurements you need to use. Parted understands sectors, cylinders, heads, bytes, kilobytes, megabytes, gigabytes, terabytes, and percentages.

You may also specify what filesystem you plan to make use of a partition for. This would not create the filesystem, however it does present metadata that might be helpful to you later.

Here’s a 50-50 cut up, one for an XFS filesystem and one other for an EXT4 filesystem:

$ parted /dev/sdX --align choose
mkpart xfs 1 50%
$ parted /dev/sdX --align choose
mkpart ext4 51% 100%

Naming a partition

In addition to marking what filesystem a partition is for, you can even title every partition. Some file managers and utilities learn partition names, which may help you determine drives. For occasion, I typically have a number of completely different drives hooked up on my media workstation, every belonging to a unique venture. When creating these drives, I title each the partition and the filesystem in order that, irrespective of how I am taking a look at my system, the places with essential knowledge are clearly labeled.

To title a partition, you have to know its quantity:

$ parted /dev/sdX print
Number  Start   End     Size   File system  Name     Flags
 1      1049kB  990MB   989MB  xfs          instance
 2      1009MB  1939MB  930MB  ext4         noname

To title partition 1:

$ parted /dev/sdX title 1 instance
$ parted /dev/sdX print
Number  Start   End     Size   File system  Name     Flags
 1      1049kB  990MB   989MB  xfs          instance
 2      1009MB  1939MB  930MB  ext4         noname

Create a filesystem

For your drive to be helpful, you have to create a filesystem in your new partition. GNU Parted would not do this as a result of it is solely a partition supervisor. The Linux command to create a filesystem on a drive is mkfs, however there are useful utilities aliased so that you can use to create a particular type of filesystem. For occasion, mkfs.ext4 creates an EXT4 filesystem, whereas mkfs.xfs creates an XFS filesystem, and so forth.

Your partition is positioned “in” the drive, so as an alternative of making a filesystem on /dev/sdX, you create your filesystem in /dev/sdX1 for the primary partition, /dev/sdX2 for the second partition, and so forth.

Here’s an instance of making an XFS filesystem:

$ sudo mkfs.xfs -L mydrive /dev/sdX1

Download our cheat sheet

Parted is a versatile and highly effective command. You can subject it instructions, as demonstrated on this article, or activate an interactive mode so that you simply’re consistently “connected” to a drive you specify:

$ parted /dev/sdX
(parted) print
Number  Start   End     Size   File system  Name     Flags
 1      1049kB  990MB   989MB  xfs          instance
 2      1009MB  1939MB  930MB  ext4         noname

(parted) title 1 mydrive

If you plan to make use of Parted typically, download our GNU Parted cheat sheet so that you’ve all of the subcommands you want shut at hand.

Most Popular features the latest multimedia technologies, from live video streaming to audio packages to searchable archives of news features and background information. The site is updated continuously throughout the day.

Copyright © 2017 Breaking Express, Green Media Corporation

To Top