How to run JUNOS installed on Qemu on VirtualBox - Part1 Introduction

1. What is Olive?
In theory, Olive is JUNOS installed on x86-based hardware instead of Juniper hardware.

2. What is JUNOS?
It is a network operating system developed by Juniper.

3. Why could I use Olive?
If you are interested in learning JUNOS, building Olive is probably the most cheapest way to do it. Instead of buying Juniper hardware you can add several NICs to your old PC and have fun with one the most powerful network operating systems.

http://juniper.cluepon.net/index.php/Olive#Network_Cards

4. Why should one buy Juniper hardware?
Have in the mind that Olive cannot substitute hardware manufactured by Juniper. Imagine Olive as a Juniper router without Packet Forwarding engine. They are not any ASIC there to speed up packet forwarding process.

Due to lack of ASIC, packet forwarding is entirely dependent on performance of CPU in your computer. It makes Olive not acceptable in a real network infrastructure when forwarding must be stable and predictable without dependency on router's CPU.

Another limitation is that not all the configuration options are working with Olive. See the list for details.

http://juniper.cluepon.net/index.php/Olive#Tested_and_apparently_not_working

5. I want to build Olive but what if I don't have any spare computer  to run Junos?
Never mind, you can virtualize your Olive boxes. All what you need, is a  computer with powerful CPU and enough RAM to run multiple Olives virtual machines.

6. What the hack? Virtualization?
Yeap. In fact, you have several options you can use for virtualization. The most known virtualization tools are Qemu, VMware and VirtualBox. They all can give you a hand with Olive.

7. Which tool is better?
It is not that simple. Each has its own benefits and it is entirely up to you which one you choose. But I would recommend you to use either Qemu or VirtualBox because they are supported by GNS3.

8. GNS3? What's it?
GNS3
is a network tool developed by community and offers GUI for your virtualized Olive boxes. Just with few clicks you can easily start/stop backup and link Olives together. From GNS3 you can also set parameters such as RAM,  NIC model  etc.  Those parameters are passed to Qemu/VirtualBox wrappers that are listening on particular port. That magic is possible almost without need of touching underlying Qemu/VirtualBox emulators.

9. Which one should I use?  Qemu or VirtualBox?
It depends on your hardware and an operating system you like.  If you prefer Windows, you cannot miss with VirtualBox. According to my observation, virtual machine runs faster on VirtualBox comparing to pure Qemu on both OS - Windows and Linux.

On the other hand, if you are running Linux and your CPU supports hardware virtualization, Qemu seems to be a better choice. In case of hardware virtualization support, Qemu takes advantage of Kernel-based Virtual Machine (KVM) and virtual machines runs faster than those running by VirtualBox.

Personally, I have an old CPU Intel Prescott 3.2GHZ in my box. This CPU does not support hardware virtualization. For this reason, virtualization with VirtualBox is a right choice for me on that PC.

10. You've mentioned KVM. What the hell is it?

According to definition, KVM is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU.

But it is enough to know that KVM is an accelerator used by Qemu which allows virtualized guest to be run near native performance. This can be only done when x86 guest CPU is virtualized on x86 host CPU architecture.

11. Well, Qemu with KVM seems to be a right choice for me
And it really is. If you are interested in installing Olive under Qemu from scratch, read my guide.

https://brezular.com/2012/07/03/installing-olive-12-1r1-9-under-qemu/

12. But the title says that the tutorial should be dedicated to Olive under VirtualBox
More precisely, it is about running Olive Qemu image under VirtualBox. If you would like to setup Olive on VirtualBox from scratch, just google for it. Here are one of the tutorials.

http://sleepyrich.blogspot.sk/2010/03/preparing-virtualbox-and-freebsd-for.html
http://sleepyrich.blogspot.sk/2010/03/juniper-olive-on-sun-virtualbox.html

13. So what should I do now?
First, you must download and install VirtualBox. If you are a Windows user, be prepared for a series of Next button. For Tux lover, compilation and installation VirtualBox might be more challenging. For those of us who do not like suffering, installation of a binary version of Virtualbox from Linux repository is the less painful way to get VirtualBox working. Among other things, the following step-by-step tutorial discuss installation of VirtualBox from Fedora repository.

https://brezular.com/2011/08/02/virtualbox-0-4-1-installation-and-configuration-for-gns3-0-8-0-on-fedora-15-linux/

14. But I have had working installation of VirtualBox since last year
Be sure that you use the latest version of VirtualBox. Mine is Oracle VM VirtualBox 4.1.18. This version is patched for UDP tunnels and multicast what is necessary requirement to use VirtualBox  with GNS3.

15. Don't worry. I have my VirtualBox installation ready
Let's test it now. Start GNS3 as root user and navigate to Edit-> Preferences-> VirtualBox-> General Settings. Select path to VBoxwrapper, Working directories. Leave other settings default. Click on the Test Settings button. You should see message saying that VBoxwrapper and Vbox API have successfully started.

Picture 1 - VirtualBox General Settings

16. What if I get message "Failed to load vboxapi"?
They are  posts on the GNS3 forum complaining about this problem. As GNS3 0.8.3 is short after release, it is too soon talking about GNS3 bug. Anyway, some guys advise to reinstall VirtualBox. In my case, I had installed a package kmod-VirtualBox2.6.43.8-1.fc15.i686 from http://rpmfusion.org/ free repo that caused vboxapi error in GNS3 0.8.3. Once I installed the package VirtualBox-4.1-4.1.18_78361_fedora15-1.i686 a problem had gone.

http://forum.gns3.net/topic4942-90.html

