WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Setting up Qemu  (Read 9701 times)

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Setting up Qemu
« on: February 20, 2023, 03:05:01 AM »
FYI: I saw that (in both x86 and x86_64 versions) the exfat.ko.gz is unusually placed in drivers, instead of fs (file system) branch, ex: /modules.gz\modules\lib\modules\6.1.2-tinycore\kernel\drivers\scsi\exfat\.

In qemu (ver 3.1) booting TC14 x86_64 with VIRTIO options, both cdrom and hda, the /cde is not used so Xfbdev is not automatically started, because /dev/vda# is not mounted.
Code: [Select]
qemu-system-x86_64 -accel kvm -machine q35 -cpu max -m 128M -vga virtio -kernel vmlinuz64 -initrd MyCore.gz -drive file=MyDVD.iso,if=virtio,media=cdrom,readonly=on,index=1 -drive file=Mydisk.qcow2,if=virtio,media=disk,index=2 -boot c -append "vga=ask nozram noswap root=/ init=/init"
Maybe I missed some initial driver parameters? because after booting I can mount cdrom from /mnt/vda and hdd-disk from /dev/vdb1. OR from /dev/sr0 an /dev/sda1 if I did not use virtio simulation.

EDIT: maybe is my mistake, /cde folder can be only on booting device, but not on another device.
« Last Edit: February 23, 2023, 08:40:18 AM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #1 on: February 20, 2023, 06:07:15 AM »
Hi nick65go
... EDIT: maybe is my mistake, /cde folder can be only on booting device, but not on another device.
I don't think that is true.

tc-config  calls  tce-setup  to load extensions.
tce-setup  contains the following:
Code: [Select]
# Finally check for CD Extensions if requested
if [ "$CDE" ]; then
        # Some cd drives are slow - if cde was requested, wait for udev to settle
        [ ! -s /etc/sysconfig/cdroms ] && udevadm settle --timeout 5

        if [ -s /etc/sysconfig/cdroms ]; then
                for DEV in `cat /etc/sysconfig/cdroms`; do
                        process_CD
                done
        fi
fi

# If nothing loaded then also check for pseudo CD, e.g., isohybrid
if [ "$CDE" -a -z "$CDELIST" ]; then
        sleep 5
        DEV="$(autoscan 'cde' 'd')"
        process_CD
fi
If it doesn't find any CDs, then it scans the rest of the system for a device
containing a  /cde  directory.

In order for that to take place, you need to pass the  cde  boot code. I don't
see  cde  anywhere in your  qemu  command.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #2 on: February 20, 2023, 06:51:11 AM »
In order for that to take place, you need to pass the  cde  boot code. I don't see  cde  anywhere in your  qemu  command.
Rich, you spot it! Thank you.
PS: I am in the process to rename the (internal) tc functions and subroutines, replacing abc() with _abc(),
same for tc variables, so iset var=blah become set tc_var=blah; and is also clear (for me) if is a function or a variable, etc.
so is self-documented then, and I "know" that is not an external command from /bin, /usr/bin (and busybox/gnu_tools, toybox). In the process I involuntary "destroyed" some scripts.
« Last Edit: February 20, 2023, 07:07:58 AM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #3 on: February 20, 2023, 08:53:53 AM »
For clarity, to do not confuse the audience, I am back to virgin files (vmlinuz, rootfs.gz, modules.gz, *.tcz), so Xvesa for now.
[BUT it is the same small "problem" as with Xfbdev running in both in x86 and x86_64];

