QEMU and booting

FirstRib/KL topics related to Virtualization


Moderator: Forum moderators

Locked
User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

QEMU and booting

Post by wiak »

wiak wrote: Tue Jan 17, 2023 9:06 am
Clarity wrote: Tue Jan 17, 2023 7:41 am
wiak wrote: Tue Jan 17, 2023 4:54 am

... Would be nice to have a simple utility for installing grub2 similarly, something like part of frugalpup that is available in Fossapup (and the newer radky FP)...

Would @shinobar's GRUB2utility be what you'd want? or maybe add GRUB2 utils package.

Yes, I wondered about that one. Answer is I don't know. I have a feeling grub2 is quite large - but maybe that is a special slimmed down version. Grub2 certainly has a lot of capability (including inbuilt scripting/encryption support - hence my believing it may be a large install). Then again if frugalpup can do it, I suppose it isn't as large as I fear. Trouble is I know nothing much about it - I'm at the stage where I can't be bothered learning enough about it to implement any particular tool of my own. There are solutions already available it seems, so I guess I don't have to, but still - how to use with KLV conveniently is the issue.

Well, in an experimental quick test I have managed to successfully boot into a qemu qcow2 image, via grub2, that I had made a frugal install into to directory KLV on that qcow2 image filesystem. I will post how I did it in detail later, once I work that out - this kind of install is more than kind of new to me (though in the past I have used frugalpup to install grub2 to a usb stick, but without trying to understand any of what that actually entails). In this instance I didn't use any such Puppy or Dog-related utility. Instead, I simply installed package grub (being for grub2) on my KLV distro using xbps-install, which was booted via its iso as a guest VM via Qemu on my Zorin lite OS host. I then basically just used the grub-install command to write grub2 to the qcow2 image (device sda) that I had attached/mounted as sda1 to the temporarily booted KLV, which was formatted as a ext4 partition. Then I copied my grub.cfg stanza from elsewhere and configured it to boot from a frugal install I made of KLV-Airedale into a KLV directory on that qcow2 sda1 frugal install. It booted. No special utility required, though such a utility may be slimmer or more convenient - end result seems to be the same though.

Sorry, I'm a bit incoherent at the moment. Tired. Everything working so I suppose I should just now relax...

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

rockedge wrote: Tue Jan 17, 2023 1:14 pm

@wiak do you have a small step by step description of how to use grub2 to install the bootloader to the qcow2 disk image?

I'm still experimenting since I'm not quite sure what I did or how useful it really is. The jist of it is as follows though.
EDIT: Tip. Once booted into the VM, you can cut and paste the commands needed for there (step 3 on) if you first start up VM browser and go to this page URL.

  1. I already had a qcow2 image, which I made with command:

    Code: Select all

    qemu-img create -f qcow2 KLV-Airedale.qcow2 5G  # or whatever size wanted
  2. I booted and attached that via qemu:

Code: Select all

qemu-system-x86_64 -enable-kvm -m 2G -vga cirrus -smp 2 -device AC97 -cdrom KLV-Airedale-rc7.2.iso -hda KLV-Airedale.qcow2 -boot once=d   # just -boot d would do I think(?)

3.. Inside that VM I used "gparted /dev/sda" to make sda1 partition on that qcow2 image as an ext4 (as it happens) partition on it. EDIT: Via gparted I needed to make partition table on it via: Device > Partition Table; I just used msdos type. EDIT2: I gave the partition LABEL KLV-Airedale. I also marked it with boot flag though whether that required depends on how I would boot it; MBR BIOS or EFI as far as I understand it - which isn't much. I can't remember if I mounted it, but seems at some stage was mounted to /mnt/sda1 (maybe used: wd_mount sda1).

  1. I then simply installed actual grub package (being grub2) using

    Code: Select all

    xbps-install -Sy grub
  2. Then, after various google searches, I found this link regarding installing grub2 onto a usb stick: https://ubuntuforums.org/showthread.php?t=1581099

  3. I referred to the part about "From the Live CD:" and tried the command:

Code: Select all

grub-install --root-directory=/mnt/sda1 /dev/sda
  1. I then checked /mnt/sda1 and noted grub2-related boot files there, though locale folder seems unneeded. At that stage I made a directory KLV and from /mnt/sr0 I was able to copy all the KLV files in /mnt/sda1/KLV, thus making a KLV frugal install into that qcow2. But at that stage I didn't have grub.cfg so I actually just copied that text file from an existing grub2 install I already had on a usb stick (I resorted to emailing them to myself as a daft way of getting them via browser into the Virtual machine! but of course I should have used ftp or that 9p share method I talked about). Oh, actually was two grub.cfg files; typical arrangement: one placed in /mnt/sda1/boot/grub/ which simply gave link to the main one at /mnt/sda1/grub.cfg

  2. Adjusted the /mnt/sda1/grub.cfg with menu stanza for that KLV frugal install and rebooted, and it booted fine.

