Extending A Logical Non-Primary Partition in Ubuntu: Part 1
Confused by the difference between primary, logical and extended drives? Yeah, me too. You know who isn't? Gabe Stone, one of our Senior SRE Software Developers. He's here to cut through the fog of partitioning for you.
Here at TextNow, in our world of both virtual and bare metal computer systems, we often need some kind of long term storage volume (either virtual or physical) for persistent data, like an operating system. And we often will want to isolate data that changes frequently so we can easily find and modify that data, migrate it if necessary, change sizes, etc.
The common method to accomplish this is to carve up (not literally) a hard drive into "pieces" called partitions.
So we buy a hard drive, start using it, and split it up if we need to, right?
Well... not quite. Each computer likely needs an operating system, each OS needs some kind of long term storage volume or drive, each drive needs a partition, and each partition needs a file system.
OK, Bear with me....Generally there are two types of drive partitions:
- Primary: Used to boot an OS.
- Extended: Used to hold logical drives and volumes.
So what's a logical drive/volume?
Glad you asked!
A logical drive or volume can be used to hold anything you want - except a bootable OS. That's something only a primary partition can do (which explains why it's called the primary).
Partitions are necessary because you can’t just start writing files to a blank drive. You must first create at least one container that has a file system. We call this container a partition. A disk with a traditional partition table can only have up to four primary partitions.
Extended and logical partitions are a way to get around this limitation.
Let’s say you want six partitions on a single drive. You’d have to create three primary partitions as well as an extended partition. The extended partition effectively functions as a container that allows you to create a larger amount of logical partitions. So, if you needed six partitions, you’d create three primary partitions, an extended partition, and then three logical partitions inside the extended partition.
You could also just create a single primary partition, an extended partition, and five logical partitions, but you can’t have more than four primary partitions at a time.
Extended partitions are a holdovers from earlier days, and was used when a drive had two or more partitions. It doesn’t actually hold data, it merely serves as a container for one or more logical drives.
It should also be noted that when you create a logical drive or volume on an extended partition, you do not need to create another partition on the logical drive, since you are technically already "in" a partition: the extended partition, which again acts as a "container" for the logical drives.
OK I follow you (so far anyway). But I didn't come here for a history lesson. I just have a machine with a drive that has some extra space, and I need my Linux operating system to see the new size, but it still shows the old size. How do I even know what kind of partition I have? Is it even possible, Mr. Smarty Pants?
Yes it certainly is possible, but there are some steps involved that need to be followed precisely. But first we have to do some recon. (And smart is a relative term, you don't have to be rude.)
Assuming you have root privileges on your Linux system, you can type...
sudo fdisk -l
...at a shell prompt to get a disk drive device listing. Here's some example output:
See that "table" above?
That's is a basic representation of the disk's partition table, showing the partitions on the disk. The table shows the various disk location markers for the partition (Start, End, Sectors), the partition size, the device name as seen by the operating system, etc.
What I'd like you to pay attention to is that penultimate column there: Id. The values for both give the number 83. That number is the magic designation for a native Linux partition. The Linux partition is usually the primary, as primary partitions have the option to be bootable. (You'll notice one of the devices has an asterisk in the "Boot" column. That means that whatever system this drive is "plugged" into, the system will try to boot off of that partition.)
Got it? Great! Let's move on.
If you see a non-bootable partition with type 83, it is likely a primary partition of some kind, but it could be a logical volume/partition.
Well how can I find that out, huh?
Fear not. Your first clue will be if you see something like this on a system with logical volumes, using the same command as above:
OK, see the second device in that partition table? It has an Id of 5, showing its type as Extended. Is that the logical volume "container"?
(At this point it should be noted that there is a veritable alphabet soup of command-line and graphical utilities for managing partitions, and this is just one way to do it. There is no One True Way.)
Here, we can use the lsblk utility to confirm. It displays information about "block devices" (which is ancient Nerdese for what are typically hard drives or USB drives). Sample output follows:
Ah ha! See that tree? One of the devices sda5 has two distinct sub-items! Could that be our logical volume container? Sure looks like it, especially considering its value in the FSTYPE column: LVM2_member. (LVM = Logical Volume Manager).
Well then what is /dev/sda2? It had the type Extended! You're killing me man.
Usually the "Extended" partition isn't used. Instead, the last partition in the table (i.e. the last entry that is not a sub-item) is the "real" container, so you can create as many logical volumes as you need until you use up the rest of the available space. That lonely "Extended" partition (/dev/sda2) you see only contains partitioning information.
Aaaaaallrighty then! So it looks like I have logical volumes on my drive and I know their device names. How can I make my logical volume use the remaining unallocated space on my drive?
For the answer to that I'll see you over at Part Two!