Skip to content

Instantly share code, notes, and snippets.

@deep5050
Created November 4, 2023 17:04
Show Gist options
  • Save deep5050/af824a7f76dfcac1032d15bdb802946b to your computer and use it in GitHub Desktop.
Save deep5050/af824a7f76dfcac1032d15bdb802946b to your computer and use it in GitHub Desktop.
install ONIE in qemu/KVM

Running ONIE on QEMU: Two Options

When it comes to running ONIE on QEMU, you have two options, each with its own advantages and disadvantages. Let's explore both methods.

Option 1: Using the ONIE Provided Script

The ONIE distribution includes a handy script called oni-vm.sh, which simplifies the process of running ONIE on QEMU. This script comes with preconfigured settings, making it user-friendly but less customizable.

  1. Navigate to the emulation directory:
cd ~/onie/build/emulation
  1. Edit the onie-vm.sh file to modify the HDD and USB device size according to your requirements:
# Virtual Hard Drive size in GB
HARD_DRIVE_SIZE=5G
# Virtual USB Drive size in MB
USB_SIZE="4096M"
  1. Run ONIE in legacy BIOS mode using the following command:
sudo ./onie-vm.sh run --machine-name kvm_x86_64 --machine-revision r0 --m-bios-clean --m-hd-clean --m-embed-onie --m-boot-cd --m-onie-iso ../build/images/onie-recovery-x86_64-kvm_x86_64-r0.iso
  1. This will create a QEMU instance that can be accessed via telnet:
telnet localhost 9300

Additional notes:

  • You can clean or format the HDD and USB with sudo ./onie-vm.sh clean.
  • Update the virtual USB drive by running sudo ./onie-vm.sh update-m-usb after manually copying files under "onie/emulation-files/usb/usb-data."
  • If you don't want to clean the HDD on each run, remove --m-bios-clean --m-hd-clean from the command.

Option 2: Manual QEMU Commands

For more control and fine-tuning of your VM, you can directly invoke QEMU commands. This approach allows you to adjust parameters like RAM, CPU, VNC, and SSH configurations as needed.

  1. Create a HDD in qcow2 format with a specified size (e.g., 5GB):
qemu-img create -f qcow2 qemu-hdd.qcow2 -o preallocation=full 5G

You can also resize an existing image using:

qemu-img resize qemu-hdd.qcow2 +10G
  1. Run ONIE with the following command, adjusting parameters to your needs:
sudo qemu-system-x86_64 --enable-kvm -cpu host -smp 1 -m 256 -name onie -boot order=cd,once=d -cdrom ./onie-recovery-x86_64-kvm_x86_64-r0.iso -drive file=qemu-hdd.qcow2,media=disk,if=virtio,index=0 -vnc 0.0.0.0:128 -device virtio-net,netdev=onienet,mac=52:54:00:13:34:1E -netdev user,id=onienet,hostfwd=tcp::4022-:22 -nographic -serial telnet:localhost:9300,server
  1. Connect to ONIE via telnet:
telnet localhost 9300

With this manual approach, you have more flexibility to customize your QEMU environment for running ONIE.

Building and Installing ONIE on KVM/QEMU (Open Network Install Environment) with DUE

In this guide, we will walk through the steps to build and install ONIE (Open Network Install Environment) on KVM/QEMU using the DUE tool. DUE is used to create a Debian Docker environment for cross-compiling ONIE. Here are the steps involved:

Step 1: Install DUE To get started, you need to install DUE. DUE is used to create a Debian Docker environment for cross-compiling ONIE. First, clone the DUE repository and navigate to the DUE directory.

git clone https://github.com/CumulusNetworks/DUE.git
cd DUE

Step 2: Enable Docker Experimental Features To make the --platform argument work during Docker container creation, you need to enable experimental features in Docker. Edit the Docker daemon configuration file.

sudo vi /etc/docker/daemon.json

Add the following content to the file:

{
    "experimental": true
}

Save the file and exit the text editor. Then, restart Docker to apply the experimental changes.

systemctl restart docker

Step 3: List Available DUE Targets You can list all the available targets that can be built with DUE by running the following command:

./due --create help

Step 4: Select ONIE Project and Prepare Debian System Select the ONIE project that you want to build with Debian 10. Note that this step prepares the Debian system to be compatible with ONIE compilation. Run the following command:

./due --create --platform linux/amd64 --name onie-build-debian-10 --prompt ONIE-10 --tag onie --use-template onie --from debian:10 --description "ONIE Build Debian 10"

Step 5: Create the Docker Container and Log In To create the Docker container and log in, run the following command:

./due --run

This command will detect the last built Docker image and create a container. The container will have a volume mounted to /home/, which means the container's filesystem is accessible on the host, allowing you to see all the files on the host as well.

Step 6: Clone ONIE Repository Inside the Docker environment, clone the ONIE repository and configure your Git user information:

cd ~
git clone https://github.com/opencomputeproject/onie.git
git config --global user.email "dipankarpal5050@gmail.com"
git config --global user.name "Dipankar Pal"
cd ~/onie/build-config

Step 7: Build ONIE Now, you can build ONIE with the following commands:

make MACHINE=kvm_x86_64 signing-keys-generate
make MACHINE=kvm_x86_64 -j4 shim-self-sign
make -j 18 MACHINE=kvm_x86_64 all recovery-iso

Step 8: Build a Demo ONIE-Installer Image To build a demo ONIE-installer image, use the following command:

make -j 18 MACHINE=kvm_x86_64 demo

These steps will guide you through building and installing ONIE on KVM/QEMU using DUE. Make sure to follow each step carefully to ensure a successful setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment