qemu-img create -f raw d.img 1G
sudo losetup /dev/loop0 d.img
sudo fdisk /dev/loop0
Command (m for help): p
Disk /dev/loop0: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f658610
Device Boot Start End Blocks Id System
/dev/loop0p1 2048 2097151 1047552 83 Linux
sudo losetup -d /dev/loop0
sudo losetup -o $((2048*512)) /dev/loop0 d.img
sudo mkfs.ext4 /dev/loop0
sudo mount -o loop /dev/loop0 /mnt
sudo cp rootfs/* /mnt/ -a
sudo umount /mnt
sudo losetup -d /dev/loop0
sudo mount -o loop,offset=$((2048*512)) d.img /mnt
qemu -kernel /boot/vmlinuz-3.3.7 \ -initrd /boot/initrd.img-3.3.7 \ -hda d.img \ -append "root=/dev/sda1" \ -m 512M \ -net user