LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1602|回复: 0

ZZ -XMAME on CD Cookbook

[复制链接]
发表于 2005-1-5 19:43:14 | 显示全部楼层 |阅读模式
XMAME on CD Cookbook
http://www.phased.co.uk/xmame/cookbook.html

This section provides a brief cookbook to creating your own bootable CD complete with XMAME and any Rom files you may have. Please note that the author has not fully tested this process and accepts no resposibility for any damage or frustration you may cause. It is also your responsibility to make sure that you do not infringe any copyright via the use of Roms of software for which you have no license agreement.

Note well that my C programming skills are "rusty", and the two programs provided are at best "flaky".

Overview of the Process
In order to create a bootable CD the following actions are required:-

1) create a stripped down version of GNU/Linux and adapt the filesystem to read only

2) install XMAME.SVGALIB, your roms and the menu system

3) create a bootable ISO image

4) write the image to a CD

I have based all of the operations around Redhat 6.2, simply because "it works", I have tried to create a system based upon later kernels, but had problems with the creation of a fully working bootable ramdisk image. Also the earlier kernel seemed to like my CD drive, whereas later versions didn't seem to work properly.

This whole process can be made much simpler,by using an ISO image that I have already created. However it is over 300Mb in size and I do not have this much ftp/http space available, email me if you can provide this and I will upload a much simpler set of instructions.

Creating the GNU/Linux System
I am assuming that you have access to another GNU/Linux system aside from the one you will use to create your CD, this is important as you are going to have to compile some programs using GCC, and in order to save space we don't want to install GCC upon the stripped down system. I guess you could install GCC, compile your programs and then remove it if you wish, personally I can't be bothered.

Right, lets get started !

Installing Redhat 6.2
First get hold of a copy of Redhat 6.2 and burn it to a CD, you can find the ISO image here if you want some help in burning the ISO image to CD then look here

Now, install Redhat 6.2 to a partition or the complete hard disk of that computer you just happen to have lying around doing nothing. Remember that you are going to create an ISO image on this computer that is over 350Mb in size, so you need to have at least 800Mb worth of disk space for this partition and either a CD writer attached or a network connection to a computer with a CD writer.

When installing Redhat, make the following choices:-

From the first menu screen type "text" at the boot: prompt

Select your language version, follow prompts to Screen titled "Installation Type", here select "Install Custom System"

Follow the screens to partition your drive, make sure you select LILO as the boot loader, follow the other screens, create a root account, don't bother with any others. Then you should eventually get to the screen titled "ackage Group Selection", deselect everything (unless you are going to burn your ISO on another PC, if so, leave "Networked Workstation" selected). Then select "Select individual packages", on the next screen, scroll down to "Applications/System" and select "mkisofs" you will need this later.

Now complete your installation of Redhat 6.2

Creating the XMAME Environment
On your usual GNU/Linux environment do the following

Download the latest version of XMAME from here

Compile XMAME for SVGALIB support, this is done by copying the makefile makefile.unix to Makefile and editing it such that the following line exists:-

DISPLAY_METHOD=svgalib

..and all other DISPLAY_METHOD lines are commented out. A copy of the Makefile which I use is located here

Type make and you will soon find a copy of xmame.svgalib in the xmame directory.

Next download the CD Mounting utility from here and a copy of the crude Xmame.svgalib front end from here

Compile the CD Mounting utility with the following command:-

gcc -static -s -o cdmount cdmount.c

Compile the XMame.svgalib front end with the following command:-

gcc -static svgalib_menu_live_v1.c -lmenu -lncurses -o smenu

You should be left with two binaries, smenu and cdmount

On your Redhat 6.2 XMame system do the following:-

Create the directories for XMame and your Roms

mkdir /root/xmame/roms -p

Copy xmame.xvgalib, smenu and cdmount into /root/xmame

Copy your roms into /root/xmame/roms

Now create a script to launch XMame and the menu system:-

vi /etc/rc.d/rc1.d/S99game

_________________________________________
#!/bin/bash
clear
while [ 1 ]; do
clear
/root/xmame/smenu
if [ $? = 1 ]; then
exit
fi
clear
done
__________________________________________
chmod +x /etc/rc.d/rc1.d/S99game

Check that it all works ok !

/etc/rc.d/rc1.d/S99game

You should see a menu dialogue allowing you to select your Rom file, pressing ENTER should then run XMame with your Rom file

Creating the Read-Only Filesystem
Now things start to get a little more involved, as we are going to run entirely from CD it is important that the OS runs from a read only filesystem. So the following changes are necessary:-

Boot the OS in single user mode
vi /etc/inittab

Change id:3:initdefault to id:1:initdefault

Remove the Swap file
vi /etc/fstab

Find the line that looks something like: "/dev/hda2 swap swap defaults" and change it to "#/dev/hda2 swap swap defaults"

