PDA

View Full Version : How to resize ext3 inside LVM (to remove a drive)


StickyC
30th January 2007, 01:27 AM
I'd like to remove one of the physical disks (/dev/sdb) from my FC4 setup. Here's my system information:


# fdisk -l

Disk /dev/sda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 4863 38957625 8e Linux LVM

Disk /dev/sdb: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 9726 78124063+ 8e Linux LVM


# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 37.12 GB / not usable 0
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 1188
Free PE 0
Allocated PE 1188
PV UUID 6tzgee-mr0Q-gtcE-u0Yf-VyVQ-zndo-ECg5c7

--- Physical volume ---
PV Name /dev/sdb1
VG Name VolGroup00
PV Size 74.50 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 2384
Free PE 2
Allocated PE 2382
PV UUID r07Hzj-cGt2-6DFD-bYDN-pRmV-Ky38-BYm7X2


#lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID eJv4rF-S2RW-RmCr-ELoo-DXgb-JYFn-K4o6xK
LV Write Access read/write
LV Status available
# open 1
LV Size 109.62 GB
Current LE 3508
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID YdY6GP-T5iM-azYe-3RST-iMLJ-Iqd6-5r2mvy
LV Write Access read/write
LV Status available
# open 1
LV Size 1.94 GB
Current LE 62
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1


# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
/dev/proc on /proc type proc (rw)
/dev/sys on /sys type sysfs (rw)
/dev/devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
/dev/shm on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
automount(pid2257) on /net type autofs (rw,fd=4,pgrp=2257,minproto=2,maxproto=4)
automount(pid2212) on /misc type autofs (rw,fd=4,pgrp=2212,minproto=2,maxproto=4)


# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
107G 24G 78G 24% /
/dev/sda1 99M 14M 80M 15% /boot
/dev/shm 1013M 0 1013M 0% /dev/shm


My understanding of the process is that I need to do the following:
pvmove /dev/sdb1 to move all of the extents off of sdb1
lvreduce -L 74500 VolGroup00 Reduced the size of VolGroup00 by 74.5gb (is this needed if I do vgreduce? Should it be the full 80gb instead of the 74.5 reported by pvdisplay?)
vgreduce VolGroup00 /dev/sdb1 Removes /dev/sdb1 from VolGroup00
I should then be able to remove the drive...

I tried to do a pvmove /dev/sdb1, and got the "No extents available for allocation". From what I read, this is because my ext3 partition / is taking up all of the logical volume, so it can't truncate the volume size. So, I need to resize / to fit on a single drive (<40gb). This is where I'm stuck - how do I go about resizing the ext3 partition? My understanding is that QTparted and such dont support LVM's yet. Can I dynamically resize an ext3 partition while it's mounted?

Thanks for any clarifications/help you guys can give - I've been reading posts/how-tos on this stuff for 2 days and my knowledge is pretty scrambled.

Jongi
30th January 2007, 08:42 AM
Here is what the LVM How-to has to say about reducing logical volumes (http://tldp.org/HOWTO/LVM-HOWTO/reducelv.html). With LVM2 and ext3 it would seem you need to unmount. Seeing as sdb1 forms part of the / partition, I am guessing you will most likely need to do this from a livecd that supports LVM.
From reading the How-to I would guess this is how you would then go about it:

# resize2fs /dev/VolGroup00/LogVol00 <new size in blocks>
# lvreduce -L-74.5G /dev/VolGroup00/LogVol00
# pvmove /dev/sdb1
# vgreduce /dev/VolGroup00/LogVol00 /dev/sdb1

I have no idea what I would set <new size in blocks> to. I really don't know why FC has LVM as a default.

EDIT: I've based some of what I have stated above on my experience in resizing and removing a drive from a reiserfs LVM setup (http://www.fedoraforum.org/forum/showpost.php?p=621109&postcount=7).

erroneus
30th January 2007, 02:14 PM
For the moment, LVM is more trouble than it's worth in my opinion. Although I haven't checked lately, typical recovery live CDs and such do not support LVM for some reason. (Specifically Knoppix and it had been a feature requested for well over a year to my knowledge) And under a typical install, there's what? Two partitions? And you cannot resize your actively in-use partition anyway.

LVM might be a terrific idea in some cases, but right now I just don't see it. LVM should be an optional selection in systems with only one hard drive as is the case for most PCs and laptops.

Please correct if I'm wrong.

Seve
30th January 2007, 02:48 PM
Hello:
Well first, I agree that lvm is probably not the best idea for a personal pc or laptop. It would be nice to see as an option and not the default for FC :)

