12.10 Network, Memory, and File-Based File Systems

Aside from the disks you physically insert into your computer: floppies, CDs, hard drives, and so forth; other forms of disks are understood by FreeBSD - the virtual disks.

These include network file systems such as the Network File System and Coda, memory-based file systems and file-backed file systems.

According to the FreeBSD version you run, you will have to use different tools for creation and use of file-backed and memory-based file systems.

12.10.1 File-Backed File System under FreeBSD 4.X

vnconfig(8) configures and enables vnode pseudo-disk devices. A vnode is a representation of a file, and is the focus of file activity. This means that vnconfig(8) uses files to create and operate a file system. One possible use is the mounting of floppy or CD images kept in files.

To use vnconfig(8), you need vn(4) support in your kernel configuration file:

    pseudo-device vn

To mount an existing file system image:

Example 12-3. Using vnconfig to mount an Existing File System Image under FreeBSD 4.X

    # vnconfig vn0 diskimage
    # mount /dev/vn0c /mnt

To create a new file system image with vnconfig:

Example 12-4. Creating a New File-Backed Disk with vnconfig

    # dd if=/dev/zero of=newimage bs=1k count=5k
    5120+0 records in
    5120+0 records out
    # vnconfig -s labels -c vn0 newimage
    # disklabel -r -w vn0 auto
    # newfs vn0c
    Warning: 2048 sector(s) in last cylinder unallocated
    /dev/vn0c:     10240 sectors in 3 cylinders of 1 tracks, 4096 sectors
            5.0MB in 1 cyl groups (16 c/g, 32.00MB/g, 1280 i/g)
    super-block backups (for fsck -b #) at:
     32
    # mount /dev/vn0c /mnt
    # df /mnt
    Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
    /dev/vn0c        4927        1     4532     0%    /mnt

12.10.2 File-Backed File System under FreeBSD 5.X

mdconfig(8) is the utility used to configure and enable memory disks, md(4), under FreeBSD 5.X. To use mdconfig(8), you have to load md(4) module or to add the support in your kernel configuration file:

    device md

The mdconfig(8) command supports three kinds of memory backed virtual disks: memory disks allocated with malloc(9), memory disks using a file or swapspace as backingstore. One possible use is the mounting of floppy or CD images kept in files.

To mount an existing file system image:

Example 12-5. Using mdconfig to mount an Existing File System Image under FreeBSD 5.X

    # mdconfig -a -t vnode -f diskimage -u 0
    # mount /dev/md0c /mnt

To create a new file system image with mdconfig:

Example 12-6. Creating a New File-Backed Disk with mdconfig

    # dd if=/dev/zero of=newimage bs=1k count=5k
    5120+0 records in
    5120+0 records out
    # mdconfig -a -t vnode -f newimage -u 0
    # disklabel -r -w md0 auto
    # newfs md0c
    /dev/md0c: 5.0MB (10240 sectors) block size 16384, fragment size 2048
        using 4 cylinder groups of 1.27MB, 81 blks, 256 inodes.
    super-block backups (for fsck -b #) at:
     32, 2624, 5216, 7808
    # mount /dev/md0c /mnt
    # df /mnt
    Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
    /dev/md0c        4846        2     4458     0%    /mnt

The utility mdconfig(8) is very useful, however it asks many command lines to create a file-backed file system. FreeBSD 5.0 also comes with a tool called mdmfs(8), this program configures a md(4) disk using mdconfig(8), puts a UFS file system on it using newfs(8), and mounts it using mount(8). For example, if you want to create and mount the same file system image as above, simply type the following:

    # mdmfs -F newimage -s 5m md0 /mnt

For more details about mdmfs(8), please refer to the manual page.

12.10.3 md: Memory File System

md is a simple, efficient means to create memory file systems.

Simply take a file system you have prepared with, for example, vnconfig(8), and:

Example 12-7. md Memory Disk

    # dd if=newimage of=/dev/md0
    5120+0 records in
    5120+0 records out
    # mount /dev/md0c /mnt
    # df /mnt
    Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
    /dev/md0c        4927        1     4532     0%    /mnt

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.