"Dual booting and swap sharing: OpenBSD and Debian GNU/Linux"

or... 

"The zen process, on the way to a better OS for your laptop"  

                  Pau Amaro-Seoane + Woodchuck 19/ May/ 07, Berlin (pau-at-ippimail.com)


Introduction

This guide is intended to help you migrate to OpenBSD from GNU/Linux, the same way some people did from micro$oft to linux. 


It may be interesting for you if you want to gradually migrate and don't have the courage to simply delete all of your GNU/Linux system at once and use the whole disc for OpenBSD. You may also have other reasons; e.g. voice per internet (and don't feel like / don't know how to set up asterisk) or 3D graph. acceleration.


The logical thing to expect is that after some time using OpenBSD you'll naturally realise that it's the best OS you could ask for and you'll end up using the whole disc space for it. Nonetheless, in order to help you and reduce the panic factor, we have thought that a smooth transition, a zen path, will help you :)

In any case, here you are the guide, given as an example.


Of course this will not strictly apply to your case but you sure will understand the fundamentals of it and translate it for your needs.



Note

This guide is, by no means, meant to replace the official document to have a dual-booting machine, whose lecture we strongly recommend:

INSTALL.linux

By the way, this article is published under the WTFPL.



Linux - running fdisk before OpenBSD installation: 

Debian "Sarge" had been installed in "blissful ignorance" mode,
as if it were the only OS ever contemplated for the machine.
This meant allowing grub 0.95 to have free rein with the disc,
it accordingly installed itself in the master boot record.

But I did leave space for OpenBSD, by creating an "unused"
fdisk partition during the installation.

We now fdisk to mark the previously emptied partition for OpenBSD.
The partition to be marked is the third, called "3" in Linux, but
"2" in OpenBSD

    bildad:~# fdisk /dev/hda

This is the way it looked after Debian installation

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    255 heads, 63 sectors/track, 486 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1               1         122      979933+  83  Linux
    /dev/hda2             123         153      249007+  82  Linux swap / Solaris
    /dev/hda3             154         486     2674822+  83  Linux

    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)

    Command (m for help): t
    Partition number (1-4): 3
    Hex code (type L to list codes): A6
    Changed system type of partition 3 to a6 (OpenBSD)

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    255 heads, 63 sectors/track, 486 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1               1         122      979933+  83  Linux
    /dev/hda2             123         153      249007+  82  Linux swap / Solaris
    /dev/hda3             154         486     2674822+  a6  OpenBSD

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

Typical Linux bug.  Ignore it:

    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.

At this point, the system is ready to install OpenBSD (I think).
Notice that no partition has been marked bootable.  Perhaps this
will matter.  Actually, I mark it bootable during installation.
putting in OpenBSD 4.0 boot CD and rebooting



OpenBSD installation


    bildad:~# shutdown -r now

    Broadcast message from root (ttyS0) (Sat Apr 28 23:04:37 2007):

    The system is going down for reboot NOW!
    bildad:~#

Hello, kitty...

    >> OpenBSD/i386 CDBOOT 1.04
    boot> boot
    booting cd0a:/4.0/i386/bsd.rd:
    entry point at 0x200120

    Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
    Copyright (c) 1995-2006 OpenBSD. All rights reserved.  http://www.OpenBSD.org

    OpenBSD 4.0 (RAMDISK_CD) #39: Sat Sep 16 19:34:26 MDT 2006
        deraadt@i386.openbsd.org:/usr/src/sys/arch/i386/compile/RAMDISK_CD
    cpu0: Intel Pentium II ("GenuineIntel" 686-class, 512KB L2 cache) 266 MHz
    cpu0: FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,MMX
    real mem  = 100233216 (97884K)
    avail mem = 85016576 (83024K)
    using 1249 buffers containing 5115904 bytes (4996K) of memory
    mainbus0 (root)
    bios0 at mainbus0: AT/286+(00) BIOS, date 04/30/97, BIOS32 rev. 0 @ 0xfd900
    pcibios0 at bios0: rev 2.1 @ 0xf0000/0x10000
    pcibios0: PCI BIOS has 6 Interrupt Routing table entries
    pcibios0: PCI Interrupt Router at 000:07:0 ("Intel 82371SB ISA" rev 0x00)
    pcibios0: PCI bus #0 is the last bus
    bios0: ROM list: 0xc0000/0x8000 0xe9000/0x1000! 0xea000/0x2000
    cpu0 at mainbus0
    pci0 at mainbus0 bus 0: configuration mode 1 (bios)
    pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02
    pcib0 at pci0 dev 7 function 0 "Intel 82371SB ISA" rev 0x01
    pciide0 at pci0 dev 7 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 0 wired to compatibility, channel 1 wired to compatibility
    wd0 at pciide0 channel 0 drive 0: <WDC AC34000L>
    wd0: 16-sector PIO, LBA, 3815MB, 7814016 sectors
    wd0(pciide0:0:0): using PIO mode 4, DMA mode 2
    atapiscsi0 at pciide0 channel 1 drive 0
    scsibus0 at atapiscsi0: 2 targets
    cd0 at scsibus0 targ 0 lun 0: <, CD-R/RW RW7063A, 1.50> SCSI0 5/cdrom removable
    atapiscsi1 at pciide0 channel 1 drive 1
    scsibus1 at atapiscsi1: 2 targets
    sd0 at scsibus1 targ 0 lun 0: <IOMEGA, ZIP 100, 23.D> SCSI0 0/direct removable
    sd0: drive offline
    cd0(pciide0:1:0): using PIO mode 4, DMA mode 2
    sd0(pciide0:1:1): using PIO mode 0
    uhci0 at pci0 dev 7 function 2 "Intel 82371SB USB" rev 0x01: irq 11
    usb0 at uhci0: USB revision 1.0
    uhub0 at usb0
    uhub0: Intel UHCI root hub, rev 1.00/1.00, addr 1
    uhub0: 2 ports with 2 removable, self powered
    vga1 at pci0 dev 11 function 0 "ATI Rage XL" rev 0x65
    wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
    ne3 at pci0 dev 17 function 0 "Realtek 8029" rev 0x00: irq 9, address 00:50:ba:52:65:ce
    isa0 at pcib0
    isadma0 at isa0
    pckbc0 at isa0 port 0x60/5
    pckbd0 at pckbc0 (kbd slot)
    pckbc0: using irq 1 for kbd slot
    wskbd0 at pckbd0: console keyboard, using wsdisplay0
    npx0 at isa0 port 0xf0/16: using exception 16
    pccom0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
    pccom0: console
    pccom1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
    fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
    fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
    isapnp0 at isa0 port 0x279: read port 0x203
    "SYM 53C416       , SLI4163, , " at isapnp0 port 0x200/32 irq 5 not configured
    "OPL3-SA3 Snd System , YMH0021, , " at isapnp0 port 0x220/16,0x530/8,0x388/8,0x330/2,0x370/2 irq 5 drq 0,1 not configured
    "OPL3-SA3 Snd System , YMH0022, PNPB02F, " at isapnp0 port 0x201/1 not configured
    pccom3 at isapnp0 "U.S. Robotics 56K FAX INT, USR3030, , " port 0x3e8/8 irq 5: ns16550a, 16 byte fifo
    biomask fdc5 netmask ffc5 ttymask ffc7
    rd0: fixed, 3800 blocks
    wd0: no disk label
    dkcsum: wd0 matches BIOS drive 0x80
    root on rd0a
    rootdev=0x1100 rrootdev=0x2f00 rawdev=0x2f02
    erase ^?, werase ^W, kill ^U, intr ^C, status ^T
    (I)nstall, (U)pgrade or (S)hell? i

    Welcome to the OpenBSD/i386 4.0 install program.

    This program will help you install OpenBSD in a simple and rational way. At
    any prompt except password prompts you can run a shell command by typing
    '!foo', or escape to a shell by typing '!'. Default answers are shown in []'s
    and are selected by pressing RETURN. At any time you can exit this program by
    pressing Control-C and then RETURN, but quitting during an install can leave
    your system in an inconsistent state.

    Terminal type? [vt220]
    kbd(8) mapping? ('L' for list) [none]

    IS YOUR DATA BACKED UP? As with anything that modifies disk contents, this
    program can cause SIGNIFICANT data loss.

    It is often helpful to have the installation notes handy. For complex disk
    configurations, relevant disk hardware manuals and a calculator are useful.

    Proceed with install? [no] yes
    Cool! Let's get to it.