I concatenated rootfs.gz + modules.gz into MyCore,gz (because I can not have multiple -initrd parameters in qemu  :( ).
I created sda1.qcow2 file, from linux I formatted as ext2 and mounted [so it has NO PARTITIONS] and I populated its /tce/optional folder with virgin *.tcz and *tcz.dep, and I have /tce/onboot.lst etc.

case 1: booting with "legacy" -hda is working, Xvesa shows up automatically.
Code: [Select]
qemu-system-i386.exe -machine q35 -cpu max -m 128M -vga virtio -kernel vmlinuz -initrd Mycore.gz -hda sda1.qcow2

case 2: booting with "Virtio" vda is NOT working by default, only manually.
Code: [Select]
qemu-system-i386.exe -machine q35 -cpu max -m 128M -vga virtio -kernel vmlinuz -initrd Mycore.gz -drive file=sda1.qcow2,if=virtio,media=disk
In cat /etc/fstab I have the mount point /mnt/vda mapped to /dev/vda, OK. But the mount command shows that /dev/vda is not mounted yet. So of course tczs are not loaded, and Xvesa is not shown.
I tried even with individual -append cases, like tce=vda, tce=/mnt/vda, tce=/dev/vda etc. No success.  :(

The bug: the virgin scripts are focused MAINLY on strings like sda* but not vda*. This happens with VIRTIO and with sda.qcow2 partitioned or not.
« Last Edit: February 20, 2023, 09:16:07 AM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #4 on: February 20, 2023, 11:42:40 AM »
As for virtio disks, it's quite possible some scripts are missing vda* cases.
Right! The culprit section may be in /etc/init.d/tc-config ? with booting variable tcvd=something;
but I am rusty with shell variable truncating... I have no success with it like tcvd=/dev/vda/tce.

Today is near no point to simulate old-pseudo-real devices, when Qemu (yes, 3.1  :) ) is so advanced in Virtio everything (blocks, devices, controllers, network-cards, files-share, video, cpu, etc). A trimmed-down kernel with just virtio drivers, eventually built-in, (and possible without spectre mitigations) will be nice to have.

PS: it is just for fun, to remind me the flow: boot-loader -> kernel -> shell (+ libs)  -> udev -> mounts -> login.
« Last Edit: February 20, 2023, 12:12:37 PM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #5 on: February 20, 2023, 11:49:15 AM »
Hi nick65go
... PS: it is just for fun, to remind me the flow: boot-loader -> kernel -> shell (+ libs)  -> udev -> mounts -> login.

This appears to be accurate:
https://forum.tinycorelinux.net/index.php/topic,22020.0.html

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #6 on: February 20, 2023, 11:52:45 AM »
Hi nick65go
If you run this:
Code: [Select]
autoscan-devicesdoes it find your virtual disk?

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #7 on: February 20, 2023, 12:01:09 PM »
Code: [Select]
autoscan-devicesdoes it find your virtual disk?
Yes, result is "vda"
« Last Edit: February 20, 2023, 12:03:49 PM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #8 on: February 20, 2023, 03:06:37 PM »
Wow, I think I found the "wrong" instruction; is in the /etc/init,d/tc-functions, at lines 91 and 106:
Code: [Select]
MOUNTPOINT="$(grep -i ^$D2\  /etc/mtab | awk '{print $2}' | head -n 1)"I think that is should be $D2, without "\"; or to be $D2\s; [where \s means space in regex].

I can execute code
Code: [Select]
D2=/dev/vda ABC="$(grep -i ^$D2 /etc/fstab)" ; echo $ABCresulting in ABC="/dev/vda" from /etc/fstab, or resulting ABC="" from /etc/mtab.

But with
Code: [Select]
D2=/dev/vda ABC="$(grep -i ^$D2\  /etc/fstab)" ; echo $ABCI stay in a loop forever.
« Last Edit: February 20, 2023, 03:28:40 PM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #9 on: February 20, 2023, 07:13:36 PM »
Hi nick65go
... I think that is should be $D2, without "\"; or to be $D2\s; [where \s means space in regex]. ...
No, it is correct as written. The "\ " tells grep to include a trailing space
as part of the search term. If you look at:
Code: [Select]
^$D2\  /etc
123456789
there are 2 spaces between  \  and  /  in positions 6 and 7.

The first space is part of the search term and the second
separates search term from the file to be searched.

As near as I can tell,  find_mountpoint  works correctly:
Code: [Select]
tc@E310:~$ for DEVICE in `autoscan-devices`; do find_mountpoint $DEVICE; echo $MOUNTPOINT; done
/mnt/sda2
/mnt/sda7
/mnt/sda3
/mnt/sda1
/mnt/sda6
/mnt/sdb1
tc@E310:~$

Rename your  /tce  directory to  /cde  and add the  cde  boot code.
The  cde  directory must be in the root of the drive.
Remove any  tce  boot codes.
It should be able to find the  /cde  directory on its own.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #10 on: February 21, 2023, 02:06:09 AM »
Hi Rich, thanks for the feed-back.
For clarification, lets forget about "cde" boot code/parameter.
Lets focus only on /tce folder in "disk" /dev/vda, in partition "vda" (not vda1, because I have no partition) with boot code tcvd=/dev/vda (or tcvd=vda/whatever, etc)
Code: [Select]
#Check for Virtual Hard Drive
if [ -n "$TCVD" ]; then
    wait $fstab_pid
    TCVD="${TCVD#/}"
    TCVD="${TCVD#dev/}"
    TCVD_DEVICE="${TCVD%%/*}"
    TCVD_LOOPFILE="${TCVD#*/}"
    if [ "$TCVD_DEVICE" == "$TCVD_LOOPFILE" ]; then
        TCVD_DEVICE="$(tc_autoscan $TCVD_LOOPFILE 'f')"
    fi   
    PARTITION="${TCVD_DEVICE##/dev/}"
    find_mountpoint "$PARTITION"
    if [ -n "$MOUNTPOINT" ]; then
        [ "$MOUNTED" == "yes" ] || /bin/mount "$MOUNTPOINT"
        usleep_progress
        if [ -f "$MOUNTPOINT"/"$TCVD_LOOPFILE" ]; then
            [ -d /mnt/tcvd ] || /bin/mkdir /mnt/tcvd
            ln -sf "$MOUNTPOINT"/"$TCVD_LOOPFILE" /dev/tcvd
            printf "/dev/tcvd \t/mnt/tcvd \text2\tloop\t0 0 #Added by TC\n" >> /etc/fstab
            sync
        fi
    fi
I started with TCVD=/dev/vda, then TCVD_DEVICE=vda and TCVD_LOOPFILE=vda;
then there I had a problem with $MOUNTPOINT==" ";
and the   if [ -n "$MOUNTPOINT" ]; then bypass all. Hm..
I was running each instruction step by step, but last time it was something like inside find_mountpoint "$PARTITION" it struggled with the grep - i ^$D2, when $D2 was /dev/vda.

PS: if you have time, could you do the same, run step by step, to reproduce my findings for $D2=/dev/vda in that part of code, to see what I mean?
« Last Edit: February 21, 2023, 02:25:24 AM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #11 on: February 21, 2023, 05:50:37 AM »
"find_mountpoint vda" works correctly
Code: [Select]
. /etc/init.d/tc-functions; MOUNTED="fake"; find_mountpoint vda ; echo $MOUNTPOINT $ MOUNTEDwill return internal MOUNTPOINT=/mnt/vda and internal MOUNTED=no (or my external MOUNTED=fake)

Code: [Select]
#Check for Virtual Hard Drive
if [ -n "$TCVD" ]; then                             # TCVD=/dev/vda/tce/abc
    wait $fstab_pid
    TCVD="${TCVD#/}"                            # TCVD=dev/vda/tce/abc
    TCVD="${TCVD#dev/}"                      # TCVD=vda/tce/abc
    TCVD_DEVICE="${TCVD%%/*}"        # TCVD_DEVICE=vda
    TCVD_LOOPFILE="${TCVD#*/}"        # TCVD_LOOPFILE=vda
    if [ "$TCVD_DEVICE" == "$TCVD_LOOPFILE" ]; then                # yes
        TCVD_DEVICE="$(tc_autoscan $TCVD_LOOPFILE 'f')"         # TCVD_DEVICE="$(tc_autoscan vda 'f')" -> TCVD_DEVICE="" !?
    PARTITION="${TCVD_DEVICE##/dev/}"              # PARTITION=""
    find_mountpoint "$PARTITION"                            # find_mountpoint "" -> MOUNTPOINT=""
    if [ -n "$MOUNTPOINT" ]; then
...
    fi
fi

Stop here now, the problem is with assignment (tc_autoscan vda 'f') to TCVD_DEVICE
« Last Edit: February 21, 2023, 05:54:22 AM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #12 on: February 21, 2023, 06:20:29 AM »
Hi nick65go
How to use/share Virtual Disks (Qemu) ?:
http://tinycorelinux.net/faq.html#qemu

Offline nick65go

  • Hero Member
  • *****
  • Posts: 800
Re: Re: Setting up Qemu
« Reply #13 on: February 21, 2023, 06:38:08 AM »
Booting with kernel + initramfs then I have only filesystems in RAM, and no access to any *.qcow2 FROM INSIDE qemu. This is by design, to have access to ONLY what I want from inside qemu, and no undesired links to host files (except self-defined network or file-shares if/when in need) so no stupid program call home to spy, or access personal files -- in theory.

Maybe I need to define myself a new boot case for boot code like "virtio".So the TCVD is for an image (qcow2, img, etc) on a disk FROM where TC booted, in my case from void  :)

But as you have all my booting parameters in my previous posts, please let me know if you have success with actual (not remastered) tinycore.As I said before, I can remaster with a trimmed down kernel, all virtual devices, one user, a small init script -- to define mount points, variable (language, path, lib-configs, etc) -- in less than 4kb (like toybox). Basically I need a shell and udev. But I am interested to re-discover what is new in tc14 in 2023.All is for fun (and learning -- I forget things the older I get), as there are a lot of ready-made distros to fully "install" in 10 minutes.
« Last Edit: February 21, 2023, 06:54:32 AM by nick65go »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Re: Setting up Qemu
« Reply #14 on: February 21, 2023, 08:48:12 AM »
Hi nick65go
The  tcvd  boot code is looking for an image file.
Assuming your file containing  /tce  is on  sda1  and is called  qcow2 , try adding this:
Code: [Select]
-append tcvd=sda1/qcow2 tce=tcvd restore=tcvd