My objective is to free some space from the lvm and create new partition. Below is the devices and lvm ontop of it.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 200G 0 disk
|-vda1 252:1 0 512M 0 part /boot
`-vda2 252:2 0 199.5G 0 part
|-vg-lv_root 253:0 0 15.5G 0 lvm /
|-vg-lv_pwcfg 253:1 0 10.9G 0 lvm /opt/pwcfg
|-vg-lv_var 253:2 0 12.5G 0 lvm /var/log
|-vg-lv_pw 253:3 0 118.4G 0 lvm /pw
`-vg-lv_opt 253:4 0 42.2G 0 lvm /opt
I want to make vg-lv_pw to 50 gb. I am doing it with the following command:
# lvreduce --resizefs -L 50G /dev/vg/lv_pw
fsck from util-linux 2.23.2
mkfs_lv_pw: 11/7007616 files (0.0% non-contiguous), 445504/31039488 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg-lv_pw to 13107200 (4k) blocks.
The filesystem on /dev/mapper/vg-lv_pw is now 13107200 blocks long.
Size of logical volume vg/lv_pw changed from <118.41 GiB (30312 extents) to 50.00 GiB (12800 extents).
Logical volume vg/lv_pw successfully resized.
Yes lvm size is set to 50GB.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 200G 0 disk
|-vda1 252:1 0 512M 0 part /boot
`-vda2 252:2 0 199.5G 0 part
|-vg-lv_root 253:0 0 15.5G 0 lvm /
|-vg-lv_pwcfg 253:1 0 10.9G 0 lvm /opt/pwcfg
|-vg-lv_var 253:2 0 12.5G 0 lvm /var/log
|-vg-lv_pw 253:3 0 50G 0 lvm
`-vg-lv_opt 253:4 0 42.2G 0 lvm /opt
Now I have to take that Pfree 68.41GB and create new partition out of it.
# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 vg lvm2 a-- <199.50g <68.41g
# vgs
VG #PV #LV #SN Attr VSize VFree
vg 1 5 0 wz--n- <199.50g <68.41g
How can I use that free space and create a new partition vda3?
-
1Why can’t you use a new LV instead of a new partition? (I’m not saying there are no reasons to do this, just curious what yours are.)Stephen Kitt– Stephen Kitt2021年10月18日 04:39:03 +00:00Commented Oct 18, 2021 at 4:39
-
1@StephenKitt our requirement is to get new partition raw vda3, I have to use it for rook-ceph, rook-ceph doesn't support lvm that's why I need vda3Hackaholic– Hackaholic2021年10月18日 04:45:25 +00:00Commented Oct 18, 2021 at 4:45
1 Answer 1
First, you need to reduce the size of the physical volume, using pvresize
:
pvresize /dev/vda2 --setphysicalvolumesize 132g
This ensures that all the data and metadata end up inside the first 132GiB of /dev/vda2
. I’m playing it safe size-wise here.
Then you need to shrink the /dev/vda2
partition entry, using fdisk
or a similar tool — delete the partition entry and re-create it with the same starting sector and the appropriate size (slightly more than 132GiB, 276,824,064 512-byte sectors, to stay safe). This will allow you to create a new partition.
Finally, resize the PV again, this time using
pvresize /dev/vda2
so that it uses all the available space in the partition.
-
after lvreduce I have to follow your steps?Hackaholic– Hackaholic2021年10月18日 05:00:15 +00:00Commented Oct 18, 2021 at 5:00
-
Yes, this isn’t a generic answer, I wrote it for your specific situation.Stephen Kitt– Stephen Kitt2021年10月18日 05:03:25 +00:00Commented Oct 18, 2021 at 5:03
-
Getting this warning: WARNING: Device /dev/vda2 has size of 257812480 sectors which is smaller than corresponding PV size of 276822016 sectors. Was device resized?Hackaholic– Hackaholic2021年10月18日 05:21:38 +00:00Commented Oct 18, 2021 at 5:21
-
What does
pvs
say?Stephen Kitt– Stephen Kitt2021年10月18日 05:23:52 +00:00Commented Oct 18, 2021 at 5:23 -
pvs
WARNING: Device /dev/vda2 has size of 257812480 sectors which is smaller than corresponding PV size of 276822016 sectors. Was device resized? One or more devices used as PVs in VG vg have changed sizes. PV VG Fmt Attr PSize PFree /dev/vda2 vg lvm2 a-- <132.00g 928.00m
Hackaholic– Hackaholic2021年10月18日 05:25:44 +00:00Commented Oct 18, 2021 at 5:25
You must log in to answer this question.
Explore related questions
See similar questions with these tags.