LVM: Moving volumes?

Forum: LinuxTotal Replies: 22
Author Content
Sander_Marechal

Aug 15, 2008
7:55 PM EDT
Hi all, I need some help moving LVM volumes around on my system. An overview:

I have a HP ProLiant server that sucks about as much power as a 3-4 person household does. It has a hardware RAID5 array containing Debian Etch. Aside from that it has two 500 GB disks that form a RAID1. That RAID1 contains an LVM volume group and inside are logical volumes that contain just data (i.e. music, movies, etcetera).

Now I bought a new low-power server (Dell T105 with 75watt CPU). In it was a single 80 GB disk. On that disk I created a volume group and inside that are three volumes that make up Debian Lenny: my boot volume, my root volume and a swap volume (Yay for grub2 which can handle /boot on LVM :-)

I moved the two 500GB disks from the old server to the new server. So now there are two volume groups on my new server. A big 500GB volume group with data volumes on it, and the original volume group containing boot, root and swap.

What I would like to do now is somehow move boot and root from the current 80 GB volume group to the 500GB volume group. That way I can take out the 80 GB disk and save power.

How should I do this? There seems to be no simple way to move logical volumes from one volume group to another. Any other options?
Sander_Marechal

Aug 18, 2008
6:48 PM EDT
Ah, so no LVM gurus here eh?!

Well, help me with this then: I need a Live CD that has support for mdadm RAID and LVM2. I can't make the changes I need while the server is running because the volumes I need to manipulate are the volumes that hold the OS itself so they are mounted.

I tried Ubuntu 8.04 but that doesn't quite support it. It was a hassle to get lvm working and it refused to start my mdadm arrays because it couldn't read the superblocks on one of my devices. I also tried a Debian Etch Live CD but it doesn't support my hardware. I prefer something Debian based because I'm more familiar with that. I do absolutely need at least kernel 2.6.24 because older kernels do not support my hardware.

Any tips?
techiem2

Aug 18, 2008
7:57 PM EDT
I don't know for sure, but you might have a good chance with SystemRescueCD. http://www.sysresccd.org

The big package list ( http://www.sysresccd.org/Detailed-packages-list ) lists mdadm and lvm2.
NoDough

Aug 18, 2008
7:59 PM EDT
Knoppix has the LVM utils. The latest uses a 2.6.x kernel, but I don't know the minor release.
Sander_Marechal

Aug 19, 2008
1:48 AM EDT
Thanks. I downloaded SystemRescueCD and will try that tonight. If that fails I'll give Knoppix a spin.
Sander_Marechal

Aug 19, 2008
5:52 PM EDT
Succes! SystemRescueCD worked out of the box. I moved the volumes simply by creating new volumes on the destination disk, making filesystems in them and finally simply using "rsync -av" to copy all data from the source volumes to the destination volumes.

Worked wonderfully!
techiem2

Aug 19, 2008
5:55 PM EDT
sweet.
number6x

Aug 20, 2008
12:14 PM EDT
Sander,

A short tutorial on the steps you followed would make a great article. (Hint Hint)
Steven_Rosenber

Aug 20, 2008
8:17 PM EDT
I'm just now exploring the wonder that is rsync, and I'd love to be able to figure out LVM.

I probably just need to set up a Debian or Ubuntu box with LVM and try not to break it.
Sander_Marechal

Aug 21, 2008
2:20 AM EDT
number6x: It's so ridiculously simple that it's not worthy of an article, but I will outline what I did in this comment.

Original system layout:

/dev/sda1 and /dev/sdb1 are a 500 GB RAID1 array. They contain an LVM volume group called "3ware" because this used to be on my 3ware card in the old server.

/dev/sdc1 contains a 80 BG "linuxvg" volume group containing my boot, root and swap volumes.

Goal: Move all volumes from "linuxvg" to "3ware" do I can remove /dev/sdc and save power.

Howto:

Since I can't move volumes around when I'm using them I used SystemRescueCD which comes with mdadm and lvm out of the box. First, activate the RAID1. I copied /etc/mdadm/mdadm.conf before I booted into SystemRescueCD so this is easy.

# mdadm --assemble --scan

Then I modified /etc/lvm/lvm.conf so that it would not look at /dev/sda and /dev/sdb. That's because it needs to look at /dev/md0 instead.

filter = [ "r|/dev/cdrom|", "r|/dev/sd[ab]1|" ]

Now, scan for all LVM volume groups and deactivate them all:

# lvscan # vgcreate -a n

Rename the volume groups:

#vgrename linuxvg linuxold #vgrename 3ware linuxvg

Activate the LVM:

# vgcreate -a y

Create new logical volumes:

# lvcreate --name boot --size 512M linuxvg # lvcreate --name root --size 40960M linuxvg # lvcreate --name swap --size 1024M linuxvg

Create filesystems

# mkfs.ext3 /dev/mapper/linuxvg-boot # mkfs.ext3 /dev/mapper/linuxvg-root # mkswap /dev/mapper/linuxvg-swap

Create mountpoints

# mkdir /mnt/src # mkdir /mnt/dst

Mount volumes and copy over data

# mount -t ext3 /dev/mapper/linuxold-boot /mnt/src # mount -t ext3 /dev/mapper/linuxvg-boot /mnt/src # rsync -av /mnt/src/ /mnt/dts/ # umount /mnt/src # umount /mnt/dst

# mount -t ext3 /dev/mapper/linuxold-root /mnt/src # mount -t ext3 /dev/mapper/linuxvg-root /mnt/src # rsync -av /mnt/src/ /mnt/dts/ # umount /mnt/src # umount /mnt/dst

Reboot the machine and make sure everything works. Note that I have renamed my 500 GB volume group to the name of the original 80 GB volume group. That means that I don't have to make any changes to the OS (e.g. edit fstab) or to grub2, because they still use the same volume names.

Next, edit /boot/grub/devices.map and remove /dev/sdc. Power down the machine. Remove 3rd harddrive. Boot.

That's all.
gus3

Aug 21, 2008
3:57 AM EDT
You could draw that into an article-length essay, if you put some PowerPoint mentality into it. You know, bullet points and pretty pictures.

Wait, did I say that out loud? ;-)
TxtEdMacs

