Run linux kernel on virtualbox

Build the Linux Kernel for VirtualBox

This post is a just a quick walkthrough of how to build the Linux kernel and run it on VirtualBox, instead of your own machine. This is useful for any development in the kernel you might do that is purely software related, and doesn’t require direct access to any hardware (though you can give VirtualBox direct access to a USB device).

The benefits of installing a custom kernel on a VM are manifold. The most compelling, in my opinion, is that you don’t have to worry about messing up your system, so you have freedom to really experiment.

  1. Go ahead and download and install VirtualBox.
  2. Next, we need to clone the Linux repository. Open a terminal tab and run:
 git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git 

load live cd

This will take a while (it is gigabytes large), and we have other stuff to do.

  • Go ahead and download the boot ISO for your favorite distro (the instructions will assume the distro you are currently running, but that doesn’t have to be the case). Make sure that the distro you want to use can work with the version of Linux that you want to build and install.
  • Next open up VirtualBox and create a new virtual machine. When you come to the option about disks make sure to choose “Create a virtual hard disk now”. Make sure to choose the “VDI” format rather than “VHD” or “VMDK”. Depending on what your’re doing and what your distro expects you might have to allocate more or less space for the virtual disk, and if disk performance isn’t a concern you can choose “Dynamically Allocated” rather than “Fixed Size” for how to store it on your machine. Make note of where the vdi file is saved. Also, make sure to size the volume decently large (say at least 15GB), the unmodified install commands we will be running require a lot of space.
  • Click on the “Settings” button for your new virtual machine and then the “Storage” setting. Click on the CD-looking icon and choose “Live CD/DVD” then choose your distro ISO from the other CD-looking icon next to the “Optical Drive” dropdown.
  • Start the virtual machine and install the distro.
  • Once the distro is installed shutdown the VM, remove the Live CD/DVD and start the VM up again to make sure the distro is installed.
  • Make sure you qemu-nbd installed:

     sudo modprobe nbd max_part=8 
     sudo qemu-nbd -c /dev/nbd1 /home/$YOUR_USER/VirtualBox\ VMs/$YOUR_DISTRO/$YOUR_DISTRO.vdi 
     sudo mount /dev/nbd1p1 /mnt # assuming this is root sudo mount /dev/nbd1p2 /mnt/boot # assuming this is boot  
     cd /home/$YOUR_USER/Development/linux-stable cp /boot/config-`uname -r`* .config make # this will take a while  
     make -jX # X is the number of cores you want to dedicate to the build process; this will slow your system  
     sudo make INSTALL_MOD_PATH=/mnt/lib/modules/`uname -r` modules_install sudo make INSTALL_PATH=/mnt/boot install 
     sudo umount /mnt/boot sudo umount /mnt sudo qemu-nbd -d /deb/nbd1 
     sudo rm /boot/initramfs-`uname -r`.img sudo update-initramfs -c -k $VERSION_OF_LINUX_YOU_BUILT # make sure this looks like what uname -r would output sudo update-grub 

    Источник

    Running Linux kernel in Virtualbox

    I just built a Linux kernel on Ubuntu and now I want to make it run on VirtualBox. I wanted it to be in an img format. I created a hard drive image by doing the commands:

    $ qemu-img create disk.img 512M $ mkfs.ext2 -F disk.img 

    Your question looks vague now, were you trying to boot from the disk(that has a boot loader installed already), or use qemu to boot that disk with an external kernel file?

    2 Answers 2

    Why are you creating the disk manually?

    You should use VirtualBox to create the disk while creating the VM, unless you plan to use it together with qemu. (why?)

    Here, when adding disks, use the existing disk that you created.

    enter image description here

    All I have done is create the kernel. I want to take the bzImage and put that with a bootloader, and a hard drive image then run that in Virtualbox (or possibly qemu if there is a way to do both).

    To run a kernel directly in qemu or kvm , use the -kernel argument:

    qemu-system-x86_64 -kernel /boot/vmlinuz-3.2.0-2-amd64 

    Virtualbox may have something similar.

    If you really want it installed on a hard drive image, it’s a bit harder. You need a bootloader installed, which may also require a partition table. Something like SYSLINUX or EXTLINUX could be straightforward, or you could just go straight ahead to what most real systems use and install GRUB. For GRUB, the instructions in Linux From Scratch will be helpful, as will the GRUB documentation itself.

    Источник

    Читайте также:  Восстановление системы линукс минт
  • Оцените статью
    Adblock
    detector