KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents
Revision 2 as of 2020-04-07 10:30:20
KernelNewbies:
  • OutreachyfirstpatchAlt_libvirtvm_draft

Running Linux in a VM

Hardware Requirements

You need a system with virtualization (VT-d), at least 4GB of RAM, and 40GB of free hard drive space in order to run Linux in a VM. If you want to download and compile the kernel, you may need additional space of up to 20GB.

Download Debian

Download link to Get a recent version of Debian.

Install Libvirt/Virtual-Manager Virtualizer

Instructions for Debian OS:

Debian setup link Debian Setup and Help Page.

Install the needed packages:

sudo apt-get install qemu-kvm libvirt-clients libvirt-daemon-system virt-manager ebtables

Add your user to libvirt group:

sudo adduser user libvirt

Configure libvirt:

virsh --connect=qemu:///system net-start default
virsh --connect=qemu:///system net-autostart default

Start virt-manager from Application Menu.

Instructions for Archlinux:

Install needed packages:

sudo pacman -S  virt-manager libvirt ebtables dnsmasq qemu

Add your user to kvm group:

sudo adduser user kvm

Archlinux setup page See this link for further setup further instructions.

Create a new VM and setup Guest OS.

Setup Qemu

You need a space for VM either a file image or disk block.

Example with using a file for VM.

Create a 50GB qcow2 format image file for VM Note qcow2 grows in space as needed. In the start it is not 50GB in size.

qemu-img create -f qcow2 debian-vm.img 50G

Simple way to start Qemu

Get a suitable iso image file for distro installation.

qemu-system-x86_64 -enable-kvm -smp 2 -boot menu=on -m 2048m -vga std -cdrom debian-install-iso.img -hda debian-vm.img

Qemu Screenshots

01) Example OS Install Screen

[ATTACH]

02) Example Guest OS Grub2 Boot Screen

[ATTACH]

Advanced Qemu

Create a script file qemu.sh with executable permissions:

touch qemu.sh;
chmod +x qemu.sh

Edit the qemu.sh and add lines like this:

MEM="2048m"
BOOT="menu=on"

[ ! -z "$1" ] && MEM="$1"
[ ! -z "$2" ] && BOOT="$2"

MACH="-machine q35"
CPU="-cpu host"

CDROM_IMG="/path/to/debian-install-iso.img"
HDA_IMG="/path/to/debian-vm.img"

CDROM="-cdrom ${CDROM_IMG}"
HDA="-hda ${HDA_IMG}"

VGA="-vga std"

SSH_ENABLE="hostfwd=tcp:127.0.0.1:10101-:22"

NET="-netdev user,id=n1,${SSH_ENABLE} -net nic,netdev=n1,model=virtio-net-pci"

PATH_9P="~/9p/shared"

P9="-fsdev local,id=p9d1,path=${PATH_9P},security_model=none"
P9="${P9} -device virtio-9p-pci,fsdev=p9d1,mount_tag=p9_mnt"

USB="-usb"
USB_MICE="-usbdevice tablet"

SOUNDHW="-device intel-hda,msi=auto -device hda-duplex"

qemu-system-x86_64 -enable-kvm ${MACH} ${CPU} -smp 2 -boot "${BOOT}" \
-m "${MEM}" ${CDROM} ${HDA} ${NET} ${P9} ${USB} ${USB_MICE} ${SOUNDHW} \
${VGA} -rtc base=utc

Put qemu.sh in PATH directory if needed. E.g. ~/bin.

Above script sets up network, usb, sound, video, 9p, and ssh access to Qemu VM Guest OS.

SSH Access

Install ssh (rsync) in both Host and Guest OS

Debian/Ubuntu install instructions:

apt-get install ssh rsync

Find your Guest's IP Address in "Show virtual hardware details" menu in NIC option. If IP address is not shown click refresh button and get it. Mind that the Guest OS is running and network is up and running in guest.

For SSH access to Guest OS run:

ssh -p 22 user@ip_address_of_guest

You can access guests with their hostnames. See this link for instructions for Debian.

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01