Aug 21, 2008
8:55 AM EDT
Sander,

Write it up, it's worthy of publication. While it may look simple to you, more can be said about some of the commands that I have neither seen or used, e.g. lvscan, vgcreate, lvcreate, vgrename. I assume all are in some way related to the large volume systems.

Another point, I relearn and forget is the necessity of creating mount points. I need them to keep tabs on an extra disc I am not currently running. I might need to see or steal one of the files and mounting them in fstab allows quick access.

For those not used to using the command line, but want to learn about LVM, you have much knowledge you you could convey.

Txt.
Sander_Marechal

Aug 21, 2008
10:18 AM EDT
Okay, I'll write it up properly on my blog with explanation on what the commands do and post it to the newswire :-)
number6x

Aug 21, 2008
10:32 AM EDT
very nice write-up.

Thanks!
azerthoth

Aug 21, 2008
12:54 PM EDT
Thanks Sander, that would go a long way in curing me of avoiding LVM like the plague.
Sander_Marechal

Aug 25, 2008
3:30 PM EDT
Here you go. Currently also on the front page: http://www.jejik.com/articles/2008/08/moving_lvm_volumes_to_...
TxtEdMacs

Aug 25, 2008
4:37 PM EDT
This is going to appear in the queue on LXer, right?

Your article deserves more attention than simply those reading this forum thread. Please post it.
Sander_Marechal

Aug 25, 2008
4:38 PM EDT
It's already on the front page here at LXer :-) I submitted it to the Linux.com NewsVac as well. Feel free to submit it to Digg if you like it.
dumper4311

Aug 25, 2008
5:40 PM EDT
>"It's so ridiculously simple that it's not worthy of an article . . ."

I thoroughly disagree.

You may have overlooked the value and beauty of such simplicity. TxtEdMacs & azerthoth touched on such value briefly. Never discount the ability to take an outwardly complex job and render it in a clear and fundamental form. "this is what I want to do, these are the tools I used, this is how I did it" sounds like a recipe for success in nearly any endeavor.

The article expanded my practical understanding of tools I've never worked very seriously with, and serves to dispel the "linux is hard" myth for everyone who reads it.

The article was fantastic, thank you for publishing it.
hkwint

Aug 25, 2008
6:42 PM EDT
Quoting:You could draw that into an article-length essay, if you put some PowerPoint mentality into it.


You mean with a different add next to each slide!

(Hmm, did I say that or was I just thinking?©)
techiem2

Aug 25, 2008
7:04 PM EDT
You mean 4 ads...one on each side...
Sander_Marechal

Aug 25, 2008
7:06 PM EDT
The PowerPoint mentality is evil anyway. It reduces wonderful stories to a list of bite-size bullet points. See this Wired story: http://www.wired.com/wired/archive/11.09/ppt2.html
gus3

Aug 26, 2008
12:41 AM EDT
Don't forget the cute slide transitions. Chicks^WStuffed shirts love that!

You cannot post until you login.