home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 February / PCpro_2006_02.ISO / boot / initrd_installer / initrd / linuxrc < prev   
Encoding:
Text File  |  2005-02-24  |  2.7 KB  |  120 lines

  1. #!/static/bash
  2. ################################################################################
  3. #
  4. # Coreworks tv dec 2004
  5.  
  6. function _debug() {
  7.         local msg="$1"
  8.         echo "DEBUG: $1"
  9.         /static/bash
  10. }
  11.  
  12. function _wait_with_bash {
  13.  
  14.         read -n 1 -s -t 3 -p "Waiting 3 seconds ... press s for a shell"
  15.         if [ "x$REPLY" = "xs" ]; then
  16.                 echo
  17.                 echo " Press CTRL-D to continue ..."
  18.                 /static/bash
  19.         else
  20.                 echo
  21.         fi
  22. }
  23.  
  24. #mount="/static/busybox mount"
  25. mount="/static/mount"
  26. umount="/static/busybox umount"
  27. insmod="/static/busybox insmod"
  28. tar="/static/busybox tar"
  29.  
  30.  
  31. dirs_to_bind_mount="bin lib opt sbin usr"
  32. MOUNTPOINT="/LIVECD"    # live cd will be mounted there
  33. CLOOPPOINT="/LIVECLOOP" # if exists cloop will be mounted there
  34. ROOTPOINT=""            # this will be the / of the cd (NOT the / of running livecd)
  35.  
  36. echo "mounting cdrom..."
  37. for i in 0 1 2 3 4 5 6 7 8 9 ; do
  38.     cddev="/dev/cdroms/cdrom$i"
  39.     $mount -o iso9660,ro $cddev $MOUNTPOINT
  40.     if [ -f /$MOUNTPOINT/livecd ] ; then
  41.         echo "found cdrom at $cddev" ;
  42.         break ;
  43.     else 
  44.         echo "cdrom $cddev was the wrong device. trying next.\n";
  45.  
  46.         $umount $MOUNTPOINT
  47.     fi
  48. done ;
  49.  
  50. #_debug "after cdrom mount"
  51.  
  52. if [ -f /$MOUNTPOINT/livecd.img ] ; then
  53.  
  54.     # live cd with cloop
  55.     echo "This is a cloop live cd"
  56.     $insmod cloop.o file=/$MOUNTPOINT/livecd.img
  57.     $mount /dev/cloop/0 /$CLOOPPOINT -o ro
  58.  
  59.     ROOTPOINT=$CLOOPPOINT
  60.  
  61. else
  62.     
  63.     # no cloop
  64.     echo "This is a normal live cd (no cloop)"
  65.     ROOTPOINT=$MOUNTPOINT
  66.  
  67. fi
  68.  
  69.  
  70. # is bind mount really he thing we should do?
  71. for i in $dirs_to_bind_mount ; do
  72.     #echo "bind mount $i"
  73.     $mount -v --bind /$ROOTPOINT/$i /$i
  74. done
  75.  
  76.  
  77. # proc mount
  78. $mount /proc /proc -t proc
  79.  
  80.  
  81. #_debug "after proc, before RAMDISK stuff"
  82.  
  83. # note: this tmpfs, it will not allocate the whole size
  84. # only if needed
  85. $mount -v -t tmpfs -o "size=50m" /ramdisk /ramdisk
  86.  
  87. # we can use /bin/cp, as we have mounted /bin already
  88.  
  89. # after this, we have etc/root/data with stuff from cd but writeable
  90. echo "Copying /etc to /ramdisk "
  91. /bin/cp -a /$ROOTPOINT/etc  /ramdisk
  92.  
  93. # we use the initrd fstab
  94. /bin/cp -v /etc/fstab /ramdisk/etc
  95. /bin/rm -rf /etc  &&  /bin/ln -sf /ramdisk/etc  /etc
  96.  
  97. echo "Copying /root to /ramdisk"
  98. /bin/cp -a /$ROOTPOINT/root /ramdisk
  99. /bin/rm -rf /root &&  /bin/ln -sf /ramdisk/root /root
  100.  
  101. echo "Copying /data to /ramdisk"
  102. /bin/cp -a /$ROOTPOINT/data /ramdisk
  103. /bin/rm -rf /data &&  /bin/ln -sf /ramdisk/data /data
  104.  
  105. # FIXME /tmp stills lives on the initrd /
  106.  
  107.  
  108. # mtab
  109. /bin/rm /etc/mtab && /bin/ln -s /proc/mounts /etc/mtab
  110.  
  111. # invoke this file if exists
  112. [ -f /linuxrc.ext ] && echo "found /linuxrc.ext, executing ..." && . /linuxrc.ext
  113.  
  114. #_wait_with_bash
  115.  
  116. # Change root device from ??? to /dev/ram0 
  117. echo "0x100" > /proc/sys/kernel/real-root-dev
  118.  
  119. exit 0
  120.