Assignment 2

Prerequisites

Create either a VM on GCP or on VirtualBox (Linux or Debian preferred). The following demonstrates the usage of VirtualBox:

Click on New and choose name=ubuntu type=linux version=ubuntu 64-bit and click continue

Select suitable amount of memory say 6000MB and click continue

Select Create a new virtual hard disk now and click create

Select hard disk type to VDI and click continue

Make the hard disk space to be dynamically allocated

Provide a minimum of 50G of storage for the hard disk and click create.

Double click on the ubuntu virtual machine and go through the set up process.

Login with credentials on the GUI and open up a terminal.

very important please run the following command:

VBoxManage modifyvm ubuntu --nested-hw-virt on 

This ensures that inner VMs can be spawed using nested virtualization.

Run the following commands:

sudo su
apt-get update
apt-get upgrade
apt-get install build-essential git

Clone the repository

git clone https://github.com/dblessy/cmpe283-assignment-2
cd cmpe283-assignment-2/linux

Set up the required packages that are required for Kernel development using:

apt-get install fakeroot ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison

Copy the .config file and set CONFIG_SYSTEM_TRUSTED_KEYS="" and CONFIG_SYSTEM_REVOCATION_KEYS=""

cp -v /boot/config-$(uname -r) .config

Build the kernel, install and reboot the system for changes to take effect.

make -j
make -j modules
make install
make modules_install

reboot

Now that we have a working set up of the installed kernel, we can test it out using kvm for which we need utilities from KVM to be installed. It can be done using:

apt install qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager cloud-image-utils libguestfs-tools
mkdir ~/images
cd ~/images
wget "http://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
cat >user-data.txt <<EOF
#cloud-config
password: secretpassword
chpasswd: { expire: False }
ssh_pwauth: True
EOF

Create a virtual disk and start up an inner VM using the same

cloud-localds user-data.img user-data.txt
qemu-img create -b ubuntu-22.04-server-cloudimg-amd64.img -F qcow2 -f qcow2 ubuntu-vm-disk.qcow2 4G
virt-install --name ubuntu-vm \
  --virt-type kvm --memory 2048 --vcpus 2 \
  --boot hd,menu=on \
  --disk path=ubuntu-vm-disk.qcow2,device=disk \
  --disk path=user-data.img,format=raw \
  --graphics none \
  --os-type Linux --os-variant ubuntu22.04

Login to the new vm

virsh --connect qemu:///system console ubuntu-vm

login using the credentials ubuntu:secretpassword Install cpuid

sudo su
apt-get update
apt-get install cpuid

Test the output of the new leaf nodes using:

cpuid --leaf=0x4FFFFFFC
cpuid --leaf=0x4FFFFFFD

Running a sample python program to emit the total calls and cpu cycles shows and output like: