Guest User

rangalo

a guest
Feb 21st, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.53 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # /etc/rc.sysinit
  4. #
  5.  
  6. . /etc/rc.conf
  7. . /etc/rc.d/functions
  8.  
  9. echo " "
  10. printhl "Arch Linux\n"
  11. printhl "${C_H2}http://www.archlinux.org"
  12. printhl "Copyright 2002-2007 Judd Vinet"
  13. printhl "Copyright 2007-2009 Aaron Griffin"
  14. printhl "Distributed under the GNU General Public License (GPL)"
  15. printsep
  16.  
  17. run_hook sysinit_start
  18.  
  19. # mount /proc, /sys and our RAM /dev
  20. /bin/mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid
  21. /bin/mount -n -t proc none /proc
  22. /bin/mount -n -t sysfs none /sys
  23.  
  24. # Copy static device nodes to /dev
  25. /bin/cp -a /lib/udev/devices/* /dev/
  26.  
  27. # start up our mini logger until syslog takes over
  28. /sbin/minilogd
  29.  
  30. # anything more serious than KERN_WARNING goes to the console
  31. # 'verbose' cmdline parameter enables more messages
  32. if /bin/grep -q " verbose" /proc/cmdline; then
  33. /bin/dmesg -n 8
  34. else
  35. /bin/dmesg -n 3
  36. fi
  37.  
  38. HWCLOCK_PARAMS="--hctosys"
  39. if [ "$HARDWARECLOCK" = "UTC" ]; then
  40. HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
  41. elif [ "$HARDWARECLOCK" = "localtime" ]; then
  42. HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
  43. else
  44. HWCLOCK_PARAMS=""
  45. fi
  46.  
  47. if [ -n "$HWCLOCK_PARAMS" ]; then
  48. # enable rtc access
  49. /sbin/modprobe rtc-cmos >/dev/null 2>&1
  50. RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null)
  51. RTC_MAJOR="${RTC_MAJOR%% *}"
  52. if [ -n "$RTC_MAJOR" ]; then
  53. /bin/mknod /dev/rtc0 c $RTC_MAJOR 0
  54. /bin/ln -s /dev/rtc0 /dev/rtc
  55. fi
  56.  
  57. # Do a clock set here for a few reasons:
  58. # 1. Make creation time on udev nodes sane (FS#8665)
  59. # 2. Filesystem checks can depend on system time
  60. # 3. This will set the clock, if using non-UTC, off the last known
  61. # configured timezone. Any new timezone put in rc.conf is copied over at
  62. # a later time.
  63. # This does *NOT* take into account a time adjustment file as /var may not be
  64. # mounted yet. A second set occurs later to match rc.conf.
  65. if [ -f /etc/localtime ]; then
  66. /sbin/hwclock $HWCLOCK_PARAMS --noadjfile
  67. fi
  68. fi
  69.  
  70. echo > /proc/sys/kernel/hotplug
  71.  
  72. stat_busy "Starting UDev Daemon"
  73. /sbin/udevd --daemon
  74. stat_done
  75.  
  76. run_hook sysinit_udevlaunched
  77.  
  78. # Trigger udev uevents
  79. if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
  80. stat_busy "Triggering UDev uevents"
  81. /sbin/udevadm control --property=STARTUP=1
  82. /sbin/udevadm trigger
  83. stat_done
  84. fi
  85.  
  86. # Load modules from the MODULES array defined in rc.conf
  87. if ! [ "$load_modules" = "off" ]; then
  88. if [ -f /proc/modules ]; then
  89. stat_busy "Loading Modules"
  90. for mod in "${MODULES[@]}"; do
  91. if [ "$mod" = "${mod#!}" ]; then
  92. /sbin/modprobe $mod
  93. fi
  94. done
  95. stat_done
  96. fi
  97. fi
  98.  
  99. # Wait for udev uevents
  100. if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
  101. stat_busy "Waiting for UDev uevents to be processed"
  102. /sbin/udevadm settle
  103. /sbin/udevadm control --property=STARTUP=
  104. stat_done
  105. fi
  106.  
  107. run_hook sysinit_udevsettled
  108.  
  109. # bring up the loopback interface
  110. if [ -d /sys/class/net/lo ]; then
  111. stat_busy "Bringing up loopback interface"
  112. /sbin/ifconfig lo 127.0.0.1 up
  113. if [ $? -ne 0 ]; then
  114. stat_fail
  115. else
  116. stat_done
  117. fi
  118. fi
  119.  
  120. # If necessary, find md devices and manually assemble RAID arrays
  121. if [ -f /etc/mdadm.conf -a "$(/bin/grep ^ARRAY /etc/mdadm.conf 2>/dev/null)" ]; then
  122. status "Activating RAID arrays" /sbin/mdadm --assemble --scan
  123. fi
  124.  
  125. if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
  126. if [ -x /sbin/lvm -a -d /sys/block ]; then
  127. # Kernel 2.6.x, LVM2 groups
  128. /sbin/modprobe -q dm-mod 2>/dev/null
  129. stat_busy "Activating LVM2 groups"
  130. /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
  131. if [ $? -ne 0 ]; then
  132. stat_fail
  133. else
  134. stat_done
  135. fi
  136. fi
  137. fi
  138.  
  139. # Set up non-root encrypted partition mappings
  140. if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then
  141. /sbin/modprobe -q dm-mod 2>/dev/null
  142. stat_busy "Unlocking encrypted volumes:"
  143. csfailed=0
  144. CS=/sbin/cryptsetup.static
  145. do_crypt() {
  146. if [ $# -ge 3 ]; then
  147. cname="$1"
  148. csrc="$2"
  149. cpass="$3"
  150. shift 3
  151. copts="$*"
  152. stat_append "${cname}.."
  153. # For some fun reason, the parameter ordering varies for
  154. # LUKS and non-LUKS devices. Joy.
  155. if [ "${cpass}" = "SWAP" ]; then
  156. # This is DANGEROUS! The only possible safety check
  157. # is to not proceed in case we find a LUKS device
  158. # This may cause dataloss if it is not used carefully
  159. if $CS isLuks $csrc 2>/dev/null; then
  160. false
  161. else
  162. $CS -d /dev/urandom $copts create $cname $csrc >/dev/null
  163. if [ $? -eq 0 ]; then
  164. stat_append "creating swapspace.."
  165. /sbin/mkswap -f -L $cname /dev/mapper/$cname >/dev/null
  166. fi
  167. fi
  168. elif [ "${cpass}" = "ASK" ]; then
  169. printf "\nOpening '${cname}' volume:\n"
  170.  
  171. if $CS isLuks $csrc 2>/dev/null; then
  172. $CS $copts luksOpen $csrc $cname < /dev/console
  173. else
  174. $CS $copts create $cname $csrc < /dev/console
  175. fi
  176. elif [ "${cpass:0:1}" != "/" ]; then
  177. if $CS isLuks $csrc 2>/dev/null; then
  178. echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null
  179. else
  180. echo "$cpass" | $CS $copts create $cname $csrc >/dev/null
  181. fi
  182. else
  183. if $CS isLuks $csrc 2>/dev/null; then
  184. $CS -d $cpass $copts luksOpen $csrc $cname >/dev/null
  185. else
  186. $CS -d $cpass $copts create $cname $csrc >/dev/null
  187. fi
  188. fi
  189. if [ $? -ne 0 ]; then
  190. csfailed=1
  191. stat_append "failed "
  192. else
  193. stat_append "ok "
  194. fi
  195. fi
  196. }
  197. while read line; do
  198. eval do_crypt "$line"
  199. done </etc/crypttab
  200. if [ $csfailed -eq 0 ]; then
  201. stat_done
  202. else
  203. stat_fail
  204. fi
  205. # Maybe someone has LVM on an encrypted block device
  206. if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
  207. if [ -x /sbin/lvm -a -d /sys/block ]; then
  208. /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
  209. fi
  210. fi
  211. fi
  212.  
  213. status "Mounting Root Read-only" /bin/mount -n -o remount,ro /
  214.  
  215. FORCEFSCK=
  216. [ -f /forcefsck ] && FORCEFSCK="-- -f"
  217. NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs"
  218.  
  219. fsck_reboot() {
  220. echo "Automatic reboot in progress..."
  221. /bin/umount -a
  222. /bin/mount -n -o remount,ro /
  223. /sbin/reboot -f
  224. exit 0
  225. }
  226.  
  227. if [ -x /sbin/fsck ]; then
  228. stat_busy "Checking Filesystems"
  229. FSCK_OUT=/dev/stdout
  230. FSCK_ERR=/dev/null
  231. /sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR
  232. fsckret=$?
  233. if [ ${fsckret} -gt 1 ]; then
  234. stat_fail
  235. fi
  236. if [ $((${fsckret}&2)) -eq 2 ]; then
  237. echo
  238. echo "********************** REBOOT REQUIRED *********************"
  239. echo "* *"
  240. echo "* The system will be rebooted automatically in 15 seconds. *"
  241. echo "* *"
  242. echo "************************************************************"
  243. echo
  244. /bin/sleep 15
  245. fsck_reboot
  246. fi
  247. if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then
  248. echo
  249. echo "***************** FILESYSTEM CHECK FAILED ****************"
  250. echo "* *"
  251. echo "* Please repair manually and reboot. Note that the root *"
  252. echo "* file system is currently mounted read-only. To remount *"
  253. echo "* it read-write type: mount -n -o remount,rw / *"
  254. echo "* When you exit the maintenance shell the system will *"
  255. echo "* reboot automatically. *"
  256. echo "* *"
  257. echo "************************************************************"
  258. echo
  259. /sbin/sulogin -p
  260. fsck_reboot
  261. fi
  262. stat_done
  263. fi
  264.  
  265. stat_busy "Mounting Local Filesystems"
  266. /bin/mount -n -o remount,rw /
  267. : >| /etc/mtab
  268. # make sure / gets written to /etc/mtab
  269. /bin/mount -o remount,rw /
  270. # Write /proc, /sys and /dev to /etc/mtab
  271. if [ -e /proc/mounts ]; then
  272. /bin/grep -e "/proc " -e "/sys " -e "/dev " /proc/mounts >> /etc/mtab
  273. fi
  274. run_hook sysinit_premount
  275. # now mount all the local filesystems
  276. /bin/mount -a -t $NETFS -O no_netdev
  277. stat_done
  278.  
  279. status "Activating Swap" /sbin/swapon -a
  280.  
  281. stat_busy "Configuring System Clock"
  282. if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
  283. /bin/rm -f /etc/localtime
  284. /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  285. fi
  286.  
  287. clock_pid=""
  288. if [ -n "$HWCLOCK_PARAMS" ]; then
  289. # This time, we set the clock for real. Use the adjustment file now that
  290. # /var will definitely be available, and then set the system clock once
  291. # the hardware clock has been adjusted accordingly. The backgrounding magic
  292. # is due to the fact that the second call to hwclock will almost always
  293. # take ~1 second because of the clock granularity, and we might as well
  294. # stay busy.
  295. (
  296. /sbin/hwclock --adjust
  297. /sbin/hwclock $HWCLOCK_PARAMS
  298. ) &
  299. clock_pid=$!
  300. fi
  301. stat_done
  302.  
  303. RANDOM_SEED=/var/lib/misc/random-seed
  304. if [ -f $RANDOM_SEED ]; then
  305. stat_busy "Initializing Random Seed"
  306. /bin/cat $RANDOM_SEED > /dev/urandom
  307. stat_done
  308. fi
  309.  
  310. stat_busy "Removing Leftover Files"
  311. /bin/rm -f /etc/nologin &>/dev/null
  312. /bin/rm -f /etc/shutdownpid &>/dev/null
  313. /bin/rm -f /var/lock/* &>/dev/null
  314. /bin/rm -rf /tmp/* /tmp/.* &>/dev/null
  315. /bin/rm -f /forcefsck &>/dev/null
  316. (cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; )
  317. : >| /var/run/utmp
  318. /bin/chmod 0664 /var/run/utmp
  319. # Keep {x,k,g}dm happy with xorg
  320. /bin/mkdir /tmp/.ICE-unix && /bin/chmod 1777 /tmp/.ICE-unix
  321. /bin/mkdir /tmp/.X11-unix && /bin/chmod 1777 /tmp/.X11-unix
  322. stat_done
  323.  
  324. #status "Updating Shared Library Links" /sbin/ldconfig
  325.  
  326. if [ "$HOSTNAME" != "" ]; then
  327. status "Setting Hostname: $HOSTNAME" /bin/hostname $HOSTNAME
  328. fi
  329.  
  330. # Set the NIS domain name, if necessary
  331. [ -f /etc/conf.d/nisdomainname ] && . /etc/conf.d/nisdomainname
  332. if [ "$NISDOMAINNAME" != "" ]; then
  333. status "Setting NIS Domain Name: $NISDOMAINNAME" /bin/nisdomainname $NISDOMAINNAME
  334. fi
  335.  
  336. status "Updating Module Dependencies" /sbin/depmod -A
  337.  
  338. # Flush old locale settings
  339. : >| /etc/profile.d/locale.sh
  340. /bin/chmod 755 /etc/profile.d/locale.sh
  341. # Set user defined locale
  342. [ -z "$LOCALE" ] && LOCALE="en_US"
  343. stat_busy "Setting Locale: $LOCALE"
  344. echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh
  345. stat_done
  346.  
  347. if echo "$LOCALE" | /bin/grep -qi utf ; then
  348. stat_busy "Setting Consoles to UTF-8 mode"
  349. # UTF-8 consoles are default since 2.6.24 kernel
  350. # this code is needed not only for older kernels,
  351. # but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8.
  352. for i in /dev/tty[0-9]*; do
  353. /usr/bin/kbd_mode -u < ${i}
  354. printf "\033%%G" > ${i}
  355. done
  356. # the $CONSOLE check helps us avoid this when running scripts from cron
  357. echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%G"; fi' >>/etc/profile.d/locale.sh
  358. stat_done
  359. [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u $KEYMAP
  360. else
  361. stat_busy "Setting Consoles to legacy mode"
  362. # make non-UTF-8 consoles work on 2.6.24 and newer kernels
  363. for i in /dev/tty[0-9]*; do
  364. /usr/bin/kbd_mode -a < ${i}
  365. printf "\033%%@" > ${i}
  366. done
  367. # the $CONSOLE check helps us avoid this when running scripts from cron
  368. echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%@"; fi' >>/etc/profile.d/locale.sh
  369. stat_done
  370. [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP
  371. fi
  372.  
  373. if [ -n "$CONSOLEFONT" ]; then
  374. stat_busy "Loading Console Font: $CONSOLEFONT"
  375. #CONSOLEMAP in UTF-8 shouldn't be used
  376. if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then
  377. CONSOLEMAP=""
  378. fi
  379. for i in /dev/tty[0-9]*; do
  380. if [ -n "$CONSOLEMAP" ]; then
  381. /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1
  382. else
  383. /usr/bin/setfont $CONSOLEFONT -C ${i} >/dev/null 2>&1
  384. fi
  385. done
  386. if [ $? -ne 0 ]; then
  387. stat_fail
  388. else
  389. for i in /dev/tty[0-9]*; do
  390. printf "\033(K" > ${i}
  391. done
  392. # the $CONSOLE check helps us avoid this when running scripts from cron
  393. echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi' >>/etc/profile.d/locale.sh
  394. stat_done
  395. fi
  396. fi
  397.  
  398. # Adding persistent network/cdrom generated rules
  399. if [ -f "/dev/.udev/tmp-rules--70-persistent-cd.rules" ]; then
  400. stat_busy "Adding persistent cdrom udev rules"
  401. /bin/cat /dev/.udev/tmp-rules--70-persistent-cd.rules >> /etc/udev/rules.d/70-persistent-cd.rules
  402. stat_done
  403. fi
  404. if [ -f "/dev/.udev/tmp-rules--70-persistent-net.rules" ]; then
  405. stat_busy "Adding persistent network udev rules"
  406. /bin/cat /dev/.udev/tmp-rules--70-persistent-net.rules >> /etc/udev/rules.d/70-persistent-net.rules
  407. stat_done
  408. fi
  409.  
  410. /bin/dmesg >| /var/log/dmesg.log
  411.  
  412. # final hwclock setting needs to be done at this point
  413. if [ -n "$clock_pid" ]; then
  414. wait $clock_pid
  415. fi
  416.  
  417. run_hook sysinit_end
  418.  
  419. # End of file
  420. # vim: set ts=2 sw=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment