PDA

View Full Version : Resizing partitions with & w/o lvm


anw
17th January 2009, 19:13
Normally, I would just try stuff to see what worked, but in this case there's real data that I don't want to lose, so thought I'd ask for advice here first.

I have three partitions on this disk, laid out thusly:

|--root--|--swap--|-------------- hda3 (lvm) --------------|

hda3 is the only one using lvm. What I want to do is shrink hda3 from the front, to give a couple of more (contiguous) gigabytes to swap. There's plenty of room. Here's the output of lvdisplay:

# lvdisplay
--- Logical volume ---
LV Name /dev/dynamic/usr
VG Name dynamic
LV UUID CDMnar-5290-7F1t-e4wf-Mvw6-ghv9-ombuVG
LV Write Access read/write
LV Status available
# open 1
LV Size 120.00 GB
Current LE 30720
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:0

--- Logical volume ---
LV Name /dev/dynamic/var
VG Name dynamic
LV UUID jdJHED-8bMO-qZ1P-IM9J-unzL-ScqQ-uyBcJU
LV Write Access read/write
LV Status available
# open 1
LV Size 120.00 GB
Current LE 30720
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:1

--- Logical volume ---
LV Name /dev/dynamic/home
VG Name dynamic
LV UUID xjGtYV-04XE-7ihk-tlkR-RrMB-Vljd-d7kun2
LV Write Access read/write
LV Status available
# open 1
LV Size 17.98 GB
Current LE 4602
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:2

and here's the output of pvdisplay:

# lvm pvs
PV VG Fmt Attr PSize PFree
/dev/hda3 dynamic lvm2 a- 435.96G 177.98G

So, there's plenty of room; but what I don't understand is there doesn't seem to be any way to tell lvresize or pvresize how to move the lv's or pv's around. In other words, I want to tell pvresize (and probably fdisk, too, right?) to scoot everything over to the right by a couple of gig, then tell fdisk to increase the swap partition by said amount.

I've found several examples on the net, but none demonstrate how to exercise this fine a control over the starting and ending locations, and, as I say, I'd be much more open to just experimenting if these weren't currently in use with (a lot) of real, live data.

TIA!

grandpagenocide
18th January 2009, 01:27
While online enlarging is no problem, you have to umount for shrinking!
Code:

# umount /dev/vg_blah/lv_blah

Perform a check of the filesystem...
Code:

# e2fsck -f /dev/vg_blah/lv_blah

Resize the filesystem first.
Code:

# resize2fs /dev/vg_blah/lv_blah 9G

Then reduce the size of the logical volume.
Code:

# lvreduce -L -1G /dev/vg_blah/lv_blah

After that you can shrink down the volume group if desired.
Code:

# vgreduce vg_blah /dev/sdxy

Warning: It is crucial that you use the exact amount of space. If you reduce volume more than the filesytem you truncate the logical volume and you risk data loss!

!!! I WOULD NEVER SHRINK A FILESYSTEM WITHOUT A BACKUP !!!

copied from linuxquestions.org, worked for me, boot off linux rescuse disk or live distro, i do advise play around on a spare box if u got one, i completly screwed up like 10 times before i found this tut and got it right

anw
18th January 2009, 03:32
Thanks for the help!

Don't I have to reduce the VG size if I'm going to reduce the partition? I have three lv's in this VG, but an extra 177 gig or so of space in the volume group, which is the full size of the partition. So, do I need to shrink any of the LVs? And, when I do shrink the VG, how do I tell it to shrink it from the front, and not from the back (i. e., add space between swap and hda3 so I can contiguously expand swap)?

falko
18th January 2009, 12:17
I think this tutorial has everything you need: http://www.howtoforge.com/linux_lvm

anw
18th January 2009, 17:25
Hey, Falko!

Thanks. I had actually read that article, but there were still a couple of questions I had. Right now, as you can see in a minute by what I'm fixing to post, this may have been OBE- I think I'm just going to get a new drive if it's pretty easy.

If not, I'll return to this and figure out exactly what question I had on that article.

Thanks for the help! New question coming...