Note: I used LABEL boot method:

Code: Select all

menuentry "KLV" {
  insmod ext2
  search --no-floppy --label KLV-Airedale --set
  linux /KLV/vmlinuz w_bootfrom=LABEL=KLV-Airedale=/KLV w_changes=RAM2
  initrd /KLV/initrd.gz
}
  1. Shutdown the RAM0 iso booted KLV VM guest, and then rebooted with command:

Code: Select all

qemu-system-x86_64 -enable-kvm -m 2G -vga cirrus -smp 2 -device AC97 -hda KLV-Airedale.qcow2 -boot c

As I say, above is just roughly from memory - may or may not be complete, and I have no idea what kind of grub2 install that grub-install command made (I assume it wrote to MBR and so on, since doesn't include EFI files). Probably better not having to install grub via xbps-install, but instead just have smaller utility like grub2config and so on if anyone gets that, or part of frugalpup, working in KLV. Actually, for EFI type booting I imagine just the files from frugal install boot related to grub2 would be enough, but I haven't tried booting via EFI using qemu so have no idea if that involves special options though I guess it will.

The above was a bit of a learning experience. I believe it was a good thing to use actual grub install for this experience rather than just rely on some scripted simple grub2 install utility that isn't mainstream, but of course such a utility is nice and simple and no doubt lighter weight in practical usage.

Note that we are needing a Kennel Linux related HowTo/Including-useful-commands-posts section to help us not lose any howto-related posts.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

Booting using UEFI bios apparently requires Open Virtual Machine Firmware (ovmf). It was already installed on my Zorin lite host OS, but I still need to work on using it to boot.
https://www.ubuntubuzz.com/2021/04/how- ... -qemu.html

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Using boot managers with Qemu disks

Post by wiak »

How @rockedge earlier did similar to the above for booting distro in Qemu using Grub4Dos: viewtopic.php?p=78765#p78765

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

A couple of nice posts on using Qemu with EasyOS (but pretty general purpose useful really) by @Federico can be found at the following links:

QEmu guide - how to install a Linux distribution on EasyOS
viewtopic.php?p=92950#p92950

QEmu guide - Windows 10 - how to install and run it on Easy
viewtopic.php?p=92523#p92523

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

There is also an interesting thread re:QEMU-KVM use started by @Clarity here:

viewtopic.php?p=75328#p75328

Clarity also produced a booklet-sized document concerning the operation and configuration of Qemu from a Puppy forum context:

"QEMU/KVM Host Use on Puppy Linux 64bit distros"
https://docs.google.com/document/d/1SaJ ... yj6rkbfl16

In addition to mentioning the above work of Clarity, @fatdoguser provided a brief description of using qemu with ssh and more generally in the following post:
viewtopic.php?p=105619#p105619

Also see:
"Start QEMU virtual machine from non-graphical boot?"
viewtopic.php?p=85310#p85310

Also, just found this by, I think, @jamesbond:
https://www.lightofdawn.org/wiki/wiki.c ... ArmForQemu

And a lot of interesting information (some relating to QEMU and use of older GlibC versions too) here:
https://caiorss.github.io/C-Cpp-Notes/L ... mming.html

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

An interesting thread concerning using img files and EasyOS (containers) by @ArrayBolt3 is here:

Installing EasyOS in a QEMU VM
viewtopic.php?p=81670#p81670

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: Using boot managers with Qemu disks

Post by wiak »

If you don't have qemu/kvm installed @ points out that there is an AppImage for it if you want that alternative:

Run QEMU as an Appimage in BookwormPup64
viewtopic.php?p=103814#p103814

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
wiak
Posts: 3996
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 60 times
Been thanked: 1155 times
Contact:

Re: QEMU and booting

Post by wiak »

Above are just some old posts that are important (to me) that I wanted to make easier to find in this one topic area. I may add other ones later.

A related thread on "QEMU and file sharing" is here: viewtopic.php?p=78844#p78844

A utility for booting an existing frugally installed distro (for example: FirstRIb, Puppy, DebianDog, FatDog, or EasyOS) into a qemu instance (without needing any boot manager aside from internal qemu arguments) is detailed here:

frugal2qemu (experimental only!): no grub required
viewtopic.php?p=126355#p126355

I've locked this thread for now because I'm arranging it with particular posts I want without clutter of comments. However, if you know of any other interesting qemu-related posts/threads of interest that I may later want to include links to feel free to alert me about them in thread KL-Dev_work/KLV To-Do List: viewtopic.php?t=7515

Many thanks in advance.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

Locked

Return to “Virtualization”