How to Create a Linux Disk Partition
Plus, one thing you should always do first
To use storage devices such as USB drives and hard drives in Linux, you need to also understand how to structure them when using Linux operating system. Storage devices are often split into separate portions called partitions. This enables you to create a file system by splitting your hard drive into multiple virtual parts.
A Linux disk partition is like a boundary device that tells each file system how much space it can use. It’s handy whencreating shared drivesand enables you to allocate andedit drive spacemore effectively.
For example, if you have a 2GB USB drive, you can create a partition that takes up the entire drive, two partitions of 1GB each, or variations of sizes. Each Linux disk partition acts as its own hard drive. It is especially useful if you are using more than one operating system on the same computer.
Use The Parted Command
Ubuntu comes preinstalled withparted. If you are using a different distribution, install it using the following command:
apt-get-install parted
To see the hard drives on your system, type:sudo parted -l. See the list of devices in the screenshot below:
You can see above that there are three Ubuntu partition disks onDisk /dev/sda. Let’s use the partition called/dev/sda5to create a new partition.
The next step is to launchparted. But be sure you are using root privileges. Choose the drive you want to partition. We will be using/dev/vdc.
Type the following command:
(parted) select /dev/vdc
To see what is in the Linux disk partition, type:print. You will see a summary of your hard drive, the size, and the partition table.
In the example below, the hard drive isModel: Virtio Block Device,the size is1396MB, and the partition table isgpt.
To configure the Ubuntu partition disk, you must exit first by typingquit. The next step is to open the selected storage device usingparted.In this article, we will use the/dev/vdcdevice.
If you don’t specify the specific device you want to use, your system will randomly select a device. Use the command below that includes the device name (vdc):
sudo parted /dev/vdc
To set the partition table, typeGPT, thenYesto accept it. You should only do this on partitions that contain no data you want to keep.
Review your partition table to show information about the storage device with the following command:
(parted) print
To see instructions on how to make a new partition, type(parted) help mkpart.
For this article, we will create a new Linux disk partition using the command below:
(parted) mkpart primary 0 1396MB
The0means you want to start the partition at the beginning of the drive. We know from the screenshot above that the drive has1396MB. The command above tells your system to start the partition at0and end it at1396MB.
To be able to use the partition, it must be formatted. First, you need to exitpartedby typingquit. Then, using theext4file system, type the command below to format the disk:
mkfs.ext4 /dev/vdc
Verify by typingsudo parted/dev/vdc. To exitparted, typequit. When you exitparted, the changes save automatically.
In command mode, use a single letter command to show you a list of the actions you can take. Typemand pressEnter.
Create Disk Partitions Using cfdisk
Cfdisk is a Linux utility program used to create, delete, and modify partitions on a disk device. To use it to create a partition, enter the following command:
cfdisk /dev/sda
The name of the drive for this example issda.
In the screenshot above, you can see summary information for the disk device. The middle of the window shows the partition table. The brackets on the bottom show selectable commands.
To select a partition from the list, use the up and down arrow keys. Select a command by using the right and left arrows.
The example above shows three primary partitions (1,2 & 3). Notice thefree spacepartition type.
Create a new partition by selectingNewfrom the bottom window. We will call this partition/dev/sdb. Type the command# cfdisk /dev/sdb. Next selectprimaryas the partition type from the next screen.
On the next screen you will specify the size of the partition. We will create a partition that is 800 KB. Now you will be asked to determine where to start the partition. Choose thebeginning of free space.
From the next screen, selectWriteto save your changes and write the partition data to disk. Verify the new partition by printing it using the following command:
fdisk -l /dev/sdb
Concluding Tips for Creating Linux Disk Partitions
You should always back up your data. Even the smallest mistake can destroy the partition of a critical drive.
Also, be sure to verify and re-verify that you are using the correct drive when creating your partition. Otherwise, you could lose data.
Let us know your questions in the comments below.
David has a background in small business and lives in Australia. He is a WordPress and Ubuntu Developer who enjoys design, CSS and tech tool integration.Read David’s Full Bio
Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.
HomeAbout UsEditorial StandardsContact UsTerms of Use
Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved