Problem with executing bash script to execute windows VM install - linux

Bash script
#!/bin/sh
WINIMG=~/vm/Win10_21H2_English_x64.iso
VIRTIMG=~/vm/virtio-win-0.1.217.iso
qemu-system-x86_64 --enable-kvm -drive driver=raw,file=~/vm/win10.img,if=virtio -m 6144 \
-net nic,model=virtio -net user -cdrom ${WINIMG} \
-drive file=${VIRTIMG},index=3,media=cdrom \
-rtc base=localtime,clock=host -smp cores=4,threads=8 \
-usb -device usb-tablet \
-net user,smb=$HOME
Output of run
qemu-system-x86_64: -drive driver=raw,file=~/vm/win10.img,if=virtio: Could not open '~/vm/win10.img': No such file or directory
Not sure why it responds as "No such file or directory", as i have checked all three files are there as seen below
loo#loo-System-Product-Name:~/Desktop/lunaLand/vm$ ls
virtio-win-0.1.217.iso vm.sh Win10_21H2_English_x64.iso win10.img

The following script should resolve the "No such file or directory" error:
#!/bin/sh
WINIMG=~/Desktop/lunaLand/vm/Win10_21H2_English_x64.iso
VIRTIMG=~/Desktop/lunaLand/vm/virtio-win-0.1.217.iso
qemu-system-x86_64 --enable-kvm -drive driver=raw,file=~/Desktop/lunaLand/vm/win10.img,if=virtio -m 6144 \
-net nic,model=virtio -net user -cdrom ${WINIMG} \
-drive file=${VIRTIMG},index=3,media=cdrom \
-rtc base=localtime,clock=host -smp cores=4,threads=8 \
-usb -device usb-tablet \
-net user,smb=$HOME
The files are located on the desktop in the lunaland/vm folder and not in a vm folder in user loo's home directory.

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!

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

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.

QEMU Hangs At Boot Time

Attempting to boot from a Live Linux Mint 18.4 (x64) ISO using QEMU under macOS Catalina (with patches to use hvf as hypervisor in place of kvm).
I am able to get as far as the boot menu, but attempting to boot into the installer leaves me with a blinking cursor.
Booting in verbose mode, I see it hangs at:
clocksource: switched to clocksource tsc
I have also attempted to boot a CentOS and Kali iso. The CentOS VM exits abruptly when booted in verbose mode after a flash of text too fast for me to read, whereas the Kali iso merely shows a black screen, without even a blinking cursor.
I attempted to also boot with the notsc kernel flag enabled, this however merely caused the Mint ISO to hang at
PCI Interrupt Link [LNKB] enabled at IRQ 10
instead, and made no apparent difference in the case of the Kali and CentOS isos.
I'm unsure if this is specifically an hvf issue, but any suggestions are welcome.
These are the command parameters I am launching my VM with.
qemu-system-x86_64 \
-m 4096 \
-show-cursor \
-vga virtio \
-usb \
--device usb-tablet \
-enable-kvm \
-cdrom ./linuxmint.iso \
-drive file=./mint.qcow2,if=virtio \
-accel hvf \
-cpu max
I have had similar issues when using the hvf accelerator with CPU host passthrough.
When I try to boot the Ubuntu 20.04.1 desktop installer ISO, I get a kernel panic immediately after the boot loader's splash screen.
Using QEMU 5.1 from HomeBrew, I have had success emulating the CPU by using the default qemu64 CPU model.
To explicitly use the emulated CPU, your command-line would look as follows:
qemu-system-x86_64 \
-m 4096 \
-show-cursor \
-vga virtio \
-usb \
--device usb-tablet \
-enable-kvm \
-cdrom ./linuxmint.iso \
-drive file=./mint.qcow2,if=virtio \
-accel hvf \
-cpu qemu64
Update
A response to my bug report solved this for me.
Ubuntu 20.04 was crashing because it attempted to use the RDTSCP feature which is supported by the CPU.
The problem is that Hyperkit.Framework fails to pass this feature through, leading to the crash.
If your crash is due to RDTSCP, then the you should be able to fix this by disabling this option.
Disabling this specific feature can be done by providing the CPU type, host, followed immediately by ,-rdtscp, like so:
qemu-system-x86_64 \
-m 4096 \
-show-cursor \
-vga virtio \
-usb \
--device usb-tablet \
-enable-kvm \
-cdrom ./linuxmint.iso \
-drive file=./mint.qcow2,if=virtio \
-accel hvf \
-cpu host,-rdtscp

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.

Using ks.cfg with virt-install?

I've been trying to get a virtual machine working with a cfg file on centos but unfortunately, I'm getting the error that ks.cfg file does not exist.
Below is the command I ran to enable the VM.
virt-install --name FedoraTest --ram 1024 --disk pool=default,size=10 --location ~/Desktop/CentosOS --initrd-inject ks.cfg --extra-args "ks=file:~/Desktop/ks.cfg"
I am new to the VM setup and am unsure if I'm doing it right.
Any advice on how to fix this will be greatly appreciated.
Also, what does initrd-inject do? And is it possible to save the above command into a file and run the file instead?
I suppose you have switched the meaning of 'initrd-inject' and 'extra-args' parameters. The initrd-inject should contain path to the ks file in your file system, while in 'extra-args' you should specify kernel to use the injected ks file. See the snippet:
virt-install --connect=qemu:///system \
--network=bridge:br0 \
--initrd-inject=/export/rhel.ks \
--extra-args="ks=file:/rhel.ks console=tty0 console=ttyS0,115200" \
--name=$domname \
--disk /export/vmimgs/$domname.img,size=20 \
--ram 2048 \
--vcpus=2 \
--check-cpu \
--accelerate \
--hvm \
--location=$location1 \
--nographics
The snippet comes from here

Resources