More on VirtualBox

From Soekris Info Wiki

Jump to: navigation, search

Installing FreeBSD on CF for a Net5501 using VirtualBox

VirtualBox is a useful environment for installing FreeBSD on a compact flash card. But don't think you can put your null modem cable away: there is a lot that can go wrong, and you still need a serial console to succeed. This checklist documents my work on a Mac laptop with VirtualBox 4.1.18 and FreeBSD 8.3. VirtualBox is quite uniform across host platforms, so most of this will apply to a variety of other OSes.

  1. Required parts
    1. The working machine with VIrtualBox.
    2. The target CF card (I bought an 8GB SanDisk card from Soekris along with my Net5501) and a card reader.
    3. An ISO image of a FreeBSD RELEASE "disk1" CD.
    4. Terminal cable as described below.
  2. Preflight check to verify your terminal software and hardware
    1. Between a serial port and the Soekris console port, your need a null modem cable (or a standard serial cable with a null modem adapter). With the Soekris box powered off, attach your cable between its console port and your working machine's serial port.
    2. Identify how your OS sees the serial port. (My laptop has no physical serial ports, so I use a Keyspan USB serial converter, model USA-19HS. It shows up in the OS as /dev/tty.KeySerial1.)
    3. Identify your terminal software. While I often still use | Kermit, the screen utility, which is standard on OS X, also does a good job.
    4. Start up a connection at speed 19,200. e.g.: screen /dev/tty.KeySerial1 19200
    5. Power up the Soekris box. You should see its POST and boot-up display.
    6. Hit Ctrl-P to enter the boot menu, and then do a few things while there:
      1. Most importantly, change the speed to 9600 so that the boot ROM and the FreeBSD console will run at the same speed. This will take affect on the next reboot. While it might be tempting to increase the speed to 19,200 on the FreeBSD side, that turns out to be much more difficult.
      2. Set the date.
      3. And set the time.
    7. Power off and disconnect.
    8. Reconnect at 9600 (screen /dev/tty.KeySerial1 9600), power on, and verify terminal connectivity.
  3. VirtualBox VM setup
    1. Put the CF card in the card reader and attach it to the laptop. In my case, the Mac OS asks me about this "unreadable new disk," and I tell it to ignore the device. In the steps that follow, we are going to assign the card to a VM and actually be able to boot the VM off of the card.
    2. The OS has assigned the card to a raw device somewhere, and you need to figure out which one. On FreeBSD or Linux, you might watch the system log and look for new entries in /dev. On my Mac, I launched Disk Utility, and its main screen informed me that the card was at /dev/disk1.
    3. Create a new VM in VirtualBox. I gave mine 172 MB of memory.
    4. For networking, I used a bridged adapter (type PCnet-PCI II).
    5. Now create a .vmdk file to represent the physical device.
      1. cd to an appropriate directory, then type this command, substituting the correct device for your setup:
      2. VBoxManage internalcommands createrawvmdk -filename ./card_reader.vmdk -rawdisk /dev/disk1
      3. Peek at the .vmdk file in a text editor. Notice that it is plain text and you can edit it, for instance if at some later date the CF card appears as a different device.
    6. Next, attach the .vmdk file to the virtual machine.
      1. This is also a VBoxManage command. Note here that "Soekris" represents the name of the VM.
      2. VBoxManage storageattach "Soekris" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ./card_reader.vmdk
    7. The rest can be done from the VirtualBox GUI.
      1. Attach the ISO file of the FreeBSD as a CD ROM drive.
      2. Under "system," check the boot order. You want to boot first from the CD ROM, then from the hard disk.
  4. Install FreeBSD.
    1. I chose an "Express" install...
    2. And accepted the default partition on the partition screen
    3. On the disklabel screen, I created a 256 MB swap partition, and then a single "/" partition, with softupdates enabled, on the rest of the card.
    4. Then you select a distribution set.
    5. And finally choose the installation media (CD).
    6. Still in sysinstall, do some post-install configuration:
      1. Set the root password.
      2. Enable sshd.
  5. Still in VirtualBox, reboot to do more configuration
    1. Remove the CD, or change the boot order, so that the VM will reboot from the hard drive.
    2. Configure some networking in /etc/rc.conf
      1. In VirtualBox, the first ethernet port is le0. Assuming the networking is bridged, and you have a DHCP server somewhere, you can configure it like this: ifconfig_le0="DHCP"
      2. On a Net5501, the first network port will be vr0. (On a Net4801, it would be sis0). You can also configure that here, and having it present in the file will not hurt you in VirtualBox. ifconfig_vr0="DHCP" or ifconfig_vr0="inet ..."
    3. ADDUSER: Use adduser to add a normal user account for yourself.
    4. Edit /etc/ttys, to enable the serial console, and (optionally) to disable some virtual terminals.
      1. ttyu0 "/usr/libexec/getty std.9600" vt100 on secure
      2. (optional) Turn "off" (from "on") some of the higher numbered VTs, such as ttyv3 through ttyv7. On the Soekris box, with no video card, these will not be available.
    5. Now verify that you can make an ssh connection from the working machine to the VM.
    6. You're almost done. Reboot the VM, and verify that it boots up, by itself, such that you can connect to it over ssh.
  6. The point of no return: /boot/loader.conf
    1. Before booting on the real Soekris hardware, you must add one line to the (empty) file /boot/loader.conf. However, in my experience, once this change is made, it will be impossible to reboot again in VirtualBox. (I don't doubt that the serial ports of the VM can be configured in a way to make it work, but I myself have not figured out how). Add this line:
    2. console="comconsole"
  7. The real hardware
    1. Shut down the VM.
    2. Remove the CF card from the card reader and install it in the Soekris.
    3. Attach the serial cable and start up your terminal software, as above in the preflight check.
    4. Power on the Soekris. It should boot into FreeBSD.
Personal tools