<\/figure><\/a><\/div>\n\n\n\nReduce or Shrink Logical Volume<\/h3>\n\n\n\n To reduce or shrink Physical Volume in Linux, begin by shrinking logical volume and the underlying filesystem.<\/p>\n\n\n\n
Logical volume details can be displayed using lvs<\/code><\/strong> or lvdisplay<\/code><\/strong> command;<\/p>\n\n\n\nlvdisplay<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
\n --- Logical volume ---\n LV Path \/dev\/ubuntu-vg\/ubuntu-lv\n LV Name ubuntu-lv\n VG Name ubuntu-vg\n LV UUID nmfKLT-IsWR-FfLX-CspJ-yaGz-CwR7-cGKSk2\n LV Write Access read\/write\n LV Creation host, time ubuntu-server, 2022-04-29 05:05:06 +0000\n LV Status available\n # open 0\n LV Size <37.29 GiB\n Current LE 9545\n Segments 1\n Allocation inherit\n Read ahead sectors auto\n - currently set to 256\n Block device 253:0\n<\/code><\/pre>\n\n\n\nIf the volumes are not activated on system boot, activate using the command below;<\/p>\n\n\n\n
vgchange -ay<\/code><\/pre>\n\n\n\nTo shrink the logical volume and the underlying filesystem, use lvreduce --resizefs<\/strong><\/code> command as follows;<\/p>\n\n\n\nlvreduce [-r|--resizefs] [-L|--size [-]Size[m|UNIT] <path\/to\/LV><\/code><\/pre>\n\n\n\ne.g;<\/p>\n\n\n\n
lvreduce -r -L 15G \/dev\/ubuntu-vg\/ubuntu-lv<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
\nfsck from util-linux 2.37.2\n\/dev\/mapper\/ubuntu--vg-ubuntu--lv: 164766\/2449408 files (0.1% non-contiguous), 2093538\/9774080 blocks\nresize2fs 1.46.5 (30-Dec-2021)\nResizing the filesystem on \/dev\/mapper\/ubuntu--vg-ubuntu--lv to 3932160 (4k) blocks.\nThe filesystem on \/dev\/mapper\/ubuntu--vg-ubuntu--lv is now 3932160 (4k) blocks long.\n\n Size of logical volume ubuntu-vg\/ubuntu-lv changed from <37.29 GiB (9545 extents) to 15.00 GiB (3840 extents).\n Logical volume ubuntu-vg\/ubuntu-lv successfully resized.\n\n<\/code><\/pre>\n\n\n\nConfirm the shrinkage;<\/p>\n\n\n\n
lvdisplay<\/code><\/pre>\n\n\n\n\n --- Logical volume ---\n LV Path \/dev\/ubuntu-vg\/ubuntu-lv\n LV Name ubuntu-lv\n VG Name ubuntu-vg\n LV UUID nmfKLT-IsWR-FfLX-CspJ-yaGz-CwR7-cGKSk2\n LV Write Access read\/write\n LV Creation host, time ubuntu-server, 2022-04-29 05:05:06 +0000\n LV Status available\n # open 0\n LV Size 15.00 GiB<\/strong>\n Current LE 3840\n Segments 1\n Allocation inherit\n Read ahead sectors auto\n - currently set to 256\n Block device 253:0\n<\/code><\/pre>\n\n\n\nIf all is good, then proceed!<\/p>\n\n\n\n
Reduce or Shrink Physical Volume<\/h3>\n\n\n\n You can now proceed to reduce or shrink Physical volume.<\/p>\n\n\n\n
At the moment, our physical volume, \/dev\/sda3, is ~37.29g. We will shrink it as well to 15G.<\/p>\n\n\n\n
You can show the details about Physical volume using pvs<\/code><\/strong> or pvdisplay<\/code><\/strong> command.<\/p>\n\n\n\npvdisplay<\/code><\/pre>\n\n\n\n\n --- Physical volume ---\n PV Name \/dev\/sda3\n VG Name ubuntu-vg\n PV Size <37.29 GiB \/ not usable 2.98 MiB\n<\/strong> Allocatable yes \n PE Size 4.00 MiB\n Total PE 9545\n Free PE 5705\n Allocated PE 3840\n PV UUID 2l4lAf-vXju-afXg-LfeQ-jcl2-Q3mR-99iXpg\n<\/code><\/pre>\n\n\n\nIn our example, we need to resize our physical volume to 15G.<\/p>\n\n\n\n
As you can see from the example above, we have Allocated PE of 3840 each of size 4.00 MiB. This totals to 15360 MiB (15 GiB) of space.<\/p>\n\n\n\n
To ensure that the last sector is counted while resizing, add 1 Extent (4 MiB). <\/p>\n\n\n\n
You can get the information about the start and length of each physical extents;<\/p>\n\n\n\n
pvs -v --segments \/dev\/sda3<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
PV VG Fmt Attr PSize PFree Start SSize LV Start Type PE Ranges \n \/dev\/sda3 ubuntu-vg lvm2 a-- 15.00g 0 0 3840 ubuntu-lv 0 linear \/dev\/sda3:0-3839<\/code><\/pre>\n\n\n\nThe total allocated extents are 3840. When you add 1 extent, it becomes 3841 extents which is equivalent to (3841x4) = 15364 MiB.<\/p>\n\n\n\n
Since pvresize command doesn't take extents an option, we can use the total volume size in MiB. Hence, to reduce or shrink our volume size to 15G, we can use the command;<\/p>\n\n\n\n
pvresize \/dev\/sda3 --setphysicalvolumesize 15364<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
\/dev\/sda3: Requested size 15.00 GiB is less than real size <37.29 GiB. Proceed? [y\/n]: y\n WARNING: \/dev\/sda3: Pretending size is 31465472 not 78200799 sectors.\n Physical volume \"\/dev\/sda3\" changed\n 1 physical volume(s) resized or updated<\/strong> \/ 0 physical volume(s) not resized<\/code><\/pre>\n\n\n\nYou may get an output that says cannot resize to XXXX extents as YYYY are allocated. In this case, you need to ensure that your segments are aligned properly.<\/p>\n\n\n\n
Confirm new Physical volume size;<\/p>\n\n\n\n
pvdisplay<\/code><\/pre>\n\n\n\n\n --- Physical volume ---\n PV Name \/dev\/sda3\n VG Name ubuntu-vg\n PV Size 15.00 GiB<\/strong> \/ not usable 3.00 MiB\n Allocatable yes (but full)\n PE Size 4.00 MiB\n Total PE 3840\n Free PE 0\n Allocated PE 3840\n PV UUID 2l4lAf-vXju-afXg-LfeQ-jcl2-Q3mR-99iXpg\n<\/code><\/pre>\n\n\n\nReduce or Shrink the Physical Volume Partition<\/h3>\n\n\n\nDisks with Primary Partitions Only<\/h4>\n\n\n\n You can now shrink the physical volume partition. You can use fdisk<\/strong> command;<\/p>\n\n\n\nfdisk \/dev\/sda<\/code><\/pre>\n\n\n\nList the partitions by pressing p<\/strong>.<\/p>\n\n\n\n\nWelcome to fdisk (util-linux 2.37.2).\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\n\nThis disk is currently in use - repartitioning is probably a bad idea.\nIt's recommended to umount all file systems, and swapoff all swap\npartitions on this disk.\n\n\nCommand (m for help): p\n<\/code><\/pre>\n\n\n\nSample output;<\/p>\n\n\n\n
\nDisk \/dev\/sda: 39.06 GiB, 41943040000 bytes, 81920000 sectors\nDisk model: VBOX HARDDISK \nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: gpt\nDisk identifier: 55B779AD-FE40-4978-9911-787F868D006B\n\nDevice Start End Sectors Size Type\n\/dev\/sda1 2048 4095 2048 1M BIOS boot\n\/dev\/sda2 4096 3719167 3715072 1.8G Linux filesystem\n\/dev\/sda3 3719168 81919966 78200799 37.3G Linux filesystem\n<\/code><\/pre>\n\n\n\nWe need to delete root partition in this case, \/dev\/sda3;<\/p>\n\n\n\n
Hence, press d and select partition 3;<\/p>\n\n\n\n
Command (m for help): d\nPartition number (1-3, default 3): \n\nPartition 3 has been deleted.\n\nCommand (m for help):<\/code><\/pre>\n\n\n\nCreate a new partition and allocate 15364M (Note that we set the PV to 15364 MiB) and when prompted to remove the signature, select No;<\/strong><\/p>\n\n\n\n\nCommand (m for help): n\nPartition number (3-128, default 3): \nFirst sector (3719168-81919966, default 3719168): \nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (3719168-81919966, default 81919966): +15364M\n\nCreated a new partition 3 of type 'Linux filesystem' and of size 15 GiB.\nPartition #3 contains a LVM2_member signature.\n\nDo you want to remove the signature? [Y]es\/[N]o: N\n\nCommand (m for help):\n<\/code><\/pre>\n\n\n\nPrint the partition tables again to confirm the size;<\/p>\n\n\n\n
\nCommand (m for help): p\n\nDisk \/dev\/sda: 39.06 GiB, 41943040000 bytes, 81920000 sectors\nDisk model: VBOX HARDDISK \nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: gpt\nDisk identifier: 55B779AD-FE40-4978-9911-787F868D006B\n\nDevice Start End Sectors Size Type\n\/dev\/sda1 2048 4095 2048 1M BIOS boot\n\/dev\/sda2 4096 3719167 3715072 1.8G Linux filesystem\n\/dev\/sda3 3719168 35176447 31457280 15G Linux filesystem\n\nCommand (m for help):\n<\/code><\/pre>\n\n\n\nWrite changes and exit fdisk;<\/p>\n\n\n\n
Command (m for help): w\nThe partition table has been altered.\nSyncing disks.<\/code><\/pre>\n\n\n\nDisks with Primary and Extended\/Logical Partitions<\/h4>\n\n\n\n What if you have a disk with Extended and logical partitions? And the first logical partition is is the one with the disk physical volume?<\/p>\n\n\n\n
This is an example;<\/p>\n\n\n\n
fdisk -l \/dev\/sda<\/code><\/pre>\n\n\n\n\nDisk \/dev\/sda: 20 GiB, 21474836480 bytes, 41943040 sectors\nDisk model: QEMU HARDDISK \nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x75b85259\n\nDevice Boot Start End Sectors Size Id Type\n\/dev\/sda1 * 2048 999423 997376 487M 83 Linux\n\/dev\/sda2 1001470 41940991 40939522 19.5G 5 Extended\n\/dev\/sda5 1001472 41940991 40939520 19.5G 8e Linux LVM<\/strong>\n<\/code><\/pre>\n\n\n\nYou need to delete the logical and extended partition and recreate them as shown below;<\/p>\n\n\n\n
fdisk \/dev\/sda<\/code><\/pre>\n\n\n\n\nWelcome to fdisk (util-linux 2.37.2).\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\n\nThis disk is currently in use - repartitioning is probably a bad idea.\nIt's recommended to umount all file systems, and swapoff all swap\npartitions on this disk.\n\n\nCommand (m for help):\n<\/code><\/pre>\n\n\n\nList the partitions by typing p<\/strong> and press ENTER;<\/p>\n\n\n\n\nCommand (m for help): p\n\nDisk \/dev\/sda: 20 GiB, 21474836480 bytes, 41943040 sectors\nDisk model: QEMU HARDDISK \nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x75b85259\n\nDevice Boot Start End Sectors Size Id Type\n\/dev\/sda1 * 2048 999423 997376 487M 83 Linux\n\/dev\/sda2 1001470 41940991 40939522 19.5G 5 Extended\n\/dev\/sda5 1001472 41940991 40939520 19.5G 8e Linux LVM\n\nCommand (m for help):\n<\/code><\/pre>\n\n\n\nSo, we need to delete the Logical partition (\/dev\/sda5) and Extended partition (\/dev\/sda2) using d<\/strong> option;<\/p>\n\n\n\n\nCommand (m for help): d\nPartition number (1,2,5, default 5): \n\nPartition 5 has been deleted.\n\nCommand (m for help): d\nPartition number (1,2, default 2): \n\nPartition 2 has been deleted.\n\nCommand (m for help):\n<\/code><\/pre>\n\n\n\nNext, create the Extended partition. The size should be exactly same as the physical volume size. Consider this physical size;<\/p>\n\n\n\n
pvdisplay<\/code><\/pre>\n\n\n\n\n --- Physical volume ---\n PV Name \/dev\/sda5\n VG Name bookworm-vg\n PV Size 10.00 GiB \/ not usable 3.00 MiB\n Allocatable yes (but full)\n PE Size 4.00 MiB\n Total PE 2560\n Free PE 0\n Allocated PE 2560\n PV UUID JK72C1-ginB-1kph-t96A-NV4c-8H3e-6wxgpc\n<\/code><\/pre>\n\n\n\nSo, in this case, we would set the size to (2560+1)x4=10244MiB. Hence, in this case, this should be our Extended partition size.<\/p>\n\n\n\n
Hence, type n<\/strong> and press enter to create new Extended partition;<\/p>\n\n\n\nPartition type is Extended (e<\/strong>)<\/p>\n\n\n\n\nCommand (m for help): n\nPartition type\n p primary (1 primary, 0 extended, 3 free)\n e extended (container for logical partitions)\nSelect (default p): e\nPartition number (2-4, default 2): \nFirst sector (999424-41943039, default 999424): \nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (999424-41943039, default 41943039): +10244M<\/strong>\n\nCreated a new partition 2 of type 'Extended' and of size 10 GiB.<\/strong>\n<\/code><\/pre>\n\n\n\nNext, create another parition, which is the logical partition. It should be same size as the extended partition above. While creating the logical partition, you will be prompted whether to remove the signature<\/strong>. PLEASE DO NOT<\/strong>. Enter N<\/strong> for No!<\/p>\n\n\n\nPartition type is Logical (l<\/strong>);<\/p>\n\n\n\n\nCommand (m for help): n\nPartition type\n p primary (1 primary, 1 extended, 2 free)\n l logical (numbered from 5)\nSelect (default p): l<\/strong>\n\nAdding logical partition 5\nFirst sector (1001472-21979135, default 1001472): \nLast sector, +\/-sectors or +\/-size{K,M,G,T,P} (1001472-21979135, default 21979135): +10244M<\/strong>\n\nCreated a new partition 5 of type 'Linux' and of size 10 GiB.\nPartition #5 contains a LVM2_member signature.\n\nDo you want to remove the signature? [Y]es\/[N]o: N<\/strong>\n<\/code><\/pre>\n\n\n\nWrite the changes to the disk by typing w<\/strong>.<\/p>\n\n\n\nDetach Live CD from the System<\/h3>\n\n\n\n Shutdown the system and remove live CD iso.<\/p>\n\n\n\n
After that, boot the system.<\/p>\n\n\n\n
Confirm Physical Volume Resize\/Shrink<\/h3>\n\n\n\n Check if all is good.<\/p>\n\n\n\n
pvdisplay<\/code><\/pre>\n\n\n\n\n --- Physical volume ---\n PV Name \/dev\/sda3\n VG Name ubuntu-vg\n PV Size 15.00 GiB \/ not usable 3.00 MiB\n Allocatable yes (but full)\n PE Size 4.00 MiB\n Total PE 3840\n Free PE 0\n Allocated PE 3840\n PV UUID 2l4lAf-vXju-afXg-LfeQ-jcl2-Q3mR-99iXpg\n<\/code><\/pre>\n\n\n\nCheck disk usage;<\/p>\n\n\n\n
df -hT<\/code><\/pre>\n\n\n\n\nFilesystem Type Size Used Avail Use% Mounted on\ntmpfs tmpfs 198M 1.2M 197M 1% \/run\n\/dev\/mapper\/ubuntu--vg-ubuntu--lv ext4 15G 7.3G 6.8G 53% \/<\/strong>\ntmpfs tmpfs 988M 0 988M 0% \/dev\/shm\ntmpfs tmpfs 5.0M 0 5.0M 0% \/run\/lock\n\/dev\/sda2 ext4 1.8G 245M 1.4G 15% \/boot\ntmpfs tmpfs 198M 4.0K 198M 1% \/run\/user\/1000\n<\/code><\/pre>\n\n\n\nAnd there you go! You have learnt how to successfully reduce or shrink physical volume in Linux (Ubuntu 22.04) using live CD!<\/p>\n\n\n\n
That marks the end of our tutorial on reducing or shrinking Physical Volume in Linux.<\/p>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n Easy Way to Extend KVM Virtual Machine Disk Size<\/a><\/p>\n\n\n\nChange Windows Boot Device from IDE to Virtio on KVM<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"How do I shrink physical volume in Linux? In this tutorial, you will learn how to reduce or shrink Physical Volume in Linux. In a<\/p>\n","protected":false},"author":10,"featured_media":15308,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[39,121,43],"tags":[6314,6312,6313,6311,6308,6309,6310],"class_list":["post-15301","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-storage","category-howtos","category-lvm","tag-how-do-i-shrink-physical-volume-in-linux","tag-how-do-you-reduce-physical-volume","tag-how-do-you-shrink-a-logical-volume","tag-linux-shrink-physical-volume","tag-reduce-or-shrink-physical-volume-in-linux","tag-resize-physical-volume-in-linux","tag-shrink-physical-volume-in-linux","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/15301"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=15301"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/15301\/revisions"}],"predecessor-version":[{"id":20677,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/15301\/revisions\/20677"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/15308"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=15301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=15301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=15301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}