How to shrink LVM group

General support questions
Post Reply
Alexegin
Posts: 6
Joined: 2018/05/19 21:58:48

How to shrink LVM group

Post by Alexegin » 2018/05/21 21:17:46

Hello all.
I have the following configuration of LVM:

Code: Select all

[root@centos ~]# lvs
  LV      VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_centos -wi-ao---- 100.00g                                                    
  lv_root vg_centos -wi-ao----  50.00g                                                    
  lv_swap vg_centos -wi-ao----   7.75g
So, the total size occupied by logical volumes is 157GB.
But, the size occupied by physical volume is:

Code: Select all

[root@centos ~]# pvs
  PV         VG        Fmt  Attr PSize   PFree  
  /dev/sda5  vg_centos lvm2 a--u 502.83g 345.08g
So, the question is - how to remove 345,08GB from physical volume and from volume group - I want to use it in another way, install CentOS 7 for example.
How to shrink partition?
Take a look at the screenshot attached.
Thank you very much for answering in advance.
Attachments
unused.png
unused.png (54.21 KiB) Viewed 260 times

User avatar
jlehtone
Posts: 1988
Joined: 2007/12/11 08:17:33
Location: Finland

Re: How to shrink LVM group

Post by jlehtone » 2018/05/22 11:45:40

Alexegin wrote:I want to use it in another way, install CentOS 7 for example.
For CentOS 7 I would simply create a new LV for its root, and mount the home and swap just like in CentOS 6.
The tricky part though is the /boot. Would it have enough space for all kernels?


That said there is pvresize. It can shrink the PV. The size of VG is dictated by the sizes of its PVs.

Once PV has gotten smaller, one can modify the partition table. (I would 1. shrink PV more than necessary, 2. change partition, and 3. expand PV to whole partition.)


/dev/sda5. Is that a logical drive in extended partition of MBR table, or simply fifth partition on GPT?

User avatar
TrevorH
Forum Moderator
Posts: 23452
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: How to shrink LVM group

Post by TrevorH » 2018/05/22 15:49:43

You cannot really coexist CentOS 6 and 7 on the same boot disk. CentOS 7 uses grub2 and that will overwrite CentOS 6's grub legacy boot records and render it unbootable. The only way to do this is to install a second disk and set it to be the boot disk in the BIOS, do your install to that and let it write grub2 to the MBR on there.

On grub legacy it used to be possible to tell it to install into the partition boot record so you could chain that grub off an existing one. With grub2 and the CentOS installer I am not aware that such a thing is still possible.
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

User avatar
jlehtone
Posts: 1988
Joined: 2007/12/11 08:17:33
Location: Finland

Re: How to shrink LVM group

Post by jlehtone » 2018/05/22 19:04:09

I do agree, but it is not impossible.

On one case I did move the (CentOS 6) contents of /boot from separate partition into the root LV of CentOS 6. Then I did let CentOS 7 repopulate the original /boot. Finally, I did add custom grub2 entry for the CentOS 6 kernel. (Grub2 can mount LVM volumes and load kernel from there.) The major disadvantage is that kernel updates to CentOS 6 will no longer update grub entries (because they cannot see them). This was MBR.

GPT (with uefi boot) is a different story. (I had CentOS 6 functional with EFI.) More possibilities, unless you have allocated all of the disk for one big partition.

Alexegin
Posts: 6
Joined: 2018/05/19 21:58:48

Re: How to shrink LVM group

Post by Alexegin » 2018/05/22 19:51:06

jlehtone wrote: /dev/sda5. Is that a logical drive in extended partition of MBR table, or simply fifth partition on GPT?
I have the following partition configuration (see comments after #):

Code: Select all

[root@centos ~]# parted /dev/sda unit MB print
Model: ATA Hitachi HTS72757 (scsi)
Disk /dev/sda: 750156MB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start     End       Size      Type      File system  Flags
 1      1.05MB    106MB     105MB     primary   ntfs         boot			# /dev/sda1 - MS Windows 7 MBR
 2      106MB     209716MB  209610MB  primary   ntfs							 # /dev-sda2 - MS Windows 7 disk C:
 3      209716MB  210241MB  524MB     primary   ext4							 # /dev/sda3 - mounted at /boot
 4      210241MB  750156MB  539916MB  extended									 # /dev/sda4 - container for logical partitions
 5      210242MB  750155MB  539914MB  logical                lvm			 # /dev/sda5 - LVM
See also the attached screenshot below:
Attachments
dev-sda.png
dev-sda.png (145.89 KiB) Viewed 216 times

Post Reply