QEMU How To

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Post Reply
Message
Author
User avatar
JmaCWQ
Posts: 230
Joined: Fri Sep 09, 2016 4:42 am

QEMU How To

#1 Post by JmaCWQ »

G'day All,

Thought I might share this here as people might find it useful, a little while ago I started learning how to use QEMU & put together the steps I followed that got it working for me.
The only thing I couldn't get working via Terminal was being able to access connected USB devices, but using AQEMU (gui version) and a bit of research I managed to get them working.
This was done on MX-17.



Here's how I get an ISO working via Terminal in QEMU, just change your username, file locations etc. etc. in the commands to suit.

First thing is create the virtual drive QEMU will use for the desired OS, which is a .img file
Choose the folder you want it in, then open Terminal & 'cd' to that desired folder.
Or when using MX you can open the desired folder, then right click > Open Terminal Here.
On my setup to keep them all together I use the hidden .aqemu folder inside my home folder but the location can be anywhere, username I log in with is 'home'.
So to cd to there in Terminal cd /home/home/.aqemu hit Enter.
Or open the folder, right click > Open Terminal Here.

Next is the command to create the .img file, it can also be named whatever you want, I usually name them the same as the OS I'm installing to make it easier to keep track of things.
In this instance I'm using the iso for the MidnightBSD 64-bit operating system which I renamed to mbsd.iso.

sudo qemu-img create -f qcow2 mbsd.img 10G

The 10G is the size of the virtual drive, that can be any size you want so long as it's large enough for the system you want's install.
It won't initially show as 10 GB when created in the folder, QEMU expands this file as needed up to a maximum of the size specified.

Once created next step is boot the .iso.
My mbsd.iso file is located in my home folder, so to run it it's:

sudo qemu-system-x86_64 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img -cdrom /home/home/mbsd.iso

Some of those options explained:
-m 2048 = amount of RAM to use, half what my system has.
-smp 2 = number of CPU cores to use.
-net nic -net user = this will enable an ethernet internet connection by default.
-hda mbsd.img = path for the virtual hard drive which will be used, in this case the .img file created earlier.
-cdrom /home/home/mbsd.iso = tells QEMU to boot the file mbsd.iso from the location /home/home.
More options can be found searching the web etc..

Once it's up and running just go through the install process as usual.
To run the installed OS from the virtual HD instead of again running the iso file, remove the -cdrom option.

sudo qemu-system-x86_64 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img

Once again 'cd' Terminal to the location of that .img file, or open the folder & right click > Open Terminal Here, before entering the command.
The above was for the x86_64 architecture but there are many others available, enter ls /usr/bin | grep qemu-system* in Terminal to see the other options.
If for example you wanted to use i386 architecture use:

sudo qemu-system-i386 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img

If you want QEMU to boot a cd/dvd from the disk drive then after the .img is created it's:

sudo qemu-system-x86_64 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img -cdrom /dev/cdrom

All the commands above will work without sudo but I found with both Win7 & Antix Linux installs the network connections/internet wouldn't work unless I ran them all using sudo.

So in a nutshell:

Cd Terminal to the desired location:
cd /home/home/.aqemu

Create the virtual drive:
sudo qemu-img create -f qcow2 mbsd.img 10G

Run the iso:
sudo qemu-system-x86_64 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img -cdrom /home/home/mbsd.iso

After installation run the installed system:
sudo qemu-system-x86_64 -m 2048 -boot d -enable-kvm -smp 2 -net nic -net user -hda mbsd.img

And that's about it, I originally wrote it here, July 2018.

Feel free to add/subtract/correct/whatever to the above if you know a better/easier way than I've shown here :cool:

Cheers :toast:

User avatar
Jerry3904
Administrator
Posts: 21942
Joined: Wed Jul 19, 2006 6:13 am

Re: QEMU How To

#2 Post by Jerry3904 »

Thanks for posting. Man, that looks pretty complicated!

I posted somewhere that I am testing Polo file manager, and one very cool feature is that I can simply right-click and ISO and I get a context menu entry: Boot into VM. And...BANG, there it is!
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
JmaCWQ
Posts: 230
Joined: Fri Sep 09, 2016 4:42 am

