How do I programmatically create a bootable CD? - osdev

I'm using a barebones tutorial as the basis for an OS I'm working on, and it seems to be an older tutorial: it has be compiling the kernel down to a floppy image, and then loading it with GRUB.
Basically, I still want to use GRUB, but I'd like to have my OS run from a CD instead. The main reason is that I don't actually have a real floppy drive available (I'm testing in VirtualBox currently) and I thus have no way to test my OS on real hardware.
I've been poking around on the net, and I can find lots of utilities that create a bootable CD from a floppy image, but these all seem to require an actual floppy drive, plus it's not really what I'm looking for. I'd like to be able to end up with a bootable CD during my make step ideally, without needing to first place the image on a floppy, which seems rather pointless.
I guess the easy way to answer this: How do I set up GRUB to read my kernel image from a CD? Will I need a special utility to do this from Windows? (The kernel can't compile itself yet, that's not for a looong while)
Thanks!

I found the solution for my project on my own, with some advice from the folks over at OSdev. There is a utility called mkisofs (which can run under Windows using a cygwin dll) that takes a directory, and makes that directory into an ISO image that can be burned to a CD. Using the -b flag, you can specify which file should reside in the boot sector of the disk.
The solution is just to have GRUB in the bootsector, and use GRUB to load the kernel image, which I can compile out in non-floppy form easily.

AFAIK a bootable CD is pretty much the same as a bootable floppy. You need to put the boot loader (GRUB) into the boot sector etc., the BIOS will take care of the low level stuff until you switch to protected mode.
You will probably have to make your image and then dd it to the actual physical disk.
Here's the El Torito Bootable CD specification:
http://www.phoenix.com/NR/rdonlyres/98D3219C-9CC9-4DF5-B496-A286D893E36A/0/specscdrom.pdf
EDIT: An alternative way to test your kernel would be a bootable USB stick. Again, the BIOS will take care of the low level USB stuff until you turn on A20 and jump to protected mode.

If you're interested in looking at code, then the Moblin Image Creator is probably a good application to check out. It's written in python and can create different types of bootable images (CD, USB and NAND) for both Live and installable configurations of Moblin Linux.

Related

Using DISM Api to Capture Image Programatically within Windows PE Environment

I've been going through the windows documentation for the Dism API with the goal of writing an exe in C++ (or whatever language can accomplish this) that can create a WIM image while running in Windows PE. I found a .NET Wrapper for the Dism API that seems like it might be useful for this purpose, but I'm unsure if a .NET app will successfully run in Windows PE. Overall, my problem is that I don't see a function that can create--and doesn't simply modify--a wim file.
If I didn't care about encapsulating this in an .exe file, the Dism documentation does show how to initially create a wim--which makes me curious why a similar function wouldn't exist within the api. Please advise if the simplest solution is to have my code call a function such as system() within the code.
To summarize, I'm looking for a way to create a wim file programmatically (called from executing an exe file) from within Windows PE.
As always, thank you for the help and advice.
I work on a project that works with DISM in WinPE quite a bit. We configure WinPE with all the .net packages as described here. Then WinPE can be configured to start an application.
I use c#, but you can do managed apps in c++ as I'm sure you know. I find putting c# code into WinPE substantially easier, but that's more a function of my experience, I suppose.
The main way we use to interact with DISM is run a command using System.Diagnostics.Process. The process runs in a separate thread, but the API is simple, and you can wait on (and/or timeout) your process for synchronization purposes. This just uses the DISM command line interface, although you can also use powershell cmdlets if you've added that package to your WinPE image. It may seem like a hacky "interface" from your app to DISM, but it works reliably, and you can keep the process window from showing up on the screen. This makes for a decent asynchronous platform for running bunches of windows imaging utilities, such as DISKPART, DISM and BCDEDIT.
The principal way you'd capture a new image is with DISM /Capture-Image. Sounds like you've already discovered this fact. Lots of options that are somewhat beyond the scope of this q/a, but I hope this gets you on a useful path.
Even though this post is a bit older, here is a possibly still relevant resource for you. Perhaps this one will help.
I've written a small GUI-based tool, project-named WIM-Backup, that uses the Windows Imaging Format (WIM) to create full backups of computer systems (operating system images) within WinPE and then restore them.
The application is hosted on GitHub, is open source, and is offered under the Apache 2.0 license.
In addition, the repository includes an illustrated step-by-step guide to help get it up and running.
Brief summary:
WIM-Backup always requires an external bootable media such as a USB flash drive.
From this drive WinPE is booted to perform a backup or restore to or from an external medium (e.g. a USB hard drive).
On the bootable USB flash drive the WinPE must be set up before (is documented illustrated in the readme).
After completion of the respective operation, a status message is displayed whether the operation was successful or failed.
After restoring a backup, you can boot normally from the destination drive.
Both the backup and restore process are relatively simple (not "rocket science").
To set up the solution, you need about 30 minutes time in the best case due to the necessary downloads (e .g. ADK)
Last but not least: it has a permissive license (non-proprietary) and is open source.
The project can be found here: WIM-Backup

Windows 7 Embedded - Disable Disk Caching Programmatically:

Preface:
We are using a Windows-7-Embedded image, for making client-ready copies of our software.
The flow is pretty standard:
Take a blank hard-drive.
Restore an in-house Windows-7-Embedded image on the hard-drive.
Install additional software on-top.
Hard-drive ready!
The Problem:
Sometimes, probably due to system crashes, some configurations that are already configured inside the image - reset.
My current problem is with a 'Disable Write Caching' option on the disk.
In the image, the option is off.
Sometimes, it just resets and turns on.
My Question:
How can I programmatically disable the disk write caching property?
Design Restrictions:
Can run an .exe on startup. The system is mostly c++ so that is that would be the optimal language for a code based solution.
Can run a .bat file.
can run a .vbs file. Not sure which version our current infrastructure are compatible with.
Images (Inside Image -> After Crash):
Clarifications:
Did my research. did not find anything related to windows write caching option in SO or SE as a whole. Did find a bunch of linux related questions.
The system crashes are by-design, at the moment. This is the obvious root cause, but cannot be fixed due to design restrictions and budget issues.
There is a registry setting EnableCache you may try to experiment with. It applies to FAT file systems and setting it to 0 shall theoretically disable disk caching. Though I have not tested it.
Look into:
HKEY_LOCAL_MACHINE\SYSTEM\StorageManager\FATFS or HKEY_LOCAL_MACHINE\SYSTEM\StorageManager\EXFAT

No FS0 in EFI Shell

I want to try programming for EFI so I created a VM using virtualbox, checked "enable efi" option and left CD empty.
The efi shell boots how it should but instead of FS0 i only see BLK0, BLK1 etc. Is there any way to have FS without inserting USB disk (which is displayed as FS)?
Edit:
Thanks for your replies. For people who still want to use VB - formatting VB disk with DISKPART using Windows CD solves the problem.
#unixsmurf answer in comments is correct. Your image need file system supported by UEFI. If you can't see fsX in output of map command then it means that non of attached block devices (blkX) contain supported file system. Please create FAT32 partition on your disk, then you will be able to see fsX in map output. To switch between file systems use DOS like syntax command ie. fs0: switch to FS0 file system.
According to UEFI specification 2.5 section 12.3:
EFI encompasses the use of FAT32 for a system partition, and FAT12 or FAT16 for removable
media.
I would suggest to use OVMF (Open Virtual Machine Firmware) directly with QEMU not through VirtualBox. Why ?
Because you can hack OVMF and learn how it works internally, this give you better understanding, VirtualBox hide internals and I'm not sure if it allow firmware replacement
OVMF was developed initially for QEMU and it is adapted by various other virtual machines, because of that there is much more support for OVMF on QEMU then OVMF on VirtualBox
using QEMU also give you ability to emulate your hardware and write drivers/applications in UEFI that use it
I wrote beginners tutorial that help setting up development environment needed for UEFI application development using OVMF.
More about OVMF.

linux application to control optical media

I want a graphical application for Linux that displays the contents of CD/DVD/blu-ray drives and allows play or eject, and I'd like the solution to be general, so that I can donate it to Linux Mint, that is any drive type and any number of drives. In my system I have three dvd drives and a blu-ray drive.
I'd like to write it in bash using the dialog functions inside a terminal window but I need to have the dialog displayed in perpitude therefore, I need an interrupt to signal when the drive is opened or closed - what signal could I trap? Also, how can I include logic to select a program to play the media depending on the media type.
Also, should I consider writing it in java, python, C++, or other language and if so how to get hardware information (such as the number and capability of drives, and the type and title of optical media in drive)?
Ignoring the side of "I want to donate this to Linux Mint", which I believe is a bit pretentious, there is a eject utility in Linux.
The source code of that can be found here:
https://git.kernel.org/cgit/utils/util-linux/util-linux.git/tree/sys-utils/eject.c
In that code, there is also code to sense if the drive is open, closed, has no disk, etc.
To do CD or DVD playback is a whole other kettle of fish. To write a audio-player is not entirely trivial (even in the simple case of a straightforward PCM encoding, obviously MP3 is a fair bit more complex again), and a video-player is a lot more than that.
To "select a program", you'd have to know what the available players may be called, and, if you want to be fancy, check which ones are actually installed. I'm not aware of any really clever way of achieving that, beyond having a list of players in your code (which needs to be updated). In fact, I know that is how the photo viewer geeqie works when you want to edit a shot: it has a list of "known editors", and it scans the PATH to find which ones are available.

Boot a program that would choose a particular Ubuntu iso and boot from it

I want to create a program that I would load on an external hard drive such that it a computer could boot from it. The basics of this program would be to list some Ubuntu LiveCD. Then, the user would select a LiveCD and I would then boot the chosen LiveCD.
What I want to know is how can I boot a c or c++ program that would list (probably from a text file) the different versions available. I know how to do that in c++ (pretty simple). However, what I don't know is how to boot this program. What kind of assembly code could I use to launch such a program?
Are there any books or tutorial that I could read about this topic?
What you are asking is incredibly hard. You are asking how to write a boot loader, which is a very complex thing to do. You will need to handle video output, mouse/keyboard, usb drivers, mounting disks, etc, etc - you are writing a mini-OS in fact.
For tips/examples take a look at GRUB.
You might "cheat" and use an existing boot loader to load a tiny linux kernel from which you can use C to boot the ISO, but this still is very hard thing to do. I would suggest looking into alternatives.