LIVE.HOWTO How to Create a Live Distro CD with Your Own Application using Linux author marco corvi date oct. 2003 version 1.0 References: 1) P. Baratta "LFS, live CD from scratch" Linux Magazine Luglio/Agosto 2003 44-49. This is the main reference i followed during the development of this document. 2) http://www.linuxfromscratch.org Linux From Scratch 3) http://www.linuxfromscratch.org Beyond Linux From Scratch 4) Linux documentation in the Documentations subdirectory of the source distribution. 5) http:syslinux/zytor.com/iso.php Isolinux documentation. 6) http://absinth.dyndns.org/cgi-bin/man/man2html Linux man pages, expecially for mkisofs and cdrecord. 7) T. Foecking C. Hesse, boot-cd_easy 0.1f, http://archives.linuxfromscratch.org/mail-archives/hints/2002-February/000505.html 8) W. Almesberger, "Lilo Generic boot loader for Linux", User Guide (Version 21) 9) S. van Vugt, "Creating a complete distribution on CD", Nov. 04, 2003 Linux Journal http://www.linuxjournal.com/print.php?sid=7233 Table of Contents + Prepare Your Distro + Customize Your Distro + X-Server Configuration + Make the CDrom + Things to Remember Overview This HowTo explains how to make a live CD distro containing your application. In order to maintain, test, and distribute the live CD we need to be able: - to boot the distro system from the harddisk partition with the normal booting procedure (maintenance); - to boot the distro from the CDrom (distribution); - to boot the distro from the harddisk emulating a boot from CDrom (test). To have all these functionalities we need to customize the booting procedure. The test and distro booting use the same initial ramdisk (initrd), but have different init scripts (linuxrc). The init script of the distro must finds the cd media and load the system from it in a ramdisk, while that of the test uses the harddisk partition without the cd media detection. Both systems need to be able to write into certain directories. Since the CDrom is readonly, these directories are links to directories contained in a "needwrite" directory. These are copied in a tmpfs, and then the tmpfs is remounted in "needwrite". The normal booting scripts do a filesystem check and mount the harddisk partition (and possibly also a swap partition). These must be skipped during the test/distro booting. For this purpose the init script (linuxrc) also touch-es a file in a writable directory, whose presence tells the booting scripts to skip certain filesystem checks and mounts. The relevant scripts are modified accordingly by adding a test on the presence of this file. Finally the configuration file for XFree86 must be generated automatically. This is done by the X server itself with the option -configure. The X server is then started again with the configuration file by xinit. The file .xinitrc contains the specific application that will be executed. ================================================================================ PREPARE YOUR DISTRO [1] Create a disk partition (about 2 GB) with fdisk. Let it be called /dev/hdb3 for the purposes of this document. [2] Make a filesystem on the new partition mkfs -t ext2 /dev/hdb3 [3] Make a mount point for the new partition/filesystem, and mount it there mkdir /mnt/lfs mount -t ex2 /dev/hdb3 /mnt/lfs [4] cd to the new filesystem and download all the necessary packages for LinuxFromScratch and BeyondLinuxFromScratch. I did all the downloads in /mnt/lfs/usr/src/downloads and uncompressed the packages in /mnt/lfs/usr/src cd /mnt/lfs mkdir bin boot dev etc home lib opt proc root sbin usr tmp var mkdir initrd mkdir -p mnt/{initrd, cdrom, floppy, disk} cd usr mkdir -p bin etc include lib local share sbin src/downloads cd src/downloads wget ... The url is http://www.linuxfromscratch.org [5] Follow the instructions in the two books of LinuxFromScratch and BeyondLinuxFromScratch and build your system and the additional packages you need. You need the old system to build the static building environment. After that you can chroot to /mnt/lfs and do everything inside it. chroot /mnt/lfs /static/bin/env -i HOME=/root TERM=$TERM \ PS1='\u:\w\$ ' PATH=/bin/:/usr/bin:/sbin:/usr/sbin:/static/bin \ /static/bin/bash --login Afterwards when the system is complete, you can chroot to it with the command chroot /mnt/lfs /usr/bin/env -i HOME=/root TERM=$TERM \ PS1='\u:\w\$ ' PATH=/bin/:/usr/bin:/sbin:/usr/sbin \ /bin/bash --login Remember to mount proc and umount it before exiting mount -t proc proc /proc umount /proc [6] Put your application in the system. Let's say it is /root/kblue/blue: "blue" is my application, i created a directory /root/kblue with its files, and compiled it there. [7] You might want to strip debugging symbols from the executables and the libraries. For the executables use strip program_name For the libraries use strip --strip-unneeded library_name Another option of strip, "-o" allows to specify the outpt file. ================================================================================ CUSTOMIZE YOUR DISTRO [1] Make sure that the kernel has built in support for 386 CONFIG_X86 and CONFIG_M386 MTRR CONFIG_MTRR isa bus CONFIG_ISA pci bus CONFIG_PCI modules CONFIG_MODULES=y module loader CONFIG_KMOD ramdisk CONFIG_BLK_DEV_RAM ramdisk size 4096 CONFIG_BLK_DEV_RAM_SIZE=4096 initrd (initial ramdisk) CONFIG_BLK_DEV_INITRD ext2fs CONFIG_EXT2_FS (or ext3 or reiserfs) ram fs CONFIG_RAMFS tmp fs CONFIG_TMPFS iso9660 fs CONFIG_ISO9660_FS proc fs CONFIG_PROC_FS fat fs (M) CONFIG_FAT_FS msdos fs (M) CONFIG_MSDOS_FS floppy device CONFIG_BLK_DEV_FD loop device (M) CONFIG_BLK_DEV_LOOP IDE CONFIG_BLK_DEV_IDE ATAPI AGP CONFIG_AGP You might add also scsi support. Not necessary altogether: Code maturity level options PCMCIA/CardBus support PCI Hotplug Support Binary emulation of other systems Memory Technology Devices (MTD) Parallel port support Plug and Play configuration Multi-device support (RAID and LVM) Cryptography support (CryptoAPI) Appletalk devices QoS and/or fair queueing Network testing Telephony Support Fusion MPT device support IEEE 1394 (FireWire) support I2O device support Network device support Amateur Radio support IrDA (infrared) support ISDN subsystem Old CD-ROM drivers Input core support I2C support Joysticks Watchdog Cards Ftape, the floppy tape device driver PCMCIA character devices Multimedia devices Video For Linux Radio Adapters Crypto Hardware support Network File Systems Sound USB support Bluetooth support Kernel hacking [2] Build the kernel and install it while you are still chroot-ed in /usr/src/linux make dep make bzImage make modules make modules_install cp arch/i386/boot/bzImage /boot/lfskernel cp System.map /boot depmod -a 2.4.?? -F /boot/System.map <-- use your kernel version number [3] Download syslinux (which contains isolinux) http://syslinux.zytor.com/ (by Peter Anvin) Copy isolinux.bin in /boot Write the /boot/isolinux.cfg file: default lfs <-- label name label lfs kernel lfskernel append initrd=/isolinux/initrd.gz root=/dev/ram0 \ init=/linuxrc ramdisk_size=10000 Notes: - Use "root=/dev/rd/0" if devfs is configured in the kernel, instead of "root=/dev/ram0" - Add the option "rw" if you need to write into the init ramdisk. - "ramdisk_size" is the size of the ramdisk in 1K units (10000 = 10 MB). The default value is 4096 (4 MB) - isolinux resolves filenames by searching in its current directory if the filename does not have a leading slash '/'. Otherwise it searches in the root directory. - The isolinux docs suggests to use the directory isolinux instead of boot. I made boot a link to isolinux: cd / mv boot isolinux ln -s isolinux boot - The argument of append is passed to the kernel therefore the syntax must be what the Linux kernel expects: - the initrd filename is the path in the distro media (/isolinux/initrd.gz) - the init script is the path in the init ramdisk (/linuxrc) See the Linux source Documentation/kernel-parameters.txt for the list of parameters that can be passed to the kernel. [4] Download and compile isoinfo http://www.ibiblio.org/pub/Linux/utils/disk-management/ cd /usr/src/isoinfo-0.03.02 ./configure make make install Notes. - "./configure" simply checks that you are using Linux. Edit the Makefile and set the installation target directory to /usr. - "make" produces a warning. To avoid it you have to change a line in the code. Replace string[i]=ptr[i++]; with string[i]=ptr[i]; i++; - "make install" installs /usr/bin/isoinfo and its man page [5] Make the initial ramdisk dd if=/dev/zero of=/boot/initrd bs=1024 count=3000 mke2fs -m 0 -i 1024 -F /boot/initrd mount -o loop -t ext2 /boot/initrd /mnt/initrd Note. Some options of mke2fs: -m specifies the percentage of blocks reserved for root (default 5%) -b block size -i bytes per inode -F force mke2fs to run even if the device is not block, or is mounted -c check for badblocks before creating the filesystem -L specifies the volume label -N specifies the number of inodes Populate it cd /mnt/initrd mkdir bin lib dev mnt proc Copy in bin bash mount grep umount mkdir echo cp test chroot pivot_root awk isoinfo expr rm test touch sleep (rm is not used) and make the two symlinks [ --> test and sh --> bash Copy in lib (version numbers may differ) libncurses.so.5 libdl.so.2 libc.so.6 ld-linux.so.2 libm.so.6 Copy in dev (scd* only if you built scsi support into the kernel) console hd* scd* null ram Copy linuxrc in the root of initrd. If the file is not big enough you may change its size umount /mnt/initrd e2fsck -f /boot/initrd resize2fs /boot/initrd 4000 [6] Prepare the linuxrc script in the root of the initrd. In essence, it does the following ( when it starts the working directory is the root of the init ramdisk ): mkdir new_root mount media_device /new_root cd /new_root compute the ram memory mount a tmpfs of /new_root/fake/ramdisk copy directories from /new_root/fake/needwrite to /new_root/fake/ramdisk bind /new_root/fake/needwrite to /new_root/fake/ramdisk touch /root/no_mountfs to inform init scripts to skip check/mount pivot_root putting the old root on /initrd umount proc from the /initrd, exec chroot, umount initrd, exec /sbin/init with name init.new (option -a) It is important that - a directory /initrd exists in the media_device root - chroot exists both in the initrd and in the new_root - dev/console is given as a relative path to the last exec See man pivot_root.8 for more informations. My script is listed in the appendix. It includes also the testmem script. The "sleep" commands are used to allow monitoring the script execution during the development. They should be removed at the end. [7] Make a second init script, say "linuxrc-em", which emulates the CDrom boot using a harddisk partition. This is useful during development to check that everything works all right, before actually creating the iso image and writing it to the CD, because these two last steps take quite a considerable amount of time. This script does not perform CD media detection, but forces the device and media type. Change the two variable definitions in the lines LFS_CDROM_DEVICE="" LFS_CDROM_MEDIA="iso9660" if [ "$LFS_CDROM_DEVICE" = "" ]; then ... in linuxrc with LFS_CDROM_DEVICE="/dev/hdb3" LFS_CDROM_MEDIA="ext2" and drop the subsequent "if [ ..." completely. Substitute your system values for the partition name and filesystem type. "linuxrc" is used in the configuration file of isolinux. "linuxrc-em" is used in the lilo (or grub) section. [8] When you are done, umount initrd and compress it, cd /boot gzip -9 initrd [9] Modify etc/rc.d/init.d/checkfs, /etc/rc.d/init.d/mountfs, and etc/rc.d/init.d/swap Change /etc/rc.d/init.d/checkfs by adding after the "fastboot" check a test on the existence of /root/no_mountfs if [ -e "/root/no_mountfs" ]; then echo "no mountfs: skipping filesystem checks ..." exit 0 fi Make a similar change in etc/rc.d/init.d/swap. Change /etc/rc.d/init.d/mountfs in the start) clause. Skip the recording of mount-ed filesystems, and the mounts of the filesystems in /etc/fstab if there is the file /root/no_mountfs if [ ! -e "/root/no_mountfs" ]; then echo "Recording existing mounts in /etc/mtab..." > /etc/mtab ... [10] Now you can add your new LinuxFromScratch system to your bootloader (do this in your old environment). Copy the lfskernel in the /boot directory of your environment. cp /mnt/lfs/boot/lfskernel /boot vi /etc/lilo.conf (or /boot/grub.conf) Then edit the lilo/grub configuration file and add two sections. One for the system boot from the harddisk partition in the normal way. The other for a CDrom boot emulation. # LILO configuration file /etc/lilo.conf ... image=/boot/lfskernel root=/dev/hdb3 label=LFS read-only image=/boot/lfskernel label=LFS-rd initrd=/boot/initrd.gz append="root=/dev/ram0 init=/linuxrc-em ramdisk_size=10000" read-only # End of /etc/lilo.conf Copy also the compressed initrd and reinstall lilo (if you have grub you do not need to reinstall it) cp boot/initrd.gz /boot /sbin/lilo ************************************************************************ * N.B. Whenever you modify the lfs kernel you have to do these steps * * (for grub only the first is necessary as long as you keep the old * * kernel name). * ************************************************************************ [11] Put the directories that need to be writable in a single subdirectory, fake/needwrite, and create the mount point, fake/ramdisk, cd / mkdir -p /fake/needwrite /fake/ramdisk mv home /fake/needwrite; ln -s fake/needwrite/home home mv root /fake/needwrite; ln -s fake/needwrite/root root mv var /fake/needwrite; ln -s fake/needwrite/var var mv tmp /fake/needwrite; ln -s fake/needwrite/tmp tmp mv dev /fake/needwrite; ln -s fake/needwrite/dev dev "tmp" and "var" are necessary. "home" is also useful in case the user want a space to do some work. "root" is not strictly necessary, however my application lives in a subdirectory of it, and needs to write data on the disk. I use it also to write a file (no_mountfs) which tells the three init.d scripts to skip their jobs. [12] Prepare /etc/fstab. This file reflects the hardware on the development environment. The init scripts "swap", "checkfs" and "mountfs" will skip this when booting from CDrom, and during emulation booting. They will follow the usual behavior during normal booting. My etc/fstab is included in the appendix. Make etc/mtab a symlink to /proc/mounts. See the man page for mount.8 [13] The directory hierarchy tree looks like / +- linuxrc +- initrd <- used to mount the initial ramdisk during boot +- XF86Config.new -> root/XF86Config.new +- boot --> isolinux +- isolinux | +- initrd.gz <- initial ramdisk compressed image | +- lfskernel <- kernel | +- isolinux.bin <- bootloader | +- isolinux.cfg <- bootloader configuration file | +- System.map <- kernel symbol file +- fake | +- ramdisk <- empty | +- needwrite | | +- root | | | +- kblue | | | | +- blue | | +- home <- empty | | +- dev <- device files | | +- tmp <- empty | | +- var <- logs, locks, etc. +- etc | +- X11 | +- rc.d | +- fstab | +- mtab -> /proc/mounts | ... +- bin +- lib +- mnt | +- initrd | +- cdrom <- used for development | +- floppy | +- disk | +- initrd <- used for development +- proc +- opt +- home -> fake/needwrite/home <- N.B. no leading '/' +- root -> fake/needwrite/root +- dev -> fake/needwrite/dev +- etc -> fake/needwrite/etc +- tmp -> fake/needwrite/tmp +- var -> fake/needwrite/var +- usr +- src +- local +- bin +- lib +- share +- X11R6 +- bin +- include +- lib +- X11 +- modules ... =========================================================================== X-SERVER CONFIGURATION [1] To configure the X server, run (you do not need to be root) XFree86 -configure This writes the configuration file ~/XF86Config.new in the user home directory (ie /root if you are root, which must therefore be writable). To use this configuration file you should call the X server with the option -xf86config, XFree86 -xf86config ~/XF86Config.new [2] In order to execute xinit with the new configuration file, you run xinit -- -xf86config /root/XF86Config.new [3] Prepare the /root/.xinitrc resource file in ... essentially it must contain only the application # BEGIN /root/.xinitrc xsetbg -geometry ... & /root/kblue/blue # END /root/.xinitrc .xinitrc is used in the boot. It is also useful if the user wants to write X intercatively from console login. The command is xinit /root/.xinitrc -- -xf86config ~/XF86Config.new [4] The directory /opt/ddcprobe contains programs that recognize the video cards. This is ddcprobe (which seems to be used by anaconda and kudzu). The program ddcxinfo is used to obtain the video modes. The XFree86 configuration does not includes video modes nor the mouse is properly detected. To fix this the directory /root contains a perls script that takes the XF86Config file produced by XFree86 and inserts the two most common mice, /dev/ttyS0 and /dev/psaux, and the list of video modes generated by ddcxinfo. To automate all this programs there is a shell script that calls ddcxinfo first, and the shell script afterward. Both scripts are contained in the appendix. The directory /opt/videoprobe contains a simple script that identifies the video cards installed on the machine. It uses the proc filesystem, and the Cards and pcitable databases. The former is included in the XFree86 distribution /usr/share/X11/hw/server/Cards ???) The latter is copied from a RedHat 8.0 distribution. However this software is not complete. [5] Create a script /etc/rc.d/init.d/xf86config which configures the Xserver, and starts the server and the application. Make a symlink to it from /etc/rc.d/rc5.d/S90xf86config which is used when booting to run level 5 (which is the default). The script is in the appendix. ========================================================================== MAKE THE CDROM [1] In your old environment create the iso image cd /mnt/lfs mkisofs -o ~/blue.iso \ -b isolinux/isolinux.bin \ <-- boot image -c isolinux/boot.cat \ <-- boot catalog -no-emul-boot \ <-- boot image not a floppy image -boot-load-size 4 \ -boot-info-table \ <-- put cd info-table in boot file -l \ <-- iso-level-2 (long) filenames -R \ <-- generate SUSP and RR records -L \ <-- allow initial period in names -D \ <-- no deep dir relocation -V "blue_$(date +%Y%m%d)" \ <-- volume label . <-- root of iso tree Notes. * the boot catalog is inserted in the iso tree but not written on the source filesystem. Its name must not be in conflict with an existing file in the source filesystem. * if -no-emul-boot were not given, the boot image should be of size either 1200, or 1440, or 2880. * -boot-load-size specifies the number of 512B sectors loaded in no-emulationmode * the -boot-info-table is 56 bytes long and is written in the boot image at offset 8 within the source filesystem before creating the isofile. Back up the boot image, if you need it. * using -r instead of -R will also set the files' modes to sensible values (nothing can be written, all execs are 555, all readable files are 444, directories are all 555, etc.) * -pad is set by default; it pads the iso file before putting the boot image; * -iso-level specifies the iso9960 level (4 is the highest) See the mkisofs man page for further informations. [2] record the isoimage on the CD cdrecord -v blank=fast -eject dev=0,0,0 speed=0 ~/blue.iso Note. cdrecord has a large set of features. Some of the general options: -dummy do everything but do not turn the laser on. Useful for pre-recording check -dao Disk At Once. cdrecord needs to know the size of the tracks -raw raw mode ... -multi multisession; leave the session open -msinfo retrieve multisession infos, suitable for mkisofs -toc retrieve TOC -fix fixate -nofix do not fixate (used only for audio) -waiti wait for input before opening the CD device; useful for multisession coming from mkisofs through a pipe -lock lock media, lock door, and exit -eject eject disk after work speed=N set the speed to a multiple of approx 150-170 KB/s; if in doubt, try speed=0 blank=type blank CDrw before writing; type can be "all" (entire surface) "fast" (only ... and toc), and others fs=N set fifo size (N is in bytes unless with suffix, 'b', 'k', 'm') default is 4MB (max 32MB); this allows to run a pipe thru mkisofs dev=target specifies the SCSI device, ex. dev=0,0,1 -checkdrive check driver and exit (with 0 if ok) -prcap print drive capabilities -inq inquiry for the drive -scanbus scan all SCSI devices Track options may be mixed with track filenames, index=list list of comma-separated number (unit 1/75 sec) -audio write in audio format (default for .au and .wav) -data write in data format (default except for .au and .wav) -swab swap byte (from little-endian to big-endian) -pad pad audio to multiple of 1/75 sec [3] Better use a RDrw: be prepared to face several failures, and have to change the layout of your distro. ========================================================================== THINGS TO REMEMBER [1] Whenever there is a change to initrd, the compressed init ramdisk initrd.gz must be copied in the directory /boot of the development environment, so that LILO or Grub can find it, during the tests of the configuration before recording the CD. [2] Whenever there is a change to the kernel, it must be copied in the directory /boot of the development environment, as well as in the /boot directory of LFS (ie, in /isolinux). [3] During the development you need to slow down the booting, with sleep's and to have many echo commands to monitor what is going on. When you are happy with your distro, comment out the "sleep" in linuxrc and possibly some of the "echo" messages. [4] When you want to chroot from the development environment into LFS=/mnt/lfs do export LFS=/mnt/lfs chroot $LFS /usr/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w \$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login mount proc /proc -t proc Before exiting back, remember to umount /proc ========================================================================== APPENDIX ------------------------- linuxrc begin ---------------------------- #!/bin/sh # # author marco corvi # date oct 2003 # licence GPL (see www.gnu.org for details) # # Credits: # linuxrc: Thomas Foecking and Christian Hesse # testmem: Klaus Knopper # # Description: # init script for the boot from a CDrom # # History # 2003-10-05 first version # # ID is the label of the CDrom created with mkisofs ID="blue" # TMP_MOUNT is the directory of the initrd where the CDrom is mounted TMP_MOUNT="/mnt" PATH="/bin:/sbin:/usr/bin:/usr/sbin" if [ -e "/bin/isoinfo" ]; then CHECK_TYPE="isoinfo" fi if [ ! -d "/proc/" ]; then mkdir /proc fi /bin/mount -n proc /proc -t proc LFS_CDROM_DEVICE="" LFS_CDROM_MEDIA="iso9660" if [ "$LFS_CDROM_DEVICE" = "" ]; then CDROM_LIST="" # search the cd driver in /proc for ide_channel in /proc/ide/ide[0-9]; do if [ ! -d "$ide_channel" ]; then break fi for ide_device in hda hdb hdc hdd hde hdf hdg hdh hdi hdj hdk hdl hdm hdn do device_media_file="$ide_channel/$ide_device/media" if [ -e "$device_media_file" ]; then /bin/grep -i "cdrom" $device_media_file > /dev/null 2>&1 if [ $? -eq 0 ]; then if [ -e "/dev/$ide_device" ]; then CDROM_LIST="$CDROM_LIST /dev/$ide_device" fi fi fi done done for scsi_cdrom in /dev/scd[0-99] do if [ -e "$scsi_cdrom" ]; then CDROM_LIST="$CDROM_LIST $scsi_cdrom" fi done # looking for the CD media ... echo "Using $CHECK_TYPE" for cdrom_device in $CDROM_LIST; do echo -n "Checking $cdrom_device ... " if [ "$CHECK_TYPE" = "isoinfo" ]; then /bin/isoinfo -i $cdrom_device > /dev/null 2>&1 media_found=$? if [ $media_found -ne 0 ]; then /bin/isoinfo -V $cdrom_device > /dev/null 2>&1 media_found=$? fi fi if [ $media_found -eq 0 ]; then echo -n "media found" if [ "$CHECK_TYPE" = "isoinfo" ]; then /bin/isoinfo -i $cdrom_device | grep -i "Volume id:" | grep "$ID" \ > /dev/null 2>&1 media_lfs=$? if [ $media_lfs -ne 0 ]; then /bin/isoinfo -V $cdrom_device | grep "$ID" > /dev/null 2>&1 media_lfs=$? fi fi if [ $media_lfs -eq 0 ]; then echo ", found LFS-blue-cdrom !!!" LFS_CDROM_DEVICE="$cdrom_device" break; else echo ", not a LFS-blue-cdrom." fi else echo "no media " fi done fi # 3. mount LFS-blue CD as / (root fs) if [ "$LFS_CDROM_DEVICE" = "" ]; then echo "No LFS-blue boot CD found !!!" exit 1 else echo "mounting to the LFS-blue CD ... " /bin/mount -n -o ro -t $LFS_CDROM_MEDIA $LFS_CDROM_DEVICE $TMP_MOUNT # insmod -f /lib/modules/cloop.o file=$TMP_MOUNT/lfs 2>&1 # mount -n -o ro -t iso9660 /dev/cloop /mnt cd $TMP_MOUNT echo "Begin testmem ..." # we still use /proc on the initrd # /bin/mount -n proc $TMP_MOUNT/proc -t proc # compute the memory on the system FOUNDMEM="$(awk '/MemTotal/{print $2}' /proc/meminfo)" TOTALMEM="$(awk 'BEGIN{m=0};/MemFree|Cached/{m+=$2};END{print m}' /proc/meminfo)" echo "Memory found: ${FOUNDMEM} kB total: ${TOTALMEM} kB" sleep 3 # Minimum size of additional ram partitions MINSIZE=2000 # At least this much memory minus 30% should remain MINLEFT=16000 # Maximum ramdisk size MAXSIZE=`/bin/expr ${TOTALMEM} - ${MINLEFT}` # Define the size of the ramdisk RAMSIZE=`/bin/expr ${TOTALMEM} / 5` # Check for sufficient memory to mount extra ramdisk for /home + /var # if [ -n "$TOTALMEM" -a "$TOTALMEM" -gt "$MINLEFT" ]; then test -z "$RAMSIZE" && RAMSIZE=100000 # tmpfs/varsize version, can use swap RAMSIZE=`/bin/expr ${RAMSIZE} \* 4` echo -n "Creating /ramdisk (dynamic size=${RAMSIZE} k) on /dev/shm ..." # CD customization: mount writable tmpfs /bin/mount -n -t tmpfs -o "size=${RAMSIZE}k" tmpfs $TMP_MOUNT/fake/needwrite echo " Done." sleep 3 # copy the dirs of ramdisk into needwrite # # Actually /fake/needwrite (mounted by /dev/shm) is empty # so there is no need to remove anything. # rm -Rf $TMP_MOUNT/fake/needwrite/* # echo "Cleared tmpfs ..." # sleep 3 cd $TMP_MOUNT/fake/ramdisk for i in * ; do echo "Copying directory $i ..." cp -dpR $i ../needwrite sleep 1 done cd $TMP_MOUNT/ # cp -dpR $TMP_MOUNT/fake/ramdisk/* $TMP_MOUNT/fake/needwrite/ else echo "mkdir /home and /var ... " # this would fail if we have not copied mkdir to the initrd # mkdir -p $TMP_MOUNT/home $TMP_MOUNT/var fi # (mc-3/3) :> $TMP_MOUNT/var/run/utmp :> $TMP_MOUNT/var/run/wtmp echo "End testmem ..." # tell init script to skip "mountfs" echo "touching no_mountfs ... " /bin/touch $TMP_MOUNT/root/no_mountfs sleep 3 echo "pivot_root ..." /bin/pivot_root . initrd umount -n /initrd/proc >/dev/null 2>&1 exec /usr/sbin/chroot . sh -c '/bin/umount -n /initrd >/dev/null 2>&1;\ /sbin/blockdev --flushbufs /dev/ram0; \ exec -a init.new /sbin/init' \ dev/console 2>&1 fi -------------------------- linuxrc end ------------------------------ --------------------- fix_xf86config.sh begin ----------------------- #!/bin/bash # # fix XF86Config.new # insert modelines and mouse # /opt/ddcprobe/ddcxinfo -modelines > /root/modes if [ ! $? ]; then echo "failed ddcxinfo" cd /root && cp -f safemodes modes fi cd /root && ./fix_xf86config.pl exit $? --------------------- fix_xf86config.sh end ------------------------- --------------------- fix_xf86config.pl begin ----------------------- #!/usr/bin/perl # open(AA, "XF86Config.new") || die "No XF86Config.new"; open(BB, ">XF86Config") || die "Cannot write XF86Config"; while ( $line = ) { print BB $line; next if (! $line =~ /Section/); if ( $line =~ /InputDevice/ ) { for ( ; ; ) { $line = ; print BB $line; last if ( $line =~ /Driver/ ); } if ( $line =~ "mouse" ) { print BB "\tOption\t\"Protocol\" \"auto\"\n"; print BB "\tOption\t\"Device\" \"/dev/ttyS0\" \n"; print BB "EndSection\n"; print BB "Section\t\"InputDevice\"\n"; print BB "\tIdentifier\t\"MouseExtra1\" \n"; print BB "\tDriver\t\"mouse\" \n"; print BB "\tOption\t\"Protocol\" \"auto\" \n"; print BB "\tOption\t\"Device\" \"/dev/psaux\" \n"; print BB "EndSection\n"; while ( $line = ) { last if ( $line =~ /EndSection/ ); } } else { while ( $line = ) { print BB $line; last if ( $line =~ /EndSection/ ); } } next; } if ( $line =~ /Monitor/ ) { while ( $line = ) { last if ( $line =~ /EndSection/ ); print BB $line; } if ( open(CC, "modes") ) { while ( ) { print BB; } close CC; } print BB $line; next; } if ( $line =~ /Screen/ ) { while ( $line = ) { print BB $line; if ( $line =~ /Display/ ) { print BB "\t\tModes \"800x600\" \"1024x768\" \n" } last if ( $line =~ /^EndSection/ ); } next; } if ( $line =~ /ServerLayout/ ) { while ( $line = ) { last if ( $line =~ /^EndSection/ ); print BB $line; } print BB "\tInputDevice\t\"MouseExtra1\"\t\"AlwaysCore\" \n"; print BB $line; } } close AA; close BB; --------------------- fix_xf86config.pl end ------------------------- ---------------- etc/rc.d/rc5.d/S90xf86config begin ----------------- #!/bin/bash source /etc/sysconfig/rc source $rc_functions case "$1" in start) cd /root export PATH=$PATH:/usr/X11R6/bin:/root/kblue /usr/X11R6/bin/XFree86 -configure > /root/xcfg.log 2>&1 cd /root && /root/fix_xf86config.sh /usr/X11R6/bin/xinit /root/.xinitrc -- -xf86config /root/XF86Config.new # /usr/X11R6/bin/XFree86 -xf86config /root/XF86Config.new & # /root/kblue/blue & # twm echo "" echo "Press Ctrl-Alt-Del to reboot," echo "or enter login \'root\' and password \'welcome\' " ;; stop) ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac ---------------- etc/rc.d/rc5.d/S90xf86config end ------------------- ---------------- etc/fstab begin ------------------------------------ # Begin /etc/fstab # filesystem mnt-point fs-type options dump fsck-order /dev/hdb3 / ext2 defaults 1 1 /dev/hdb2 swap swap pri=1 0 0 # tmpfs /dev/shm tmpfs defaults 0 0 proc /proc proc defaults 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner 0 0 # uncomment this if you are using devpts # (you need devpts support compiled into the kernel) # devpts /dev/pts devpts gid=4,mode=620 0 0 # uncomment this if you intend to use USB devices # (USB support must be compiled into the kernel) # usbfs /proc/bus/usb usbfs defaults 0 0 # End /etc/fstab ---------------- etc/fstab end --------------------------------------