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
- Get latest sources
- Compile new kernel and tools
- Create PV, LV and VG's and enjoy
You can checkout the latest sources with this command
$ export CVS_RSH="ssh" $ export CVSROOT="email@example.com:/cvsroot" $ cvs checkout -dfP src
Or update by command
$ export CVS_RSH="ssh" $ export CVSROOT="anoncvs@anoncvs.NetBSD.org:/cvsroot" $ cvs update -dfP
There are only 3 directories which were changed in my branch
The easiest way is to build distribution and sets. You need to build with flag MKLVM set to yes.
$ cd /usr/src $ ./build.sh -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.
Kernel compilation procedure is described here http://www.netbsd.org/docs/guide/en/chap-kernel.html#chap-kernel-build.sh To get device-mapper compiled in kernel you have to add this option to kernel config file
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.
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).
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).
Review locking - I will probably allow only one ioctl call to be inside dm driver at time. DONE
Write snapshot driver -only skeleton was written yet.
Add ioctls needed to correct newfs functionality. I tried to implement them in device-mapper.c::dmgetdisklabel but it doesn't work yet. DONE
Write lvm rc.d script to enable LVM before disk mount so we can use lvm for system partitions. DONE