📄 linuxrc
字号:
#!/bin/shexport PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin. liblinuxlive# storage filesMOUNTS=/mounts.logMNTORDER=/mnt.orderINSORDER=/ins.orderSTGFILE=/mnt/tmp/ovlfs.stor# pathsLIVECDDATA=/mnt/mnt/livecdLIVECD_SGN=livecd.sgnIMGRO=$LIVECDDATA/imgroIMGRW=$LIVECDDATA/imgrwCP2RAM=$LIVECDDATA/cp2ramCHANGES=$LIVECDDATA/changes# init script, absolute path for chrooted filesystemLINUXINIT=/tmp/initheader "linuxrc-start"echo "creating root filesystem in /mnt"mount -t tmpfs -o "size=90%" tmpfs /mntmkdir -p /mnt/{bin,boot,dev,etc/X11,home,lib,mnt,opt,proc,root,sbin,tmp,usr,sys,var/run,var/lock}mkdir -p /mnt/mnt/{ramdisk,livecd}# touch to avoid "overmounting" by ovlfs, which could sometimes cause errors# with locking. For example /etc/mtab locking or /root/.Xauthority lockingtouch /mnt/{etc,root,tmp,var/run,var/lock}/.disable_overmountmount -t proc proc /procDEBUG="`cmdline_value debug`"if [ "$DEBUG" = "" ]; then DEBUG="`cmdline_parameter debug`" if [ ! "$DEBUG" = "" ]; then DEBUG="cat /proc/self/environ /proc/mounts" fifi$DEBUG# mount /dev filesystem only if it's not already mounted by kernelif [ ! -r /dev/.devfsd ]; then mount -t devfs devfs /dev if [ ! "$?" = "0" ]; then header "ERROR!" echo "devfs is not mounted in /dev and mount attempt failed" echo "Your kernel probably doesn't support devfs" echo "try cat /proc/filesystems | grep devfs" echo "Press Ctrl+Alt+Del for reboot." while [ 1 = 1 ]; do bash; done fifi# mount this very soon to allow modules to include device filesmount -t devfs devfs /mnt/devif [ ! "`cmdline_parameter nolock`" = "" ]; then echo "CD locking disabled by nolock kernel parameter" echo "0" >/proc/sys/dev/cdrom/lockfi# to be able to boot from hdc=ide-scsimodprobe_module ide-scsiif [ ! "`cmdline_parameter probeusb`" = "" ]; then echo "probing usb hardware" modprobe_module usbcore modprobe_module usb-storage modprobe_module usb-uhci modprobe_module uhci modprobe_module usb-ohci modprobe_module ehci-hcd sleep 5fi# call mount_all_cds function, to mount /dev/hdc hdd etc.echo "mounting all available CDs"mount_all_cds /mnt/mnt >>$MOUNTSecho "mounting other discs (ro)"mount_all_discs /mnt/mnt >>$MOUNTSif [ ! "`cmdline_parameter floppy`" = "" ]; then echo "mounting floppy if available (ro)" mount_device /dev/floppy/0 /mnt/mnt/floppy ro echo "/dev/floppy/0" >>$MOUNTSfiLIVECD_SUBDIRECTORY=`cmdline_value livecd_subdirectory`LIVECD_SUBDIR=`cmdline_value livecd_subdir`# and choose the longer one:if [ ${#LIVECD_SUBDIR} -lt ${#LIVECD_SUBDIRECTORY} ]; then LIVECD_SUBDIR="$LIVECD_SUBDIRECTORY"fiecho "liveCD subdirectory is $LIVECD_SUBDIR";# search what mount directory is our CD infor DIR in /mnt/mnt/*do if [ -r "$DIR/$LIVECD_SUBDIR/$LIVECD_SGN" ]; then LIVECD_MOUNT="$DIR" LIVECD_PATH="`dirname \"$DIR/$LIVECD_SUBDIR/x\"`" echo "LiveCD path is now $LIVECD_PATH" break fidone$DEBUGTOHD="`cmdline_value tohd`"FROMHD="`cmdline_value fromhd`"HDSUBDIR="`cmdline_value hdsubdir`"if [ "$HDSUBDIR" = "" ]; then HDSUBDIR="LIVECD";fi# copy entire CD to harddisk and use it from thereif [ ! "$TOHD" = "" ]; then echo "Remounting $TOHD read-write" remount /mnt/mnt/$TOHD rw if [ $? -eq 0 ]; then TOHDDIR=/mnt/mnt/$TOHD/$HDSUBDIR mkdir -p $TOHDDIR 2>/dev/null touch $TOHDDIR/slax.tmp 2>/dev/null if [ $? -eq 0 ]; then echo "Copying the LiveCD source to $TOHDDIR..." cp -Rf $LIVECD_PATH/* $TOHDDIR 2>/dev/null if [ $? -eq 0 ]; then FROMHD=$TOHD TOHD_OK=1 fi echo "Remounting $TOHD read-only" remount /mnt/mnt/$TOHD ro fi fi if [ ! $TOHD_OK -eq 1 ]; then header "ERROR!" echo "An error occured while copying CD to $TOHD." echo "Not enough free space? Wrong directory name? ($TOHD)" echo "The original source CD will be used." echo fifi# use already copied CD from harddiskif [ ! "$FROMHD" = "" ]; then echo "FROMHD parameter detected, using $FROMHD" LIVECD_MOUNT="/mnt/mnt/$FROMHD" LIVECD_PATH="/mnt/mnt/$FROMHD/$HDSUBDIR"fi# if no data found, run bashif [ ! -r "$LIVECD_PATH/$LIVECD_SGN" ]; then header "ERROR!" echo "cannot find your compressed IMG files! Maybe you are trying" echo "to start the LiveCD from unsupported CDROM drive (scsi?)" echo "Or you entered wrong livecd_subdir= parameter?" echo "Or you entered wrong fromhd= parameter?" echo "Press Ctrl+Alt+Del for reboot." while [ 1 = 1 ]; do bash; donefiecho "liveCD found in $LIVECD_PATH"mkdir -p $LIVECDDATA $IMGRO $IMGRW $CP2RAM $CHANGESecho -n "copying selected modules to RAM... "# basels -aA1b "$LIVECD_PATH/base" 2>/dev/null | while read IMG; do echo "`cp2ram \"$LIVECD_PATH/base/$IMG\" \"$CP2RAM\"`" >>$MNTORDERdone# modulesls -aA1b "$LIVECD_PATH/modules" 2>/dev/null | while read IMG; do echo "`cp2ram \"$LIVECD_PATH/modules/$IMG\" \"$CP2RAM\"`" >>$MNTORDERdone# optional modules (insert only modules specified by load= kernel boot parameter)cmdline_value load | tr "," "\\n" | while read IMG; do ls -aA1b "$LIVECD_PATH/optional/$IMG"* 2>/dev/null | while read IMAGE; do echo "`cp2ram \"$IMAGE\" \"$CP2RAM\"`" >>$MNTORDER donedoneechoecho -n "unpacking .tar.gz from the CD... "ls -aA1b $LIVECD_PATH/packs | while read PACK;do echo -n "$PACK " tar -C /mnt -xzmf "$LIVECD_PATH/packs/$PACK"doneechoecho -n "mounting all images... "cat $MNTORDER | while read IMG;do echo -n "`basename \" $IMG\"` " mount_img $IMG $IMGRO $INSORDER -ndoneecho$DEBUGheader "creating live filesystem"echo "Starting ovlfs support (by Arthur Naseef)"modprobe_module ovlmount -t ovl cdrom_ovl $IMGRW -o root=$IMGRO,storage=$CHANGES,stg_file=$STGFILEif [ ! "$?" = "0" ]; then header "ERROR!" echo "cannot overmount cdrom in pseudo-write mode." echo "Maybe your kernel doesn't support ovlfs?" echo "Press Ctrl+Alt+Del for reboot." while [ 1 = 1 ]; do bash; donefiecho -n "inserting images into filesystem... "cat $INSORDER | while read IMG;do IMG=$IMGRW/${IMG:${#IMGRO}} echo -n "`basename \"$IMG\"` " if [ -x $IMG/preinsert ]; then $IMG/preinsert; fi make_links $IMG/data /mnt /mnt if [ -x $IMG/postinsert ]; then $IMG/postinsert; fidoneecho$DEBUGif [ ! "`cmdline_parameter eject`" = "" ]; then echo "trying to eject LiveCD medium..." eject "$LIVECD_MOUNT" >/dev/null 2>/dev/null if [ ! "$?" = 0 ]; then echo "error, cdrom cannot be unmounted or doesn't support ejecting" fielse mount --rbind $LIVECD_PATH /mnt/bootfiecho "exporting LIVECD variables to profile.d..."echo "export LIVECD_MOUNT="${LIVECD_MOUNT:4} >/mnt/etc/profile.d/slax.shecho "export LIVECD_PATH="${LIVECD_PATH:4} >>/mnt/etc/profile.d/slax.shchmod 755 /mnt/etc/profile.d/slax.shecho "setenv LIVECD_MOUNT "${LIVECD_MOUNT:4} >/mnt/etc/profile.d/slax.cshecho "setenv LIVECD_PATH "${LIVECD_PATH:4} >>/mnt/etc/profile.d/slax.cshchmod 755 /mnt/etc/profile.d/slax.cshecho "creating fstab..."echo "tmpfs / tmpfs defaults 0 0" >/mnt/etc/fstabecho "proc /proc proc defaults 0 0" >>/mnt/etc/fstabcat $MOUNTS | while read DEVICE; do LINE="`cat /proc/mounts | egrep \"^$DEVICE[[:space:]]\"`" if [ "$LINE" = "" ]; then continue; fi umount "$DEVICE" 1>/dev/null 2>/dev/null if [ "$?" = 0 ]; then LINERO=${LINE/ \/mnt/ } LINEDEF=${LINERO/ ro / defaults } echo $LINEDEF >>/mnt/etc/fstab fidonesed 's/vfat defaults/vfat iocharset=cp936,defaults/g' /mnt/etc/fstab > /mnt/etc/fstab.1sed 's/ntfs defaults/ntfs iocharset=cp936,defaults/g' /mnt/etc/fstab.1 > /mnt/etc/fstab.2cp /mnt/etc/fstab.2 /mnt/etc/fstabrm /mnt/etc/fstab.1 /mnt/etc/fstab.2list_swaps >>/mnt/etc/fstabecho >/mnt/etc/mtabtouch -t 197001010000.00 /mnt/etc/modules.conf # to avoid error messagesecho "creating init script in /tmp/init..."echo >/mnt/$LINUXINITchmod 0755 /mnt/$LINUXINITNEWROOTPASS="`cmdline_value passwd`"if [ "$NEWROOTPASS" = "ask" ]; then echo -ne "\nEnter new password for root: " read -s NEWROOTPASSfiif [ ! "$NEWROOTPASS" = "" ]; then echo "root:$NEWROOTPASS" | chroot /mnt /usr/sbin/chpasswdfiecho 'echo "freeing ramdisk..."umount -nl /mnt/ramdisk/sbin/blockdev --flushbufs /dev/rd/0echo "'"`header \"starting init\"`"'"exec /sbin/init <dev/console >dev/console 2>&1' >>/mnt/$LINUXINITmount -o remount,ro /mntcd /mnt$DEBUGecho "changing root directory..."/sbin/pivot_root . mnt/ramdiskexec /usr/bin/chroot . $LINUXINIT <dev/console >dev/console 2>&1header "ERROR!"echo "You are not supposed to be here, something went wrong!"echo "calling /mnt/usr/bin/chroot failed?"echo "Press Ctrl+Alt+Del for reboot."while [ 1 = 1 ]; do bash; done
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -