1

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

  1. What are the other two drives Linux device-mapper (linear) (dm)?
  2. I would like to resize partition number 2 on VMware Virtual disk (scsi). Would this be possible using parted resize NUMBER START END? or should I use resize2fs
  3. 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?
  4. Would the following parted resize 2 325MB 65.9GB be correct?
  5. Would the resizing affect the current data on the parition?

1 Answer 1

3

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 partition

    set 3 lvm on → sets it as a LVM typed one

    Note: 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 use partprobe) 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
8
  • Thanks 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. Feb 28, 2016 at 15:36
  • That'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. Feb 28, 2016 at 16:07
  • Aah 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. Feb 28, 2016 at 16:40
  • Nope it should be available right after, you don't even have to reboot the server. Feb 28, 2016 at 16:41
  • 1
    Centos 7 replace last command with xfs_growfs /dev/mapper/VolGroup-lv_root
    – Ashley
    Mar 3, 2018 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .