BSD DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to BSD Subscribe to Newsletters

Big Scary Daemons BSD Disk Images

by Michael W. Lucas
11/21/2002

I'm repeatedly installing OpenBSD on a test machine, but I don't want to waste a keyboard or a monitor on it. While I have the equipment, desk space is precious. That leads me to a serial console. Booting an OpenBSD system with a serial console is pretty easy: enter set tty com0 at either the boot prompt or in /etc/boot.conf. The first won't work in this case. If I had a keyboard and monitor attached, I wouldn't need the serial console. The second seems difficult, given that the OpenBSD boot disks are disk images downloaded from the Internet. But editing those images isn't that difficult. In this article, we'll show how to set up and use /etc/boot.conf on an OpenBSD installation boot floppy. This same approach works on both FreeBSD and NetBSD as well.

OpenBSD's /etc/boot.conf has a variety of other features, such as letting you adjust the memory configuration to skip the famous Compaq 16MB memory hole, or letting you choose an alternate boot disk. You can see all the details in boot(8), but we're going to focus on diverting the console to the serial port. Since I'm going to be running this install repeatedly, I'd like to have a custom boot floppy image that I can use to burn as many floppies as I like. Floppies tend to go bad after all, and I don't want my single customized boot floppy to die after only 60 or so installs. The simplest way to do this is to mount the disk image, edit it, and write that image to a floppy disk.

Mounting a disk image file has two steps. First, you need to tie the disk image to a device node. Then, you can mount that device node as you would any other device. This is true for floppy disk images, CD-ROM images, or any other sort of disk image you might have. OpenBSD provides vnconfig(8) to map an image to a device node. NetBSD and FreeBSD also have vnconfig(8) programs, although their syntax differs. You can edit the disk image on any operating system so long as the operating system can mount the filesystem used on the image.

Also in Big Scary Daemons:

Running Commercial Linux Software on FreeBSD

Building Detailed Network Reports with Netflow

Visualizing Network Traffic with Netflow and FlowScan

Monitoring Network Traffic with Netflow

Information Security with Colin Percival

If you look at the manual page for vnconfig, it talks about vnode disks. What the heck is a vnode disk? Originally, the Fast File System had index nodes, or inodes, that marked how files were laid out on disk. The kernel read inodes to get information on files. Each group of inodes was tied to a disk device, so the kernel knew to ask vnode number X on device node Y.

Foreign filesystems (such as CD-ROMs and FAT floppy disks) don't have inodes, but instead have their own file indexing and layout systems. This was fine, until it became necessary to mount these filesystems on a UNIX box. Virtual nodes, or vnodes, were introduced as an abstraction layer between certain kernel functions and the filesystems that they wanted to access. The vnodes handle any translations between the kernel and inodes, File Allocation Tables, and so on. So, a vnode disk is pretty much anything that vnodes can talk to, a disk image.

The file has vnodes, but the kernel needs a device to read those vnodes through. That's where vnconfig(8) comes in; it ties vnodes to a device node.

OpenBSD provides two different sorts of device nodes for different sorts of disk access. Disks that contain filesystems should be accessed through the buffer cache, and hence should use a safe vnode device, such as /dev/svnd0. Disk images that do not contain filesystems, such as those used for swap space, should use unbuffered access vnode devices, /dev/vnd0. The GENERIC kernel provides 4 vnode devices.

Once we have a device node for our filesystem, mounting it will be trivial.

First, download the OpenBSD install disk image you need. Copy this image to a separate file, so you don't have to re-download the image if you make a mistake. You could just re-download it, but remember: bandwidth costs money, if not for you then for the people hosting the mirrors.

vnconfig(8) has a simple syntax: the command, the type of node to use, and the disk image to mount. Since this is a complete disk image, to use the appropriate node for a complete image, a whole disk is a "c" partition. We want to access this device through the buffer cache, so we'll use a safe vnode. Since this is our first safe vnode device, we can use /dev/svnd0c. Our test disk image is /tmp/floppy32custom.fs.

