How do I mount an external disk in qemu-system-ppc? - emulation

I am trying to use an external disk instead of a .img file in qemu-system-ppc. I am using the following code:
cd "$(dirname "$0")"
./qemu-system-ppc -L pc-bios -boot d -M mac99 -m 512 \
-prom-env 'auto-boot?=true' -prom-env 'boot-args=-v' -prom-env 'vga-ndrv?=true' \
-drive file=MacOS9.2.2.iso,format=raw,media=cdrom \
-drive file=/dev/disk3s2,format=raw,if=virtio \
-netdev user,id=network01 -device sungem,netdev=network01 \
-device VGA,edid=on \
When I run this code I get the following output from the terminal:
hamishmoore#Hamishs-Mini ~ % /Applications/QEMU\ Mac\ OS\ 9.2.2/qemu.command ; exit;
qemu-system-ppc: -drive file=/dev/disk3s2,format=raw,if=virtio: If device /dev/disk3s2 is mounted on the desktop, unmount it first before using it in QEMU
qemu-system-ppc: -drive file=/dev/disk3s2,format=raw,if=virtio: Command to unmount device: diskutil unmountDisk /dev/disk3s2
qemu-system-ppc: -drive file=/dev/disk3s2,format=raw,if=virtio: Command to mount device: diskutil mountDisk /dev/disk3s2
qemu-system-ppc: -drive file=/dev/disk3s2,format=raw,if=virtio: Could not open '/dev/disk3s2': Permission denied
[Process completed]
The disk has been unmounted from the desktop. And I've tried formatting the disk a few different ways. I am running macOS Catalina.
Help Appreciated.

QEMU will print the suggestion about unmounting from the desktop for pretty much any error attempting to open a device as an image file. The important line here is the last one, which tells you the specific error:
qemu-system-ppc: -drive file=/dev/disk3s2,format=raw,if=virtio: Could not open '/dev/disk3s2': Permission denied
"Permission denied" usually means that the user you're running QEMU as does not have write access to the /dev/disk3s2 device; check the permissions/ownership on it.

Related

Qemu Always Reinstall The Guest

I want to simulate an arm environment for arm ubuntu 20.04 LTS.
The host is also ubuntu 20.04 LTS but not arm.
First I created an image like this:
qemu-img create -f qcow2 ubuntu.img 3G
then I ran this command:
sudo qemu-system-aarch64 -m 2048 -cpu cortex-a57 -M virt -nographic \
-bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd -drive \
file=ubuntu.img,if=none,id=hd0 -device virtio-blk-device,drive=hd0 \
-cdrom ubuntu.iso -boot d -netdev user,id=net0,hostfwd=tcp::5555-:22 \
-device virtio-net-device,netdev=net0
I installed the ubuntu on the qemu successfully and everything is working untill I reboot the guest or close the qemu.
After I close the qemu I tried to use the same command to boot the ubuntu without reinstalling it. But this doesn't worked and reinstall the ubuntu again.
I am stack about this problem for a while, and I would love to get some help.
I tried to remove the -cdrom ubuntu.iso but that boot the UEFI because the boot loader didn't find any OS.
Also I tried this command:
sudo qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic \
-drive file=flash0.img,format=raw,if=pflash \
-drive file=flash1.img,format=raw,if=pflash \
-drive file=user-data.img,format=raw \
-drive if=none,file=ubuntu.img,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-net-device,netdev=net0,mac=$randmac \
-netdev type=tap,id=net0
That I took from the ubuntu website and again the boot loader didn't find any OS.
Thanks in advance!

Running FreeBSD wth QEMU on macOS: system gets very slow a few seconds after the start

I am running the FreeBSD image using QEMU.
When I start it with QEMU it works smoothly for a few seconds, but then the FreeBSD system starts being very slow to respond to my keystrokes. Sometimes this happens a few seconds after the FreeBSD has loaded and I have logged in the system using as a root and sometimes it is already slow when it shows the user/password lines.
What is interesting though is that when I open a second terminal session and connect to the slowly running FreeBSD via SSH (I have set up the sshd in the FreeBSD), the connection seems to work without any issues. Also if I do a verbose command such as find / in the QEMU's terminal session it stops being slow for a short while after I stop the command, and then it goes back to being slow again.
It is the first time I am trying QEMU so my guess that the problem is around -serial mon:stdio line but it is just a guess.
This is the command I am using:
qemu-system-x86_64 \
-m 8192 \
--bios $(OVMF_LOCATION) \
-serial mon:stdio \
-net nic \
-net user,hostfwd=tcp::10022-:22 \
freebsd.img
The background: I am following the RTEMS OS setup instructions for running it on the QEMU AMD64: Board Support Package: amd64.
I was suspicious about the -serial mon:stdio part of my original command so I looked around to see what else do people try. I found that I have to replace this line with -nographic and it starts working without being slow.
This is how my command looks now:
qemu-system-x86_64 \
-m 8192 \
--bios $(OVMF_LOCATION) \
-nographic \
-no-reboot \
-net nic \
-net user,hostfwd=tcp::10022-:22 \
freebsd.img

How to use QEMU's deterministic record and replay feature for a Linux kernel boot?

