OS Development - booting from floppy drive using qemu - boot

I have been reading BrokenThorn's OS development tutorial and am at the part of creating and loading the second stage bootloader. The tutorial is for Windows, but I am doing this in Linux(Ubuntu 13.04).
This is what I have done:
Created file floppy.img under ~/Documents/floppy with the mkfs.vfat command
Compiled by boot.asm file using nasm giving me boot.bin
Then I ran this command : dd if=boot.bin of=~/Documents/floppy/floppy.img bs=512 count=1
Thus I have the floppy image with the first stage bootloader. On starting that using qemu, it works fine.
However, after I create the second stage bootloader, (if I am correct)I would have to mount the floppy.img and copy stage 2 on to the mounted filesystem. In such a case, how can one boot a mounted floppy using qemu ? Is it even possible ? If not, how do I work with the second stage bootloader.
Please forgive me for any stupid assumption/question as I am new with this.

Where is your problem? You mount the image:
mount -oloop ~/Documents/floppy.img /mnt/floppy
Copy the stage2:
cp stage2.bin /mnt/floppy
Unmount it:
umount /mnt/floppy
And launch it with QEMU:
qemu -fda ~/Documents/floppy.img
VoilĂ !

Related

Qemu can't load bios-256k.bin when running on Windows

I was trying to test qemu on Windows OS and when I tried to start an ubuntu iso whith the following command:
qemu-system-x86_64.exe -boot d -cdrom .\ubuntu-20.04.1-desktop-amd64.iso -m 2048
Then I getting the following error:
qemu: could not load PC BIOS 'bios-256k.bin'
Qemu folder is set in Enviroment Varibles and the bios-256k.bin file is in the folder
How can I solve this problem?
Add an option for bios file directory entry with -L switch. Your command should look like this:
qemu-system-x86_64.exe -boot d -cdrom .\ubuntu-20.04.1-desktop-amd64.iso -m 2048 -L "C:\Program Files\qemu"
Of course in case your default qemu installation is in C:\Program Files\qemu and bios files are inside that directory. For some reason, qemu has a bug that doesn't search bios files in defined path and look for them in current working directory.
Edit: I found a bug report that mentions this issue. It also seems to be fixed in newest version. Anyway, here is the link: https://bugs.launchpad.net/qemu/+bug/1915794
This is a known and documented problem with a simple workaround: "Known issue: currently requires start from installation directory or -L option to specify the location of the firmware files."
And it is already fixed in the newer installer.

Ejecting/unmounting random USB flash drive in Raspberry pi / Python

So I'm trying to get a working code in Python that will eject/unmount all USB flash drives attached to the Pi (Running Raspbian) - so that they can be removed safely. The final code will be run from within the python program.
Additionally, I'd like to eject/unmount the USB flash drive even if it's in use.
I've looked around and can't see how to do this. Thanks.
udisks --detach /media/pi/DOCS/ - 'Blocked device... Resource temporarily available'...
udisks --detach /media/pi/ - 'Blocked device...Resource temporarily available'...
udisks --detach /media/ - 'Blocked device...Resource temporarily available'...
sudo udisks --detach /media/pi/DOCS/ - still blocked...
sudo umount /path/to/devicename - command not found...
eject /media/pi/DOCS/ - Unable to open '/dev/sda'
(DOCS is the name if my USB flash drive. - though I want to eject all USB flash drives - not just my one)
So I'm going to ask the user in Python to select their USB flash drive from a list, which is pretty easy (just read in the folder) - so I will have the pathway to the USB. I'm still not sure which code can safely disconnect the USB flash drive - Maybe more research is the answer. Thanks for your help so far.
For udisks --detach the parameter should be the device, not the mounting point.
For example, if the USB Disk is /dev/sdb the command would be udisks --detach /dev/sdb
If the command still doesn't work you could try udiskctl power-off -b <device> which should also work.
so I found the answer:
sudo eject /dev/sda1
-This disconnects the USB flash drive on a Raspberry Pi.
Thank you very much to everyone who helped!

Can't mount Android Things image file in OS X to tweak config files

