August 4, 2007

Dumping LVM2 logical volumes under FreeBSD

Category: Sysadmin.

At work, I generally use the Debian GNU/Linux operating system: as all our servers run Debian, it avoids loads of clashes when we put in production our work. But I am frequently complaining about how Debian works and globally can't bear it's frustrating package management system (which becomes even worth than ever when you run a advanced-user / developer / desktop machine). Anyway, there are many situations I could do my job with another operating system that fits much more my needs, let's say FreeBSD... The problem is that as a paranoid sysadmin, my current /home directory is a LVM2 logical volume on top of software RAID controlled by mdadm.

FreeBSD features a cool abstraction layer in the kernel called GEOM and documented as a modular disk I/O request transformation framework. Basically, it fits between your devices as represented by files in /dev and the physical disks, providing on the fly mirroring / stripping / whatever, without the need of any external tool (it's a bit more complex in fact, but keep it simple :)).

Unfortunately, all this is uterly not compatible with either MD or LVM2.

A quick search on the Internet did not reveal any compatibility toolkit. Maybe people who use FreeBSD and GNU/Linux on the same system avoid using LVM2 just as they avoid the use of UFS/FFS because of the lack of support of the other operating system? Or maybe they just dump their LVM2 logical volumes and create corresponding gvinum subdisks under FreeBSD when migrating form a system to the other? Anyway, implementing a basic LVM2 support for FreeBSD may be a really cool challenge :).

lvm2hack

Before coding a kernel module that provides a transparent access to LVM2 logical volumes under FreeBSD, I have created a program that reads a physical volume and creates images of the logical volumes it contains. It is by design not suitable for production, but it puts the basis of understanding how LVM2 works internally.

Because the programs borrows information about some data structures in GNU GPL programs, is is licensed under the GPL. For that reason I am looking for someone to re-code these data structures under a BSD-derivative license so that the future LVM2 kernel module will not taint the kernel. If you are interested, please read the project's README file for details, drop a comment, and *do not read* the source code (until it is licensed as BSD software at least ;)).

Get the source:

% svn co http://vcs.sigabrt.org/svn/freebsd-lvm2/branches/lvm2hack

Compile it:

% make

Run it (beware of the place that will be used by the filesystem images):

% ./lvm2hack /dev/ad0s7
===> Reading /dev/ad0s7
[...]
===> Reading banana/chocolate from offset 196608 (0x30000)
===> Reading banana/split from offset 33751040 (0x2030000)
===> Reading banana/cream from offset 100859904 (0x6030000)
[...]
% ls banana
chocolate  cream      split
%

That's it! You can mount the images:

% sudo ggatel create banana/chocolate
ggate0
% sudo mount_ext2fs /dev/ggate0 /mnt/
% ls /mnt
CHOCOLATE   lost+found/
% cat /mnt/CHOCOLATE
CHOCOLATE
% 

Beyond lvm2hack

Right now, a lots of improvements are required before thinking about a kernel module to access LVM2 logical volumes under FreeBSD:

  1. the code is currently under the GNU GPL;
  2. a lot of tests are missing in the code (only basic LVM2 setups are correctly managed, but the program only checks that the device given is a physical volume. It is mandatory to assert that the logical volume has a single segment);
  3. The program has to be tested: reverse engineered parts may be going bad.

Comments

On January 13, 2008, Travis M. wrote:

First of all, my homepage is low-bandwidth, so to download my files, please limit the download rate to 5KB/s before downloading.

I am interested in this project, but I am an amateur programmer, and am only a teen. I would like to use Linux LVM2 volumes under FreeBSD, with all the kernel support and usermode support you could have. After I finish The C Programming Language, 2nd Edition, I will see about working on this project. Since I do not know Calculus (and will not pretend to know it), how hard will this project be in math and programming skills?

Thanks,
Travis M.

On February 20, 2008, Romain Tartière wrote:

Hi Travis,

If you dig into LVM, you will see that there is not a lot of calculus: the idea is basically to remap I/O access to a virtual device blocks to physical devices. The most complex thing is so to make this fit in the existing FreeBSD disk I/O transformation framework: GEOM.

As you can see, I started to play with GEOM and wrote about tasting. Unfortunately, things are staled since this post.

The good news is that some LVM2 support has been spoken about in the last FreeBSD Quarterly Status Report [2], and has even already been committed [3]!

References:

  1. https://romain.blogreen.org/blog/2007/08/learning-geom-tasting/
  2. http://www.freebsd.org/news/status/report-2007-10-2007-12.html
  3. http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/geom/linux_lvm/g_linux_lvm.c

Comments RSS feed | Leave a Reply…

top