QEMU supports deterministic record and replay as documented at: https://github.com/qemu/qemu/blob/v2.9.0/docs/replay.txt
However, I could not get replay working for a full Linux kernel boot: it always hangs at some point.
These are the commands I'm running:
#!/usr/bin/env bash
cmd="\
time \
./buildroot/output.x86_64~/host/usr/bin/qemu-system-x86_64 \
-M pc \
-append 'root=/dev/sda console=ttyS0 nokaslr printk.time=y - lkmc_eval=\"/rand_check.out;wget -S google.com;/poweroff.out;\"' \
-kernel './buildroot/output.x86_64~/images/bzImage' \
-nographic \
\
-drive file=./buildroot/output.x86_64~/images/rootfs.ext2,if=none,id=img-direct,format=raw \
-drive driver=blkreplay,if=none,image=img-direct,id=img-blkreplay \
-device ide-hd,drive=img-blkreplay \
\
-netdev user,id=net1 \
-device rtl8139,netdev=net1 \
-object filter-replay,id=replay,netdev=net1 \
"
echo "$cmd"
eval "$cmd -icount 'shift=7,rr=record,rrfile=replay.bin'"
# Different than previous.
eval "$cmd -icount 'shift=7,rr=record,rrfile=replay.bin'"
# Same as previous.
eval "$cmd -icount 'shift=7,rr=replay,rrfile=replay.bin'"
and my kernel and root filesystem were generated with this Buildroot setup: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/0a1a600d49d1292be82a47cfde6f0355996478f0 which uses QEMU v2.9.0.
lkmc_eval gets evaled by my init scripts. Here we print userspace stuff that is usually random to check that we are actually deterministic, and then power off the machine.
How I came up with those commands:
start from the working command I used in my repo without record replay
copy paste the hard disk and networking parts from the wiki: https://wiki.qemu.org/Features/record-replay
The in-tree docs say there is no networking support, but the wiki and git log says they were added as of v2.9.0, so I think the docs are just outdated compared to the wiki.
Using that setup, the boot replay progresses quite far, but hangs at the message:
[ 31.692427] NET: Registered protocol family 17
In the initial record, the next message would have been:
[ 31.777326] sd 1:0:0:0: [sda] Attached SCSI disk
so I'm suspicious that it is a block device matter.
The timestamps are however identical, so I'm confident that the record and replay has worked so far.
If for the networking I use just:
-net none
then the record itself hangs at:
[ 19.669685] ALSA device list:
[ 19.670756] No soundcards found.
If anyone wants to try a QEMU patch against it, just checkout to your patch inside /qemu/ and run:
./build -t host-qemu-reconfigure
to rebuild.
Your command line looks ok, but unfortunately record/replay is QEMU is broken in this release.
I hope that it will be fixed in the nearest weeks.

How to access original harddisk files in live CD session started using qemu?

I have 32bit ubuntu OS. On it I download lubuntu OS iso (64 bit). Then I ran qemu command
qemu-system-x86_64 -boot d -cdrom image.iso -m 512
After choosing live CD option I can access terminal.
What path do I use to access files on my original harddisk?
I don't see anything under /media/
also no directories of the type /dev/sda are shown under / in the live CD session.
Warning: this can unrecoverable destroy your data! Concurrent writing access to a disk is dangerous.
It is better to transfer files via nfs or ssh.
That said, it can be done this way (where '/dev/sdX' is '/dev/sdb' or alike):
qemu-system-x86_64 -boot d -cdrom image.iso -m 512 -hda /dev/sdX

KVM guest os boot error

I'm trying to boot up a guest os to continue with my work but I have a problem with my virsh installation.
Here is the part of installation script:
qemu-img create -f qcow2 -o preallocation=metadata ~/images/${vm_name}.qcow2 ${pool_size}G
# create dir for images
mkdir ~/images/
virt-install \
--connect qemu:///system \
--name $vm_name \
--ram 10240 \
--vcpus 4 \
--disk ~/images/${vm_name}.qcow2,size=$pool_size,bus=virtio,sparse=false,format=qcow2 \
--network network=default,model=virtio \
--location http://ua.archive.ubuntu.com/dists/trusty-updates/main/installer-amd64/ \
--initrd-inject=$current_dir/preseed.cfg \
--extra-args="file=file:/preseed.cfg vga=788 quiet console=tty0 utf8 console=ttyS0,115200" \
--os-type=linux \
--virt-type kvm \
--video=vga \
--noreboot \
--cpu host \
--hvm
virsh start $vm_name
echo "----------Login to console----------"
virsh console $vm_name
WHen Im trying to run this script as a file like ./script.sh it produces an error:
Formatting '/home/{username}/images/test.qcow2', fmt=qcow2 size=53687091200 encryption=off cluster_size=65536 preallocation='metadata' lazy_refcounts=off refcount_bits=16
mkdir: cannot create directory '/home/flash/images/': File exists
ERROR 'DebianDistro' object has no attribute '_prefix'
error: failed to get domain 'test'
error: Domain not found: no domain with matching name 'test'
----------Login to console----------
error: failed to get domain 'test'
error: Domain not found: no domain with matching name 'test'
I have tried already reinstalling kvm qemu packages using this guide - https://help.ubuntu.com/community/KVM/Installation
and everything completed successfully.
I am sure that script will work file as I was using it before on the other machine without any problems.
Another try:
Using that script below
virt-install --connect qemu:///system -n test -r 10240 \
--vcpus=4 \
--disk path=/data0/images/test.img,size=50,format=qcow2,bus=virtio,cache=none \
--cdrom /home/{username}/Downloads/kvm/ubuntu-14.iso \
--vnc \
--os-type=linux \
--accelerate \
--network network=default \
--hvm
Produces an error:
ERROR internal error: process exited while connecting to monitor: Could not access KVM kernel module: Permission denied
failed to initialize KVM: Permission denied
Also when I'm trying to list all os variants by virt-install --os-variant list it cannot recognize this command and trying to boot up a guest os instead of listing variants.
Can you please help me to find out what is the problem here?
To fix this error:
ERROR 'DebianDistro' object has no attribute '_prefix'
Edit the file /usr/share/virt-manager/virtinst/urlfetcher.py and change this in line 1034:
if self._prefix:
to this:
if self._url_prefix:
Ubuntu 14.04.

Resources