You can do certain things such as rename and resize with the FC install disc and you do not necessarily need a 3rd party Live CD.
The trick is to boot into linux rescue and do not mount your lvm group. When the option to search for a FC installation appears you select skip and then the command prompt will appear.

At this point you can use the lvm tools which are present.
For example:

lvm vgrename VolGroup00 Newname

This will rename the current VolGroup00 to Newname

[But do not do this as this is only an example and may cause you some real issues with your /etc/fstab etc. unless you are very comfortable with what you are doing]

Seve

StickyC
30th January 2007, 06:01 PM
Erroneous - that is the crux of my problem - I can't find a live CD that supports LVM.

Seve - dont I still have to shrink the ext3 partition that's inside the LVM before I can do any LVM shrinking?

Agreed LVM is not the best course for desktop uses.

The main reason I'm doing this is to get the system into a VMWare image - I've not found a tool that can back up the LVM into a format I can restore into VMWare. At this point, I think it'd be easier just to start from scratch with a new install in VMWare and rsync over the important bits.

Jongi
30th January 2007, 08:01 PM
The Kubuntu Edgy LiveCDs can handle LVM

dvrdwn
11th March 2008, 09:01 PM
For a live CD/DVD to work with LVM2, I use Knoppix (5.1.1)

This is actually something I have been doing over the last few days. The following set of commands will help you work with and resize LVM "partitions". Note: they are provided without any documentation and assume that you either know them, or know how to use man to look up their usage. This also assumes ext2/ext3 file system


Boot with Knoppix
Start a root shell
lvm vgscan (discover volume groups)
lvm vgchange -ay (activate all discovered VGs)
lvm lvscan (scan and return info about the LVs)
vgdisplay (display info about the VGs)
lvdisplay (display info about the LVs)
tune2fs -l /dev/volumegroup/rootvolume (return file system information for a specific LV) --or-- tune2fs -l /dev/mapper/volumegroup-rootvolume
e2fsck -f /dev/volumegroup/rootvolume (do a check of the current fs)
resize2fs /dev/mapper/volumegroup-rootvolume nnng (resize the file system, where nnn is the number of gigabytes you want, and g tells resize2fs that nnn is in gigs). --or-- use gparted in Knoppix to resize. If you want to use gparted, you first need to set the root password, which you will be prompted for... or start gparted& from the root shell.
lvreduce -L-xxG /dev/volumegroup/rootvolume (to reduce the size by xx Gigs).
e2fsck -f /dev/volumegroup/rootvolume (recheck the fs) Note: If the check fails, do an lvextend -L+xxG /dev/volumegroup/rootvolume to resize the LV back to where it was, and then re-run the e2fsck to confirm that it's ok. The most likely cause is using the wrong xx or nnn for the resizes.


When determining the amount to resize, you should use 1024 x Gigs to determine the amount with resize2fs... subtract the amount you want to resize from the current size of the "partition".

I have done this procedure, and similar with both "root" and "swap" LVs... it is very do-able and relatively safe... at least as far as resizing partitions ever is "safe".

stevea
11th March 2008, 09:33 PM
Read NOT very safe. If you lvreduce too much it's completely possible that the e2fsck will still succeed - and you'll pay the piper much later when your FS is corrupted.

Now does "G" mean 2^30 or does if mean 10^9 ? If you're wrong your fs is toast, and the resize2fs man page really doesn't say.

Oddly it's safest to shrink the partition (LV) and then resize2f with no size param (defaults to partition size) - of course w/ the fs unmounted.


I'm not bashing you dvrdwn, it's a very fine post, but this is an error prone process and you're notes are most likely correct, but we should really use a tool written by someone who has examined all the fine details and has inputs that prevent typos. If the Fedora live cd has the system-config-lvm tool, then that's the way to go. Sad that gparted doesn't handle LVM.

F.User_4_Life
11th March 2008, 09:41 PM
install either gparted or qtparted and look for a thread about this i personally added a thread about the same subjevt and decided to stick with just fedora and nothing else.