# qemu-kvm fs image setup

## Wizumwalt

I'm trying to run the same custom kernel in my guest OS as is running on the host OS using qemu-kvm-0.12.5-r1. So using help from another thread, which seems to have died, here's where I'm at ...

I've got a qcow image created by doing the following:

```

qemu-img create -f qcow2 gentoo-i386.img 10G

```

Then I ran losetup and formated it with a filesystem.

```

$ losetup /dev/loop0 ./gentoo-i386.img

$ mkfs.ext3 /dev/loop0

$ losetup -a

/dev/loop0: [0811]:14655814 (/home/winky/kvm/gentoo-i386.img)

```

```

$ mount /dev/loop0 /mnt/loop

$ mount

...

/dev/loop0 on /mnt/loop type ext2 (rw)

...

```

Then I was going to get the stage3 and do a gentoo installation from chapt. 5 of the handbook up till the kernel install. So when I tried to copy the 'stage3-amd64-20100930.tar.bz2' into /mnt/loop, where I would extract the archive ... I get the following error:

```

$ sudo cp ./stage3-amd64-20100930.tar.bz2 /mnt/loop/

cp: writing `/mnt/loop/stage3-amd64-20100930.tar.bz2': No space left on device

```

```

$ df -h /mnt/loop/

Filesystem            Size  Used Avail Use% Mounted on

/dev/loop0            247K  247K     0 100% /mnt/guestOS

```

Any ideas here?

----------

## frostschutz

You're trying to use a qcow2 image (which is a special format) like a normal raw image (by loop mounting and mkfsing it). It won't work this way. Basically the mkfs would destroy the qcow2 structure and the result would be a file system much smaller than 10GB.

Personally I prefer using LVM partitions for KVM. It's also what gives me best performance inside the VM. See also http://www.linux-kvm.org/page/Tuning_KVM

This also allows you to directly mount it from the host if need be. However it will actually occupy 10GB, whereas qcow2 could be much smaller (especially if the VM is not actually using the storage space). I dislike that concept though since in practice it means the VMs will blow up in your face if they suddenly start actually using the storage assigned to them.

----------

## Wizumwalt

I've got a running system and installing LVM seemed like a real hassle according to the Gentoo LVM2 installation guide which expects you to start from scratch. That was a bit too much.

Is there a howto anywhere's that would help line by line w/ what I need? I just want to have a running kernel (same as is on host OS) to test modules with in the guest OS so in case my kernel crashes, the entire machine won't crash.

Any easier way to do this?

----------

## Hu

You can create a raw file containing the filesystem, which will let you mount it from the host.  However, it will occupy 10G up front, just like LVM would.  Even worse, you will not get the performance benefit of bypassing the host filesystem.

You could also try using qemu-nbd to mount the qcow2 block device as a network block device, if your host kernel supports network block devices.

----------

