Maragda: Running Linux from CD
There are three things to do:
Prepare a software installation containing all the packages you want on Maragda; we'll call it source installation.
Distribute the source installation between two big files, ROOT.FS and WHOLE.FS; they both should fit inside an ext2 file system.
Develop a boot mechanism in charge of detecting the CD-ROM drive and locating ROOT.FS on it. Then, it should load ROOT.FS as a RAM disk, preparing it to be the root file system, and finally it should leave the boot process to continue on the root file system.
All the necessary pieces that do the work (mainly shell scripts) are arranged into two working directories:
boot: in charge of developing the boot mechanism
system: contains the tools to create ROOT.FS and WHOLE.FS from the source installation
I should mention that, perhaps, some device files (files under /dev) might not be correct due to the copy from an ext2 file system to a CD file system (iso9660). In this case, you should replace those files by the corresponding /dev files from your system.
Now, let's outline the relevant steps in the building process and describe the purpose of each shell script as well as the main configuration files. Minor details are left out of the explanation; if you decide to build your own Maragda-like system, you should consult doc/developer.html on the CD and carefully read each shell script on the working directories.
Figure 1 shows the main steps to be taken in the boot process.
The target here is to create a bootable floppy disk that will be merged into the CD to make it bootable.
The boot loader for setting up the floppy is syslinux. It can boot a Linux system from a DOS-formatted floppy containing a kernel and an initial RAM disk file (compressed) with the root file system inside.
So, we'll need a kernel along with its loadable modules. (Only the kernel is required now.) I will not explain here how to compile a kernel but will only remark that it should support
CD-ROM (iso9660 file system)
initial RAM disk
(You can find my kernel configuration on doc/developer.html.)
Now we have to build the initial RAM disk (initrd) holding the root file system for the first-stage boot. The easiest way to obtain one is to borrow it from a floppy rescue disk. But, I follow the “do it yourself” philosophy. The directory boot/initrd is a skeleton of the contents of my RAM disk. The script named Init_initrd fills that directory from scratch, copying files from the source installation. It creates directories, copies a subset of dev-files onto initrd/dev and populates initrd/bin. The size of an initrd must be kept small, so you should leave only the essential binaries on initrd/bin. Then you must run Cp_lib; it will copy the libraries on initrd/lib for the binaries you left before.
When you are finished, run Make_initrd_fs_gz. It will create a file (Minix formated), copying to it the files on boot/initrd and then compress it.
Now you have a kernel and an initial RAM disk. Next, you should generate the bootable floppy with syslinux. The syslinux configuration file, SYSLINUX.CFG, is contained in boot/syslinux_boot_floppy-20MB. The line:
append initrd=initrd.gz ramdisk_size=20480 vga=0x315
instructs the boot loader to load the initial RAM disk file on the floppy and passes two parameters to the kernel to inform it of the size of the RAM disk and the framebuffer video mode. The RAM disk size should be customized to the size of the ROOT.FS used.
Finally, the bootable floppy is created by the Write_syslinux_boot_floppy script. It will also extract a raw image of the floppy to be merged onto the CD.
The most relevant file here is boot/initrd/linuxrc (/linuxrc on the initial RAM disk) because this script is executed at boot up. It performs the main tasks intended for this stage:
It searches for the device holding the files:
/MARAGDA /system/ROOT.FS /system/WHOLE.FS
If that is found, it then states which device will be the new root file system:
mount -n /proc /proc -t proc echo 0x101 > /proc/sys/kernel/real-root-dev (0x101 represents /dev/ram1)
It dumps WHOLE.FS on /dev/ram1.
Finally, it writes on cdrom_dev which device the .FS files were found. This file will be consulted during the second-stage boot.
If everything goes okay, the boot process will continue by executing init, already in the new root file system. The old file system (initrd) will remain mounted under /initrd on the new one.
Webinar: 8 Signs You’re Beyond Cron
11am CDT, April 29th
Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.Join us!
|Android Candy: Intercoms||Apr 23, 2015|
|"No Reboot" Kernel Patching - And Why You Should Care||Apr 22, 2015|
|Return of the Mac||Apr 20, 2015|
|DevOps: Better Than the Sum of Its Parts||Apr 20, 2015|
|Play for Me, Jarvis||Apr 16, 2015|
|Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites||Apr 15, 2015|
- Tips for Optimizing Linux Memory Usage
- "No Reboot" Kernel Patching - And Why You Should Care
- DevOps: Better Than the Sum of Its Parts
- Return of the Mac
- Android Candy: Intercoms
- Drupageddon: SQL Injection, Database Abstraction and Hundreds of Thousands of Web Sites
- Designing Foils with XFLR5
- Non-Linux FOSS: .NET?
- Play for Me, Jarvis