感谢大家!
分类: LINUX
2008-02-12 23:58:45
mkdir -pv /opt/iso/{boot,modules} cd /opt/iso
cd / mksquashfs bin lib sbin usr SYSTEM
mv /SYSTEM /opt/iso
cd /opt/iso/boot mkdir initrd dd if=/dev/zero of=initrd.img bs=1M count=8 mkfs.ext2 initrd.img mount -o loop initrd.img initrd
export INITRD=/opt/iso/boot/initrd cd ${INITRD} mkdir bin boot dev etc lib proc sbin sys
cp -a /bin/bash ${INITRD}/bin
mv /opt/iso/modules ${INITRD}/lib
cp -a /lib/udev ${INITRD}/lib
cp -a /lib/firmware ${INITRD}/lib
cp -a /dev/{console,null} ${INITRD}/dev
cp -a /etc/udev ${INITRD}/etc
cat > ${INITRD}/linuxrc << "EOF" #!/bin/bash mount -t proc proc /proc mount -t sysfs sysfs /sys # 如果你将loop模块化,那么需要加入 /sbin/modprobe loop # 建立/dev设备目录,并使用udev来创建各种设备文件 mount -n -t tmpfs -o mode=0755 udev /dev cp --preserve=all --recursive --remove-destination /lib/udev/devices/* /dev chmod 1777 /dev/shm echo "" > /sys/kernel/uevent_helper echo "Starting Udev..." /sbin/udevd --daemon mkdir -p /dev/.udev/queue /sbin/udevtrigger /sbin/udevsettle # 创建用户使用环境 # 在/SYSTEM中准备目录结构 export SYSTEM=/SYSTEM mkdir -p ${SYSTEM} mount -t tmpfs tmpfs ${SYSTEM} mkdir -p ${SYSTEM}/{system,cdrom,dev,proc,sys,tmp,mnt,initrd,home,root} chmod 0777 ${SYSTEM}/tmp chmod 0700 ${SYSTEM}/root # 搜索LiveCD所在的设备 for i in /proc/ide/hd* do if test `cat $i/media` = "cdrom" ; then mount -t iso9660 /dev/`basename $i` ${SYSTEM}/cdrom 2>/dev/null if test $? = 0 ; then if [ -f ${SYSTEM}/cdrom/LABEL ] ; then if grep -q "Sunhaiyong's LiveCD" ${SYSTEM}/cdrom/LABEL ; then break; fi fi umount ${SYSTEM}/cdrom fi fi done # 加载squashfs压缩的主文件系统 mount -o loop -t squashfs ${SYSTEM}/cdrom/SYSTEM ${SYSTEM}/system ln -s /system/bin ${SYSTEM} ln -s /system/sbin ${SYSTEM} ln -s /system/lib ${SYSTEM} ln -s /system/usr ${SYSTEM} # 将根目录从initrd转换到主系统 killall /sbin/udevd echo 0x0100 > /proc/sys/kernel/real-root-dev pivot_root ${SYSTEM} ${SYSTEM}/initrd cd / # 解压缩一些必要的目录和文件 tar xf /cdrom/etc.tar.bz2 -C / #转移内核文件系统 mount --move /initrd/dev /dev mount --move /initrd/proc /proc mount --move /initrd/sys /sys mkdir -p /var/{run,log,lock} touch /var/run/utmp /var/log/{btmp,lastlog,wtmp} chgrp utmp /var/run/utmp /var/log/lastlog chmod 664 /var/run/utmp /var/log/lastlog #结束 EOF
cp -a /bin/{bash,bunzip,bzcat,bzip2,killall,chmod,cp,grep,mount,tar,ln,cat,mkdir} ${INITRD}/bin cp -a /usr/bin/basename ${INITRD}/bin cp -a /sbin/pivot_root ${INITRD}/sbin cp -a /sbin/{udevd,udevsettle,udevtrigger,modprobe} ${INITRD}/sbin
cp -a /lib/ld-* ${INITRD}/lib/ cp -a /lib/libc-2.5.1.so ${INITRD}/lib/ cp -a /lib/libc.so.6 ${INITRD}/lib/ cp -a /lib/lib{dl,pthread,rt}-* ${INITRD}/lib/ cp -a /lib/lib{readline,history,ncursesw,dl,bz2,blkid,uuid,rt,pthread}.so* ${INITRD}/lib/
touch ${INITRD}/etc/fstab
echo "Sunhaiyong's LiveCD" > /opt/iso/LABEL
cd /opt/iso/boot umount initrd gzip -9 initrd.img
cd /opt/iso cp -a /etc ./
tar -cjf etc.tar.bz2 etc rm -r etc
cd /opt/iso mkdir -p boot/grub cp -a /usr/lib/grub/i386-pc/stage2_eltorito boot/grub
cd /opt/iso/boot/grub cat > menu.lst << "EOF" default 0 timeout 3 color green/black light-green/black title MyLiveCD 1.0 root (cd) kernel /boot/kernel initrd /boot/initrd.img.gz
cd /opt mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o mylivecd.iso iso
chinaunix网友2008-09-19 11:56:11
"编译内核,将内核文件放入/opt/iso/boot目录中,将模块放入/opt/iso/modules中。"怎么找到这个模块啊? 你好,这个我有些不明白。编译内核我知道步骤了。将内核文件放入 /opt/iso/boot目录下,应该是类似下面几个命令的操作。但是将模块放入/opt/iso/modules中,模块文件是哪些呢?路径呢?麻烦指点一下。非常感激。 cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.16.27 cp -v System.map /boot/System.map-2.6.16.27 cp -v .config /boot/config-2.6.16.27 install -d /usr/share/doc/linux-2.6.16.27 && cp -r Documentation/* /usr/share/doc/linux-2.6.16.27
chinaunix网友2008-06-09 00:13:36
哦, 那Linuxrc脚本中: echo 0x0100 > /proc/sys/kernel/real-root-dev 这条语句转换根设备 0x0100代表的是scsi硬盘 咱们做的不是光盘吗?为什么还要用到硬盘啊?
chinaunix网友2008-06-08 23:09:34
豹哥,Linuxrc脚本中有一段 if test $? = 0 ; then if [ -f ${SYSTEM}/cdrom/LABEL ] ; then if grep -q "Sunhaiyong's LiveCD" ${SYSTEM}/cdrom/LABEL ; then break; fi fi umount ${SYSTEM}/cdrom fi 其中的 test $? = 0 是什么意思?