OpenWrt 18.06.0 in VirtualBox

Source (needs improvement, but a lot better than nothing ...): https://openwrt.org/docs/guide-user/virtualization/virtualbox-vm (it's a wiki: I was using it 2018-08-12, with any luck it's been improved by the time you read it).

$ VBoxManage convertfromraw --format VDI openwrt-18.06.0-x86-64-combined-ext4.img openwrt-18.06.0-x86-64-combined-ext4.vdi
Converting from raw image file="openwrt-18.06.0-x86-64-combined-ext4.img" to file="openwrt-18.06.0-x86-64-combined-ext4.vdi"...
Creating dynamic image with size 285736960 bytes (273MB)...
  • VBoxManage has no man page
  • VBoxManage --help seems like a good idea, but produces 676 lines of parameters and flags without a single word of actual "help"
  • however, this page seems to have fairly decent documentation: https://www.virtualbox.org/manual/ch08.html
  • OpenWrt's documentation (linked above) now recommends that you resize the virtual HD with this command:
$ VBoxManage modifymedium openwrt-18.06.0-x86-64-combined-ext4.vdi --resize 128
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize medium operation for this format is not implemented yet!
  • the reason for the failure isn't obvious because VirtualBox's errors kind of suck
  • and this is also, unfortunately, an error by the folks at OpenWrt - the virtual HD is already 256M, so resizing it to 128M doesn't work ('modifymedium' only supports size increases, not decreases)
  • I'm going to recommend you resize the drive ... after you've got it running, as my previous experience with VBoxManage suggests it prefers to work with appliances that VirtualBox already knows about
  • place the .vdi you've created somewhere permanent - I say this because you're about to identify it VirtualBox, and VirtualBox will panic if you later move the file
  • in VirtualBox, click "New" -> ... I named it "OpenWrt 18.06.0 x86-64" with type "Linux" and "Other Linux (64-bit)" -> "Next" -> I let it go with the default 512M of memory, although that's awfully high if you're thinking of emulating a standard router -> and this next step is the important one: choose "Use an existing virtual hard disk file" and navigate to the VDI created above
  • once this is done and the machine appears in your list of appliances, select it and click "Start"
  • my experience has always been (this release, and several before it) that it comes up to this:
...
[   7.683577] br-lan: port 1(eth0) entered blocking state
[   7.685743] br-lan: port 1(eth0) entered forwarding state
[   7.686531] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
  • note the lack of a login prompt or shell prompt. Press enter and you'll be in as root
  • you can now play with OpenWrt, but I'd suggest (for now) typing poweroff
  • back to your hosting machine's command prompt
  • resizing the OpenWrt virtual HD isn't strictly necessary to get the virtual machine running (as you just saw), but if you're planning on installing packages and experimenting, increasing the size of the virtual disk is recommended:
$ VBoxManage modifymedium openwrt-18.06.0-x86-64-combined-ext4.vdi --resize 512
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
  • we succeeded this time - but if you looked at the documentation link for VBoxManage you may have noticed an important caveat: "... this only changes the drive capacity; you will typically next need to use a partition management tool inside the guest to adjust the main partition to fill the drive."
  • which means that the virtual HD is now bigger, but the partition(s) containing the OS inside the virtual HD don't know about it yet
  • with most forms of Linux you would use 'resize2fs' from within the OS, but finding instructions to do that with OpenWrt is difficult, so do it from the host machine: my blog entry Mounting or Resizing a VirtualBox VDI Virtual Hard Drive explains how (I gave a package name for Debian last time: to get 'qemu-nbd' on Fedora you'll need the 'qemu-img' package)
  • when you start using OpenWrt you'll find you don't actually have a network, see another of my blog entries, Getting OpenWRT Working in VirtualBox