Don' t execute depmod
We have a read only file system and depmod writes to modules.dep (which we have made readonly)

chmod a-x /sbin/depmod

Change /etc/mtab
Again, we have a read only filesystem and cannot write to /etc/mtab, so:-

rm /etc/mtab

ln -s /proc/mounts /etc/mtab

Move /var/lock, /var/run and /var/tmp
Boot scripts write to these directories, later on we are going to create a ramdisk where /tmp will be mounted to, so we move these files and create symbolic links:-

cd /var

mv loc lock-0

mv run run-0

mv tmp tmp-0

ln -s /tmp/var/lock .

ln -s /tmp/var/run .

ln -s /tmp .

Edit rc.sysinit
The directories linked above need to be created in the rc.sysinit scriot, before other scripts try to use them

vi /etc/rc.d/rc.sysinit

FIND the line: "action "Remounting root filesystem in read-write mode"....

ADD BELOW the line:-

mkdir -p /tmp/var/run /tmp/var/lock/subsys /tmp/var/lock/console

Edit halt script
The whole system will crash if you try to shutdown after booting from CD-ROM due to the unusual filesystem mount. so:-

vi /etc/rc.d/init.d/halt

FIND the lines: "/sbin/fuser -k -m $sig $remaining > /dev/null"

ADD BEFORE this line:-

break

Creating the Bootable CD-ROM
Making a bootable CD is split into two stages, first a Ramdisk image is created, this is used as the first boot image and mounts the CD filesystem.. Next the ramdisk is loaded within a linux boot sector and written to the CD along with the readonly filesystem that has been previously created.

Making the RamDisk Image
/sbin/mkinitrd -v -f /boot/initrd-game.img 2.2.14-5.0 (note insert your kernel image version here if different)
zcat /boot/initrd-game.img > /tmp/initrd-game
mkdir /mnt/tmp
mount -o loop /tmp/initrd-game /mnt/tmp
cd /mnt/tmp
mkdir -p mnt/cdrom
mv bin dev etc lib mnt/cdrom
ln -s mnt/cdrom/* .
ln -s mnt/cdrom/usr mnt/cdrom/sbin mnt/cdrom/var mnt/cdrom/root .
touch fastboot
mkdir proc
mkdir tmp chmod 1777 tmp
cp -a /dev/hd[abcd]* /dev/scd0 /dev/sda* mnt/cdrom/dev
cp -p /root/xmame/cdmount .
vi linuxrc
_________________________________________________

#!/bin/sash

echo "Mounting CD-ROM from Ramdisk"

/cdmount

mount -t proc none /proc

echo 0x100 > /proc/sys/kernel/real-root-dev

umount /proc

___________________________________________________

cd /
umount /mnt/tmp
/sbin/losetup -d /dev/loop
gzip -9 < /tmp/initrd-game > /boot/initrd-game.img
When you are testing you may find that you need to carry out these operations more than once, to make life a little bit easier I have created two shell scripts, this one for making and mounting a ramdisk image and this one for unmounting it.

Creating a Boot Sector
The CDROM needs a boot image to boot from, this is created by making a boot floppy and then adding the ramdisk image to it:-

INSERT A FLOPPY DISK

/sbin/mkbootdisk -v 2.2.14-5.0 (insert your kernel image version here if different)

mount /dev/fd0 /mnt/floppy

rm /mnt/floppy/initrd.img

cp -p /boot/initrd-game.img /mnt/floppy/initrd-game.img

vi /mnt/floppy/etc/lilo.conf

__________________________________________________
boot=/dev/fd0
timeout=30
message=/boot/message
prompt
image=/vmlinuz-2.2.14-5.0
label=MAME-CD
root=0x101
initrd=/initrd-game.img
___________________________________________________
vi /mnt/floppy/boot/message

________________________________________________________________
MAME CD is SIMPLY the GREATEST thing SINCE sliced BREAD
<or insert your own boot message>
________________________________________________________________
/sbin/lilo -r /mnt/floppy
umount /mnt/floppy
mkdir /images
dd if=/dev/fd0 of=/images/boot.img bs=18k
Making the ISO Filesystem
Next you will create a complete filesystem for the bootable CD.

cd /tmp

TZ=UTC mkisofs -R -J -o MAMECD.iso -b images/boot.img -x /tmp -x /proc

This will leave you with a file /tmp/MAMECD.iso which is a complete image of your bootable system, this needs to be written to a CDR (or RW although some CD drives will not boot CDRW disks). This can be done under linux using:-

cdrecord -v dev=<your cd writer> speed=<your speed> -pad -dao MAMECD.iso

Or by using a Windows CD burning package

Booting the CD
You can boot the CD using one of two methods:-

Either change your Bios settings to boot from CD
Or insert both the CD you have created AND the floppy you created earlier and boot from the floppy diskette
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表