Based on the integration we made a few days ago, we finally wrote a one-click Linux script. This is really a key, with common commands, as well as the welcome interface, plus a prompt and so on.
Join the network module tomorrow to make it accessible to the internet!
HOST: RedHat Enterprise 5 (2.6.18)
Target machine: 256 memory, 8 GB hard disk.
#! /Bin/bash #: Title: all_mini_linux.sh #: Synopsis: #: datetime: 12:33:02 #: Version: 0.2 #: Author: Weiyan #: Options: # Read-P "the target disk:" dskif fdisk-L $ DSK | grep "^/dev" &>/dev/NULL; then fdisk-L $ DSK | grep "^/dev" parts = 'fdisk-L $ DSK | grep "^/dev" | awk '{print $1} ''for I in $ parts; do if Mount | grep "$ I" &>/dev/NULL; then mount | grep "$ I" else echo "$ I is not mounted. "Fi donefispart () {read-P" Warning !!!!! Next you do it will wipe your disk !!!! Continue (y/n )? "Choice case $ choice in Y | Y) for I in $ parts; do if Mount | grep" $ I "&>/dev/NULL; then Fuser-km $ I umount $ I fi DONE dd If =/dev/Zero of = $ DSK BS = 512 COUNT = 1 &>/dev/nullecho 'N P 1 + 50mnp2 + 512mnp3 + 256mt382w '| fdisk $ DSK &>/dev/null sleep 1 mke2fs-J $ {DSK} 1 &>/dev/null mke2fs-J $ {DSK} 2 & >/dev/null mkswap $ {DSK} 3 &>/dev/null return 0 ;; N | N) return 1; *) return 2; esac} Spart [$? -EQ 0] & Echo "the disk wipe success !!!!!!! "| Echo" failure "##===================== 2 ============ ========= function guazai {[-D/mnt/boot] | mkdir-P/mnt/boot umount/mnt/boot &>/dev/null Mount $1/mnt/boot [-D/mnt/sysroot] | mkdir-P/mnt/boot umount/mnt/sysroot &>/dev/null Mount $2/mnt/ sysroot} guazai $ {DSK} 1 $ {DSK} 2 ###================== ================## firstblood! Rootfs $1 =/mnt/sysrootfunction rootfs {if [-d $1]; then if Mount | grep "$1" &>/dev/NULL; then CD $1 chmod 1777 tmp/# create/etc/inittabcat> $1/etc/inittab <eofid: 3: initdefault: Si: sysinit:/etc/rc. d/RC. sysinitl0: 0: Wait:/etc/rc. d/RC. shutdownl1: 1: Wait:/sbin/init-T1 sl3: 3: Wait:/sbin/init-T1 3 # mingetty1: 2345: respawn:/sbin/mingetty tty12: 2345: respawn:/sbin/mingetty tty23: 2345: respawn:/sbin/m Ingetty tty34: 2345: respawn:/sbin/mingetty tty45: 2345: respawn:/sbin/mingetty tty56: 2345: respawn:/sbin/mingetty Secret # create/etc/rc. d/RC. shutdowncat> $1/etc/rc. d/RC. shutdown <EOF #! /Bin/bashsyncsleep 1 syncsleep 1 umount/dev/sda1umount/dev/sda2exec/sbin/halt-peof # create RC. sysinitcat> $1/etc/rc. d/RC. sysinit <EOF #! /Bin/bashecho-e "\ t \ twelcome to \ 033 [031; 1mlittle \ 033 [0 m Linux... "Mount-n-o remount, RW/Mount-n-A # Set hostname [-F/etc/sysconfig/network] & source/etc/sysconfig/network [-Z $ hostname] & hostname = localhostecho $ hostname>/proc/sys/kernel/hostnameeof # create/etc/sysconfig/networkcat> $1/etc/sysconfig/Network <eofhostname = weiyaneof # create/etc/sysctl. confcat> $1/etc/sysctl. conf <EOF EOF # create/etc/issuecat >1 1/etc/issue <eofwelcome to little. Linux. orgusername: Root Password: nicai? EOF # create/root/. bash_profilecat> $1/root/. bash_profile <eofps1 = '[\ U @ \ H \ W] \EOF chmod +x etc/rc.d/rc.shutdown# create fstabcat >>$1/etc/fstab<< EOF/dev/sda2 / ext3 defaults 0 0/dev/sda1 /boot ext3 defaults 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0EOF else read -p "Error,the $1 still mount ! Contiune(y|N)?" MOT case $MOT in *) echo "Exit......" return 5 ;; esac fi fi}ROOTFS /mnt/sysroot##====================4========================# copy lib to your sys . $1= COMMAND $2 = /mnt/sysrootfunction COPYLIB { #copy command if which $1 &> /dev/null ;then AA=`which $1 | tail -1 | awk '{print $1}'` cp "$AA" $2"$AA" else echo "$1 is not exist" fi #copy lib LIBPATH=`echo $LIB | sed 's@\(.*\)/[^[:space:]]\{1,\}@\1@g'` [ -d ${2}$LIBPATH ] || mkdir ${2}$LIBPATH [ ! -e $2/$LIB ] && cp -f $LIB ${2}$LIBPATH done echo "$1 has cp done."}echo "=========================================================="# zhijie jia ru ming ling COPYLIB $CMDD /mnt/sysrootdone#ln bash & sh !!!!!ln -sv bash sh &> /dev/null# copy lib/libnss*. with nsswitchcp /usr/lib/libnss3.so /mnt/sysroot/usr/lib/cp /usr/lib/libnssckbi.so /mnt/sysroot/usr/lib/cp /usr/lib/libnssutil3.so /mnt/sysroot/usr/lib/cp -d /usr/lib/libnss_compat.so /mnt/sysroot/usr/lib/cp -d /usr/lib/libnss_files.so /mnt/sysroot/usr/lib/cp -d /lib/libnss_files* /mnt/sysroot/lib/cp -d /lib/libnss_compat* /mnt/sysroot/lib/## copy login !cd /mnt/sysroot/bin/wget ftp://192.168.0.254/pub/login &> /dev/nullchmod +x logincp /lib/libcrypt.so.1 /mnt/sysroot/lib/cp /lib/libm.so.6 /mnt/sysroot/lib/cd ~## copy passwd .... nsswitch.confcp /etc/{passwd,shadow,group,gshadow} /mnt/sysroot/etc/cp /etc/nsswitch.conf /mnt/sysroot/etc/#########until xunhuan let user input ############################echo -e "Please input COMMAND with \033[31mbash\033[0m and \033[31minit\033[0m !!!!!"#read -p "COMMAND you want?(Quit for 'q') :" CMD1 #until [ $CMD1 == 'q' ]; do# COPYLIB $CMD1 /mnt/sysroot# read -p "Which COMMAND you want use ?(Quit for 'q') :" CMD1 #done###############################################################echo "=========================================================="##==========================5===================================# $1 = /mnt/sysrootfunction YDFQ {TMPDIR=`mktemp -d /tmp/little.XX`cd $TMPDIRzcat /boot/initrd-`uname -r`.img | cpio -id &> /dev/null ## zhankai bing songgeised -i 's@^echo Scanning and configuring dmraid supported devices@#&@g' initsed -i 's@^echo Scanning logical volumes@#&@g' initsed -i 's@^lvm vgscan --ignorelockingfailure@#&@g' initsed -i 's@^echo Activating logical volumes@#&@g' initsed -i 's@^lvm vgchange -ay --ignorelockingfailure vol0@#&@g' initsed -i 's@^resume LABEL=SWAP-sda3@#&@g' initsed -i "s@\(mkrootdev.*\) /.*@\1 sda2@" initfind . | cpio -H newc -o --quiet | gzip -9 > /mnt/boot/initrd.gzcp /boot/vmlinuz-`uname -r` /mnt/boot/vmlinuz}YDFQ /mnt/sysroot##==============================6================================## $1 = /dev/sdc $2=/mnt/boot $3=kernel'name $4 initrd's namefunction GRUB {if [ `basename $2` == boot ];then grub-install --root-directory=/mnt $1 &> /dev/null cat >>$2/grub/grub.conf<< EOFdefault=0timeout=10title Little Linux root (hd0,0) kernel /${3} ro root=/dev/sda2 quiet initrd /${4}EOFelse echo "It's not boot !Exit & Please set it again !" fi}GRUB $DSK /mnt/boot vmlinuz initrd.gzsyncsyncsyncsyncsyncsleep 10echo "Congratulation ! Your Mini Linux is install OK !"
After all the tasks are completed ~
OK, everything is done!