歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell for linux-bootdisk

Shell for linux-bootdisk

日期:2017/2/27 14:15:50   编辑:SHELL編程
  #!/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 ALLFAT\VFAT \#\# suport VFAT FS $0 nokernel \#\# without kernel but busybox $0 \#\# install with kernel and busybox 作者: 程文龍 於,長春星宇網軟. 如有問題請聯系 EMail:[email protected] [email protected] 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_IN99vRD grep -v CONFIG_MODULESgrep -v CONFIG_MODVERSIONSgrep -v CONFIG_KMOD grep -v CONFIG_BLK_DEV_RAMgrep -v CONFIG_BLK_DEV_IN99vRD > .config echo 'CONFIG_BLK_DEV_RAM=y' >> .config echo 'CONFIG_BLK_DEV_RAM_SIZE=4096' >> .config echo 'CONFIG_BLK_DEV_IN99vRD=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 IN99v_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: [email protected]' >> 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 /



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 /



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 /



Copyright © Linux教程網 All Rights Reserved