|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
|
|
Shrinking logical volume is complex operation that should generally be avoided on production servers.
It is easier to backup logical volume, delete it, create new smaller, format it and then restore data to it.
If you are forced to go this way please note that you need to understand LVM well and verify each step carefully in order to succeed. One important thing is that first you need to shrink ext partition that exists on this logical volume and then shrink the volume itself. Discrepancies in the size of logical volume and ext filesystem can be deadly.
See Linux-BSD sharing experiences HowTo Shrink size of ext4 LVM logical volume for details.
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
June 1, 2012 | Linux-BSD sharing experiences
... the required steps to reduce the size of an LVM logical volume formatted as an ext4 filesystem...
1) Unmount the logical volume (or boot into a live CD if the logical volume contains the root filesystem)
2) Check the filesystem for errors
3) Shrink the filesystem to the desired size
4) Reduce the size of the underlying logical volume
5) Check if the resulting logical volume and filesystem are ok
6) Re-mount the logical volumeTo illustrate the procedure assume a volume group name vg_d620 which contains the lv_example logical group. The objective will be to shrink the lv_example logical group that is formatted with ext4 to 30G.
1) Unmount the logical volume
Change to the superuser and unmount the logical volume filesystem that is to be resized:
$ su
# umount /dev/mapper/vg_d620-lv_example
2) Check the filesystem for errors
e2fsck checks a Linux ext2/ext3/ext4 filesystem for errors, in this case the -f switch is used to force the check even if the filesystem appears to be clean:
# e2fsck -f /dev/mapper/vg_d620-lv_example
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information/dev/mapper/vg_d620-lv_example: 11448/3678208 files (1.5% non-contiguous), 4768046/14704640 blocks3) Shrink the filesystem to the desired size
resize2fs is used to shrink our unmounted filesystem located on vol_d620-lv_example. The -p switch is prints out percentage completion bars for the resize operation. Here the ext4 filesystem is reduced to the desired filesystem final size, in this case I want it to be of 30 gigabytes:
# resize2fs -p /dev/mapper/vg_d620-lv_example 30G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_d620-lv_example to 7864320 (4k) blocks.
Begin pass 2 (max = 16894)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 449)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 1866)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXThe filesystem on /dev/mapper/vg_d620-lv_example is now 7864320 blocks long.4) Reduce the size of the underlying logical volume
Having shrunk the ext4 filesystem it is time to reduce the logical volume size accordingly. To achieve this the lvreduce tool is employed. The -L switch specifies final size of the logical volume which should match the size of the ext4 filesystem.
# lvreduce -L 30G /dev/mapper/vg_d620-lv_example
WARNING: Reducing active logical volume to 30.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_example? [y/n]: y
Reducing logical volume lv_example to 30.00 GiBLogical volume lv_example successfully resized5) Check if the resulting logical volume and filesystem are ok
Everything should have proceeded as planned however let's verify things. e2fsck and resize2fs are used verify the new filesystem, respectively. Notice that this time the resize2fs doesn't specify any size, the goal here is to have the filesystem match the size of the logical volume.
# e2fsck -f /dev/mapper/vg_d620-lv_example
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information/dev/mapper/vg_d620-lv_example: 11448/1966080 files (1.5% non-contiguous), 4658570/7864320 blocks# resize2fs -p /dev/mapper/vg_d620-lv_example
resize2fs 1.41.12 (17-May-2010)The filesystem is already 7864320 blocks long. Nothing to do!
6) Re-mount the logical volume
Finally, mount the updated logical volume:
# mount /dev/mapper/vg_d620-lv_example /mnt/example
It should be noted that if in step 4 e2fsck fails because the partition is tool small lvextend can be used to extend the logical volume until e2fsck completes with success.
Further information on lvm, lvreduce, lvextend,e2fsck and resize2fs can be obtained in the associated man pages.
In this article, and in this article, we showed how to install and extend logical volumes with LVM. Now, we want to shrink the filesystem we created and the logical volume, so we can remove the drive.
Note: Before you do anything involving your partitions or volumes, make a complete backup.
Make sure to set up a test system with the same kernel and distribution to see how this stuff works. This article was written using our lab box. Read our terms of use. Note that this article was written using a Fedora RC 1 distribution and a generic 2.4.24 kernel.] As we do all of this, we have a text file on our logical volume called ruk.txt that we can use to somewhat test the integrity of our filesystem and volume:
[root@srv-1 root]# mount /dev/sda1 on / type ext3 (rw) none on /proc type proc (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sdb1 on /opt type ext3 (rw) /dev/sdc1 on /usr/src type ext3 (rw) /dev/sdd1 on /usr/local type ext3 (rw) /dev/volgroup/logicalvol on /mnt type ext3 (rw) [root@srv-1 root]# cat /mnt/ruk.txt test [root@srv-1 root]# umount /mntOK. We have data on our volume. Now, we want to shrink down the filesystem on our volume so we can remove one of the drives:[root@srv-1 root]# lvmdiskscan lvmdiskscan -- reading all disks / partitions (this may take a while...) lvmdiskscan -- /dev/sda1 [ 3.75 GB] Primary LINUX native partition [0x83] lvmdiskscan -- /dev/sda2 [ 250.98 MB] Primary LINUX swap partition [0x82] lvmdiskscan -- /dev/sdb1 [ 4 GB] Primary LINUX native partition [0x83] lvmdiskscan -- /dev/sdc1 [ 4 GB] Primary LINUX native partition [0x83] lvmdiskscan -- /dev/sdd1 [ 4 GB] Primary LINUX native partition [0x83] lvmdiskscan -- /dev/sde [ 4 GB] USED LVM whole disk lvmdiskscan -- /dev/sdf [ 4 GB] USED LVM whole disk lvmdiskscan -- /dev/sdg [ 4 GB] USED LVM whole disk lvmdiskscan -- /dev/sdh [ 4 GB] free whole disk lvmdiskscan -- 8 disks lvmdiskscan -- 4 whole disks lvmdiskscan -- 0 loop devices lvmdiskscan -- 0 multiple devices lvmdiskscan -- 0 network block devices lvmdiskscan -- 5 partitions lvmdiskscan -- 0 LVM physical volume partitions [root@srv-1 root]# ot@srv-1 root]# e2fsck -f /dev/volgroup/logicalvol e2fsck 1.34 (25-Jul-2003) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/volgroup/logicalvol: 12/1441792 files (0.0% non-contiguous), 53460/2883584 blocks [root@srv-1 root]# ot@srv-1 root]# resize2fs /dev/volgroup/logicalvol 40000 resize2fs 1.34 (25-Jul-2003) Resizing the filesystem on /dev/volgroup/logicalvol to 40000 (4k) blocks. The filesystem on /dev/volgroup/logicalvol is now 40000 blocks long. [root@srv-1 root]#Check our test file:[root@srv-1 root]# mount /dev/volgroup/logicalvol /mnt [root@srv-1 root]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 3874108 1611852 2065460 44% / none 3874108 1611852 2065460 44% /dev/pts /dev/sdb1 4127076 235028 3682404 6% /opt /dev/sdc1 4127076 278956 3638476 8% /usr/src /dev/sdd1 4127076 32828 3884604 1% /usr/local /dev/volgroup/logicalvol 155872 32832 116640 22% /mnt [root@srv-1 root]# [root@srv-1 root]# ls /mnt lost+found ruk.txt [root@srv-1 root]# cat /mnt/ruk.txt test [root@srv-1 root]# [root@srv-1 root]# umount /mnt umount: /mnt: not mounted
Our test file is still complete after resizing the filesystem. Note that the logical volume is still the same size. Let's shrink it by 8 Gigs:
[root@srv-1 root]# lvreduce -L -8G /dev/volgroup/logicalvol lvreduce -- WARNING: reducing active logical volume to 3 GB lvreduce -- THIS MAY DESTROY YOUR DATA (filesystem etc.) lvreduce -- do you really want to reduce "/dev/volgroup/logicalvol"? [y/n]: y lvreduce -- doing automatic backup of volume group "volgroup" lvreduce -- logical volume "/dev/volgroup/logicalvol" successfully reduced [root@srv-1 root]# mount /dev/volgroup/logicalvol /mnt [root@srv-1 root]# ls /mnt lost+found ruk.txt [root@srv-1 root]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 3874108 1611996 2065316 44% / none 3874108 1611996 2065316 44% /dev/pts /dev/sdb1 4127076 235028 3682404 6% /opt /dev/sdc1 4127076 278956 3638476 8% /usr/src /dev/sdd1 4127076 32828 3884604 1% /usr/local /dev/volgroup/logicalvol 155872 32832 116640 22% /mnt [root@srv-1 root]# ot@srv-1 root]# cat /mnt/ruk.txt test [root@srv-1 root]#
Our file is still there, and the logical volume is shrunk down. Let's remove /dev/sdg from the volume group:
[root@srv-1 root]# vgreduce volgroup /dev/sdg vgreduce -- doing automatic backup of volume group "volgroup" vgreduce -- volume group "volgroup" successfully reduced by physical volume: vgreduce -- /dev/sdg [root@srv-1 root]#
Let's do a scan:
[root@srv-1 root]# pvscan pvscan -- reading all physical volumes (this may take a while...) pvscan -- ACTIVE PV "/dev/sde" of VG "volgroup" [3.99 GB / 1016 MB free] pvscan -- ACTIVE PV "/dev/sdf" of VG "volgroup" [3.99 GB / 3.99 GB free] pvscan -- inactive PV "/dev/sdg" is in no VG [4 GB] pvscan -- total: 3 [12 GB] / in use: 2 [8 GB] / in no VG: 1 [4 GB] [root@srv-1 root]#
We are now ready to replace or reconfigure our logical volume.There are six articles in this series:
Setting Up Logical Volume Manager
Extending a Logical Volume
Shrinking a Logical Volume With LVM
Adding a RAID1 Device to a Volume With LVM
Upgrading LVM To Version 2 and Patching The Linux Kernel
Finish Conversion And Expansion to Two RAID1 Devices With LVM
The following steps will show you how to shrink an LVM volume. In this example we will be shrinking volume VolGroup00-LogVol00 down to 20GB. Note: This can and will cause data loss if performed improperly or on a volume that you attempt to shrink below the current volume usage. With that said, the steps are as follows:
1 2
34
5umount
/dev/mapper/VolGroup00-LogVol00
e2fsck -f /dev/mapper/VolGroup00-LogVol00
resize2fs /dev/mapper/VolGroup00-LogVol00
20G
lvreduce -L 20G /dev/mapper/VolGroup00-LogVol00
e2fsck -f /dev/mapper/VolGroup00-LogVol00
The process is similar when expanding a logical volume except the
lvextend
command is used in place oflvreduce
.
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: March 12, 2019