Tux Linux - a free operating system

The Gimp


Valid XHTML 1.0!

Valid CSS!

Resizing COW files

User-Mode-Linux (UML) is a way to run Linux without root privileges in userspace. It is a convenient tool when testing kernel code which is not strictly dependent on direct device access.

UML accesses its file systems by means of image files, similar to the loop-mounting technique. It is however possible to configure a copy-on-write (COW) behaviour; in such a case, every write operation acts on a shallow copy of the image file, whereas read operations either act on the copy (if the appropriate block has been written in there already), or the original image. The following picture illustrates this behaviour.

COW screenshot

So how does the kernel know which blocks are dirty? It keeps a sector table, similar to how the memory manager keeps a pagetable with various flags. Also, there's a header at the beginning with a magic number, size and sector size settings, and the location and modification time of the backing file to make sure the right one is used (it would result in data corruption otherwise).

COW screenshot

Now on to the resizing procedure. It consists of 2 steps: One is executed by UML directly, the other one must be done in userspace. This is a limitation of the Kernel 2.4, and will likely improve in the future. Basically, we just enlarge the virtual partition without changing the filesystem. This will however have to be moved because a larger number of blocks means a larger number of entries in the sector table. The whole filesystem, starting with the last bytes and up to the superblock at the beginning, is moved towards the end of the enlarged partition.

COW screenshot

Now the filesystem can be enlarged as well with tools such as ext2online. Note that due to the lack of physical data in the backing file, the new sector table entries must be marked dirty even though there is no valid data in the COW file yet.

COW screenshot

So, is there an implementation already? Well, more or less, there is. Except for heavy testing, everything has been implemented for Kernel 2.4.20. The patches are available here:

Diff for arch/um/driver/ubd_kern.c
Diff for arch/um/driver/ubd_user.c
Diff for arch/um/include/ubd_user.h

This setup has been tested using UML 2.4.20-4um-1 (Debian/unstable source package) and the Slackware 8.1 root filesystem from the UML home page. As the only difference, add the size to the process invocation, such as:

linux ubda=cowfile,backingfile,400M devfs=mount mem=128M

A demonstration of the patch
Back to the index page

Josef Spillner (mail)
Created: 26.04.2003