O'Reilly logo

KVM Virtualization Cookbook by Konstantin Ivanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Perform the following steps outlined to partition and create a filesystem on the blank image:

  1. Load the nbd kernel module:
    root@kvm:~# modprobe nbd    root@kvm:~#
  1. Using the qemu-nbd tool, associate the blank image file to the /dev/nbd0 block device:
root@kvm:~# qemu-nbd --format=raw --connect=/dev/nbd0          debian.img  root@kvm:~#
  1. Create two partitions on the block device. One will be used for swap, and the other as the root partition for the guest OS:
root@kvm:~# sfdisk /dev/nbd0 << EOF    >,1024,82    >;    >EOF    Checking that no-one is using this disk right now ...OKDisk /dev/nbd0: cannot get geometryDisk /dev/nbd0: 1305 cylinders, 255 heads, 63 sectors/tracksfdisk: ERROR: sector 0 does not have an msdos signature /dev/nbd0: unrecognized ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required