感谢大家!
分类: 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网友2011-06-06 19:32:33
豹哥,如果我在系统中安装了一些程序,想把目前的整个系统做成ISO,应该怎么做,是要把其他整个目录压缩吗,具体详细命令是什么,谢谢
chinaunix网友2011-06-05 14:04:14
豹哥你好,我在建立initrd的过程中,“mkfs.ext2 initrd.img”命令不理解,系统输出如下的信息,我选择了"y"进行确认,完整信息如下,不知是否正确: root:/opt/iso/boot# mkfs.ext2 initrd.img mke2fs 1.40.2 (12-Jul-2007) initrd.img is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 2048 inodes, 8192 blocks 409 blocks (4.99%) reserved for the super user First data block=1 Maximum filesystem blocks=8388608 1 block group 8192 blocks per group, 8192 fragments per g
chinaunix网友2011-05-08 19:54:11
感谢豹哥,在 LiveCD 里摸索了蛮久的,虽然我不是用LFS,用的是Slackware ,但是还是觉得您的文章象明灯一样指明了前进方向。 努力学习如何重写自己的 Linuxrc 脚本。。。。。