Load modules, in this case kvm of intel cpu;
# modprobe -a kvm-intel tun virtio
Add users to kvm group;
# usermod -a -G kvm c9admin # usermod -a -G kvm username
Create hard disk image, there is different types, this describes how to create a qcow2 type;
$ qemu-img create -f qcow2 crux-img.qcow2 15G
You can mount disk image;
$ sudo modprobe nbd $ sudo qemu-nbd -c /dev/nbd0 /crux-img.qcow2
To disconnect image disk (ndb);
$ sudo qemu-nbd -d /dev/nbd0
Information about preparing partitions and storage administration. You can use image as a normal disk, example how to use parted to create a gpt system table;
# parted --script $DEV \ mklabel gpt \ mkpart ESP fat32 1MiB 120MiB \ mkpart primary ext4 120MiB 720MiB \ mkpart primary ext4 720MiB 2720MiB \ mkpart primary ext4 2720MiB 5000MiB \ set 1 boot on
# kpartx -a -s -l -u /dev/nbd0
Use /dev/mapper/$(name_of_device) to assign correct blocks;
# mkfs.fat -F 32 $BLK_EFI # mkfs.ext4 $BLK_BOOT # mkfs.ext4 $BLK_ROOT # mkfs.ext4 $BLK_VAR
Mount partition;
# mount $BLK_ROOT $CHROOT # mkdir -p $CHROOT/boot # mount $BLK_BOOT $CHROOT/boot # mkdir -p $CHROOT/boot/efi # mount $BLK_EFI $CHROOT/boot/efi # mkdir -p $CHROOT/var # mount $BLK_VAR $CHROOT/var
Network configuration;
KERNEL=="tun", GROUP="kvm", MODE="0660", OPTIONS+="static_node=net/tun"
Create bridge, create new tap and add it to bridge;
# DEV="br0" # TAP="tap1"
# ip tuntap add ${TAP} mode tap group kvm # ip link set ${TAP} up
# ip link set ${TAP} master ${DEV}
Create interface with correct permissions set for kvm group.
# sysctl -w net.ipv4.ip_forward=1 # iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
Start qemu with 512 of ram, mydisk.img as disk and boot from iso
See scripts/system-qemu.sh, as template. Run virtual machine that uses above tap device;
$ ISO=~/crux-3.2.iso $ IMG=~/crux-img.qcow2 $ TAP="tap1" $ qemu-system-x86_64 \ -enable-kvm \ -m 1024 \ -boot d \ -cdrom ${ISO} \ -hda ${IMG} \ -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no
$ ISO=~/crux-3.2.iso $ IMG=~/crux-img.qcow2 $ qemu-system-x86_64 \ -enable-kvm \ -m 1024 \ -boot d \ -cdrom ${ISO} \ -hda ${IMG} \ -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=noTools Index
This is part of the c9 Manual. Copyright (C) 2016 c9 team. See the file Gnu Free Documentation License for copying conditions.