1. Introduction
  2. Details


This page describes howto setup NetBSD to be able to use linux lvm tools and libdevmapper for lvm. For now my work was done on haad-dm branch in main netbsd repository I want to merge my branch back to main repository as soon as it will be possible.

LVM support has been merged to NetBSD-current on the 23rd of December 2008.


Tasks needed to get LVM on NetBSD working

Howto update/checkout sources

You can checkout the latest sources with this command

$ export CVS_RSH="ssh"
$ export CVSROOT=""
$ cvs checkout -dfP src

Or update by command

$ export CVS_RSH="ssh"
$ export CVSROOT=""
$ cvs update -dfP

There are only 3 directories which were changed in my branch

  1. sys/dev/dm
  2. external/gpl2/libdevmapper
  3. external/gpl2/lvm2tools

Howto setup NetBSD system to use lvm

The easiest way is to build distribution and sets. You need to build with flag MKLVM set to yes.

$ cd /usr/src $ ./ -u -U -V MKLVM=yes tools distribution sets 

After successful build update your system with them. You can also run make install (as root) in src/external/gpl2/lvm2 to install userland part of LVM into the existing NetBSD system. There is also simple driver used by LVM2 tools in our kernel in src/sys/modules/dm you have to install and load this driver before you test lvm. The NetBSD LVM uses same tools as Linux and therefore we have the same user interface as is used in many common linux distributions.

Howto compile new kernel

Kernel compilation procedure is described here To get device-mapper compiled in kernel you have to add this option to kernel config file

pseudo-device dm

Using new MODULAR modules

There are two versions of modules in NetBSD now old LKM and new MODULAR modules. New modules are build in sys/modules/. All GENERIC kernels are compiled with support for new modules. There is reachover makefile for dm driver in sys/modules/dm. You can use it to build dm module.

For loading new style modules new module utils are needed. You need to add


to /etc/mk.conf and build modload, modstat and modunload.

Compile lvm2tool and libdevmapper

To get lvm working it is needed to compile and install linux lvm tools. They are located in

Only make/make install is needed to build/install tools to machine. Tools are not integrated in to lists and build system now. Therefore it is possible that when you try to add them to build process it will fail(with error to many file in destdir).

Using lvm on NetBSD

lvm2tools are used to manage your lvm devices.

lvm pvcreate /dev/raw_disk_device # create Physical Volume 
lvm vgcreate vg00 /dev/raw_disk_device #create Volume Group-> pool of available disk space.
lvm lvcreate -L20M -n lv1 vg00 # create Logical volume aka Logical disk device
newfs  /dev/vg00/rlv1 # newfs without -F and -s doesn't work
mount /dev/vg00/lv1 /mnt # Enjoy

After reboot, you can activate all existing Logical Volumes (LV) in the system with the command:

lvm vgchange -a y

You can use:

lvm lvdisplay vgdisplay pvdisplay to see the status of your LVM devices.

You can also use lvm lvextend/lvreduce to change size of LV.

I haven't tested my driver on SMP system there are probably some bugs in locking so be aware of it :) and do not try to extend/reduce partition during I/O (something bad can happend).