论坛: UNIX系统 标题: 制作linux启动盘的shell[转] 复制本贴地址    
作者: TecZm [teczm]    版主   登录

#!/bin/sh
## confirm you login use root or you prompt with help.If True ,then display help infomation;
## 确认你是否以root用户登录,或者你键入的第一个参数是 help ,为真时,显示帮助信息.
if [ "$USER" != 'root' ]|| [ "x$1" == "xhelp" ];then
clear
echo "

You must login use 'root' !
你必须以root登录才可以顺利完成全部工作。

Please use :
$0 install \#\# without MSDOS .OR. FAT
$0 install DOS \#\# suport MSDOS FS
$0 install ALL|FAT\|VFAT \#\# suport VFAT FS
$0 nokernel \#\# without kernel but busybox
$0 \#\# install with kernel and busybox


作者: 程文龙 于,长春星宇网软.
如有问题请联系 EMail:chwl771118@163.com
chengwl@xynetsoft.com
Editer: ChengWenlong ,
ChangChun Xynetsoft LTD.,COM.
2004-04-08"

read
exit
fi
#制作linux的启动盘(软盘)
#你需要准备:
# 1) 内核,可以编译,也可在/boot/文件夹中找到,最好用vmlinuz的内核.
# 2) busybox, 可以在http://sunsite.ulatina.ac.cr/Unix/Linux/Slackware/
# slackware-8.0/source/rootdsks/下载,
# 因为软盘空间为1.44M而内核就占用近一半的空间,所以,其它的可执行程序一定要小
# ,选择busybox(静态的)执行时不需要/lib/目录下的库文件.

#步骤:

echo '#(一) 建软盘文件系统.'
export busybox='busybox-0.60.1'
export linuxkernel=linux-2.4.18
export workdir='floppy-linux'
##!!! 请不要随意改动'$'变量前的直接目录,否则当目录不存在时可能破坏系统原有文件.
cd /tmp/
if [ "x$1" == "xinstall" ] || [ "x$1" == "xnokernel" ];then
rm -rf /tmp/$workdir
mkdir /tmp/$workdir
cd /tmp/$workdir
## 建立必须的文件夹,并设置属性.
mkdir dev etc bin proc mnt tmp
chmod 755 dev etc mnt tmp
ln -s /tmp var
chmod 555 proc
##建立 必要的设备,tty1 tty2 tty3 tty4 仅供多个虚拟终端登录时使用.
cd /tmp/$workdir/dev/
#cp -aRp /dev/tty* /dev/ram* .
mknod tty c 5 0
mknod tty0 c 4 0
mknod tty1 c 4 1
mknod tty2 c 4 2
mknod tty3 c 4 3
mknod tty4 c 4 4
mknod console c 5 1
mknod ram0 b 1 0
mknod ram1 b 1 1
mknod fd0 b 2 0
mknod null c 1 3
chmod 666 *
fi
if [ "x$1" == "xinstall" ] ;then
echo '#(二)编译内核'
#首先,确认你安装了内核的源文件到/usr/src/linux.
if [ ! -d /usr/src/linux ];then
cd /usr/src/
ln -s `uname -r` linux
cd linux
else
cd /usr/src/linux
fi
## 当你的系统已经存在原有内核时,对其进行贝份,此处没有设置自动下载内核文件的功能.
if [ -f /usr/src/linux/arch/i386/boot/bzImage ];then
cp /usr/src/linux/arch/i386/boot/bzImage /tmp/bzImage.`uname -r`
fi
make clean
make xconfig
if [ "$?" != "0" ];then
make config
fi
mv .config myconfig
##对内核进行必要的配置,使之支持虚拟内存,
##当你对此文件复制,粘贴时,要保证命令的完整,
##尤其是,cat和grep的组合及if后的条件
cat myconfig |grep -v CONFIG_BLK_DEV_INITRD |grep -v CONFIG_MODULES|grep -v CONFIG_MODVERSIONS|grep -v CONFIG_KMOD |grep -v CONFIG_BLK_DEV_RAM|grep -v CONFIG_BLK_DEV_INITRD > .config
echo 'CONFIG_BLK_DEV_RAM=y' >> .config
echo 'CONFIG_BLK_DEV_RAM_SIZE=4096' >> .config
echo 'CONFIG_BLK_DEV_INITRD=y' >> .config
if [ "x$2" == "xDOS" ] || [ "x$2" == "xdos" ] || [ "x$2" == "xMSDOS" ] || [ "x$2" == "xmsdos" ] || [ "x$2" == "xVFAT" ] || [ "x$2" == "xvfat" ] || [ "x$2" == "xfat" ] || [ "x$2" == "xFAT" ];then
echo 'CONFIG_FAT_FS=y' >> .config
echo 'CONFIG_MSDOS_FS=y' >>.config
if [ "x$2" != "xDOS" ] || [ "x$2" != "xdos" ] || [ "x$2" != "xMSDOS" ] || [ "x$2" != "xmsdos" ];then
echo 'CONFIG_VFAT_FS=y' >> .config
fi
fi
sleep 3s
make dep
make bzImage
fi
if [ "x$1" == "xinstall" ] || [ "x$1" == "xnokernel" ] || [ ! -f /tmp/$busybox.tgz ];then
echo '#(三)编译busybox'
#下载busybox的软件包 如:busybox-0.51.tar.gz
#rm -rf /tmp/busybox-0.60.1.tgz
##此处,实现连网情况下从方舟公司,的共享网站下载体busybox