Some tutorials recommend making modifications to files such as wpa_supplicant.conf within the Android Things image file, as per this answer https://stackoverflow.com/a/41732035/766115. I'm trying with the Android Things developer preview 4.1 image file.
However, I've had no luck mounting this file for editing purposes on OS X. Various attempts to use os x Disk Utility or the mount command from the terminal all result in some type of error message telling me the file format is not compatible. I can see in Disk Util, or through terminal mount, that the ISO image has 15 sectors (or partitions), but I can't access them.
I've even tried spinning up an Ubuntu in AWS, uploading and mounting from there. No dice.
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
Any advice? What am I missing.
On macOS I have done this way:
Connect the sdcard on your Mac
Run on terminal diskutil list and see the name of your sdcard (in my case /dev/disk2s1)
Create a directory where the sdcard will be mounted: sudo mkdir -p /Volumes/pisdcard
Mount the sdcard: sudo mount -t msdos /dev/disk2s1 /Volumes/pisdcard
Edit what you want and unmount the sdcard with: sudo umount /dev/disk2s1
It worked for me, I used to change config.txt and cmdline.txt to change UART mode and use a GPS module on Android Things.
hdiutil attach [file] is the macOS command to treat an image file as a disk device. If the image file contains a filesystem macOS can read, it should also mount any volumes contained in the file. If your image contains a volume not supported by macOS (e.g., ext4), you also need to install an appropriate driver before you can mount the volume.

Removing GRUB from sda from Mac Internet Recovery

I tried to make a bootable Ubuntu DVD on my MAC. This lead to messing up my bootloader which I have been unable to fix.
https://discussions.apple.com/thread/3109456?tstart=0
One person states
Boot OSX and in the terminal write:
mkdir mnt ; sudo mount -t msdos /dev/disk0s1 mnt
Will show a new drive EFI
Open this drive and open the folder EFI
Inside you will have the folders APPLE and UBUNTU
Just delete the UBUNTU folder
So I keep reading and see
When in -Recovery From Internet- it is impossible to use mkdir, but
you can "cd /tmp" and mount it there.
So I haven't been able to figure out how to mount disk0s1 in the /tmp. If someone could please show me the commands to get into the EFI Folder so I can delete the Ubuntu folder.
I assume the link means you can do something like:
mount -t msdos /dev/disk0s1 /tmp/
then
cd /tmp
and you should see the APPLE and UBUNTU directories. I am not in Recovery Mode now so I can't try that, but deleting UBUNTU from there may help you.
This page:
http://www.rodsbooks.com/refind/getting.html
is what I use when I want to install Linux on a Mac, and has a lot of useful explanation about EFI booting on Mac machines. I have had good luck with SuperGrub2 when I've gotten in trouble:
http://www.supergrubdisk.org/category/download/supergrub2diskdownload/super-grub2-disk-stable/

Run a docker container in Windows

I have a Linux x86 application inside a docker container and I want to run it under Windows. I don't want to force users to install Virtual Box. Ideally a qemu or similar virtualization tool can be used, since it is very tiny and requires no installation at all.
My approach was to use qemu for Windows and
boot2docker, so I can boot a minimal Linux with docker installed and than run my docker container within it.
This is the command I'm using to run it:
qemu-system-x86_64.exe -m 256 -cdrom boot2docker.iso
The boot goes well, but I have several problems:
at every boot the image goes trough all the configuration steps (generating keys for ssh, setting hostname, etc.) that can be skipped the second time the image runs; seems that the changes to the image are not persisted trough runs. I want to build an image that is already configured and needs only to boot;
to add my application inside the image I have to rebuild the whole boot2docker.iso image by using the steps described in How to build boot2docker.iso locally.
So, the question is: how can I use the base boot2docker.iso image and add some persisting data (such as configurations and my application)? Perhaps a read/write partition mounted from another file?
like the idea.
Maybe you can check MobaliveCD, it has a nice lightweight GUI and it embeds qemu system inside. I tried it for tinycore live cd iso (base of boot2docker), which works quite ok.
While it seems it doesn't support 64bit (which boot2docker needs), but the function fits for you need.
Your command
qemu-system-x86_64.exe -m 256 -cdrom boot2docker.iso
launches an ISO, what you want is
reserve some disk place for this iso in a .img
run this iso and install it in this .img
reboot
In a Linux you would start by doing
qemu-img create -f qcow2 /home/myuser/my_image.img 6G
There is docker-cli for Windows, it seems to be what you look for, see
http://azure.microsoft.com/blog/2014/11/18/docker-cli-for-windows-clients/
You can use boot2docker http://boot2docker.io/
On boot2docker installation, it will install virtualbox behind the scenes.
You only have to start the boot2docker shortcut and the virtual box management and vms are hidden.

Resources