Linux CD-ROM Game System |
||
YAMAMORI Takenori <yamamori> |
We have to well understand the mechanism of booting Linux in order to make this CD-ROM game system. At first I show the following that is a flowchart of the system start after the power supply switched on. It is a usual Linux system installed in a hard drive.
+--------------------+ | Power supply ON | +--------------------+ | +--------------------+ | PC BIOS starts | +--------------------+ | +---------------------------------------------------+ | BIOS looks for a bootable media according to the | | setting and loads a program(=LILO) written on MBR | | of a hard drive, and then LILO gains control. | +---------------------------------------------------+ | +---------------------------------------------------------------+ | LILO loads a kernel(vmlinuz) and an initial RAM disk | | (initrd)(*Note 1) by BIOS, and then the kernel gains control. | +---------------------------------------------------------------+ | | (BIOS is no longer used from now on) | +------------------------------------------+ | The kernel expands initrd and mounts it | | as a temporary root file system. | +------------------------------------------+ | +----------------------------------------------------------------------+ | If an executable /linuxrc exists in the initrd, | | the kernel executes it(*Note 2). | | Usually, /linuxrc is a shell script, which does necessary processing | | before mounting a real root file system. | | By the system that use SCSI hard drive as a real root file system, a | | SCSI module is loaded by an insmod command described in the /linuxrc.| +----------------------------------------------------------------------+ | +--------------------------------------------------------------------+ | After the /linuxrc is finished, the kernel mounts a real root file | | system which may be /dev/hda1 or /dev/sda1, for example(*Note 3), | | and then executes sbin-init on the real root file system. | +--------------------------------------------------------------------+ | +----------------------------------------------+ <- In Vine 2.0, a message of | At first, init executes /etc/rc.d/rc.sysinit | "Welcome to Vine Linux" | according to a description of /etc/inittab. | is displayed by a color +----------------------------------------------+ in execution of rc.sysinit. | +---------------------------------------+ | Next, init executes /etc/rc.d/rc with | | a default run level as an argument. | +---------------------------------------+ | +----------------------------------------------------------------+ | If it is run level 3, for example, /etc/rc.d/rc executes | | shell scripts like SnnXXXX(nn=number) under /etc/rc.d/rc3.d | | directory in order of S00XXXX to S99XXXX with a start argument.| +----------------------------------------------------------------+ | +-----------------------------------------------------------------------+ | According to a description of /etc/inittab, only mingetty(CUI login) | | is activated in case of run level 3, or xdm(GUI login) is activated | | moreover in case of run level 5, and then it becomes login wait state.| +-----------------------------------------------------------------------+ |
In this CD-ROM game system, the flowchart of the system start becomes like the following.
+--------------------+ | Power supply ON | +--------------------+ | +--------------------+ | PC BIOS starts | +--------------------+ | +-------------------------------------------------------------------+ | BIOS looks for a bootable media according to the setting and | | finds El Torito bootable CD-ROM with a floppy disk emulation mode.| +-------------------------------------------------------------------+ | +----------------------------------------------------------------+ | BIOS loads a program(=LILO) from a boot sector of the emulated | | floppy disk image in the CD-ROM, and then LILO gains control. | +----------------------------------------------------------------+ | +---------------------------------------------------------------------+ | LILO loads a kernel (vmlinuz) and an initial RAM disk (initrd) from | | the emulated floppy disk by BIOS, and then the kernel gains control.| +---------------------------------------------------------------------+ | | (BIOS is no longer used from now on) | +------------------------------------------+ | The kernel expands initrd and mounts it | | as a temporary root file system. | +------------------------------------------+ | +-----------------------------------------------------------------------+ | The kernel executes /linuxrc in the initrd. | | A special command of cdmount (described later) is executed according | | to a description of /linuxrc so that the CD-ROM of the game system | | is mounted on a /mnt/cdrom directory. | | Furthermore, the kernel changes a device of real root file system to | | the initrd itself by some commands in /linuxrc, and finishes /linuxrc.| +-----------------------------------------------------------------------+ | +--------------------------------------------------------+ | Because the real root file system is the initrd itself,| | the kernel just executes /sbin/init which is symbolic | | linked to /mnt/cdrom/sbin/init in the CD-ROM. | +--------------------------------------------------------+ | +----------------------------------------------+ <- In Vine 2.0, a message of | At first, init executes /etc/rc.d/rc.sysinit | "Welcome to Vine Linux" | according to a description of /etc/inittab. | is displayed by a color +----------------------------------------------+ in execution of rc.sysinit. | +-----------------------------------------------------------+ | The default run level has been set to 1(single user mode) | | so that /etc/rc.d/rc is executed with an argument 1. | +-----------------------------------------------------------+ | +-------------------------------------------------------------------+ | /etc/rc.d/rc executes a shell script under /etc/rc.d/rc1.d from | | S00single sequentially(*Note). And a shell script of S99game made | | in this directory especially is executed last. | +-------------------------------------------------------------------+ | +----------------------------------------------------------+ | In S99game, a PATH is set, a floppy disk for a save-data | | is mounted, the X Window System is launched by xinit. | | Just an execution command of a game has been written on | | a .xinitrc so that the game starts directly. | +----------------------------------------------------------+ |
The mechanism of booting is considerably complicated, but you should understand the abstract mentioned above. Basically, the CD-ROM for the game system itself is a copy of a usual Linux system which includes whole directory tree from the root. However, because we cannot mount the CD-ROM on the root directly, at first we mount initrd as root, and then we mount the CD-ROM on /mnt/cdrom in the inside of initrd. Here, we have to use symbolic links well so that the directory tree after the mount of the CD-ROM can be seen as the same as usual Linux.
By the way, it is the CD-ROM game system which needs no hard drive, but we have to install Linux on a hard drive once as a base system and set it in a condition that a game starts with a single user mode, in order to make the CD-ROM. That is, we have to do the following procedure.