embedded linux root filesystem on disk - linux

I would like to know how to create a root file system for an embedded Linux system that is stored on a hard drive. Would this be the same procedure if it was on a flash card?

No, your boot loader would need to know how to initialize the hard drive. With flash cards the boot loader initializes as an MTD and can understand the file system.
You might be able to make progress with an IDE HD and IDE support in the boot loader.
On a regular computer (e.g., PC) the BIOS takes care of initializing all peripherals, like a primary HD.

Typically Linux embedded system is not operate directly in disk based filesystem, but use a mechanism to load the OS from a persistent storage (hard drive, flash card or memory, etc.) to volatile memory space (RAM). In general, these OS's file (commonly called as firmware) are kernel image file and a initrd (Initial RAM Disk) file, the initrd file contains root filesystem's files and any system's related files, upon boot the initrd will be uncompressed and deployed into a RAM based filesystem such as tmpfs, once completed, the system will use the tmpfs filesystem just like any disk based filesystem (ext3, btrfs), for example to run init program or script to do system initialization. Embedded system is tend to minimize I/O on persistent storage for some advantages: reliability, speed and cost.
You can learn how to accomplish this by learning any general Linux distribution on how to create and modify a initrd file.

Related

UEFI Memory location

I am attempting to write an x86_64 PC emulator. I was wondering in what memory location the UEFI is mapped. I know that a BIOS is usually mapped from 0xf0000-0xfffff and 0xf0000000-0xffffffff. Is UEFI mapped to the same locations?
Yes, the UEFI firmware is loaded to the same locations as well as legacy BIOS. Otherwise, why is cs:ip is pointing 0xFFFFFFF0 in its initial state?
Check out the OvmfPkg in EDK II. This is an open-source UEFI firmware for virtual machines. You can load it into famous emulators like Bochs, QEMU.
You can also use VMware's EFI firmware, but in that it is proprietary, you might want to read VMware's license before you really want to proceed with it.
UEFI is not loaded in a specific memory location. Something needs to be placed where the processor starts fetching instructions, and then SEC and PEI stages prepare for DXE to be uncompressed somewhere dynamically - loading individual PE/COFF as it goes.
The way you find out what memory regions are reserved is by calling the GetMemoryMap boot service at runtime.
You may find the documentation of the existing EDK2 virtual machine port helpful.

Best way to configure root file system in an embedded linux environment

I am developing scripts for my embedded board ( a zynq board) and I need some scripts to be loaded prior to login. Since the filesystem is loaded into DDR memory, any modifications will be erased after a reboot. So for my development, I have to remove the SD card, then mount the filesystem on my development machine and after that, I have to unmount the FS and wrap u-boot headers on top of it. Finally write everything to SD card and see if everything is working or not. I was wondering if there is any better solution??? like reloading file system while linux is running???

Associating device node with physical disk manually

I am new to the Linux architecture, i was wondering how one can create a device file like sdb or sda and associate it with a physical disk in absence of udev, if it is possible. I have created a hard disk in VBOX now I am building a Linux system from scratch which has very minimal features and doesn't have udev. So is it possible to create device file in the minimal Linux and associate the VBOX hard disk to the device file.
Used devtmpfs for /dev and it worked automatically without udev.

Creating multi-OS boot CD using codes

Is it possible to write coding that will allows one to store multiple OS (in their ISO format) into a CD/DVD and turn them into a Live CD/DVD for later use?
Yes. You would probably want to use Grub4DOS as your boot loader because it can boot operating systems from disk images, which, to my knowledge, other boot loaders don't do. So you could potentially load up a DVD-ROM with Grub4DOS and several live CD isos so that you could then boot multiple operating systems from that DVD-ROM.

Mounting ISO image from USB at boot time

Is it possible to mount a ISO image from USB disk and to use it as a filesystem at boot time(with grub)? I ask it because I would like to put the kernel linux image and an ISO to be used as a filesystem(with fedora bootstrap) into an USB disk(without creating new partitions, etc.), as it is possible to do by using Qemu, for example.
Qemu is a virtualization/emulation environment. Grub is a bootloader, designed to get a kernel loaded into memory and start it executing. Neither program is directly related to your question, although you could certainly use Qemu to execute a VM that uses Grub to start Linux to do what you want.
Modern Linux distributions create an initrd, which the bootloader puts into memory for the kernel to use as its initial root file system. The initrd does things like loading the modules necessary to access the hard disks where the real root file system lives. In your case, you should look at having the initrd find your ISO, mount it, and use it as the root.
The contents of initrd vary based on what distro you're using. I'd grab a livecd from somewhere, dump its initrd's contents with zcat /boot/initrd-2.6.whatever.img | cpio -id, and check out what it's doing. Look for the init file, which will be the first user-space process run by the kernel.
Grub's loopback feature should allow you to boot a kernel and initrd from within an ISO image. Unfortunately, there's no way to allow the kernel to mount a loopback device as the root filesystem, so I think you're out of luck.

Resources