QNX qemu vm: how to create virtual diskimage for vm

Hi all,
I have created a virtual machine for QNX ARM using Qemu by the command below,

qemu-system-aarch64 -M xlnx-zcu102 -m 8G -serial mon:stdio -device loader,file=/root/xlinxbsp/images/QNX-IFS,addr=0x00100000,cpu-num=0 -nographic -global xlnx,zynqmp-boot.cpu-num=0 -global `xlnx,zynqmp-boot.use-pmufw=true

after logining in to the VM I found no any drive like dev/hd0 or /dev/hd1.
No I realize that I have to create a virtual disk for this VM and pass it into the Qemu command,
so that I can have /dev/hd0 /dev/hd1 and mount these drive and then transfer my test cases to execute.

can anyone guide me how can I create this virtual disk image or download already created virtual disk image.

looking forwaard for the solution.
Thanks in Advance :slight_smile:

BRß
Faiq

https://community.qnx.com/sf/wiki/do/viewHtml/projects.core_os/wiki/QEMUAndNeutrino

https://community.qnx.com/sf/wiki/do/viewPage/projects.qemu/wiki/NeutrinoAsGuestInQEMU

Tim

Hi Tim,
Thank you for responding the question.
Unfortunately the given links did not helped me for the solution I am looking for.
As the provided links opening a new door for me to restart my work in other way from the initial stage.
For example when I use the command

qemu-system-aarch64 -hda vr-hd.img -cdrom QNX-IFS -boot d -k en-us

it says “No machine specified, and there is no default Use -machine help to list supported machines”

So the actual command which I am using to start the VM, now with additional parameter for the device like

qemu-system-aarch64 -M xlnx-zcu102 -m 8G -serial mon:stdio -device loader,file=/root/xlinxbsp/images/QNX-IFS,addr=0x00100000,cpu-num=0 
drive=vr-hhd.img,format=raw -nographic -global xlnx,zynqmp-boot.cpu-num=0 -global xlnx,zynqmp-boot.use-pmufw=true

I just want to create a virtual hard disk that I can attached to the VM which I have already created. I have created a virtual hard disk with Qemu (qemu create-image) in both formate raw and qcow2 and tired to attached with. but when the vm start it does not show any drive inside the VM (/dev/hd0).

Could you please provide more explanation as I am stuck in the issue for about a week and it is very crucial to resolve the issue.
if you required more information, feel free to let me know.

Thanks in advance :slight_smile:

In your QNX boot image (the one you log into), are you starting the disk driver and trying to mount the virtual hard drive you created?

For example did you include the command ‘fdisk’ in your QNX boot image? If so, what does running fdisk report and if not, create another boot image with fdisk.

You’ll also need to format this virtual disk for a QNX file system so you’ll need mkqnxfs and dinit in your boot image (I am assuming you are using a QNX 6 or version of the OS).

In your QNX image you’ll also need the right driver for the virtual disk (does qemu present virtual disks as IDE or SATA). devb-eide is for IDE emulated hardware and devb-ahci is for SATA emulated hardware

The basic order of things you need to do is:

  1. Confirm with fdisk that QNX sees your virtual hard drive
  2. Format the virtual harddrive for a QNX file system
  3. Start the (IDE / Sata) driver for the file system
  4. Mount the partition

Steps 1 and 2 you only do once. Steps 3 and 4 you do every time you boot (most people build this into the boot image so it gets done automatically but you can do it manually obviously).

Tim

Hi Tim,

Thank you for meaningful information.

currently, I am stuck at the point number 1, as you mentioned.

So there are few things I need to mention here.

The QNX image I am using is provided by one of our vender/Partner,
and we are using this image in the hardware along with SD card and
the OS running in board shows the SD card.

so may be they only considered the SD card while creating the image.

But inside the Qemu VM, when I execute the fdisk it shows nothing inside /dev/hd#.
does it means that I also need to recreate/alter the image to accomodate virtual HD?

if Yes, can you guide me how can I create the new image? or alter (any link)
as this very fisrt experience for me with embaded system.

if No, may be the way which I have attached virtual HD with qemu is not correct, or I have created virtual HD wrongly.

I hope I tried to let you understand the issue, and you further comments will be really meaningful to me.

Thank-
Faiq

I understand your setup.

The CF card is really just an IDE/SATA drive so it reality it’s no different than a regular hard drive.

I have a question for you. Can you (or are you already) take a raw image of the CF card and use that as your virtual drive in qemu? Since you can’t change the OS image, it will be very unlikely you’ll be able to format a ‘blank’ virtual drive as I doubt the vendor supplied all the QNX commands in the boot image (most only put in a few commands to mount the hard drive and then run commands off the hard drive) and I suspect you want to access the data on the CF card anyway in your virtual machine.

Once you have a raw image of the CF card, then I think you just need to modify the drive parameter

drive=vr-hhd.img,format=raw

to add the interface type (eg if=ide)

Unfortunately, it doesn’t look like qemu supports SATA yet

so if this CF is meant accessed by a SATA driver you may be out of luck.

Do either of the ‘pidin’ or ‘ps’ commands work (or ‘sin’ command if you are using QNX 4). Those will tell us which kind of disk driver is being used.

Tim

A- Can you (or are you already) take a raw image of the CF card and use that as your virtual drive in qemu?
Yes, I have taken out card data in which I found following two files, I am using QNX-IFS as a QNX VM image
1.QNX-IFS
2.BOOT.bin
for the BOOT.bin I dont have any idea

B- I suspect you want to access the data on the CF card anyway in your virtual machine?
I actually dont know what they have put in the image/CF card, I guess they just put only the OS related stuff.
but at the moment I am not looking for any data in the SD card other than OS.

C- Do either of the ‘pidin’ or ‘ps’ commands work (or ‘sin’ command if you are using QNX 4). Those will tell us which kind of disk driver is being used?
Yes, only Pidin command is working in the VM.

unfortunately the command below did not worked for me

drive=vr-hhd.img,format=raw

And fortunately, now there is further progress,
I have created SD card image in my host machine and attached that with Qemu. after that one partition is now visible as /dev/hd0.

dd if=/dev/zero of=qemu_sd.img bs=256M count=1
mkfs.vfat -F 32 qemu_sd.img

I executed a script manually that I received from them, for mounting and creating the folder structure.
now, I can see some /mnt/conf folder but I can not create further directories inside these folders like

mkdir /mnt/conf/etc
it says,

`/bin/sh: mkdir: cannot execute - No such file or directory`

interestingly it allowed me to create a file so I created a bash script with touch command

if I execute I can see more directories but previously only ifs row was visible.

ifs                        42184     42184         0     100%  /               
/dev/hd0t179              378848     14392    364456       4%  /mnt/data/      
/dev/hd0t178               94176      3624     90552       4%  /mnt/conf/      
/dev/hd0t177               40928      1600     39328       4%  /mnt/apps/      
/dev/hd0t11                10160         0     10160       0%  /mnt/boot/      
/dev/hd0                  524288    524288         0     100%

I would also like to know the cause, what could be the reason for the error /bin/sh: mkdir: cannot execute - No such file or directory

Secondly, is there any way I can take mounting script while creating a VM for automated mounting and creating folder structure.

Meanwhile let me also try the proposed solution

Thanks :slight_smile:

BOOT.bin - This belongs to the QNX O/S. You can’t and don’t want to do anything to that.

Finding /dev/hd0 is major progress as it means the disk driver was able to find your CF image.

`/bin/sh: mkdir: cannot execute - No such file or directory`

This means that the mkdir executable was not included as part of the QNX O/S image. Unfortunately it means you won’t be able to create any new directories unless it was included elsewhere (see below).

ifs                        42184     42184         0     100%  /               
/dev/hd0t179              378848     14392    364456       4%  /mnt/data/      
/dev/hd0t178               94176      3624     90552       4%  /mnt/conf/      
/dev/hd0t177               40928      1600     39328       4%  /mnt/apps/      
/dev/hd0t11                10160         0     10160       0%  /mnt/boot/      
/dev/hd0                  524288    524288         0     100%

I assume this output came from the df command.

The IFS is where the O/S is booting from. Then there are 4 other partitions mounted as /mnt/data, /mnt/conf, /mnt/apps/, /mnt/boot. So you should be able to do things like 'ls /mnt/apps to see what files/directories are in /mnt/apps or cd /mnt/apps to walk the directory structure directly and so on.

Now it’s possible that mkdir is available in /mnt/apps (or it may just be apps to support whatever the product is). You can use the ‘find’ command (hopefully it’s available) to search for mkdir in each of those 4 mounted partitions.

But the good news is that the partitions are already mounted for you so you don’t need a script to do it or are you wanting to do something else?

Tim

Yes, indeed, this is significant progress.

I’ve used the command below. Please have a look to see if anything seems unusual:

qemu-system-aarch64 -M xlnx-zcu102 -m 8G -serial mon:stdio -name qnx-partition-machine -device loader,file=/home/faiq/Downloads/QNX-IFS,addr=0x00100000,cpu-num=0 -drive file=qemu_sd.img,if=sd,format=raw,index=1 -boot mode=5 -net nic,model=cadence_gem -net nic,model=cadence_gem -net nic,model=cadence_gem -net nic,model=cadence_gem,netdev=xzynq0 -netdev user,id=xzynq0,tftp=/tftpboot -nographic -global xlnx,zynqmp-boot.cpu-num=0 -global xlnx,zynqmp-boot.use-pmufw=true

Regarding the partition, I’ve manually mounted all of these partitions (/mnt/app, /mnt/conf, /mnt/data, /mnt/boot). Now, I want to execute a script automatically as soon as the VM starts. How can I get this script from the host to the guest?

Below is the script I received and intended to execute:

# partition emmc
fdisk /dev/emmc0 delete -a
fdisk /dev/emmc0 add -t 11 -b -p 2
fdisk /dev/emmc0 add -t 177 -p 8
fdisk /dev/emmc0 add -t 178 -p 20
fdisk /dev/emmc0 add -t 179
mount -e /dev/emmc0

# format emmc
mkdosfs /dev/emmc0t11
echo y | mkqnx6fs /dev/emmc0t177
echo y | mkqnx6fs /dev/emmc0t178
echo y | mkqnx6fs /dev/emmc0t179

# mount emmc
mount -t dos /dev/emmc0t11 /mnt/boot
mount -t qnx6 /dev/emmc0t177 /mnt/apps
mount -t qnx6 /dev/emmc0t178 /mnt/conf
mount -t qnx6 /dev/emmc0t179 /mnt/data

fdisk /dev/emmc0 show
ls /dev

# create folder structure
mkdir /mnt/conf/etc
mkdir /mnt/conf/etc/ssh
mkdir /mnt/conf/etc/profile
mkdir /mnt/conf/var
mkdir /mnt/conf/var/etc
mkdir /mnt/conf/var/etc/ssh
mkdir /mnt/conf/home

While the folder creation part isn’t working from the script, I’ve also tried using mkdir and find commands manually, which aren’t working in the VM but are functional in real hardware. This indicates that the image have these commands, and I’m unable to locate/execute them in the VM because all the mounted directories are empty. Similarly, I’ve created a run.sh script with all the necessary permissions, but this script isn’t running either.

I not overly familiar with qemu so I wouldn’t be likely to spot anything wrong. The fact you are able to boot QNX and find the hard drive image on your host PC tells me you probably have everything correct.

If I understand you correctly, if you log into QNX on the actual hardware you are able to use find and mkdir commands. If that’s the case, log into QNX on the actual hardware and check the environmental PATH variable to see what the path is set to (‘echo $PATH’). Then compare that to the path on your VM. One of the directories in the PATH on the actual hardware will have those missing commands.

Are you saying there is nothing in /mnt/boot, /mnt/apps, /mnt/conf etc? The df command from your last post showed they were ~4% full each so there should be something in there.

One other thing. When you log in on the actual hardware and your VM, what is the home directory set to (‘pwd’ command after logging in)? This matters because by default QNX boots from an IFS (image file system) that you can’t modify. At boot time that IFS gets uncompressed into memory as a read-only file system. If the home directory is in the IFS (ie it’s in the / directory path and not in one of the /mnt areas) you won’t be able to modify (add, remove etc) anything in the home directory or as part of system startup. Which means you won’t be able to auto run the scripts you want. If that’s the case you’ll have to log in first and then manually run the script from one of the /mnt directories.

Tim

I understand the point, I will compare it tomorrow but at the moment in VM I have following result of echo $PATH

# ls
bin     etc     mnt     sbin    usr
dev     lib     proc    tmp     var
# echo $PATH
/proc/boot:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib
# pwd
/
# 

Yes its about ~4% but its showing nothing, have a look at below results…

# fdisk /dev/hd0 show 

     _____OS_____     Start      End     ______Number______   Size    Boot  
     name    type    Cylinder  Cylinder  Cylinders   Blocks                 

1.   FAT32     11          0          4         5       10208      4 MB   *
2.   QNX6     177          5         24        20       40960     20 MB
3.   QNX6     178         25         70        46       94208     46 MB
4.   QNX6     179         71        255       185      378880    185 MB

# cd /mnt/
# cd conf/
# ls -a
.        ..       .boot
# cd .
../     ./      .boot/  
# cd ./
# ls
# ls -a
.        ..       .boot
# cd .boot/
# ls -a
.     ..
# ls -ll
total 0
# pwd
/mnt/conf/.boot
# 

At the time of log in, the home directory is root directory /
Ok, so I understand the point I have to manually execute the script every time.
Q: is there any way I can get my script inside VM?
I also noticed that the connection between host and guest is I think, also not established,

# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33136
	inet 127.0.0.1 netmask 0xff000000
	inet6 ::1 prefixlen 128
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1

Faiq

From the results of ‘echo $PATH’ it appears all the command are built into the boot image. That’s fairly standard stuff as most companies want a read-only boot image that can’t be tampered with.

It will be interesting to see if the real system has anything different. More importantly, you need to locate on the real system which directory contains mkdir, find and other commands and then look in the same places on your VM so we can try and understand why your VM isn’t able to use those commands.

I looked at /mnt/conf at 90000 blocks (512 bytes per block) is only about 45 megs in size. So depending on how big that .boot file is, it could actually be the only file there (4% of 45 megs is ~2 megs)

# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33136
	inet 127.0.0.1 netmask 0xff000000
	inet6 ::1 prefixlen 128
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1

I’m going to assume the real system has an Ethernet card in it and that its configured. If that’s true, can you figure out which network card is in the real system (the QNX command is ‘nicinfo’ if that’s there). My guess is the network driver is started looking for a specific network card. With luck qemu emulates that card and you just tell qemu to use that card. If not, you’ll have to tell qemu to emulate a specific card QNX support and manually start networking. After that with some luck there will be telnet available (does the real system use telnet or drive mapping?) in order to transfer files (otherwise you’ll have to manually run an editor and type them in if there is an editor available)

See this link about how to set specific network card emulation in qemu (something like -net nic,model=lan9118 for a lan9118 card)

Tim

So here is the command output from both machines

from real hardware


# which mkdir
/bin/mkdir
#
#
# echo $PATH
/bin:/usr/bin:/sbin:/usr/sbin:/proc/boot

# env
_=/usr/bin/env
SSH_CONNECTION=xxx
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/proc/boot
SHELL=/bin/sh
USER=root
MAIL=/var/spool/mail/root
HOME=/
SSH_CLIENT=xxx
TERM=xterm
SSH_TTY=/dev/ttyp0
LOGNAME=root
#

and below is the output from VM

# echo $PATH
/proc/boot:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib

# which mkdir
which: no mkdir in /proc/boot:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib

# env
_=/usr/bin/env
PATH=/proc/boot:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib
PCI_BKWD_COMPAT_MODULE=/lib/dll/pci/pci_bkwd_compat.so
PCI_SLOG_MODULE=/lib/dll/pci/pci_slog2.so
PCI_BASE_VERBOSITY=0
LD_LIBRARY_PATH=/proc/boot:/lib:/usr/lib:/lib/dll:/lib/dll/pci
PCI_DEBUG_MODULE=/lib/dll/pci/pci_debug2.so
PCI_HW_MODULE=/lib/dll/pci/pci_hw-xzynq-zcu102.so
HOME=/
TERM=qansi
ENV=/etc/profile
SYSNAME=nto





# cd bin/
# ls
canctl                    ksh                       slay
cat                       ln                        slog2info
chmod                     login                     slogger2
cp                        ls                        stty
dd                        mount                     su
dev-can-xzynq             mv                        sync
df                        on                        umount
du                        passwd                    uname
getmac-i2c-zcu102         pidin                     waitfor
hostname                  rm
isendrecv                 sh

Does this could be the possible solution ?

No, that link is for someone creating their own QNX boot image in order to boot and install QNX onto a board. You are trying to boot an already existing system.

There is quite a bit of difference between your VM and the actual machine. I re-read everything from the top and I’m now wondering if the QNX.IFS you are booting is not the right thing because normally the qnx bootloader boots from the boot.bin file which you aren’t using. It’s likely the missing stuff is in there.

Instead of trying to boot the QNX.IFS file, can you instead have qemu boot the raw image of the CF disk you have. Here’s an example of what I mean and you can add in the options you already know work for the hard drive, CD rom and eventually network card.

If this boots then log in again and run those same commands to make sure the path/environment are the same as the real hardware.

Tim

So, you mean just remove completely the device parameter that contains QNX-IFS file

-device loader,file=QNX-IFS,addr=0x00100000,cpu-num=0

and boot instead only with

-drive file=qemu-boot_sd.img,if=sd,format=raw,index=1 -boot mode=5

Actually I tried this by first creating a new raw image with

dd if=/dev/zero of=qemu_sd.img bs=256M count=1
mkfs.vfat -F 32 qemu_sd.img
mcopy -i qemu_sd.img BOOT.BIN ::/
mcopy -i qemu_sd.img Image ::/
mcopy -i qemu_sd.img system.dtb ::/

and then executed the below command

qemu-system-aarch64 -M xlnx-zcu102 -m 16G -serial mon:stdio -drive file=qemu-boot_sd.img,if=sd,format=raw,index=1 -boot mode=5
-net nic,model=cadence_gem -net nic,model=cadence_gem -net nic,model=cadence_gem -net nic,model=cadence_gem,netdev=xzynq0 -netdev user,id=xzynq0,tftp=/tftpboot -nographic -global xlnx,zynqmp-boot.cpu-num=0 -global 'xlnx,zynqmp-boot.use-pmufw=true'

but as soon as I executed the command it did not worked and screen hanged.

I suspect the reason it hangs is because the hardware emulation you have specified doesn’t match the hardware of the real machine. So that’s likely causing QNX to hang when it goes looking for the disk and network card etc.

This person (who wasn’t successful) set a lot of things to try and match his hardware
https://community.qnx.com/sf/discussion/do/listPosts/projects.qemu/discussion.general.topc27609?pageSize=-1#post_post119448

I think you are going to need to know the hardware in your real machine in order to set the right things for qemu in order to get it to boot.

I don’t suppose there is any chance you could ask for the original QNX boot file that was used to create the image. If we had that we’d know exactly what hardware wise needs to be set.

Tim

The board of real hardware is xlnx-zcu102 and I am passing the machine type exactly the same as it is requires. I also tried with different machine types and different settings that doesn’t work.

So, as per my understanding there is some mismatching with the disk image that creating this issue and need to figure out what is the correct disk image with correct parameters.

Meanwhile, I have asked for the QNX boot file on which the OS image is created.
lets see if I receive any thing.

So now I received a new QNX-IFS file which is bigger in size.
and now I am getting
qemu-system-aarch64: warning: hub 0 is not connected to host network

Hi Tim,
I found that I was working with some wrong QNX-IFS file, for which I was able to attached virtual hard disk.
But now with correct QNX image I am getting the warning

qemu-system-aarch64: warning: hub 0 is not connected to host network

not not even able to create VM and the terminal hangs…