0

My goal is to create new LVM physical volume named sda3. I installed the Centos 7.5 in such partitioning:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   468877311   233389056   8e  Linux LVM

Disk /dev/mapper/centos-root: 222.9 GB, 222885314560 bytes, 435322880 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 10.7 GB, 10733223936 bytes, 20963328 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Actually, I have 3 partitions, swap, home and root which the OS is installed on the root partition. I tried to create a new LVM physical volume using the command pvcreate but it errors:

Device /dev/sda3 not found.

and when I tried /dev/sda2 it says:

Can't open /dev/sda2 exclusively.  Mounted filesystem?

So I guess I should do the following steps to create a new LVM physical volume:

  1. Repartition(resize) the sda2 and create a new partition named sda3
  2. Unmount sda3 and now I can create a new LVM physical volume from sda3

The question is how can I resize the root(sda2) to make space for new partition sda3 while the OS is installed on the sda2?

In the following, I add some related command outputs.

Here is the output of the command lvmdiskscan

  /dev/centos/root [    <207.58 GiB] 
  /dev/sda1        [       1.00 GiB] 
  /dev/centos/swap [     <10.00 GiB] 
  /dev/sda2        [    <222.58 GiB] LVM physical volume
  /dev/centos/home [       5.00 GiB] 
  3 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

and here is the output of lsblk command:

sda               8:0    0 465.8G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0 464.8G  0 part 
  ├─centos-root 253:0    0 451.9G  0 lvm  /
  ├─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0     5G  0 lvm  /home

The lvs command:

 LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----    5.00g                                                    
  root centos -wi-ao---- <207.58g                                                    
  swap centos -wi-ao----  <10.00g 

The vgs command:

VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   3   0 wz--n- 222.57g    0 

The pvs command:

PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  222.57g    0 
  • Why would you want to create another physical volume (PV)? – roaima Nov 26 '18 at 8:11
  • I want to use it as the OpenStack Cinder volume group. I tried sda2 but it was mounted (running the OS) – Soheil Pourbafrani Nov 26 '18 at 8:14
  • Kindly add the output of lvs vgs and pvs command. – erTugRul Nov 27 '18 at 6:36
  • @erTugRul has been Added. – Soheil Pourbafrani Nov 27 '18 at 6:41
  • Forgot to ask you to show the output of df -Th. My bad. Kindly add that one also – erTugRul Nov 27 '18 at 7:17
0

You have a problem. Your /dev/centos/root LV is about 207 GiB in size, and together with /dev/centos/swap and /dev/centos/home it looks like your /dev/sda2 PV is fully in use. By default, CentOS uses a XFS filesystem which cannot be shrunk, neither as online nor offline operation, other than by backing up its contents, destroying the filesystem and recreating it in smaller size. Under such conditions, you should always initially configure your filesystems to be as small as reasonable, and be prepared to extend them if needed, since XFS offers a robust on-line extension mechanism.

To get free space for /dev/sda3 partition/PV, you would first need to shrink the /dev/centos/root filesystem, then shrink the LV to match, make sure the free extents are at the end of the disk (using pvmove to rearrange them if necessary) then pvresize to shrink the PV, then edit the partition table to shrink the actual /dev/sda2 partition... a lot of work.

If you don't have anything too complicated on the system yet, the easiest way would probably be to backup everything necessary, and then completely reinstall CentOS 7.5, this time either configuring the installer to create an empty /dev/sda3 partition for you, or otherwise ensuring that the space won't get added to any filesystem. In cases like this, the automatic partitioning feature of the OS installer is definitely not your friend.

  • Thanks, If I had created partitions as standard partition and not LVM at the OS installation, I could shrink it easily and make it LMV group, yes? – Soheil Pourbafrani Nov 26 '18 at 12:39
  • 1
    A bit less steps perhaps, but the first step, shrinking an XFS filesystem, would remain just as impossible. – telcoM Nov 26 '18 at 14:12
  • Thanks, I want to allocate 100G to sda2 and make free about 200G and create new sda3. I wanted to use the command pvresize --setphysicalvolumesize 100G /dev/sda2 but according to your advice I think I should rearrange data using to prevent data loss. Could give me an example of the command pvmove, pls? – Soheil Pourbafrani Nov 26 '18 at 14:27
  • Please add the output of lsblk into your question post. – telcoM Nov 26 '18 at 14:56
  • I edited the post and add the output of the lsblk command. – Soheil Pourbafrani Nov 27 '18 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.