Resizing CentOS partition using parted
1 - the 2 other devices are the LVM logical volumes.
/dev/mapper/VolGroup-lv_root being your root partition
/dev/mapper/VolGroup-lv_swap being your swap
That's the "devices" that are used by your system as "hard drives", the system doesn't use the drive directly but uses these layers instead, so it makes it easier to add more disks and so on after.
2 - I guess by resize you mean increase the size of your root partition. But before you can actually resize the filesystem itself you have to make it aware that the underlying "disk" has grown, because it sees, not your disk, but the LVM Logical Volume /dev/mapper/VolGroup-lv_root. So you have to make this thing bigger and then extend the filesystem so it fits to the new size.
In order to do this you have a few steps to follow.
- backup your data, all the steps can be done live, but working with partitions is never a 100% safe work.
create a LVM partition on your free space of type LVM
mkpart primary ext2 10.7GB 65.9GB
→ create a partitionset 3 lvm on
→ sets it as a LVM typed oneNote: If
mkpart
complains about not being able to re-read the device's partition table and tells you to reboot, you need to do so (or usepartprobe
) before continuing with the next step.add this partition as a new LVM Physical Volume
pvcreate /dev/sda3
get the name of your LVM Volume Group
vgdisplay
add this new LVM Physical Volume to your already existing LVM Volume Group
vgextend thevgnameyoufound /dev/sda3
- now check there is some free space in your Volume Group with vgdisplay you should see a line like
Free PE / Size 5129 / 20.04 GiB
, not exactly like this, but similar with 55GB of free space or so. extend now your LVM Logical Volume to this free space (there are a lot of options here to grow to just 10 GB more, or to 25% of free space, etc, but I assume you want all the free space).
lvextend /dev/mapper/VolGroup-lv_root -l +100%FREE
extend your current partition to its full size with resize2fs.
resize2fs /dev/mapper/VolGroup-lv_root
- check the new size of your root partition
Related videos on Youtube
andthereitgoes
Updated on September 18, 2022Comments
-
andthereitgoes over 1 year
I am using CentOS 6.x. I would like to resize the LVM partiion, but I am little confused when I use
parted
to see the partition information. I have a few questions. Please look at the partition information below.$ parted GNU Parted 2.1 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print all Model: VMware Virtual disk (scsi) Disk /dev/sda: 65.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 325MB 324MB primary ext4 boot 2 325MB 10.7GB 10.4GB primary lvm Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup-lv_swap: 1215MB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 1215MB 1215MB linux-swap(v1) Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/VolGroup-lv_root: 10.9GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 10.9GB 10.9GB ext4
Here's the parted print free information
print free Model: VMware Virtual disk (scsi) Disk /dev/sda: 65.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 325MB 324MB primary ext4 boot 2 325MB 10.7GB 10.4GB primary lvm 10.7GB 65.9GB 55.2GB Free Space
I have a few questions
- What are the other two drives
Linux device-mapper (linear) (dm)
? - I would like to resize partition number 2 on
VMware Virtual disk (scsi)
. Would this be possible usingparted resize NUMBER START END
? or should I useresize2fs
- If I am using
parted resize NUMBER START END
in my case I would be resizing number 2 partition. I am confused about what would the appropriate START and END be in case I want to use the entire free space? - Would the following
parted resize 2 325MB 65.9GB
be correct? - Would the resizing affect the current data on the parition?
- What are the other two drives
-
andthereitgoes about 8 yearsThanks for the detailed steps. What would happen to the data in the current partition number 2? It contains data that I can't afford to lose.
-
Roman Diez about 8 yearsThat's why I advise you to backup your data before doing anything related to partition. Actually your data are not really on partition number 2, they're on the file system that is on the logical volume that is on the volume group which is itself composed of partition number 2. And that you will extend to partition number 3 later. And they should remain safe, exactly where they are. But seriously, do backup them first ! One never knows what could happen.
-
andthereitgoes about 8 yearsAah I see.Just one last thing. The above mentioned machine is used as Postgresql machine. Will I have to change anything as far Postgresql is concerned for it to utilise the extra space? The reason for resizing IS Postgresql running out of space.
-
Roman Diez about 8 yearsNope it should be available right after, you don't even have to reboot the server.
-
andthereitgoes about 8 yearsyour instructions worked perfectly except for a reboot that I had to do before using pvcreate. I have added a line to your answer.
-
Roman Diez about 8 yearsAh alright, glad to know that it worked. Thanks for improving the answer :)
-
andthereitgoes about 8 yearsNo worries. I see you've improved my line as well. Thanks. Can you also elaborate on what needs to be done with partprobe? Just for future reference.