Advertisement
Guest User

fanthom

a guest
Apr 24th, 2010
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.95 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # /etc/rc.d/rc.S: System initialization script.
  4. #
  5. # Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
  6. #
  7.  
  8. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  9.  
  10. # Try to mount /proc:
  11. /sbin/mount -v proc /proc -n -t proc 2> /dev/null
  12.  
  13. # Mount sysfs next, if the kernel supports it:
  14. if [ -d /sys ]; then
  15. if grep -wq sysfs /proc/filesystems ; then
  16. if ! grep -wq sysfs /proc/mounts ; then
  17. /sbin/mount -v sysfs /sys -n -t sysfs
  18. fi
  19. fi
  20. fi
  21.  
  22. # Initialize udev to manage /dev entries and hotplugging for 2.6.x kernels.
  23. # You may turn off udev by making the /etc/rc.d/rc.udev file non-executable
  24. # or giving the "nohotplug" option at boot, but in the 2.6.x+ kernels udev
  25. # has taken over the job of hotplug (finding hardware and loading the kernel
  26. # modules for it, as well as creating device nodes in /dev). Realize that
  27. # if you turn off udev that you will have to load all the kernel modules
  28. # that you need yourself (possibly in /etc/rc.d/rc.modules, which does not
  29. # promise to list all of them), and make any additional device nodes that you
  30. # need in the /dev directory. Even USB and IEEE1394 devices will need to have
  31. # the modules loaded by hand if udev is not used with a 2.6 kernel. So use it. :-)
  32. if grep -wq sysfs /proc/mounts && grep -q tmpfs /proc/filesystems ; then
  33. if ! grep -wq nohotplug /proc/cmdline ; then
  34. if [ -x /etc/rc.d/rc.udev ]; then
  35. /bin/sh /etc/rc.d/rc.udev start
  36. fi
  37. fi
  38. fi
  39.  
  40. # Initialize the Logical Volume Manager.
  41. # This won't start unless we find /etc/lvmtab (LVM1) or
  42. # /etc/lvm/backup/ (LVM2). This is created by /sbin/vgscan, so to
  43. # use LVM you must run /sbin/vgscan yourself the first time (and
  44. # create some VGs and LVs).
  45. if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
  46. echo "Initializing LVM (Logical Volume Manager):"
  47. # Check for device-mapper support.
  48. if ! grep -wq device-mapper /proc/devices ; then
  49. # Try to load a device-mapper kernel module:
  50. /sbin/modprobe -q dm-mod
  51. fi
  52. # Scan for new volume groups:
  53. /sbin/vgscan --mknodes --ignorelockingfailure 2> /dev/null
  54. if [ $? = 0 ]; then
  55. # Make volume groups available to the kernel.
  56. # This should also make logical volumes available.
  57. /sbin/vgchange -ay --ignorelockingfailure
  58. fi
  59. fi
  60.  
  61. # Open any volumes created by cryptsetup:
  62. if [ -f /etc/crypttab -a -x /sbin/cryptsetup.static ]; then
  63. # First, check for device-mapper support.
  64. if ! grep -wq device-mapper /proc/devices ; then
  65. # If device-mapper exists as a module, try to load it.
  66. # Try to load a device-mapper kernel module:
  67. /sbin/modprobe -q dm-mod
  68. fi
  69. # NOTE: we only support LUKS formatted volumes (except for swap)!
  70. cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
  71. eval LUKSARRAY=( $line )
  72. LUKS="${LUKSARRAY[0]}"
  73. DEV="${LUKSARRAY[1]}"
  74. PASS="${LUKSARRAY[2]}"
  75. OPTS="${LUKSARRAY[3]}"
  76. LUKSOPTS=""
  77. if echo $OPTS | grep -wq ro ; then LUKSOPTS="${LUKSOPTS} --readonly" ; fi
  78.  
  79. # Skip LUKS volumes that were already unlocked (in the initrd):
  80. /sbin/cryptsetup.static status $LUKS 1>/dev/null 2>/dev/null && continue
  81. if /sbin/cryptsetup.static isLuks $DEV 2>/dev/null ; then
  82. echo "Unlocking LUKS crypt volume '${LUKS}' on device '$DEV':"
  83. if [ -n "${PASS}" ]; then
  84. if [ -f ${PASS} ]; then
  85. /sbin/cryptsetup.static ${LUKSOPTS} --key-file=${PASS} luksOpen $DEV $LUKS
  86. elif [ "${PASS}" != "none" ]; then
  87. # A password field of 'none' indicates a line for swap:
  88. echo "${PASS}" | /sbin/cryptsetup.static ${LUKSOPTS} luksOpen $DEV $LUKS
  89. fi
  90. else
  91. for i in seq 1 3 ; do
  92. /sbin/cryptsetup.static ${LUKSOPTS} luksOpen $DEV $LUKS </dev/tty0 >/dev/tty0 2>&1
  93. [ $? -eq 0 ] && break
  94. done
  95. fi
  96. elif echo $OPTS | grep -wq swap ; then
  97. # If any of the volumes is to be used as encrypted swap,
  98. # then encrypt it using a random key and run mkswap:
  99. echo "Creating encrypted swap on device '$DEV' mapped to '${LUKS}':"
  100. /sbin/cryptsetup.static --cipher=aes --key-file=/dev/urandom --key-size=256 create $LUKS $DEV
  101. mkswap /dev/mapper/$LUKS
  102. fi
  103. done
  104. fi
  105.  
  106. # Enable swapping:
  107. /sbin/swapon -a 2> /dev/null
  108.  
  109. # Start FUSE, if requested:
  110. if [ -x /etc/rc.d/rc.fuse ]; then
  111. sh /etc/rc.d/rc.fuse start
  112. fi
  113.  
  114. # Set the system time from the hardware clock using hwclock --hctosys.
  115. if [ -x /sbin/hwclock ]; then
  116. # Check for a broken motherboard RTC clock (where ioports for rtc are
  117. # unknown) to prevent hwclock causing a hang:
  118. if ! grep -q -w rtc /proc/ioports ; then
  119. CLOCK_OPT="--directisa"
  120. fi
  121. if grep -wq "^UTC" /etc/hardwareclock ; then
  122. echo "Setting system time from the hardware clock (UTC)."
  123. /sbin/hwclock $CLOCK_OPT --utc --hctosys
  124. else
  125. echo "Setting system time from the hardware clock (localtime)."
  126. /sbin/hwclock $CLOCK_OPT --localtime --hctosys
  127. fi
  128. fi
  129.  
  130. # Test to see if the root partition is read-only, like it ought to be.
  131. READWRITE=no
  132. if touch /fsrwtestfile 2>/dev/null; then
  133. rm -f /fsrwtestfile
  134. READWRITE=yes
  135. else
  136. echo "Testing root filesystem status: read-only filesystem"
  137. fi
  138.  
  139. # See if a forced filesystem check was requested at shutdown:
  140. if [ -r /etc/forcefsck ]; then
  141. FORCEFSCK="-f"
  142. fi
  143.  
  144. # Check the root filesystem:
  145. if [ ! $READWRITE = yes ]; then
  146. RETVAL=0
  147. if [ ! -r /etc/fastboot ]; then
  148. echo "Checking root filesystem:"
  149. /sbin/fsck $FORCEFSCK -C -a /
  150. RETVAL=$?
  151. fi
  152. # An error code of 2 or higher will require a reboot.
  153. if [ $RETVAL -ge 2 ]; then
  154. # An error code equal to or greater than 4 means that some errors
  155. # could not be corrected. This requires manual attention, so we
  156. # offer a chance to try to fix the problem in single-user mode:
  157. if [ $RETVAL -ge 4 ]; then
  158. echo
  159. echo "***********************************************************"
  160. echo "*** An error occurred during the root filesystem check. ***"
  161. echo "*** You will now be given a chance to log into the ***"
  162. echo "*** system in single-user mode to fix the problem. ***"
  163. echo "*** ***"
  164. echo "*** If you are using the ext2 filesystem, running ***"
  165. echo "*** 'e2fsck -v -y <partition>' might help. ***"
  166. echo "***********************************************************"
  167. echo
  168. echo "Once you exit the single-user shell, the system will reboot."
  169. echo
  170. PS1="(Repair filesystem) \#"; export PS1
  171. sulogin
  172. else # With an error code of 2 or 3, reboot the machine automatically:
  173. echo
  174. echo "***********************************"
  175. echo "*** The filesystem was changed. ***"
  176. echo "*** The system will now reboot. ***"
  177. echo "***********************************"
  178. echo
  179. fi
  180. echo "Unmounting file systems."
  181. /sbin/umount -a -r
  182. /sbin/mount -n -o remount,ro /
  183. echo "Rebooting system."
  184. sleep 2
  185. reboot -f
  186. fi
  187. # Remount the root filesystem in read-write mode
  188. echo "Remounting root device with read-write enabled."
  189. /sbin/mount -w -v -n -o remount /
  190. if [ $? -gt 0 ] ; then
  191. echo
  192. echo "Attempt to remount root device as read-write failed! This is going to"
  193. echo "cause serious problems."
  194. echo
  195. echo "If you're using the UMSDOS filesystem, you **MUST** mount the root partition"
  196. echo "read-write! You can make sure the root filesystem is getting mounted "
  197. echo "read-write with the 'rw' flag to Loadlin:"
  198. echo
  199. echo "loadlin vmlinuz root=/dev/hda1 rw (replace /dev/hda1 with your root device)"
  200. echo
  201. echo "Normal bootdisks can be made to mount a system read-write with the rdev command:"
  202. echo
  203. echo "rdev -R /dev/fd0 0"
  204. echo
  205. echo "You can also get into your system by using a boot disk with a command like this"
  206. echo "on the LILO prompt line: (change the root partition name as needed)"
  207. echo
  208. echo "LILO: mount root=/dev/hda1 rw"
  209. echo
  210. echo "Please press ENTER to continue, then reboot and use one of the above methods to"
  211. echo -n "get into your machine and start looking for the problem. "
  212. read junk;
  213. fi
  214. else
  215. echo "Testing root filesystem status: read-write filesystem"
  216. echo
  217. echo "*** ERROR: Root partition has already been mounted read-write. Cannot check!"
  218. echo
  219. echo "For filesystem checking to work properly, your system must initially mount"
  220. echo "the root partition as read only. Please modify your kernel with 'rdev' so that"
  221. echo "it does this. If you're booting with LILO, add a line:"
  222. echo
  223. echo " read-only"
  224. echo
  225. echo "to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it."
  226. echo
  227. echo "If you boot from a kernel on a floppy disk, put it in the drive and type:"
  228. echo " rdev -R /dev/fd0 1"
  229. echo
  230. echo "If you boot from a bootdisk, or with Loadlin, you can add the 'ro' flag."
  231. echo
  232. echo "This will fix the problem *AND* eliminate this annoying message. :^)"
  233. echo
  234. echo -n "Press ENTER to continue. "
  235. read junk;
  236. fi # Done checking root filesystem
  237.  
  238. # Any /etc/mtab that exists here is old, so we delete it to start over:
  239. /bin/rm -f /etc/mtab*
  240. # Remounting the / partition will initialize the new /etc/mtab:
  241. /sbin/mount -w -o remount /
  242.  
  243. # Read in the correct / filesystem complete with arguments so mount will
  244. # show them correctly. This does not stop those arguments from functioning
  245. # but does prevent a small bug with /etc/mtab.
  246. /bin/grep ' / ' /proc/mounts | grep -v "^rootfs" > /etc/mtab
  247.  
  248. # Fix /etc/mtab to list sys and proc if they were not yet entered in
  249. # /etc/mtab because / was still mounted read-only:
  250. if [ -d /proc/sys ]; then
  251. /sbin/mount -f proc /proc -t proc
  252. fi
  253. if [ -d /sys/bus ]; then
  254. /sbin/mount -f sysfs /sys -t sysfs
  255. fi
  256.  
  257. # Configure ISA Plug-and-Play devices:
  258. if [ -r /etc/isapnp.conf ]; then
  259. if [ -x /sbin/isapnp ]; then
  260. /sbin/isapnp /etc/isapnp.conf
  261. fi
  262. fi
  263.  
  264. # This loads any kernel modules that are needed. These might be required to
  265. # use your ethernet card, sound card, or other optional hardware.
  266. # Priority is given first to a script named "rc.modules.local", then
  267. # to "rc.modules-$FULL_KERNEL_VERSION", and finally to the plain "rc.modules".
  268. # Note that if /etc/rc.d/rc.modules.local is found, then that will be the ONLY
  269. # rc.modules script the machine will run, so make sure it has everything in
  270. # it that you need.
  271. if [ -x /etc/rc.d/rc.modules.local -a -r /proc/modules ]; then
  272. echo "Running /etc/rc.d/rc.modules.local:"
  273. /bin/sh /etc/rc.d/rc.modules.local
  274. elif [ -x /etc/rc.d/rc.modules-$(uname -r) -a -r /proc/modules ]; then
  275. echo "Running /etc/rc.d/rc.modules-$(uname -r):"
  276. . /etc/rc.d/rc.modules-$(uname -r)
  277. elif [ -x /etc/rc.d/rc.modules -a -r /proc/modules -a -L /etc/rc.d/rc.modules ]; then
  278. echo "Running /etc/rc.d/rc.modules -> $(readlink /etc/rc.d/rc.modules):"
  279. . /etc/rc.d/rc.modules
  280. elif [ -x /etc/rc.d/rc.modules -a -r /proc/modules ]; then
  281. echo "Running /etc/rc.d/rc.modules:"
  282. . /etc/rc.d/rc.modules
  283. fi
  284.  
  285. # Configure runtime kernel parameters:
  286. if [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then
  287. /sbin/sysctl -e -p /etc/sysctl.conf
  288. fi
  289.  
  290. # Check all the non-root filesystems:
  291. if [ ! -r /etc/fastboot ]; then
  292. echo "Checking non-root filesystems:"
  293. /sbin/fsck $FORCEFSCK -C -R -A -a
  294. fi
  295.  
  296. # Mount usbfs:
  297. if grep -wq usbfs /proc/filesystems; then
  298. if ! grep -wq usbfs /proc/mounts ; then
  299. if ! grep -wq usbfs /etc/fstab; then
  300. /sbin/mount -v usbfs /proc/bus/usb -t usbfs
  301. else
  302. /sbin/mount -v /proc/bus/usb
  303. fi
  304. fi
  305. fi
  306.  
  307. # Mount non-root file systems in fstab, but not NFS or SMB
  308. # because TCP/IP is not yet configured, and not proc or sysfs
  309. # because those have already been mounted. Also check that
  310. # devpts is not already mounted before attempting to mount
  311. # it. With a 2.6.x or newer kernel udev mounts devpts.
  312. # We also need to wait a little bit to let USB and other
  313. # hotplugged devices settle (sorry to slow down the boot):
  314. echo "Mounting non-root local filesystems:"
  315. sleep 3
  316. ###########################
  317. #fanthom
  318. ###########################
  319.  
  320. LVM=`blkid | grep /dev/mapper | wc -l`
  321. if [ ! "$LVM" = "" ]; then
  322. file=/tmp/mapper
  323. x=1
  324. blkid | grep /dev/mapper > /tmp/mapper
  325. while [ $x -le $LVM ]; do
  326. NAME=`awk NR==$x $file | awk '{print$1}' | cut -d ':' -f1 | sed "s@/dev/mapper/@@"`
  327. FS=`awk NR==$x $file | awk '{print$3}' | cut -d '=' -f2 | sed s/'"'//g`
  328. echo "mounting LVM volume $NAME"
  329. mkdir /mnt/$NAME
  330. echo "/dev/mapper/$NAME /mnt/$NAME $FS auto,noatime,users,suid,dev,exec 0 0 # AutoUpdate" >> /etc/fstab
  331. x=$(($x+1))
  332. done
  333. rm $file
  334. fi
  335.  
  336. ##########################
  337. #fanthom
  338. ##########################
  339.  
  340. if /bin/grep -wq devpts /proc/mounts ; then
  341. /sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs,nodevpts
  342. else
  343. /sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs
  344. fi
  345.  
  346. # Enable swapping again. This is needed in case a swapfile is used,
  347. # as it can't be enabled until the filesystem it resides on has been
  348. # mounted read-write.
  349. /sbin/swapon -a 2> /dev/null
  350.  
  351. # Clean up some temporary files:
  352. rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
  353. /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
  354. /var/state/saslauthd/saslauthd.pid \
  355. /tmp/.Xauth* 1> /dev/null 2> /dev/null
  356. ( cd /var/log/setup/tmp && rm -rf * )
  357. ( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )
  358.  
  359. # Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
  360. if [ ! -e /tmp/.ICE-unix ]; then
  361. mkdir -p /tmp/.ICE-unix
  362. chmod 1777 /tmp/.ICE-unix
  363. fi
  364. if [ ! -e /tmp/.X11-unix ]; then
  365. mkdir -p /tmp/.X11-unix
  366. chmod 1777 /tmp/.X11-unix
  367. fi
  368.  
  369. # Create a fresh utmp file:
  370. touch /var/run/utmp
  371. chown root:utmp /var/run/utmp
  372. chmod 664 /var/run/utmp
  373.  
  374. # Update the current kernel level in the /etc/motd (Message Of The Day) file,
  375. # if the first line of that file begins with the word 'Linux'.
  376. # You are free to modify the rest of the file as you see fit.
  377. if [ -x /bin/sed ]; then
  378. /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
  379. fi
  380.  
  381. # If there are SystemV init scripts for this runlevel, run them.
  382. if [ -x /etc/rc.d/rc.sysvinit ]; then
  383. . /etc/rc.d/rc.sysvinit
  384. fi
  385.  
  386. # Run serial port setup script:
  387. # CAREFUL! This can make some systems hang if the rc.serial script isn't
  388. # set up correctly. If this happens, you may have to edit the file from a
  389. # boot disk, and/or set it as non-executable:
  390. if [ -x /etc/rc.d/rc.serial ]; then
  391. sh /etc/rc.d/rc.serial start
  392. fi
  393.  
  394. # Carry an entropy pool between reboots to improve randomness.
  395. if [ -f /etc/random-seed ]; then
  396. echo "Using /etc/random-seed to initialize /dev/urandom."
  397. cat /etc/random-seed > /dev/urandom
  398. fi
  399. # Use the pool size from /proc, or 512 bytes:
  400. if [ -r /proc/sys/kernel/random/poolsize ]; then
  401. dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(cat /proc/sys/kernel/random/poolsize) 2> /dev/null
  402. else
  403. dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
  404. fi
  405. chmod 600 /etc/random-seed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement