In this article, we discuss the concept of partitioning a drive, naming conventions for Linux partitions, types of partitions and demonstrate how to partition a drive in Linux using parted utility.
Table of contents.
- Naming conventions.
- Types of partitions.
- Partitioning process.
Partitioning a disk is the first step before installing a file system since creation of any files or directories is done in a file system.
It involves dividing a HDD into smaller logical drives, therefore we can say that a partition is a contiguous set of block treated as an independent disk.
A partition table is an index which shows the relationship between the HDD and its partitions.
We partition a HDD for the following reasons,
- Ability to run multiple OSs or multiple OS versions on the same disk.
- Load balancing and distribution by managing processor allocations across applications ans system users.
- Leveraging Capacity on demand and Pay As You Grow hardware models.
sd is used for SCSI disks although modern Linux systems will treat all disks as SCSI and therefore name them with starting with sd.
- hda/sda - primary master.
- hdb/sdb - primary slave.
- hdc/sdc - Secondary master.
- hdd/sdd - Secondary slave.
- Others may be sde, sdf etc.
Each disk and partition in a Linux system is represented as a device special file and it is stored in the /dev directory. i.e
/dev/sda would represent the first disk, /dev/sdb the second etc.
Logical partitions inside an extended partition start at 5 i.e /dev/hda5 the first logical partition and /dev/hda6 the second and so on.
Types of partitions.
Different partitions will contain different file systems.
This partition will store all operating system files. Only four primary partitions can be created.
For example the first primary partition will be labeled /dev/sda1.
A primary partition may be partitioned again into sub-partitions, we refer to these as logical partitions.
Logical partitions allow us to go above the 4-partition limitation.
The primary partition housing logical partitions is referred to as an extended partition.
Logical partitions must be contiguous. Each logical partition will have a pointer to the next implying that we can have an unlimited number of logical partitions however Linux limits this where by we can only have 15 for SCSI and 63 for IDE.
These partitions start at 5, i.e /dev/sda5.
Running processes are allocated a number of RAM blocks called pages. In-memory pages referenced by the processor in the near future are referred to as a working set.Linux predicts memory accesses by assuming that used pages will be used in subsequent accesses and therefore stores these pages in RAM.
If there are too many processes running, the kernel tries to free up space by writing the pages to disk.
Swap space is used to increase the amount of memory available although disk accesses are still very slow compared to RAM.
Swap space is important although it is no substitute to RAM.
Partitioning can be done with various different tools, they include, sfdisk, cfdisk, parted, partition magic or, disk drake.
Partitioning using parted.
Parted is a command line utility that allows users to easily manage hard disk partitions. With parted we can add, delete, extend or shrink disk partitions together with their corresponding file systems.
To get started type in the parted command.
From the output we can see the version and the primary partition /dev/sda.
To exit we type *quit.
The help command while still in parted, will show all available options.
To view disk partitions while still in parted we write,
To view free partitions we write,
To select a disk we want to partition we write,
We then create a new partitioning table by using the mklabel command, but first lets look at the mklabel options.
From the output we can see that the disk label type must be among the listed ones.
For example lets create a msdos type partition,
You can use print command to view the created table.
To create a primary partition we use the mkpart command as follows,
For a logical partition we write,
We can also specify the file system and storage space as follows,
mkpart primary ext4 1MB 2048MB
The above command states that, create a new partition using the ext4 file system whose disk start is 1MB and end is 2048MB.
We can remove a partition using the rm command as follows,
First we have to know the partition number therefore we use th print command to list all partitions.
From the output, get the partition number in the Number column.
To remove a partition, write
Then enter the partition number.
In this article we have discussed how partitions are labeled in Linux, the various types of partitions and demonstrated how to partition a drive using the parted utility.
We have also talked about reasons why one would need to partition a disk.