Disk initialization

Where many are ruined, hearts are broken, tragedies develop, and rough
Beasts, their hours come round at last, slouch towards Bethlehem to be
born.



    You will now initialize the disk(s) that OpenBSD will use. To enable all
    available security features you should configure the disk(s) to allow the
    creation of separate filesystems for /, /tmp, /var, /usr, and /home.

    Available disks are: sd0 wd0.

Note, the sd0 is an old IOmega floppy.  It is not in the boot
sequence, ignore it.

    Which one is the root disk? (or 'done') [done] wd0
    Do you want to use *all* of wd0 for OpenBSD? [no] no

Read next paragraph.  It is what we MUST have.  What it doesn't
say is whether the partition must be a "primary" or if it
can be a "logical" partition.

    You will now create a single MBR partition to contain your OpenBSD data. This
    partition must have an id of 'A6'; must *NOT* overlap other partitions; and
    must be marked as the only active partition.

We have already set up the partition under Linux, but we could
also do it here.  Since things are OK, except for the "active partition"
marking, that's all we do now:

    The 'manual' command describes all the fdisk commands in detail.

    Disk: wd0       geometry: 969/128/63 [7814016 Sectors]
    Offset: 0       Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 83    0   1  1 -  243   5 63 [          63:     1959867 ] Linux files*
     1: 82  243   6  1 -  304 102 63 [     1959930:      498015 ] Linux swap
     2: A6  304 103  1 -  968  25 63 [     2457945:     5349645 ] OpenBSD
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused
    Enter 'help' for information
    fdisk: 1> help
        flag            Flag given table entry as bootable
    fdisk: 1> flag 2
    Partition 2 marked active.
    fdisk:*1> p
    Disk: wd0       geometry: 969/128/63 [7814016 Sectors]
    Offset: 0       Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 83    0   1  1 -  243   5 63 [          63:     1959867 ] Linux files*
     1: 82  243   6  1 -  304 102 63 [     1959930:      498015 ] Linux swap
    *2: A6  304 103  1 -  968  25 63 [     2457945:     5349645 ] OpenBSD
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused
    fdisk:*1> w

Note, offset 0 in partition 2:  (I think)
OpenBSD nomenclature is confusing.  It needs to be rationalize,
and technical terms given a single meaning.

    Writing MBR at offset 0.
    wd0: no disk label
    fdisk: 1> q
    Here is the partition information you chose:

    Disk: wd0       geometry: 969/128/63 [7814016 Sectors]
    Offset: 0       Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 83    0   1  1 -  243   5 63 [          63:     1959867 ] Linux files*
     1: 82  243   6  1 -  304 102 63 [     1959930:      498015 ] Linux swap
    *2: A6  304 103  1 -  968  25 63 [     2457945:     5349645 ] OpenBSD
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused

    You will now create an OpenBSD disklabel inside the OpenBSD MBR
    partition. The disklabel defines how OpenBSD splits up the MBR partition
    into OpenBSD partitions in which filesystems and swap space are created.

Note the following paragraph

    The offsets used in the disklabel are ABSOLUTE, i.e. relative to the
    start of the disk, NOT the start of the OpenBSD MBR partition.

    # Inside MBR partition 2: type A6 start 2457945 size 5349645

    Treating sectors 2457945-7807590 as the OpenBSD portion of the disk.
    You can use the 'b' command to change this.

Resist any temptation to use the 'b' command.  'b' stands for 'breakage'

    Initial label editor (enter '?' for help at any prompt)
    >
    > p
    device: /dev/rwd0c
    type: ESDI
    disk: ESDI/IDE disk
    label: WDC AC34000L
    bytes/sector: 512
    sectors/track: 63
    tracks/cylinder: 16
    sectors/cylinder: 1008
    cylinders: 7752
    total sectors: 7814016
    free sectors: 5349645
    rpm: 3600

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5349645       2457945  unused      0     0
      c:       7814016             0  unused      0     0
      i:       1959867            63  ext2fs
      j:        498015       1959930 unknown

That is the partition table that OpenBSD kernel deduced from
inspecting the drive.  This is a 4GB IDE drive, so should have
about 8,000,000 sectors; it does.  See the 'c' partition. It
is correct.
The 'i' and 'j' partitions are from Linux.  'j' is the Linux
swap partition.  Note that disklabel doesn't directly know about
fdisk partitions.  Note that disklabel partitions *can* overlap
fdisk partition boundaries, and *can* overlap other disklabel
partitions, both within their own disklabel, and those in a
disklabel on another partition.  This comes into play if another
OS that uses disklabels, or another version/release/configuration
of OpenBSD is installed in different fdisk partition.

This disklabel is unsatisfactory as-is, I want several partitions
and a swap area for OpenBSD.  For simplicity, I will ignore the
chance that the Linux swap partition 'j' could be useful.

Note the offset of the Linux 'i' partition, 63 sectors from the
start of the disk.  OpenBSD partitions must avoid that area, too.
That's where the bootloader lives, in this case grub 0.95.

