Imaging LVM systems?

Forum: LXer Meta ForumTotal Replies: 16
Author Content

Jan 08, 2010
3:25 PM EDT
Most of our machines we've been simply using partimage to create backups for our labs and servers and such.

We are planning to build out a new domain controller box since we need the new samba version to handle Windows 7 (gag) clients, and the boss would like to use lvm on the new server if he can.

We are wondering if there's a good way to handle imaging lvm.

Any ideas, suggestions?


Mark II

Jan 08, 2010
3:49 PM EDT
This could be a job for Clonezilla.

Jan 08, 2010
3:54 PM EDT
hmm...I'll have to see what it will do with them. It might be an option. I know partimage would work, but you'd have to mount the lvm volumes etc. then image the partitions in them. Which would mean on a bare system you'd have to manually setup the lvm structure before imaging. Which would be somewhat of a pain I would think.

Jan 08, 2010
5:07 PM EDT

Probably it depends on what you want, I'm not entirely sure.

If you want to 'image' the filesystems on your logical LVM-volumes on a live-system you could just make a snapshot (a copy of your lvm logical volume frozen in time) and use dd. Something like #lvcreate -L8G -s -n var_backup /dev/vg0/var #dd if=/dev/vg0/var_backup of=~/var.img

This could lead to large files, because most of the times the filesystems will contain random data. There are tools available to zero out the non-used bits of filesystems. If you zero them out, it would be easier to compress your resulting image.

If you want to image the partitions that contain the entire LVM system, you could also use dd, but than it's more complex because they could span multiple disks. So to put the image back on some other disks, those other disks need to have the same configuration. I guess that's not what you want.

I'm not aware of imaging-tools being able to handle LVM, because I'm unfamiliar with any imaging tools beyond dd / iso's at all.

Jan 08, 2010
6:00 PM EDT
techiem2, looks like this could be scripted/automated, or atleast point you in a possible direction.

Jan 08, 2010
6:02 PM EDT
Also, there may be some filesystem-specific tools for whatever filesystem(s) you're using inside the logical volumes. For example, XFS has xfs_dump and xfs_restore.

As for Hans' idea for using "dd", here's what I'd do:

# dd if=/dev/vg0/var_backup bs=1048576 | gzip -9 > ~/var.img.gz

Unless the system is dealing with lots of CPU-heavy processes, the "gzip -9" should have little effect overall. What's lost in compression work, is gained in less filesystem load writing "var.img.gz".

Jan 08, 2010
9:31 PM EDT
Features of Clonezilla

* Filesystem supported: ext2, ext3, ext4, reiserfs, xfs, jfs of GNU/Linux, FAT, NTFS of MS Windows, and HFS+ of Mac OS. Therefore you can clone GNU/Linux, MS windows and Intel-based Mac OS, no matter it's 32-bit (x86) or 64-bit (x86-64) OS. For these file systems, only used blocks in partition are saved and restored. For unsupported file system, sector-to-sector copy is done by dd in Clonezilla. * LVM2 (LVM version 1 is not) under GNU/Linux is supported.

Jan 09, 2010
11:37 AM EDT
It should be no problem using any imaging tool that works on the partition level. LVM lives on top of regular partitions.

Jan 10, 2010
5:02 PM EDT
Sander, do you know of a good resource/reference on how to manipulate LVM?

I rely on GParted for all of my non-LVM needs, and I don't need a GUI, but I'd really like some guidance on how to work with new and existing LVM setups, including those with encryption.

I feel like I'm really benefiting from my move to LVM, but now that the Debian installer set it up for me, I don't know where to go from here.

Jan 10, 2010
5:47 PM EDT
Steven, there are quite a few good tutorials around. The basics are simple though.

At the lowest level you have physical volumes. PVs. You manipulate them with the commands that start with pv*. Physical volumes are your real hard drive partitions. Above that is a volume group (VG). It's basically any number of PVs roped together as a group. You manipulate them with the commands that start with vg*. Inside the volume group you can create logical volumes (LV). These are basically "virtual partitions". They act the same way a real partition does (e.g. you still need to create a filesystem on them). You manipulate them with the commands that start with lv*.

That's the basics. The rest is fluff, nifty options and what-not.

Jan 10, 2010
6:09 PM EDT
Side note, apropos of very little:

On my dual-core system, JFS saturates easily under heavy system load.

But when I set up a 2-stripe logical volume, it doubled the I/O on a slow CPU (1GHz), and tripled the I/O on a fast CPU (2.5GHz). The only change was introducing LVM.

Go figure.

Jan 11, 2010
4:14 AM EDT
Back when I used encryption + LVM1, encryption was handled using 'cryptsetup' - written by Saout, like I said in the other thread. It took some bypassing using the LiveCD because back in the LVM1 days you needed to activate LVM before you could mount it, but because /usr, /var and /tmp were on LVM (and /tmp was encrypted) the system wouldn't boot. However, as of LVM2 it just starts and runs!

Then the name changed from cryptsetup to cryptsetup-luks, and after that came something more advanced. However, I didn't use it anymore.

One of the nifty problems in my setup back then, was: -You could first start LVM, have physical partitions added to a volume group, logical volumes taken from that volume group and the encryption-device mapped on top of the LVM-logical volume, -You could take your physical partition, use encryption to map it to an encrypted volume, add that encrypted volume to the LVM volume group, and then assign space of the volume group to some logical volume.

In the beginning, Gentoo init was inflexible and didn't allow for the first scheme, the one I had. I tried hacking the init scripts (note the Gentoo ones are not really in Bash but Gentoo's own language, though it's "almost" bash) but to no avail, so I just made some 'manual intervention' somewhere early on in init to do this. Later I added a layer of complexity by using EVMS to add software RAID to the scheme.

Again a while later on, and probably in Debian too, there are really complex scripts to handle all kind of different order of even more different mappings. Lately I have been watching the multiple thousands line of init scripts in OpenSuse 11.2, and yeah, it's really flexible since it also needs to handle hacks like clicfs over NFS, some Xen-cruft and all the like. It probably takes multiple evenings to fully understand those init-scripts.

EVMS - a sort of LVM2 / mdraid-wrapper with GUI, ncurses interface and plugins - has nice documentation on LVM2, though EVMS is a little different and unmaintained nowadays.The functions that were in EVMS are almost all in ZFS as far as I understood.

Best LVM2 doc can be found somewhere at RedHat (Google knows), and the LVM1 doc can still be found at TLPD. However, LVM1 is more limited than LVM2.

PS: When performance is an issue, be sure to choose aes-i586 instead of plain aes in the kernel. I'm not sure what the options are nowadays, but a few years ago it did make a difference.

Jan 11, 2010
2:31 PM EDT
My boss said he'll take a look at Clonezilla again and try it on the test machine. I'll find out tomorrow if he tried it yet or not and if so, what the results were.


Jan 12, 2010
12:05 PM EDT
might want to look at lvm snapshots

Aug 26, 2010
10:55 AM EDT

Aug 27, 2010
8:34 AM EDT
> WTH???

Spam. Two accounts so far, different posts which superficially seem related to the subjects, but don't really make sense when read, and the same ad and URL on the bottom of all of them.

Oct 13, 2010
1:15 PM EDT
Now that this thread is back, techiem2 - how well did Clonezilla work?

Posting in this forum is limited to members of the group: [Editors, MEMBERS, SITEADMINS.]

Becoming a member of LXer is easy and free. Join Us!