Using Qemu

Jump to navigationJump to search


Ok .. so my mind was buzzing to make mac os work in qemu .. doesn't work ! :P so don't bother .. here's what I did so far .. this should be usable at any other OS though ..


1) create a disk image ! ( that would replace the regular hdd )

qemu-img create -f qcow2 /media/win_d/Downloads/isos/mac.cow 2000M

this means create a qcow2 fs ( that would only take as much space as it needs .. it won't create a 2GB file ! ) at mac.cow pwd .. max size 2000M !


qemu -hda /media/win_d/Downloads/isos/mac.cow -boot d -cdrom /media/win_d/Downloads/isos/file.iso -m 384 -localtime

which means to load hda in the file we created .. boot from cdrom .. the cdrom being the iso with 384 ram and use the local system time now .. in linux if you don't have enough space in /dev/shm .. you could use -no-kqemu to disable acceleration or do this:

umount /dev/shm
mount -t tmpfs -o size=400m none /dev/shm

which would create a bigger shm partition ! :)


qemu -hda /media/win_d/Downloads/isos/mac.cow -boot c -m 384 -localtime

which would tell qemu to boot from the virtual hdd we created :) this would be it

qemu -h for other options !

Other info

It would be nice of you to install kqemu - the qemu acceleration layer ... Also, if you're on a console only .. use -nographic ... if you want a vnc add -vnc ip:1 ( to start a vnc on display 1 ) and don't use -nographic ( it'll lock ) ... Also if you want to .. you can use -daemonize to be able to reuse the console after it started ..


If you want your box just to use the internet .. use dhclient inside it to access get the ip ( qemu will act as the dhcp server ) .. no other stuff is necesarry ...

If not .. you need to do this as root Be sure to chmod +x /etc/qemu-ifup containing and add -net nic -net tap to qemu

/sbin/ifconfig $1 netmask up
sleep 2

Inside the guest do this:

ifconfig eth0 netmask

You should be able to ping one another .. don't forget to this on the qemu host:

echo 1 > /proc/sys/net/ipv4/ip_forward

and this in the host's gateway

# allow to come from ( my qemu host ip ) via eth0 ( gw eth )
ip ro add via dev eth0
# make him exit to the internet with external_ip and whatever comes from the external_ip to go to qemu
iptables -t nat -A POSTROUTING -s -j SNAT --to-source external_ip
iptables -t nat -A PREROUTING -d external_ip -j DNAT --to-destination

Qemu needs to be ran as root in order to be able to access the tap ..

Resizing the partition .... from the initial 2000M to 4G

First step would be to convert the qcow2 disk image to raw format

qemu-img convert -f qcow2 mac.cow -O raw mac.raw

Then resize the raw partition using dd .. it won't harm the file contents .. ( 4096 means 4 G .. you can use 8192 and stuff .. )

dd if=/dev/zero of=mac.raw bs=1M count=0 seek=4096

And last ... convert it back to the qcow2 format so only used blocks would take up space ...

qemu-img convert -f raw mac.raw -O qcow2 newmac.cow

You can now verify

qemu-img info newmac.cow




So ... you'd have a fully functional virtual machine with whatever settings you want .. hope it helped ..