歡迎您光臨本站 註冊首頁

製作linux啟動盤的shell

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  #!/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的愛好者.
##使用過程中如有問題無法解決,只限漢語和英語,我會儘力幫你解決,聯繫方式如上


[火星人 ] 製作linux啟動盤的shell已經有213次圍觀

http://coctec.com/docs/linux/show-post-69642.html