I will delete the existing 'a' partition (I might have "edited" it
instead, but deleting it is simple.
(I will snip the device specs in the disklabel printout.)

    > d a
    > p

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      c:       7814016             0  unused      0     0
      i:       1959867            63  ext2fs
      j:        498015       1959930 unknown

Now add a new a partition.  Accept many defaults.  You paid
good money for this program, trust its judgment.

    > a
    partition: [a]
    offset: [2457945]
    size: [5349645] 256M
    Rounding to nearest cylinder: 523719
    FS type: [4.2BSD]
    mount point: [none] /

Add another partition

    > a
    partition: [b]
    offset: [2981664]
    size: [4825926] 256M
    Rounding to nearest cylinder: 524160
    FS type: [swap]

And one for /usr

    > a
    partition: [d] e
    offset: [3505824]
    size: [4301766]
    FS type: [4.2BSD]
    mount point: [none] /usr
    > p

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:        523719       2457945  4.2BSD   2048 16384   16 # /
      b:        524160       2981664    swap
      c:       7814016             0  unused      0     0
      e:       4301766       3505824  4.2BSD   2048 16384   16 # /usr
      i:       1959867            63  ext2fs
      j:        498015       1959930 unknown

Write it to the disk, it looks good.

    > w

Think a little more, and quit.

    > q
    No label changes.

Done with disklabel!

    Mount point for wd0e (size=2150883k)? (or 'none' or 'done') [/usr] done
    Available disks are: sd0.
    Which one do you wish to initialize? (or 'done') [done]

    OpenBSD filesystems:
    wd0a /
    wd0e /usr

    The next step *DESTROYS* all existing data on these partitions!
    Are you really sure that you're ready to proceed? [no] yes
    /dev/rwd0a:     523716 sectors in 520 cylinders of 16 tracks, 63 sectors
        255.7MB in 2 cyl groups (328 c/g, 161.44MB/g, 20608 i/g)
    Warning: inode blocks/cyl group (190) >= data blocks (114) in last
        cylinder group. This implies 3652 sector(s) cannot be allocated.
    /dev/rwd0e:     4298112 sectors in 4264 cylinders of 16 tracks, 63 sectors
        2098.7MB in 13 cyl groups (328 c/g, 161.44MB/g, 20608 i/g)
    /dev/wd0a on /mnt type ffs (rw, asynchronous, local, ctime=Sun Apr 29 03:10:29 2007)
    /dev/wd0e on /mnt/usr type ffs (rw, asynchronous, local, nodev, ctime=Sun Apr 29 03:10:29 2007)



Remainder of Installation, disks are now done

    System hostname? (short form, e.g. 'foo') bildad
    Configure the network? [yes]
    Available interfaces are: ne3.
    Which one do you wish to initialize? (or 'done') [ne3]
    Symbolic (host) name for ne3? [bildad]
    The media options for ne3 are currently
        media: Ethernet autoselect (10baseT)
    Do you want to change the media options? [no]
    IPv4 address for ne3? (or 'none' or 'dhcp') 192.168.1.10
    Netmask? [255.255.255.0]
    IPv6 address for ne3? (or 'rtsol' or 'none') [none]
    No more interfaces to initialize.
    DNS domain name? (e.g. 'bar.com') [my.domain] chuck
    DNS nameserver? (IP address or 'none') [none] 192.168.1.1
    Use the nameserver now? [yes]
    Default IPv4 route? (IPv4 address, 'dhcp' or 'none') 192.168.1.1
    add net default: gateway 192.168.1.1
    Edit hosts with ed? [no]
    Do you want to do any manual network configuration? [no]
    Password for root account? (will not echo)
    Password for root account? (again)

    Let's install the sets!
    Location of sets? (cd disk ftp http or 'done') [cd] cd
    Available CD-ROMs are: cd0.
    Which one contains the install media? (or 'done') [cd0]
    Pathname to the sets? (or 'done') [4.0/i386]

    Select sets by entering a set name, a file name pattern or 'all'. De-select
    sets by prepending a '-' to the set name, file name pattern or 'all'. Selected
    sets are labelled '[X]'.

        [X] bsd
        [X] bsd.rd
        [ ] bsd.mp
        [X] base40.tgz
        [X] etc40.tgz
        [X] misc40.tgz
        [X] comp40.tgz
        [X] man40.tgz
        [X] game40.tgz
        [ ] xbase40.tgz
        [ ] xetc40.tgz
        [ ] xshare40.tgz
        [ ] xfont40.tgz
        [ ] xserv40.tgz
    Set name? (or 'done') [bsd.mp] done
    Ready to install sets? [yes]
    Getting bsd ...
    100% |**************************************************|  5904 KB    00:03
    Getting bsd.rd ...
    100% |**************************************************|  4889 KB    00:02
    Getting base40.tgz ...
    100% |**************************************************| 40675 KB    00:50
    Getting etc40.tgz ...
    100% |**************************************************|  1133 KB    00:03
    Getting misc40.tgz ...
    100% |**************************************************|  2233 KB    00:03
    Getting comp40.tgz ...
    100% |**************************************************| 77933 KB    01:13
    Getting man40.tgz ...
    100% |**************************************************|  7427 KB    00:14
    Getting game40.tgz ...
    100% |**************************************************|  2548 KB    00:03
    Location of sets? (cd disk ftp http or 'done') [done]
    Start sshd(8) by default? [yes]
    Start ntpd(8) by default? [no]
    Do you expect to run the X Window System? [no]
    Change the default console to com0? [no] yes
    Available speeds are: 9600 19200 38400 57600 115200.
    Which one should com0 use? (or 'done') [9600]
    Saving configuration files...done.
    Generating initial host.random file...done.
    What timezone are you in? ('?' for list) [Canada/Mountain] US/Eastern
    Setting local timezone to 'US/Eastern'...done.
    Making all device nodes...done.

This is a critical point, the installation of the bootblocks
Note, during installation the harddisc is mounted on /mnt;
/mnt/boot will be /boot in the finished system.

    Installing boot block...
    boot: /mnt/boot
    proto: /usr/mdec/biosboot
    device: /dev/rwd0c
    /usr/mdec/biosboot: entry point 0
    proto bootblock size 512
    /mnt/boot is 3 blocks x 16384 bytes

Here's where it skips over all the Linuxy stuffs:

    fs block shift 2; part offset 2457945; inode block 64, offset 808
    using MBR partition 2: type 166 (0xa6) offset 2457945 (0x258159)
    done.

 Notice that the bootblocks were written into MBR partition 2, not to
 the "whole disk".  Notice the offset of 2457945
 This is the offset of the 'a' disklabel partition

      a:        523719       2457945  4.2BSD   2048 16384   16 # /

 Note also that this is the offset of the third (#2) fdisk partition:

     2: A6  304 103  1 -  968  25 63 [     2457945:     5349645 ] OpenBSD

 This is all as it should be


    CONGRATULATIONS! Your OpenBSD install has been successfully completed!
    To boot the new system, enter halt at the command prompt. Once the
    system has halted, reset the machine and boot from the disk.

and that is that!
When we reboot, I expect to see the grub screen, without any hint
of the OpenBSD installation.
This might cause panic in the uninitiated.
We will then modify, under Linux, the grub menu.

    # halt
    syncing disks... done

    The operating system has halted.
    Please press any key to reboot.

    rebooting...



The day after: Adjusting GRUB

Sure enought, it comes up Linux.  There is no hint of the OpenBSD
installation yet.  But be of strong heart, O ye faithful!

    Debian GNU/Linux 3.1 bildad ttyS0

    bildad login: root
    Password:
    Last login: Sat Apr 28 23:00:37 2007 on ttyS0
    Linux bildad 2.4.27-2-386 #1 Mon May 16 16:47:51 JST 2005 i686 GNU/Linux

    The programs included with the Debian GNU/Linux system are free software;

well, 'free' in a limited sense.

    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.

Now, under Linux, we edit the /boot/grub/menu.lst file to
include a block for chainloading the OpenBSD installation
on the third partition of the hard disk.

Let's have a look at this file

    bildad:~# cat /boot/grub/menu.lst
    # menu.lst - See: grub(8), info grub, update-grub(8)
    #            grub-install(8), grub-floppy(8),
    #            grub-md5-crypt, /usr/share/doc/grub
    #            and /usr/share/doc/grub-doc/.

    ## default num
    # Set the default entry to the entry number NUM. Numbering starts from 0, and
    # the entry number 0 is the default if the command is not used.
    #
    # You can specify 'saved' instead of a number. In this case, the default entry
    # is the entry saved with the command 'savedefault'.
    default        0

    ## timeout sec
    # Set a timeout, in SEC seconds, before automatically booting the default entry
    # (normally the first entry defined).
    timeout        5

Be sure to break any monochrome monitors :-(

    # Pretty colours
    color cyan/blue white/blue

    ## password ['--md5'] passwd
    # If used in the first section of a menu file, disable all interactive editing
    # control (menu entry editor and command-line)  and entries protected by the
    # command 'lock'
    # e.g. password topsecret
    #      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
    # password topsecret

    #
    # examples
    #

Once we overcome our natural revulsion at seeing the W word in a
decent file in a nice, innocent computer, we recognize that this is
probably the template we want for our righteous work below.

    # title        Windows 95/98/NT/2000
    # root        (hd0,0)
    # makeactive
    # chainloader    +1
    #

This next sample Linux block won't work.
Grub 0.95 can't handle an OpenBSD elf kernel, no matter what
it says on the grub website.  This is why we'll be chainloading.
Chainloading means that grub will pass off control to whatever
code resides at the offset in the partition mentioned in the
'root' command.  Our fervent hope is that that offset is that
of the OpenBSD bootloader.  My suspicion is that the +1 (skip
1 sector) is to skip over the 512b "primary bootstap", to
start the boot at the OpenBSD "1 1/2" stage bootstrap.  See
man boot on an OpenBSD 386 system.  Stage 1 1/2 is code to
access and transfer control to stage 2, which I think is in
/boot.  /boot knows about filesystems, and all the good things
needed to load and start the kernel.

    # title        Linux
    # root        (hd0,1)
    # kernel    /vmlinuz root=/dev/hda2 ro
    #

    #
    # Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

    ### BEGIN AUTOMAGIC KERNELS LIST
    ## lines between the AUTOMAGIC KERNELS LIST markers will be modified
    ## by the debian update-grub script except for the default options below

I haven't tried the magickal update-grub script.  Maybe it would discover
the OpenBSD installation now and do the Right Thing.  I noticed, when I
booted Linux, that the boot messages went through a lot of trouble scanning
the disc and made mention of discovering the OpenBSD installation.

    ## DO NOT UNCOMMENT THEM, Just edit them to your needs

Oh, Linux, Alas.  What magic lies in editing comments?
What they mean is leave the comment alone (it is autogenerated, perhaps)
but yank it (vi), paste it, uncomment the pasted one, and change
that one.  I think that's what they mean.  I can't scry any other meaning.
Anyway, I left this section alone.

    ## ## Start Default Options ##
    ## default kernel options
    ## default kernel options for automagic boot options
    ## If you want special options for specifiv kernels use kopt_x_y_z
    ## where x.y.z is kernel version. Minor versions can be omitted.
    ## e.g. kopt=root=/dev/hda1 ro
    # kopt=root=/dev/hda1 ro

    ## default grub root device
    ## e.g. groot=(hd0,0)
    # groot=(hd0,0)

    ## should update-grub create alternative automagic boot options
    ## e.g. alternative=true
    ##      alternative=false
    # alternative=true

    ## should update-grub lock alternative automagic boot options
    ## e.g. lockalternative=true
    ##      lockalternative=false
    # lockalternative=false

    ## altoption boot targets option
    ## multiple altoptions lines are allowed
    ## e.g. altoptions=(extra menu suffix) extra boot options
    ##      altoptions=(recovery mode) single
    # altoptions=(recovery mode) single

    ## controls how many kernels should be put into the menu.lst
    ## only counts the first occurence of a kernel, not the
    ## alternative kernel options
    ## e.g. howmany=all
    ##      howmany=7
    # howmany=all

    ## should update-grub create memtest86 boot option
    ## e.g. memtest86=true
    ##      memtest86=false
    # memtest86=true

    ## ## End Default Options ##

    title        Debian GNU/Linux, kernel 2.4.27-2-386
    root        (hd0,0)
    kernel        /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro
    initrd        /boot/initrd.img-2.4.27-2-386
    savedefault
    boot

    title        Debian GNU/Linux, kernel 2.4.27-2-386 (recovery mode)
    root        (hd0,0)
    kernel        /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro single
    initrd        /boot/initrd.img-2.4.27-2-386
    savedefault
    boot

    ### END DEBIAN AUTOMAGIC KERNELS LIST

Now I do my part with vi

    bildad:~# # This will make for an ugly log
    bildad:~# vi /boot/grub/menu.lst

<delete ugly edit session>  I added this at the end of the file:

    # OpenBSD Chainloading stanza.  Cribbed from the Windoze example above.
    #

    title        OpenBSD 4.0
    root        (hd0,2)
    makeactive
    chainloader    +1

 title -- appears in the grub boot menu
 root  -- specifies some partition to boot on some drive
 hd0  -- means drive 0, the ,2 means the third fdisk partition
 makeactive -- must have some purpose ;-)
 chainloader -- number of sectors from root to move to find the
   non-grub loader.  Why 1?  See above, and man boot (on OpenBSD).


for details of grub commands, see the grub documents.
They are in "info" format; use info2html to convert them
to something useful.

    bildad:~#
    bildad:~#

OK, this thing should reboot now, with the OpenBSD entry
showing on the grub boot screen.  Let's try it:

    bildad:~#
    bildad:~# shutdown -r now

    Broadcast message from root (ttyS0) (Sat Apr 28 23:26:59 2007):

    The system is going down for reboot NOW!

The "OpenBSD 4.0" entry appeared on the grub boot screen, I
selected it.

Hello, kitty:

    >> OpenBSD/i386 BOOT 2.10
    boot>
    booting hd0a:/bsd:
    entry point at 0x200120

    [ using 530356 bytes of bsd ELF symbol table ]
    Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
    Copyright (c) 1995-2006 OpenBSD. All rights reserved.  http://www.OpenBSD.org

    OpenBSD 4.0 (GENERIC) #1107: Sat Sep 16 19:15:58 MDT 2006
        deraadt@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC
    cpu0: Intel Pentium II ("GenuineIntel" 686-class, 512KB L2 cache) 266 MHz
    cpu0: FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,MMX
    real mem  = 100233216 (97884K)
    avail mem = 83537920 (81580K)
    using 1249 buffers containing 5115904 bytes (4996K) of memory
    mainbus0 (root)
    bios0 at mainbus0: AT/286+(00) BIOS, date 04/30/97, BIOS32 rev. 0 @ 0xfd900
    pcibios0 at bios0: rev 2.1 @ 0xf0000/0x10000
    pcibios0: PCI BIOS has 6 Interrupt Routing table entries
    pcibios0: PCI Interrupt Router at 000:07:0 ("Intel 82371SB ISA" rev 0x00)
    pcibios0: PCI bus #0 is the last bus
    bios0: ROM list: 0xc0000/0x8000 0xe9000/0x1000! 0xea000/0x2000
    cpu0 at mainbus0
    pci0 at mainbus0 bus 0: configuration mode 1 (bios)
    pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02
    pcib0 at pci0 dev 7 function 0 "Intel 82371SB ISA" rev 0x01
    pciide0 at pci0 dev 7 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 0 wired to compatibility, channel 1 wired to compatibility
    wd0 at pciide0 channel 0 drive 0: <WDC AC34000L>
    wd0: 16-sector PIO, LBA, 3815MB, 7814016 sectors
    wd0(pciide0:0:0): using PIO mode 4, DMA mode 2
    atapiscsi0 at pciide0 channel 1 drive 0
    scsibus0 at atapiscsi0: 2 targets
    atapiscsi1 at pciide0 channel 1 drive 1
    scsibus1 at atapiscsi1: 2 targets
    sd0 at scsibus1 targ 0 lun 0: <IOMEGA, ZIP 100, 23.D> SCSI0 0/direct removable
    sd0: drive offline
    atapiscsi0(pciide0:1:0): using PIO mode 4, DMA mode 2
    sd0(pciide0:1:1): using PIO mode 0
    uhci0 at pci0 dev 7 function 2 "Intel 82371SB USB" rev 0x01: irq 11
    usb0 at uhci0: USB revision 1.0
    uhub0 at usb0
    uhub0: Intel UHCI root hub, rev 1.00/1.00, addr 1
    uhub0: 2 ports with 2 removable, self powered
    vga1 at pci0 dev 11 function 0 "ATI Rage XL" rev 0x65
    wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
    wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
    ne3 at pci0 dev 17 function 0 "Realtek 8029" rev 0x00: irq 9, address 00:50:ba:52:65:ce
    isa0 at pcib0
    isadma0 at isa0
    pckbc0 at isa0 port 0x60/5
    pckbd0 at pckbc0 (kbd slot)
    pckbc0: using irq 1 for kbd slot
    wskbd0 at pckbd0: console keyboard, using wsdisplay0
    pms0 at pckbc0 (aux slot)
    pckbc0: using irq 12 for aux slot
    wsmouse0 at pms0 mux 0
    pcppi0 at isa0 port 0x61
    midi0 at pcppi0: <PC speaker>
    spkr0 at pcppi0
    lpt0 at isa0 port 0x378/4 irq 7
    lm0 at isa0 port 0x290/8: LM78
    npx0 at isa0 port 0xf0/16: using exception 16
    pccom0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
    pccom0: console
    pccom1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
    fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
    fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
    isapnp0 at isa0 port 0x279: read port 0x203
    "SYM 53C416       , SLI4163, , " at isapnp0 port 0x200/32 irq 5 not configured
    ym0 at isapnp0 "OPL3-SA3 Snd System , YMH0021, , " port 0x220/16,0x530/8,0x388/8,0x330/2,0x370/2 irq 5 drq 0,1
    midi1 at ym0: <YM MPU-401 UART>
    audio0 at ym0
    joy0 at isapnp0 "OPL3-SA3 Snd System , YMH0022, PNPB02F, " port 0x201/1
    pccom3 at isapnp0 "U.S. Robotics 56K FAX INT, USR3030, , " port 0x3e8/8 irq 3: ns16550a, 16 byte fifo
    biomask ed45 netmask ef45 ttymask ffc7
    pctr: 686-class user-level performance counters enabled
    mtrr: Pentium Pro MTRR support
    dkcsum: wd0 matches BIOS drive 0x80
    root on wd0a
    rootdev=0x0 rrootdev=0x300 rawdev=0x302
    Automatic boot in progress: starting file system checks.
    /dev/rwd0a: file system is clean; not checking
    /dev/rwd0e: file system is clean; not checking
    setting tty flags
    starting network
    starting system logger
    starting initial daemons:.
    savecore: no core dump
    checking quotas: done.
    building ps databases: kvm dev.
    clearing /tmp
    starting pre-securelevel daemons:.
    setting kernel security level: kern.securelevel: 0 -> 1
    creating runtime link editor directory cache.
    preserving editor files
    ssh-keygen: generating new DSA host key... done.
    ssh-keygen: generating new RSA host key... done.
    ssh-keygen: generating new RSA1 host key... done.
    openssl: generating new isakmpd RSA key... done.
    starting network daemons: sendmail inetd sshd.
    starting local daemons:.
    standard daemons: cron.
    Sat Apr 28 23:28:51 EDT 2007

    OpenBSD/i386 (bildad.chuck) (tty00)

    login: root
    Password:
    OpenBSD 4.0 (GENERIC) #1107: Sat Sep 16 19:15:58 MDT 2006

    Welcome to OpenBSD: The proactively secure Unix-like operating system.

    Please use the sendbug(1) utility to report bugs in the system.
    Before reporting a bug, please try to reproduce it with the latest
    version of the code.  With bug reports, please try to ensure that
    enough information to reproduce the problem is enclosed, and if a
    known fix for it exists, include that as well.

    You have mail.
    Terminal type? [vt220]
    # uname -a
    OpenBSD bildad.chuck 4.0 GENERIC#1107 i386
    #
    #

...and that's that!!



 What's happened from the OpenBSD perspective?

First the fdisk:
    #
    # fdisk wd0
    Disk: wd0       geometry: 969/128/63 [7814016 Sectors]
    Offset: 0       Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 83    0   1  1 -  243   5 63 [          63:     1959867 ] Linux files*
     1: 82  243   6  1 -  304 102 63 [     1959930:      498015 ] Linux swap
    *2: A6  304 103  1 -  968  25 63 [     2457945:     5349645 ] OpenBSD
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused
    #

note that the third partition (2) is marked active.
I marked it that way during the fdisk session during the BSD installation.
But maybe grub changes the marking.  At any rate, I am no longer
changing it manually.

here's the disklabel:

    #
    # disklabel wd0
    # Inside MBR partition 2: type A6 start 2457945 size 5349645
    # /dev/rwd0c:
    type: ESDI
    disk: ESDI/IDE disk
    label: WDC AC34000L
    flags:
    bytes/sector: 512
    sectors/track: 63
    tracks/cylinder: 16
    sectors/cylinder: 1008
    cylinders: 7752
    total sectors: 7814016
    rpm: 3600
    interleave: 1
    trackskew: 0
    cylinderskew: 0
    headswitch: 0           # microseconds
    track-to-track seek: 0  # microseconds
    drivedata: 0

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:        523719       2457945  4.2BSD   2048 16384  328 # Cyl  2438*-  2957
      b:        524160       2981664    swap                   # Cyl  2958 -  3477
      c:       7814016             0  unused      0     0      # Cyl     0 -  7751
      e:       4301766       3505824  4.2BSD   2048 16384  328 # Cyl  3478 -  7745*
      i:       1959867            63  ext2fs                   # Cyl     0*-  1944*
      j:        498015       1959930 unknown                   # Cyl  1944*-  2438*
    #


Notice these things:


The 'c' partition covers the *whole harddrive*, cylinders 0 to the end.
The portion of the disc that OpenBSD is using is in partitions 'a', 'b'
and 'e', (/, swap, and /usr), starting at offset 2457945.

The existing Linux partitions appeared magically during the OpenBSD
installation as partitions 'i' and 'j', 'j' is swap.

I didn't use partition 'd', as I intended to define it as NetBSD does,
to cover that part of wd0 that OpenBSD uses.  It is then a "don't
normally touch" partition, like c.  If I need it, I'll define it.
(I would need it if I wanted to wipe the OpenBSD stuff, including
any bootloaders, for another demo, using dd).

mounting the Linux partition for inspection:


    #
    # mount -t ext2fs /dev/wd0i /mnt
    # ls /mnt
    bin        etc        lib        opt        srv        var
    boot       home       lost+found proc       sys        vmlinuz
    cdrom      initrd     media      root       tmp
    dev        initrd.img mnt        sbin       usr
    #

we could get to /boot/grub/* now if we wanted to mess with it.

All done!

Let's see if Linux will reboot now...


It's still the default boot in grub's boot menu
This will be "hands off" reboot

    # shutdown -r now
    Shutdown NOW!
    shutdown: [pid 20997]
    #
    *** FINAL System shutdown message from root@bildad.chuck ***
    System going down IMMEDIATELY

    System shutdown time has arrived
    /etc/rc.shutdown in progress...
    /etc/rc.shutdown complete.

    # syncing disks... done
    rebooting...

Here it comes:

    Debian GNU/Linux 3.1 bildad ttyS0

    bildad login: root
    Password:
    Last login: Sat Apr 28 23:21:17 2007 on ttyS0
    Linux bildad 2.4.27-2-386 #1 Mon May 16 16:47:51 JST 2005 i686 GNU/Linux

    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    bildad:~#

looks like it works.

    bildad:~#
    bildad:~# # let's look at Linux's fdisk now that all is done:
    bildad:~#
    bildad:~# fdisk /dev/hda

    The number of cylinders for this disc is set to 7752.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    16 heads, 63 sectors/track, 7752 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1               1        1945      979933+  83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/hda2            1945        2439      249007+  82  Linux swap / Solaris
    Partition 2 does not end on cylinder boundary.
    /dev/hda3   *        2439        7746     2674822+  a6  OpenBSD
    Partition 3 does not end on cylinder boundary.

    Command (m for help): q

Looks like OpenBSD is still marked active; grub is ignoring
that, which is what we want.  Fussing with grub's default
is for later.

As if by magic, Linux fdisk is now complaining that the partitions
do not end on cylinder boundaries.

Recall that the only fdisk-ing that defined those partitions was
using Linux fdisk during the Debian installation.  The BSD fdisk
was used to flag the third partition as "active", and nothing else.

So why the complaints?  Who knows?

A Linux dmesg for the record:


    # dmesg
    Linux version 2.4.27-2-386 (horms@tabatha.lab.ultramonkey.org) (gcc version 3.3.5 (Debian 1:3.3.5-12)) #1 Mon May 16 16:47:51 JST 2005
    BIOS-provided physical RAM map:
     BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
     BIOS-e820: 0000000000100000 - 0000000006000000 (usable)
     BIOS-e820: 00000000fff80000 - 0000000100000000 (reserved)
    96MB LOWMEM available.
    On node 0 totalpages: 24576
    zone(0): 4096 pages.
    zone(1): 20480 pages.
    zone(2): 0 pages.
    ACPI disabled because your bios is from 97 and too old
    You can enable it with acpi=force
    Kernel command line: root=/dev/hda1 ro
    Local APIC disabled by BIOS -- reenabling.
    Found and enabled local APIC!
    Initializing CPU#0
    Detected 265.913 MHz processor.
    Console: colour VGA+ 80x25
    Calibrating delay loop... 530.84 BogoMIPS
    Memory: 91244k/98304k available (1069k kernel code, 6672k reserved, 459k data, 96k init, 0k highmem)
    Dentry cache hash table entries: 16384 (order: 5, 131072 bytes)
    Inode cache hash table entries: 8192 (order: 4, 65536 bytes)
    Mount cache hash table entries: 512 (order: 0, 4096 bytes)
    Buffer cache hash table entries: 4096 (order: 2, 16384 bytes)
    Page-cache hash table entries: 32768 (order: 5, 131072 bytes)
    CPU: L1 I cache: 16K, L1 D cache: 16K
    CPU: L2 cache: 512K
    CPU:     After generic, caps: 0080fbff 00000000 00000000 00000000
    CPU:             Common caps: 0080fbff 00000000 00000000 00000000
    CPU: Intel Pentium II (Klamath) stepping 03
    Checking 'hlt' instruction... OK.
    Checking for popad bug... OK.
    POSIX conformance testing by UNIFIX
    enabled ExtINT on CPU#0
    ESR value before enabling vector: 00000000
    ESR value after enabling vector: 00000000
    Using local APIC timer interrupts.
    calibrating APIC timer ...
    ..... CPU clock speed is 265.9145 MHz.
    ..... host bus clock speed is 66.4785 MHz.
    cpu: 0, clocks: 664785, slice: 332392
    CPU0<T0:664784,T1:332384,D:8,S:332392,C:664785>
    ACPI: Subsystem revision 20040326
    ACPI: Interpreter disabled.
    PCI: PCI BIOS revision 2.10 entry at 0xfd921, last bus=0
    PCI: Using configuration type 1
    PCI: Probing PCI hardware
    PCI: Probing PCI hardware (bus 00)
    Limiting direct PCI/PCI transfers.
    Activating ISA DMA hang workarounds.
    Linux NET4.0 for Linux 2.4
    Based upon Swansea University Computer Society NET3.039
    Initializing RT netlink socket
    Starting kswapd
    VFS: Disk quotas vdquot_6.5.1
    devfs: v1.12c (20020818) Richard Gooch (rgooch@atnf.csiro.au)
    devfs: boot_options: 0x0
    pty: 256 Unix98 ptys configured
    Serial driver version 5.05c (2001-07-08) with HUB-6 MANY_PORTS MULTIPORT SHARE_IRQ SERIAL_PCI enabled
    ttyS00 at 0x03f8 (irq = 4) is a 16550A
    ttyS01 at 0x02f8 (irq = 3) is a 16550A
    COMX: driver version 0.85 (C) 1995-1999 ITConsult-Pro Co. <info@itc.hu>
    RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
    Initializing Cryptographic API
    NET4: Linux TCP/IP 1.0 for NET4.0
    IP: routing cache hash table of 512 buckets, 4Kbytes
    TCP: Hash tables configured (established 8192 bind 16384)
    Linux IP multicast router 0.06 plus PIM-SM
    RAMDISK: cramfs filesystem found at block 0
    RAMDISK: Loading 3692 blocks [1 disk] into ram disk... done.
    Freeing initrd memory: 3692k freed
    VFS: Mounted root (cramfs filesystem).
    Freeing unused kernel memory: 96k freed
    NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
    Uniform Multi-Platform E-IDE driver Revision: 7.00beta4-2.4
    ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx
    ide: late registration of driver.
    PIIX3: IDE controller at PCI slot 00:07.1
    PIIX3: chipset revision 0
    PIIX3: not 100% native mode: will probe irqs later
        ide0: BM-DMA at 0xffa0-0xffa7, BIOS settings: hda:DMA, hdb:pio
        ide1: BM-DMA at 0xffa8-0xffaf, BIOS settings: hdc:DMA, hdd:pio
    hda: WDC AC34000L, ATA DISK drive
    blk: queue c6825b60, I/O limit 4095Mb (mask 0xffffffff)
    hdc: CD-R/RW RW7063A, ATAPI CD/DVD-ROM drive
    hdd: IOMEGA ZIP 100 ATAPI, ATAPI FLOPPY drive
    ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
    ide1 at 0x170-0x177,0x376 on irq 15
    hda: attached ide-disk driver.
    hda: 7814016 sectors (4001 MB) w/256KiB Cache, CHS=7752/16/63, (U)DMA

This is the interesting bit, the "partition check".  It evidently
"sees" the OpenBSD installation. It sees "p3" as the home of
OpenBSD, the p5,p6,p7 are the three partitions ('a','b','e')
in the OpenBSD disklabel on partition 2 (p3).

    Partition check:
     /dev/ide/host0/bus0/target0/lun0: p1 p2 p3
     p3: <openbsd: p5 p6 p7 >
    Journalled Block Device driver loaded
    kjournald starting.  Commit interval 5 seconds
    EXT3-fs: mounted filesystem with ordered data mode.
    Adding Swap: 248996k swap-space (priority -1)
    EXT3 FS 2.4-0.9.19, 19 August 2002 on ide0(3,1), internal journal
    Real Time Clock Driver v1.10f
    hdc: attached ide-cdrom driver.
    hdc: ATAPI 32X CD-ROM CD-R/RW drive, 2048kB Cache, DMA
    Uniform CD-ROM driver Revision: 3.12
    ne2k-pci.c:v1.02 10/19/2000 D. Becker/P. Gortmaker
      http://www.scyld.com/network/ne2k-pci.html
    eth0: RealTek RTL-8029 found at 0xff80, IRQ 9, 00:50:BA:52:65:CE.
    SCSI subsystem driver Revision: 1.00
    hdd: attached ide-scsi driver.
    scsi0 : SCSI host adapter emulation for IDE ATAPI devices
      Vendor: IOMEGA    Model: ZIP 100           Rev: 23.D
      Type:   Direct-Access                      ANSI SCSI revision: 00
    usb.c: registered new driver usbdevfs
    usb.c: registered new driver hub
    usb-uhci.c: $Revision: 1.275 $ time 16:52:03 May 16 2005
    usb-uhci.c: High bandwidth mode enabled
    usb-uhci.c: USB UHCI at I/O 0xff40, IRQ 11
    usb-uhci.c: Detected 2 ports
    usb.c: new USB bus registered, assigned bus number 1
    hub.c: USB hub found
    hub.c: 2 ports detected
    usb-uhci.c: v1.275:USB Universal Host Controller Interface driver
    uhci.c: USB Universal Host Controller Interface driver v1.1
    bildad:~#

The OpenBSD partitions are mountable but not writeable under
Debian.  See man mount for details.



END


PS: Extended partitions??

Installation to extended partition --> no go. To fix, will need to
rewrite disklabel (or study the "b" for "breakage" command more) and
installboot. Made several trials; something is overwriting the
first track of the disc, ruining grub. I suspect this is disklabel.
(installboot fails, but it doesn't write anything when it fails.)
I may make yet another try, and dump the first track of the disc to
someplace or other (hard to do on an unbootable system, since I don't
know if I have a rescue disc that supports serial console and also
has hexdump or someother tool like that on it. The floppy drive on
the sacrifice box may not work, otherwise I'd do something like

dd if=/dev/rwd0c of=/dev/fdc0 bs=512 count=63

But I'd rather pipe it to hexdump first.

Maybe I should try making a "grub floppy", this might work to restore
grub and get Linux back. But BSD wrote something in track 0, and
it will probably expect to read that something later. :-(

The problem is that each experiment takes 1-2 hours. (Pokey Debian
installation + thinking time). Also the harddisk in the box is getting
flakey under both OSes.

There is NO GOOD REASON for OpeBSD to not be bootable from anywhere
on a harddisk where grub could find it. It's some sort of @#$%$#
bull-headedness on OpenBSD's part that this is not supported. I
can understand that, but it doesn't seem like it would be very hard
to fix. Just because it's i386 specific is no excuse, that's far
and away the most common architecture these days.



HOW TO SHARE SWAP FOR OpenBSD + GNU/LINUX

I installed Debian Sarge to the whole harddisk, which resulted in
one large partition mounted on /, and a second partition (#5, i.e.
a logical partition) for swap.  This would be a typical "naive"
Linux installation, done in "blissful ignorance" of any future
multibooting.

My intention now is to install OpenBSD.

So I shrank the Linux '/' partition using parted from the command
line, in single user mode.  Run e2fsck first, then parted.  (To
enter single user mode, execute "telinit S" or use the "recovery"
option from grub.)  Don't even think about doing this while the
system is active.  Best practice would be to not have the partition
mounted while shrinking it, but I only have one partition, Debian
install disk, while including the kitchen sink, doesn't seem to
have an "emergency fixit mode", and the floppy drive on bildad/peleg
is flakey.  So next best is single user and a certain attitude
tolerating some possible corruption and glitches.

So I did it.  Man parted, all I did was "resize".

Parted does not or did not adjust the partition table!  

Maybe parted has some command to fixup the partition table to
match the now-shrunken filesystem, but I don't have a Linux
system handy right now to check.

I rebooted and changed the size of the '/' partition to be somewhat
larger than the size of the filesystem shrunk by parted.  This I
did with Linux's fdisk(8) program.

I then created and marked active an OpenBSD partition to receive
the OpenBSD installation.  My intention is to have OpenBSD share
the Linux swap partition, by establishing the 'b' partition in
OpenBSD's disklabel to be somewhat smaller than the Linux swap
partition.  This may obviate the need to run Linux's  mkswap(8)
kludge before every boot of Linux.

This is an ugly wart on Linux ... Linux swapon should check swap
partitions and files for the required signature and setup and call
mkswap itself.  Or just construct the data in the kernel, where it
belongs, since that's where it's used.

I am assuming that the mkswap(8) manpage is accurate in its description
of the swap area.  Apparently the first page of the swap area is
reserved for some sort of bitmap.  The last ten bytes of the first
page holds a signature, which is either either "SWAP_SPACE" for the
old type or "SWAPSPACE2" for the new type.  Known page sizes are
4096 bytes on the PeeCee architecture.  Evidently the rest of this
swap area is fair game. (I would need the code for mkswap or some
experiments to verify.  I am nervous enough to verify.)

Let's experiment.  Create a trial file:

    peleg:~# dd if=/dev/zero of=trialswap bs=4096 count=16
    16+0 records in
    16+0 records out
    65536 bytes transferred in 0.004890 seconds (13401954 bytes/sec)
    peleg:~# mkswap -v trialswap
    Setting up swapspace version 0, size = 61 kB
    peleg:~#

Now hexdump to see what's in it that isn't a zero.

    peleg:~# hexdump trialswap
    0000000 fffe 0000 0000 0000 0000 0000 0000 0000
    0000010 0000 0000 0000 0000 0000 0000 0000 0000
    *
    0000ff0 0000 0000 0000 5753 5041 532d 4150 4543
    0001000 0000 0000 0000 0000 0000 0000 0000 0000
    *
    0010000
    peleg:~#

OK, after 4096 bytes, it's all zero.  But maybe it ~has~ to be
zero?  

Let's pack it with DEADBEEF first, before mkswap.
(I happen to have a little program to write 0xdeadbeef on fd 1.)

    peleg:~# ./beef >trialswap
    peleg:~# hexdump trialswap
    0000000 beef dead beef dead beef dead beef dead
    *
    0010000
    peleg:~# mkswap -v trialswap
    Setting up swapspace version 0, size = 61 kB
    peleg:~# hexdump trialswap
    0000000 fffe 0000 0000 0000 0000 0000 0000 0000
    0000010 0000 0000 0000 0000 0000 0000 0000 0000
    *
    0000ff0 0000 0000 0000 5753 5041 532d 4150 4543
    0001000 beef dead beef dead beef dead beef dead
    *
    0010000
    peleg:~#

OK looks promising for this method.  Mkswap didn't eat any of the
deadbeef after the first 4096 byte page.  All we need do, I theorize,
is set the start of OpenBSD's 'b' swap area to be 4096/512 = 8
sectors beyond the start of this partition, and its size 8 sectors
smaller.

Here is the Linux fdisk at this point:

    peleg:~# fdisk /dev/hda

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    255 heads, 63 sectors/track, 486 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1               1         136     1092388+  83  Linux
    /dev/hda2             463         486      192780    5  Extended
    /dev/hda3   *         140         462     2594497+  a6  OpenBSD
    /dev/hda5             463         486      192748+  82  Linux swap / Solaris

    Partition table entries are not in disk order

 Show them in sectors, since that's BSD's mode of thought.

    Command (m for help): Command (m for help): u
    Changing display/entry units to sectors

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    255 heads, 63 sectors/track, 486 cylinders, total 7814016 sectors
    Units = sectors of 1 * 512 = 512 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1              63     2184839     1092388+  83  Linux
    /dev/hda2         7422030     7807589      192780    5  Extended
    /dev/hda3   *     2233035     7422029     2594497+  a6  OpenBSD
    /dev/hda5         7422093     7807589      192748+  82  Linux swap / Solaris

    Partition table entries are not in disk order

    Command (m for help):


So the start of the OpenBSD 'b' partition should be 7422093+8 =
7422101 Its size should be 7807589 - 7422101 = 385488 sectors.
We'll probably not cut it so close.



  Installation of OpenBSD with an attempt to share the swap
  partition with Linux

  Irrelevant parts of the installation script will be elided.



    >> OpenBSD/i386 CDBOOT 1.04
    boot>
    entry point at 0x200120

    Copyright (c) 1982, 1986, 1989, 1991, 1993
        The Regents of the University of California.  All rights reserved.
    Copyright (c) 1995-2006 OpenBSD. All rights reserved.  http://www.OpenBSD.org

    OpenBSD 4.0 (RAMDISK_CD) #39: Sat Sep 16 19:34:26 MDT 2006
        deraadt@i386.openbsd.org:/usr/src/sys/arch/i386/compile/RAMDISK_CD
     ...

    erase ^?, werase ^W, kill ^U, intr ^C, status ^T
    (I)nstall, (U)pgrade or (S)hell? i

...
    You will now initialize the disk(s) that OpenBSD will use. To enable all
    available security features you should configure the disk(s) to allow the
    creation of separate filesystems for /, /tmp, /var, /usr, and /home.

 We'll ignore that sound advice to keep the Good Work here simple.
 One partition will suffice for the demonstration.

    Available disks are: sd0 wd0.
    Which one is the root disk? (or 'done') [done] wd0

 As in all multibooting work, we are careful to Just Say No:

    Do you want to use *all* of wd0 for OpenBSD? [no] no

    You will now create a single MBR partition to contain your OpenBSD data. This
    partition must have an id of 'A6'; must *NOT* overlap other partitions; and
    must be marked as the only active partition.

 We have already done what that paragraph enjoined us to do.

 The 'manual' command describes all the fdisk commands in detail.


 This is how OpenBSD fdisk displays a disk with extended partitions.
 It is neither friendly nor obvious.  We won't be messing too much
 with it.  In fact, we're not going to anything with fdisk at
 this point except to exhibit its wonders.

    Disk: wd0       geometry: 969/128/63 [7814016 Sectors]
    Offset: 0       Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 83    0   1  1 -  270 119 63 [          63:     2184777 ] Linux files*
     1: 05  920  50  1 -  968  25 63 [     7422030:      385560 ] Extended DOS
    *2: A6  276 117  1 -  920  49 63 [     2233035:     5188995 ] OpenBSD     
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
    Offset: 7422030 Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 82  920  51  1 -  968  25 63 [     7422093:      385497 ] Linux swap  
     1: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
     2: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      


 This area of the disk in the "Linux Swap" area is something we want to use
 by BSD.  We'll skip over several blocks at the beginning of that area to avoid
 trashing Linux's magic signature and block map.  (See man mkswap(8) on Linux).

 All of this crap is necessary because Linux won't construct this map at
 boot time  (run "time mkswap /dev/hdxx" sometime, it takes about .1 sec)
 They are paranoid about this because there might be 'bad blocks' in the
 swap file... clue, disks started mapping those blocks out themselves
 sometime in the early 1990's on the PeeCee architecture.  So this is relevant
 if you're running MFM or RLL drives for your swap, and if you are, you
 deserve them, since you can get a used ATA or SCSI drive for $5 that is larger
 and faster than even the wildest dreams of the MFM/RLL days.

 I could, following the Linux-FreeBSD HOWTO that is on the 'net at various and
 sundry places, insert a "mkswap" in the Linux boot sequence, but I want to try
 it without.  (I do recommend reading this HOWTO for backround; my approach
 is slightly different.  My approach is "better" because in the usual case
 the Linux swap partition already exists, and BSD is the newcomer.  The HOWTO
 treats with Linux using an already existing BSD partition.  Six of one,
 half-dozen of the other, actually.  I didn't want to edit any Linux rc files,
 since shoving in mkswaps in there should be done with more care (i.e. BSD
 paranoid style ;-) than the Linux HOWTO.


    Enter 'help' for information
    fdisk: 1> q

 make no changes from what we set up in Linux

    You will now create an OpenBSD disklabel inside the OpenBSD MBR
    partition. The disklabel defines how OpenBSD splits up the MBR partition
    into OpenBSD partitions in which filesystems and swap space are created.

    The offsets used in the disklabel are ABSOLUTE, i.e. relative to the
    start of the disk, NOT the start of the OpenBSD MBR partition.

    # Inside MBR partition 2: type A6 start 2233035 size 5188995

    Treating sectors 2233035-7422030 as the OpenBSD portion of the disk.
    You can use the 'b' command to change this.


 It turns out that this will be necessary, the use of the dreaded
 'dangerous' and mysterious 'b' command.

 ("It turns out that" means "After several aborted installations, a
 kernel panic or two, the taking of several strong oaths, a whimpered
 prayer, some reading, some quality time with hexdump  and a nice cup
 of tea, it turns out that")

 An alternative is to notice the 'j' partition, write down its
 dimensions somewhere safe, calculate where you want your 'b' to be
 as shown below, and just ~delete~ the 'j' partition.  Then restart
 the OpenBSD installation, maybe.  I want to leave the 'j' partition
 there for esthetic and pedagogic purposes.
 

    Initial label editor (enter '?' for help at any prompt)
    > p
    device: /dev/rwd0c
    type: ESDI
    disk: ESDI/IDE disk
    label: WDC AC34000L    
    bytes/sector: 512
    sectors/track: 63
    tracks/cylinder: 16
    sectors/cylinder: 1008
    cylinders: 7752
    total sectors: 7814016
    free sectors: 5188995
    rpm: 3600

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  unused      0     0      
      c:       7814016             0  unused      0     0      
      i:       2184777            63  ext2fs                   
      j:        385497       7422093 unknown                   
 here goes 'b' command:
    > b
    Starting sector: [2233035]
    Size ('*' for entire disk): [5188995] *

 Notice how we have used 'b' and defined the "OpenBSD Area" of the
 disk to start at 2233035 and run to the end.  I think that's what
 the '*' meant.  Note that there is no way do discover what this
 "OpenBSD Area" really means, or to print it out after changing it,
 so far as I know.  I suspect that it is a fictional concept used
 within the disklabel program for error checking when using the -E
 option.  I seem to recall that in other ways of running disklabel
 (i.e. those not [easily] available during installation), nearly
 anything can be shoved into the innocent disklabel.


     > p
    device: /dev/rwd0c
    type: ESDI
    disk: ESDI/IDE disk
    label: WDC AC34000L    
    bytes/sector: 512
    sectors/track: 63
    tracks/cylinder: 16
    sectors/cylinder: 1008
    cylinders: 7752
    total sectors: 7814016

 Notice that "free sectors" has changed

    free sectors: 5195484
    rpm: 3600


 Now for the nitty-gritty:

 First, modify 'a' to be a 4.2BSD fstype.  Leave its size and offset alone.

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  unused      0     0      
      c:       7814016             0  unused      0     0      
      i:       2184777            63  ext2fs                   
      j:        385497       7422093 unknown                   
    > m a
    FS type: [unused] 4.2BSD
    offset: [2233035]
    size: [5188995]
    mount point: [none] /
    > p

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  4.2BSD      0     0    0 # /
      c:       7814016             0  unused      0     0      
      i:       2184777            63  ext2fs                   
      j:        385497       7422093 unknown                   


 This is the tricky part, and it leaves a bad taste.

 We 'know' that 'j' is the Linux swap partition, so it is
 not really 'unknown'.  On the other hand, we're going to
 get even vaguer, and say it is 'unused', which, strictly
 speaking will be true during BSD operation.  

 Without this change, the actual definition of 'b' as a swap
 area will fail with an error from disklabel.

    > m j
    FS type: [unknown] unused
    offset: [7422093]
    size: [385497]
    > p

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  4.2BSD      0     0    0 # /
      c:       7814016             0  unused      0     0      
      i:       2184777            63  ext2fs                   
      j:        385497       7422093  unused      0     0      
    > a b

 Now the meat: we add partition 'b' as type swap, with a special
 starting point, to dodge the aforementioned Linux signature/map,
 and take the default size.  Recall we need at least 4096 bytes,
 which is one Linux memory page.  That's 4096/512 = 8 sectors.
 I'll goose it up to the next cylinder boundary, just for esthetics.
 
 Note that the default offset is size('a')+offset('a'), no reference
 to 'j'.  We need a offset of 7422093 (offset('j')) + 8 = 7422101.
 I give it a lot more, later after this works, I can trim it if I
 want.  OpenBSD doesn't care what's initially in a swap area.

    offset: [7422030] 7422912
    size: [391104]
    FS type: [swap]
    > p

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  4.2BSD      0     0    0 # /
      b:        391104       7422912    swap                   
      c:       7814016             0  unused      0     0      
      i:       2184777            63  ext2fs                   
      j:        385497       7422093  unused      0     0      
    > m b
    FS type: [swap]
    offset: [7422912]
    size: [391104] 384678
    > w
    > q
    No label changes.
    Available disks are: sd0.
    Which one do you wish to initialize? (or 'done') [done] done

    OpenBSD filesystems:
    wd0a /


 Now the bootblocks...


    Installing boot block...
    boot: /mnt/boot
    proto: /usr/mdec/biosboot
    device: /dev/rwd0c
    /usr/mdec/biosboot: entry point 0
    proto bootblock size 512
    /mnt/boot is 3 blocks x 16384 bytes
    fs block shift 2; part offset 2233035; inode block 248, offset 4264
    using MBR partition 2: type 166 (0xa6) offset 2233035 (0x2212cb)
    done.

 Installed it where we wanted.

    Debian GNU/Linux 3.1 peleg ttyS0

    peleg login: root
    Password:
    Last login: Sun May  6 22:56:08 2007 from pequod.chuck on pts/1
    Linux peleg 2.6.8-2-386 #1 Thu May 19 17:40:50 JST 2005 i686 GNU/Linux

                                      __
                      ____  ___  / /__  ____ _
                     / __ \/ _ \/ / _ \/ __ `/
                    / /_/ /  __/ /  __/ /_/ /
                   / .___/\___/_/\___/\__, /  
                  /_/                    /____/   

 Let's see how this looks to Linux:
 
    peleg:~# fdisk /dev/hda

    Command (m for help): p

    Disk /dev/hda: 4000 MB, 4000776192 bytes
    255 heads, 63 sectors/track, 486 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1               1         136     1092388+  83  Linux
    /dev/hda2             463         486      192780    5  Extended
    /dev/hda3   *         140         462     2594497+  a6  OpenBSD
    /dev/hda5             463         486      192748+  82  Linux swap / Solaris

    Partition table entries are not in disk order

    Command (m for help): q


 Yeah, not in disk order, but they're what we want.


    peleg:~# vi /boot/grub/menu.lst

 Put in a boot stanza with root on (hd0,2) for OpenBSD.  See if it
 works:

    The system is going down for reboot NOW!
    peleg:~#

    >> OpenBSD/i386 BOOT 2.10

    OpenBSD/i386 (bildad.chuck) (tty00)

    login: root
    Password:
    OpenBSD 4.0-stable (GENERIC) #0: Sat Mar 17 22:38:56 EDT 2007

     0: 83    0   1  1 -  270 119 63 [          63:     2184777 ] Linux files*
     1: 05  920  50  1 -  968  25 63 [     7422030:      385560 ] Extended DOS
    *2: A6  276 117  1 -  920  49 63 [     2233035:     5188995 ] OpenBSD     
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
    Offset: 7422030 Signature: 0xAA55
         Starting       Ending       LBA Info:
     #: id    C   H  S -    C   H  S [       start:      size   ]
    ------------------------------------------------------------------------
     0: 82  920  51  1 -  968  25 63 [     7422093:      385497 ] Linux swap  
     1: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
     2: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
     3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
    # disklabel wd0
    # Inside MBR partition 2: type A6 start 2233035 size 5188995
    # /dev/rwd0c:
    type: ESDI
    disk: ESDI/IDE disk
    label: WDC AC34000L    
    flags:
    bytes/sector: 512
    sectors/track: 63
    tracks/cylinder: 16
    sectors/cylinder: 1008
    cylinders: 7752
    total sectors: 7814016
    rpm: 3600
    interleave: 1
    trackskew: 0
    cylinderskew: 0
    headswitch: 0           # microseconds
    track-to-track seek: 0  # microseconds
    drivedata: 0

    16 partitions:
    #             size        offset  fstype [fsize bsize  cpg]
      a:       5188995       2233035  4.2BSD   2048 16384  328 # Cyl  2215*-  7363*
      b:        384678       7422912    swap                   # Cyl  7364 -  7745*
      c:       7814016             0  unused      0     0      # Cyl     0 -  7751
      i:       2184777            63  ext2fs                   # Cyl     0*-  2167*
      j:        385497       7422093  unused      0     0      # Cyl  7363*-  7745*
    #
    

 I ran some programs to cause swapping, and filled the swaparea.
 Let's see if Linux still works:



    Debian GNU/Linux 3.1 peleg ttyS0

    peleg login: root
    Password:
    Last login: Mon May  7 00:02:06 2007 on ttyS0
    Linux peleg 2.6.8-2-386 #1 Thu May 19 17:40:50 JST 2005 i686 GNU/Linux

                          __
                      ____  ___  / /__  ____ _
                     / __ \/ _ \/ / _ \/ __ `/
                    / /_/ /  __/ /  __/ /_/ /
                   / .___/\___/_/\___/\__, /  
                  /_/                /____/   
    peleg:~# cc
    -bash: cc: command not found
    peleg:~# fg  gcc
    -bash: gcc: command not found

 Wot, no compiler?

    peleg:~# cc
    -bash: cc: command not found
    peleg:~# gcc
    -bash: gcc: command not found

 Ah, there it is :-/


    peleg:~# gcc-3.4

 create hello.c...    

    peleg:~# file hello
    -bash: file: command not found

 Wot, no file(1)?

    peleg:~# ./hello

    Hello, penguin

    peleg:~#


 Here's a nice core hog:

    peleg:~# cat hawg.c
    char foo[100000000];

    main()
    {
        int i;

        sleep(5);

        for(;;) {
            i=random()&100000000;
            foo[i]= random();
        }
    }
        
           
    peleg:~# gcc-3.4 -O0 -o hawg hawg.c

 Anyway, run enough instances of hawg or halfhawg (not shown) to eat up all
 the swap space.  OpenBSD still worked when I rebooted to it.
 Linux didn't crash.  

 "Success"






The style of this page is an abhorrent, sleazeball, abominable, vile, revolting and even gross adaptation of an original by Jonathan Hedley