Re: QEMU How To

#3 Post by JmaCWQ »

Here's how I got the USB connections working correctly with AQEMU (gui version) with a Windows 7 guest.
To test this I used a 32GB USB stick, a 2 TB USB3 hard drive & and successfully checked for/installed updates for a Garmin Montana plugged in via USB using Garmin Express.
I can't remember if USB3 speed was achieved or not, don't think I even tested that, just that I could access, read and write to the drive.

Have the desired USB device plugged in & powered on (if necessary) but unmounted when starting AQEMU.
Open AQEMU, highlight the VM in the list, click the Media tab, click Computer Ports, click the USB icon under 'Add Ports'.
That should bring up a list of USB devices, find the one you want, highlight it, then click OK.
Then click Apply & start the VM, USB should now work.
If it doesn't maybe try starting AQEMU with Terminal and sudo aqemu

If uncertain of the correct device one way to find it is run lsusb in Terminal & take note of the Bus & Device numbers, compare them with what AQEMU settings show on the list.
Bus number is the same & Device = addr:

AQEMU throws up a 'No Device' error after safely removing the USB device via the guest and unplugging it, there's an option to change when it notifies about that on the message window.
It'll also show a 'Not Found' warning if starting the VM & the device isn't plugged in, unless it's removed from the Computer Ports settings page in AQEMU.
Plug n Play seems to work ok, I found if wanting to use a device on the host to transfer files or something while the guest OS was still loaded it was just a matter of pausing the VM, unplug the USB, plug it back in again & mount it with the host, then when finished unmount & unpause the VM & Win7 would pick it up again & it worked fine.

Also posted in that same Austech thread, July 2018 :toast:

philotux
Posts: 280
Joined: Sun Apr 22, 2018 12:57 pm

Re: QEMU How To

#4 Post by philotux »

Thought to install qemu via Synaptic and I get this warning:
qemu-warning.png
Can I assume that it is safe after all to install?
You do not have the required permissions to view the files attached to this post.

User avatar
JmaCWQ
Posts: 230
Joined: Fri Sep 09, 2016 4:42 am

Re: QEMU How To

#5 Post by JmaCWQ »

Jerry3904 wrote: Fri Feb 01, 2019 9:20 pm Thanks for posting. Man, that looks pretty complicated!
No probs Jerry :cool:
I struggled a little when first attempting to learn it, I think the hardest thing was interpreting all the info that's out there & adjusting it to suit what I was trying to learn.
I tried with a few different ISO's & file locations, then all of a sudden it just 'clicked' and now find it quite easy.
It's really just a matter of changing the desired ISO & file locations etc. in those commands when pasting them into Terminal.
I rarely run QEMU from Terminal any more, I've setup a launcher that starts AQEMU & use the GUI for most things.
Jerry3904 wrote: Fri Feb 01, 2019 9:20 pmI posted somewhere that I am testing Polo file manager, and one very cool feature is that I can simply right-click and ISO and I get a context menu entry: Boot into VM. And...BANG, there it is!
Yes I read that, it's now on my bucket list :happy:

User avatar
JmaCWQ
Posts: 230
Joined: Fri Sep 09, 2016 4:42 am

Re: QEMU How To

#6 Post by JmaCWQ »

philotux wrote: Fri Feb 01, 2019 9:29 pm Can I assume that it is safe after all to install?
To be honest I can't remember if I got that warning on MX-17 when I first installed it, I'm thinking I might have & just installed it anyway, I do things like that :p
In my Synaptic it shows these as installed.

qemu.png
You do not have the required permissions to view the files attached to this post.

philotux
Posts: 280
Joined: Sun Apr 22, 2018 12:57 pm

Re: QEMU How To

#7 Post by philotux »

JmaCWQ wrote: Fri Feb 01, 2019 9:53 pm just installed it anyway, I do things like that
Lol, I am a bit like that too. :bagoverhead:

Thanks for the reply, the screenshot and not the least your great how-to. I will give it a try after I have digested what it is all about.

Post Reply

Return to “Tips & Tricks by users”