17. My VirtualBox installation seems to be working. What's next step?
Prepare your Qemu Olive image. Either build your own or search for it on the Internet. Read back answer to question 11 if want to build one.

18. I have everything what I need. Can we start?
Sure. We are going to convert Qemu qcow2 format to VirtualBox vdi image. First, find out your qemu-img version.

$ /usr/local/bin/qemu-img | grep version

qemu-img version 1.1.0, Copyright (c) 2004-2008 Fabrice Bellard

Now, we are going to inspect our Olive Qemu image. Parameters such as file format and disk size can be obtained with qemu-img utility.

$ /usr/local/bin/qemu-img info olive-base.img

image: olive-base.img
file format: qcow2
virtual size: 16G (17179869184 bytes)
disk size: 2.3G
cluster_size: 65536

Qemu-img utility offers option to convert between qcow2 and vdi format. Following command creates a virtual disk from existing Qemu image.

$ /usr/local/bin/qemu-img convert -O vdi olive-base.img olive-base.vdi

During creating a new virtual machine, a new VDI virtual disk must be created or existing VDI disk attached to VBox machine.  It is contrast to Qemu where a Qemu image file represents a virtual machine itself. Let's inspect our new VDI virtual disk with VBoxManage utility.

$ /usr/bin/VBoxManage showhdinfo olive-base.vdi

UUID:                 1aaaa639-0430-4a9d-83b2-664602a854f7
Accessible:           yes
Logical size:         16384 MBytes
Current size on disk: 2388 MBytes
Type:                 normal (base)
Storage format:       VDI
Format variant:       dynamic default
Location:             /home/brezular/olive-base.vdi

We have created a virtual disk with UID: 1aaaa639-0430-4a9d-83b2-664602a854f7. Notice a type of our virtual disk. Every normal virtual disk type might be attached to only one virtual machine. If we created copy of our olive-base.vdi disk and try to attach it to Vbox machine, it would complain that the virtual disk UUID already exists.

19. How to attach my new VDI hard disk to more than one Vbox virtual machine?
The fastest method is to clone your virtual disk. A new disk will be created with different UUID.

$ /usr/bin/VBoxManage clonehd olive-base.vdi olive-base-copy.vdi

20. OK, but can I just simply copy and change UUID of this copy?
Sure. Here is the command you need.

$ /usr/bin/VBoxManage internalcommands sethduuid olive-base-copy.vdi

Notice, UUID has changed to: 85fb74d2-a1c9-48cf-86bc-26673b8f4905

21. Is it any way to attach the same VDI disk to multiple VBox virtual machines?
Yes, it is. It can be done using multi-attach VDI virtual disk. In this case, a differencing VDI disk is created for each virtual machine. This concept allows to have data written to one disk and not seen by other virtual machines.
Unfortunately we cannot use simple command to convert normal VDI disk to multi-attach VDI disk type. First, a little trick has to be done. The trick consists of creating  a new VirtualBox machine and attaching our olive-base.vdi disk to this machine.  After that, the disk must be detached from machine and command for converting between formats can be used.

Start VirtualBox with the following command. Navigate to Machine-> New-> Next. Set Name and OS type.

$ /usr/bin/VirtualBox

Picture 2 - Creating a new VBox machine

Select amount of memory. JUNOS 12.1R1.9 needs at least 512MB RAM. Set path to existing disk as it is shown on the picture.

Picture 3 - Attaching VDI disk to VBox machine

Your new VirtualBox machine has been created. Right click on machine and navigate to Settings.

Picture 4 - Deattaching VDI disk from VBox machine

Go to Storage section and do right click on hard disk - olive-base.vdi. Select Remove Attachment.

Picture 5 - VDI disk has been deattached  from VBox machine

Now you can use following command to convert normal (base) disk to multi-attach type disk.

$ /usr/bin/VBoxManage modifyhd olive-base.vdi --type multiattach

Check again your virtual hard disk. Notice that the type of virtual disk has changed to mutiattach type. The disk can be now attached to another virtual machines.

$ /usr/bin/VBoxManage showhdinfo olive-base.vdi

UUID:                 1aaaa639-0430-4a9d-83b2-664602a854f7
Accessible:           yes
Logical size:         16384 MBytes
Current size on disk: 2388 MBytes
Type:                 multiattach
Storage format:       VDI
Format variant:       dynamic default
Location:             /home/brezular/olive-base.vdi

22.  I can see that disk is mutliattach under normal user but it is normal type under root account
I noticed it, too. Always convert your disk under the account you normally use to start GNS3. For instance, if you start GNS3 as root user, make conversion under root account.

23. Is it any way to quickly create a new VirtualBox machine from existing machine?
Absolutely. VirtualBox offers option to clone your existing Vbox machine. Click on machine you want to clone and press Ctrl-O. Clone will be created with a new UUID.

24. Links
Qemu
http://wiki.qemu.org/Main_Page
http://en.wikipedia.org/wiki/QEMU
http://www.ibm.com/developerworks/linux/library/l-qemu/

Hardware virtualization with Qemu
http://alien.slackbook.org/dokuwiki/doku.php?id=slackware:qemu

2 thoughts on “How to run JUNOS installed on Qemu on VirtualBox - Part1 Introduction

  1. Hey,
    Very nice post and quite new. You wrote just yesterday!

    I’m already a virtualization professional, so, I won’t get trouble working with such thing. But, my labs are already well deployed on VMware Workstation.

    So, I’d like to know if it’s possible to do same thing you showed here on VM Workstation. If not directly, is it possible to convert this Virtual Box VM to a Workstation format with no further compatibility issues?

    Best regards!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.