3、初始化rootfs脚本--创建小型linux


#!/bin/bash
# function:Initalize the system script
source /scripts/automount.sh

ROOTFS () {
[ -d $N ] && (mount |grep $N) || echo "ERROR,The $N is not mounted";read -p "Do you want to continue.(y/n)" ANSWER
if [ "$ANSWER" = "n" -o "$ANSWER" = "N" ];then
       exit
fi
 rm -rf $N/*
 mkdir -pv $N/{boot,proc,sys,dev,home,root,etc/{rc.d,sysconfig,init.d},bin,sbin,lib,usr/{bin,sbin,lib,include},var/{log,run},tmp,mnt,opt,media}
 echo "mkdir directory sucessful."
 chmod 1777 $N/tmp
 echo "change the tmp type sucessful."
 cat >> $N/etc/inittab << EOF
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
EOF
[ $? -eq 0 ] &&  echo "$N/etc/inittab is sucessful."
 cat >> $N/etc/rc.d/rc.sysinit << EOF
       #!/bin/bash
       echo -e "Welcome to fish linux."
       mount -n -o remount,rw /
       mount -n -a
       /bin/bash
EOF
[ $? -eq 0 ] && echo "$N/etc/rc.d/rc.sysinit is sucessful."
  chmod +x $N/etc/rc.d/rc.sysinit
  cat >> $N/etc/fstab << EOF
       /dev/sda2       /       ext3    defaults        0 0
       /dev/sda1       /boot   ext3    defaults        0 0
       sysfs           /sys    sysfs   defaults        0 0
       proc            /proc   proc    defaults        0 0
EOF
[ $? -eq 0 ] && echo "The $N/etc/fstab is sucessful."

}
ROOTFS $N

你可能感兴趣的:(创建系统启动所需配置文件)