if [ ! -f /tmp/$busybox.tgz ];then
ftp -i -n ftp.arca.com.cn << END
user anonymous
bin
cd /pub/Arca-Products/
cd 5Software/6app/
cd busybox/source/
lcd /tmp
get $busybox.tgz
quit
END
fi
sleep 4s
cd /tmp/
if [ -f $busybox.tgz ] ;then
cp $busybox.tgz busybox.tar.gz
fi
tar zxvf busybox.tar.gz -C /tmp
if [ -d /tmp/$busybox ];then
cd /tmp/$busybox
fi
#编辑 Makefile ,修改 DOSTATIC = false 为DOSTATIC = true
#编辑 init.c 修改 #define INIT_SCRIPT "/etc/init.d/rcS"
##成为你所期望的脚本名称,如:/etc/rc.sysinit
#编辑 Config.h 可以更改你希望保留的程序.可不改动.
if [ -f Makefile ];then
mv Makefile myfile
cat myfile | sed 's/DOSTATIC = false/DOSTATIC = true/g' > Makefile
mv init.c myfile
cat myfile |sed 's/init.d\/rcS/sysinit/g' > init.c
mv Config.h myfile
# echo '#define BB_VI' > Config.h
# cat myfile |grep -v BB_VI >> Config.h
make clean ;make ; ./install.sh /tmp/$workdir
fi
fi
echo '#编辑配置文件'
cd /tmp/$workdir/etc
rm -rf *
cat > inittab << EOF
::sysinit:/etc/sysinit
::askfirst:/bin/sh
tty1::respawn:/bin/sh
tty2::respawn:/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/bin/swapoff -a
EOF
echo root::0:0:root:/:/bin/sh > passwd
echo \#\!\ \/bin/sh > sysinit
echo mount -n -o remount,rw / >> sysinit
echo mount /proc >> sysinit
# echo 'echo ChengWenlong' >> sysinit
# echo 'echo Email: chwl771118@163.com' >> sysinit
chmod 755 *
echo /dev/ram0 / ext2 defaults 0 0 > fstab
echo /proc\ /proc\ proc\ defaults 0 0 >> fstab
chmod 644 fstab
echo ' Make initrd file system 建立虚拟文件系统,确认,你安装了util的工具包'
cd /
dd if=/dev/zero of=/tmp/tmp_loop bs=1k count=4096
sleep 2s
umount /dev/loop0 1>/dev/null 2>/dev/null
losetup -d /dev/loop0 1>/dev/null 2>/dev/null
losetup /dev/loop0 /tmp/tmp_loop
sleep 2s
mke2fs -m 0 /dev/loop0
sleep 2s
umount /mnt > /dev/null 2>&1
mount -t ext2 /dev/loop0 /mnt > /dev/null 2>&1
sleep 2s
if [ "x$?" != "x0" ] ; then
echo " I can't mount loop0 at /mnt ........... "
echo " Please exit other program which at /mnt "
exit 1
fi
cd /tmp/$workdir/bin
ln -s busybox linuxrc
cd ..
rm -rf linuxrc
ln -s bin/linuxrc linuxrc
if [ ! -d /tmp/$workdir/sbin ];then
cd sbin
for var in `ls`
do
if [ ! -L /tmp/$workdir/bin/$var ];then
cd /tmp/$workdir/bin/ ; ln -s busybox $var
fi
cd /tmp/$workdir/sbin/ ;rm -rf /tmp/$workdir/sbin/$var
done
fi
cd /tmp/$workdir
rm -rf /tmp/$workdir/sbin
ln -s bin sbin
rm -rf /mnt/*
cp -aRp /tmp/$workdir/* /mnt
rm -rf /mnt/lost+found
ls /mnt
umount /mnt
losetup -d /dev/loop0 > /dev/null 2>&1
rm -f /tmp/Image.gz
dd if=/tmp/tmp_loop | gzip -9 > /tmp/Image.gz
rm -f /tmp/tmp_loop
sync
mkdosfs /dev/fd0
syslinux /dev/fd0
mount -t msdos /dev/fd0 /mnt
if [ "x$?" != "x0" ];then
echo "I can't finished the working ............. "
echo "Please Umount you /mnt directorys ........ "
exit 1
fi
cd /mnt

if [ -f /usr/src/linux/arch/i386/boot/bzImage ];then
cp /usr/src/linux/arch/i386/boot/bzImage /mnt/linux
else
cp /boot/vmlinuz /mnt/linux
fi
if [ -f /mnt/Image.gz ];then
rm -f /mnt/Image.gz
fi
cat << EOF > /mnt/syslinux.cfg
timeout 2
default linux
append root=/dev/ram0 initrd=Image.gz
EOF
cp /tmp/Image.gz /mnt
cd /
sync
umount /mnt
echo -e -n "\n\n
All Finish
ChengWenlong
程文龙 长春, 吉林。 chwl771118@163.com
"
echo
##希望,此SHELL能帮助linux的爱好者.
##使用过程中如有问题无法解决,只限汉语和英语,我会尽力帮你解决,联系方式如上





[此贴被 TecZm(teczm) 在 06月24日07时13分 编辑过]

地主 发表时间: 04-06-24 07:12

回复: fcuuff [fcuuff]   论坛用户   登录
这么热情怎么没人顶啊,

B1层 发表时间: 04-07-11 22:53

论坛: UNIX系统

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号