# vnconfig /dev/svnd0c /tmp/floppy32custom.fs

This disk image is now tied to that device node. You can mount it just as you would any other device node.

mount /dev/svnd0c /mnt

Go into /mnt, and voila, you're inside the disk image.

# ls -lai /mnt/
total 1394
2 drwxr-xr-x   2 root  wheel      512 Oct 11 18:07 .
2 drwxr-xr-x  16 root  wheel      512 Jan  9  2002 ..
3 -rw-r--r--   1 root  wheel    53248 Oct  3 21:06 boot
4 -rw-r--r--   1 root  wheel  1360545 Oct  3 21:06 bsd
# 

Most people have probably never actually looked at a disk image before. The boot file is the i386 system bootstrap loader, while /bsd is the compressed kernel and installation utilities.

A df shows that this disk is 99 percent full, but that's OK; there's enough room to cram on a single file and a directory. Create an /etc/ directory, and make an /etc/boot.conf file containing the single line:

set tty com0

Save your work, and unmount the disk image. The svnd0c device will remain attached to this image until you unconfigure it. It's important to unconfigure your vnode devices, because you cannot re-use that device until it is unconfigured.

vnconfig -u /dev/svnd0c

Then copy your custom boot image onto floppy disk, and boot your installation machine. It will go almost immediately to serial console, without any user intervention.

You can use this same technique to make any other simple boot.conf alterations on an OpenBSD system, or to mount disk images of other sorts. This technique works for CD-ROM images, FAT disk images, ZIP disk images, or anything else.

Michael W. Lucas


Read more Big Scary Daemons columns.

Return to the BSD DevCenter.



What's on your custom boot disk?
You must be logged in to the O'Reilly Network to post a talkback.
Post Comment
Full Threads Oldest First

Showing messages 1 through 5 of 5.

  • trying
    2007-02-12 10:24:05  pfbsd [Reply | View]

    I'm gonna try and test this option and build the PERC 3/Di driver on openbsd and put it on an existing mounted bootdisk. **crossfingers** hopefully i can get this to work.
  • Excellent!
    2002-12-01 10:35:39  anonymous2 [Reply | View]

    I was wondering how to do this not a week ago; I keep a Wyse hooked to my OpenBSD box for day to day use, and wanted to do the net upgrade to the
    latest version. Thanks!
  • the big problem
    2002-11-26 16:36:44  anonymous2 [Reply | View]

    but the big problem is how to create this
    customfloppy32.fs ... :/
    I need to change some things there... and
    i dont have tha awnser (like tha language, for
    example)...

  • [newbie] how to access serial console
    2002-11-22 06:53:17  anonymous2 [Reply | View]

    Hi,

    I have a SparcStation 5 over here running OpenBSD.
    It sits without a monitor or keyboard under my desk.
    I see it through ssh from my w2k laptop.

    Now, I modified the boot floppy, but how do i access my SS via serial. I mean, what sorts of cables do I need, where can I get 'm, what (windows) software would one use to initiate a serial connection.

    thank you


    nice article btw, been wanting to do that for a long time now
    • [newbie] how to access serial console
      2003-08-24 12:31:16  anonymous2 [Reply | View]

      You will need to by a "null modem cable". Check the available Com ports on you PC to determine the connector required e.g. I use 9pinF to 9pinF:

      OpenBSD
      [com port 0]
      |
      |
      [null modem cable]
      |
      |
      [com port 0]
      Windows/OpenBSD dual boot

      Then in Windows, start hyperterminal and chose to connect "Direct to com0" with settings:
      Bits per second = 9600
      Data bits = 8
      Parity = None
      Stop bits = 1

      Better still, go buy "Absolute OpenBSD" by Michael W. Lucas - craking read!

      Cheers


Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com