Subject: volume management software
To: None <netbsd-users@netbsd.org>
From: Christian Limpach <chris@pin.lu>
List: netbsd-users
Date: 02/04/2003 20:29:09
Hello!

I've packaged Linux LVM2 for NetBSD.  LVM2 is a userspace volume 
management software.  LVM2 needs a kernel driver called device-mapper
to provide virtual disks/partitions.

LVM2 reads and writes metadata to real disks and uses the device-mapper 
to present virtual disks/partitions to the user.  A partition created 
with device-mapper is defined from ranges of sectors.  Each range is 
mapped to one or many real disks through a mapping.  Possible mappings 
include linear, striping, mirror, snapshot...

I've implemented a device-mapper compatible driver as an LKM for NetBSD.  
The only currently implemented mapping is linear.  The Linux device-mapper
package also includes a library (libdevmapper) and a simple setup
program (dmsetup) which can be used to create partitions much like
ccdconfig.  LVM2 uses libdevmapper to interface with the device-mapper
driver.  Partitions created with device-mapper behave like virtual disks 
created with ccd.  Partitions can be disklabel'ed but libdevmapper only 
creates device nodes in /dev/mapper for the raw partition.

I've also ported FreeBSD's growfs and I've had to make some changes to 
newfs and fsck to get them to work on devices with arbitrary names.

I've made 3 pkgsrc packages:
ftp://lola.pin.lu/pub/NetBSD/packages/device-mapper/pkgsrc-device-mapper-
0.01.tar.gz
    This package contains the LKM and infrastructure to load it very
    early during system startup.  It also contains the libdevmapper and
    dmsetup from the Linux device-mapper package.  It installs to the
    system directories.

ftp://lola.pin.lu/pub/NetBSD/packages/device-mapper/pkgsrc-device-mapper-
addons-0.01.tar.gz
    This package contains growfs and the patches to newfs and fsck.
    The package installs growfs and the replacement newfs and fsck in
    the system directories, keeping backup copies of the originals for
    later deinstallation.

ftp://lola.pin.lu/pub/NetBSD/packages/lvm2/pkgsrc-lvm2-1.95.15.tar.gz
    This package contains Linux LVM version2.  It installs by default
    to the system directories.

The LKM works on NetBSD 1.6_STABLE, specifically on the i386 port 
although there's no reason why it wouldn't work on other ports.  I 
suspect it won't work on current since there have been changes to 
the bdev/cdev switch table code.

Build instructions:
- be confident that you know what you're doing ;-)
  standard disclaimers apply...
- unpack the pkgsrc-* archive to .../pkgsrc/sysutils
- run `make install' in each directory (the packages are missing 
  dependencies, you need to do them in order, starting with
  device-mapper and finishing with lvm2)
- load the LKM: (you need a kernel with LKM support)
    modload -p /lkm/device_mapper_post.sh /lkm/device_mapper.o
  you might need to use one of the other 2 methods (described below)
  if your kernel only allows loading modules during boot.

Usage examples:
[you must have loaded the device-mapper driver, 
`dmsetup version' should print some version numbers and not an error ;-)]
create a physical volume on partition wd0g:
    pvcreate /dev/wd0g
create a volume group on the physical volume:
    vgcreate vgtest /dev/wd0g
create a logical volume in the volume group:
    lvcreate -n test1 -L 100M vgtest
make a filesystem:
    newfs /dev/vgtest/test1
mount the filesystem:
    mount /dev/vgtest/test1 /mnt
unmount the filesystem:
    umount /mnt
    (only works on the mountpoint)
resize logical volume and filesystem:
    umount /mnt
    lvextend -L +64M /dev/vgtest/test1
    growfs /dev/vgtest/test1
    mount /dev/vgtest/test1 /mnt

(re)scan disks for volume groups:
    vgscan
activate volume groups manually:
    vgchange -a y
deactivate volume groups manually:
    vgchange -a n

System startup:
load the devicemapper driver through /etc/rc.d/devicemapper
    devicemapper=YES in /etc/rc.conf
  a less intrusive way to load the devicemapper is to add it 
  to /etc/lkm.conf:
    device_mapper.o - - ${LIBEXECDIR}/device_mapper_post.sh - -
  but it won't be possible to have LVM-managed filesystems 
  in /etc/fstab since LKMs are loaded after fsck.
activate volume groups through /etc/rc.d/lvm
    lvm=YES in /etc/rc.conf

Enjoy!
-- 
Christian Limpach <chris@pin.lu>