init 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. #!/bin/sh
  2. #(c) Copyright 2007 Barry Kauler, www.puppylinux.com
  3. #2007 GPL licence v2 (/usr/share/doc/legal/gpl-2.0.txt)
  4. #Aug 2007, init script in initramfs, for puppy v2.20, Sept: v3.00, Oct: v3.01
  5. #Nov 2007, v3.91: bugfix for humongous puppy.
  6. #dec 2007, v3.93: update for 2.6.24 kernel, no /dev/hd*. v3.94: bugfix.
  7. #v3.95 28dec07: load scsi_wait_scan.ko to fix sync problem with usb.
  8. #v3.95 1jan08: fix for renaming of pmedia ide/sata -> ata.
  9. #v3.96 26jan08: 2.6.24 kernel, remove scsi_wait_scan.ko and the delays.
  10. #v3.97 31jan2008: restore support for hd* drives.
  11. #v3.97 25feb2008: removed tmpfs on /tmp.
  12. #v3.97 5mar2008: handle SAVEMARK file (see universal installer and rc.shutdown).
  13. #v3.97 6mar2008: fix 'pfix=ram' for multisession cd/dvd.
  14. #v3.97 6mar2008: multisession, copy saved .sfs files to '/' in ram.
  15. #v3.98 3apr2008: partial fix, encrypted pup_save losetup failing.
  16. #v4.00 21apr2008: ntfs-3g upgraded v1.417 to v1.2412.
  17. #v4.00 26apr2008: slightly lowered threshold for copying pup_xxx.sfs to a tmpfs.
  18. #v4.00 27apr2008: k2.6.25: strange sync problem. try restore scsi_wait_scan. NO, DO NOT.
  19. #v4.01 7may2008: new system with all modules builtin to initrd, if ZDRVINIT='yes'
  20. #v4.02 31may2008: export ZDRVINIT in /etc/rc.d/PUPSTATE
  21. #v403 21jun08: reintroduce basic pcmcia support.
  22. #v403 23jun08: fix for humongous initrd.
  23. #v403 23jun08: fix boot from usb cd drive (classmate laptop).
  24. #v404 13Jul08: pfix=noram removed, now need pfix=copy to copy .sfs to ram.
  25. #v404 15jul08: prevent crash in PUPMODE 6,7. add pfix=fsck, otherwise never do fsck.
  26. #v404 16jul08: fix for classmate with internal usb flash, PUPMODE now 13, not 12.
  27. #v405 18jul08: default is now aufs. maybe won't even have unionfs module.
  28. #v406 2aug08: restore support for old /dev/hd* ide devices.
  29. #v406 9aug08: copy pup_xxx.sfs to same place as pup_save if fast media.
  30. #v407 fix for module name change.
  31. #v410 fix to allow 3 extra sfs files (a bug only allowed 2).
  32. #v411 multisession, load saved /dev entries.
  33. #v412 simplified module loading.
  34. #v412 slight changes for new busybox v1.12.1.
  35. #v412 fix usb-storage probe bug.
  36. #v412 DISTRO_SPECS file. pup_xxx.sfs, zdrv_xxx.sfs renamed.
  37. #v412 bugfix, /tmp/versioncleanup got overwritten by tmpfs mounted on /tmp.
  38. #v412 bugfix, pup_ro6 was not created (for 3rd sfs file).
  39. #w001 DISTRO_FILE_PREFIX, pup files renamed again, to woofsave.2fs, woofr001.sfs.
  40. #w003 fix for loading yenta-socket module.
  41. #w003 changed default to copy woofr001.sfs to ram >256MB ram.
  42. #w003 /usr/sbin/snapmergepuppy now saves whiteout files to save-layer, change 'ro' to 'ro+wh'.
  43. #w004 LANG=C
  44. #w007 load nls_utf8.ko
  45. #w012 bugfix. w014 usb flash can now have iso9660 f.s.
  46. #w014 BootFlash utility can create 2 partitions in usb drive, one for boot, other for save.
  47. #w015 allow 6 extra sfs files, up from 3.
  48. #w019 pmedia=ataflash, PUPMODE=13 to constrain writes to drv.
  49. #w460 bugfixes for zdrv, new name zu500629.sfs, handling 6 extra sfs files (7 incl. zdrv).
  50. #w460 bugfix, boot usb, 1st shutdown was not offering to save session sometimes.
  51. #w464 tidyup, make sure /etc/puppyversion is history.
  52. #w468 load nls_cp850, now default for fat f.s. (2.6.29.2 kernel).
  53. #w476 mntfunc() rewritten, support 'pkeys' boot param (work in progress).
  54. #w478 modify sfs exclusion rules.
  55. #w479 fix finding optical drive for kernel with old ide drivers.
  56. #w481 record fast partitions, used by rc.shutdown.
  57. #w482 lowered limit for copy sfs to ram, so multisession will work in 256mb pc.
  58. #v423 k2.6.29.6 dmesg has warning that ehci-hcd should load before uhci-hcd and ohci-hid.
  59. #v423 problem recent kernels: hid-* extra drivers needed as well as usbhid.
  60. #v423 need to reject wrong squashfs version, 3.x or 4.0.
  61. #v424 BootManager no longer has checkbox to only load _nnn.sfs files.
  62. #v424 try again, fix tmpfs overwrites /tmp/versioncleanup
  63. #v424 whiteout processing for aufs2 fixed.
  64. #v426 pkeys=de caused failure to boot from vfat partition.
  65. #v426 record of layers needs to include zdrv.
  66. #v431 piratesmack: fix boot from ext4.
  67. #091031 support quirky, kernel with initramfs built-in, maybe also <main f.s.>.sfs.
  68. #091122 now have /lib/keymaps, /lib/consolefonts, load map if pkeys boot param.
  69. #091222 first support for recognising mmc/sd cards at bootup.
  70. #091225 copy executables from initrd to main f.s.
  71. #100113 TARGETEXES file needed in main f.s., for universal installer.
  72. #100214 one config of 2.6.33 has base floppy and ps/2 mouse support not builtin.
  73. #100222 fix sync problem writing to BOOTCONFIG. technosaurus: consider very big puppies.
  74. #100318 fix any improper shutdowns. see /etc/rc.d/rc.sysinit, rc.shutdown, /sbin/init.
  75. #100323 hwclock path was wrong.
  76. #100401 fix so pupsave can be ext2, ext3 or ext4.
  77. #100406 latest patched aufs may allow sfs mntd one layer to be resident another layer.
  78. #100423 try yet again, fix tmpfs overwrites /tmp/versioncleanup
  79. #100427 despite the help inside the hwclock applet, it doesn't accept long-options.
  80. #100520 pkeys boot param wasn't working for 'uk', 'dvorak'.
  81. #100710 if pupsave file is in a subdirectory, only look for extra sfs's in that subdirectory.
  82. #100711 modify above, look in top dir and in subdirectory.
  83. #100820 multisession shutdown may now relocate some content of /var to /root/.var_saved.
  84. #100831 fix KERNELSUBVER for olpc people, have 'uname -r' returning version with '_'.
  85. #100911 simplified file names: vmlinuz, initrd.gz, puppy.sfs, zdrv.sfs, devx.sfs.
  86. #100911 fsckme.err filename changed to fsckme.flg. see also initNEW, rc.sysinit, rc.shutdown.
  87. #100911 completely overhauled the code to find puppy files. note, dropped support for /proc/ide.
  88. #100914 fallback, search depth 3 -- sub-sub-folders. improve psubdir search.
  89. #100915 technosaurus suggested 'pupsfs' and 'zdrv' kernel boot params. 100916 remove devxsfs. 100919.
  90. #100920 fix decision copy .sfs to ram.
  91. #100922 frugal install, multiple save-files in install-folder, was not offering choice.
  92. #101005 echo extra info if attempted mount failed.
  93. #101013 puppy.sfs was copied to tmpfs so can unmount partition.
  94. #101020 SAVEMARK file can be in sub-directory that pup is installed in, improve searching for save-file.
  95. #101021 avoid finding vmlinuz on hd when booting from cd.
  96. #101028 ask if upgrading save-file. check if puppy.sfs copied to same place as save-file.
  97. #101101 fix load zdrv if in humongous initrd.
  98. #101102 zdrv.sfs was not getting loaded for PUPMODE=6/7 (save to entire partition).
  99. #101103 ignore any session saved to entire partition if puppy installed in a subdir.
  100. #101103 maybe network boot, no local vmlinuz.
  101. #101103 modified logic to find save-file, tried some restrictions.
  102. #101127: pakt: A precfg area for faster re-mastering, no need to regenerate a .SFS.
  103. #101127 added some debugging into /tmp. Will end up in /initrd/tmp after bootup.
  104. #101127 force update of /proc/partitions (slow to update for usb).
  105. #101218 if boot from cd with 'pfix=ram', do not search other drives (do not want to load puppy.sfs off hd).
  106. #110114 if a drive unplugged in previous boot, but plugged in at bootup, device-nodes will be missing in main f.s...
  107. #110116 jamesbond: for netboot, PDEV1 is empty, tests modified. see: http://murga-linux.com/puppy/viewtopic.php?t=63400&start=180
  108. #110116 shinobar: do not change PUPMODE 6 to 7, 12 to 13, if extern usbhd.
  109. #110122 bypass update code, maybe causes more trouble than worth it. Rely on /etc/rc.d/update for all updating.
  110. #110126 restored support for /proc/ide, device nodes /dev/hd*.
  111. #110204 110205 110206 bug fixes: booting ide kernel, copying .sfs to sub-folder. warning: busybox grep -F different from full grep.
  112. #110212 recent aufs: .wh.__dir_opaque name changed to .wh..wh..opq.
  113. #110217 very bad hack, see /etc/rc.d/rc.update, rc.shutdown.
  114. #110223 reset /tmp/PUPSAVES if loop back to do deeper search.
  115. #110304 fix a test.
  116. #110405 fix 'free' applet output format different in later versions of busybox.
  117. #110422 DISTRO_VERSION variable now has dotted format. note, also now using full dotted version# in puppy filenames.
  118. #110424 do not copy puppy*.sfs into a sub-dir (reverse of 110204). see also rc.shutdown.
  119. #110425 major change, /sbin/wait4usb parallel process while searching ata drives, to speed booting.
  120. #110426 move done/failed 2 places to right (also in rc.sysinit script).
  121. #110509 fix for 'grep -f filename' where filename was empty only one LF char.
  122. #110521 also convert bytes to kb.
  123. #110710 handle kernel with usb driver built-in, and/or without my usb-drive-discovery patch (2.6.34+).
  124. #110722 fix deleting of old boot scripts.
  125. #110810 some builds may have many scsi drivers in initrd, if needed will have already loaded, so delete them.
  126. #110810 problem kernel numbering 2.6.32-40, 2.6.32-44 both in /lib/modules/2.6.32.
  127. #111003 ldolse: pemasu 2.6.39 kernel showing usb at also ata, causing double writes to /tmp/PUPSAVES.
  128. #111120 workarounds for missing support utilities: fusermount (no longer needed), e2fsck, resize2fs
  129. #120130 bring back Underdog Linux. Refer "take 2": http://puppylinux.com/development/howpuppyworks.html
  130. #120215 internationalized (with help from L18L). /PUPPYLANG inserted by quicksetup (in future, Woof too).
  131. #120216 /PUPPYKEYMAP inserted by quicksetup. if PLANG but no PKEYS, try assign matching PKEYS. L18L: new fonts.
  132. #120217 L18L: export LANGUAGE and OUTPUT_CHARSET.
  133. #120222 remove setting LANGUAGE. fix if boot param shortened, ex: plang=de
  134. #120328 could have iso9660 f.s. booting off a usb flash/hard drive (see BootFlash). exclude /dev/sd and /dev/mmc.
  135. #121102 file DISTRO_SPECS has new variable DISTRO_DB_SUBNAME. ex: for 14.0-based slacko, DISTRO_DB_SUBNAME=slacko14
  136. #121227 more f.s. drivers as modules, need to load (see also 3builddistro).
  137. #130128 support udf f.s.
  138. #130211 ntfs-3g needs "silent" option.
  139. #130216 preliminary support for f2fs. note, guess_fstype binary updated for f2fs, not yet busybox.
  140. #130513 if we find a rw f.s., create pupdesk.flg. only needed in PUPMODE=5, see /usr/sbin/quicksetup.
  141. #130514 shinobar: extra sfs in the order of EXTRASFSLIST.
  142. #130514 disable pupdesk.flg mechanism if boot param "pfix=ram".
  143. #130515 woof 3builddistro ask question to disable pupdesk.flg, edit this script.
  144. #130518 fix mounting ntfs for creating pupdesk.flg. fix paths.
  145. #130612 support devtmpfs.
  146. #130618 DEVTMPFSFLG now set by 3builddistro. refer also /etc/rc.d/rc.sysinit.
  147. #130728 always try to copy sfs to ram if >=700MB.
  148. #140102 better font for Russian, font is added to /lib/consolefont (in rootfs-skeleton)
  149. #140102 rodin.s: added utf8-option to VFAT_OUT_PARAM for flash drive to be mounted with utf-8 if boot is done from flash drive
  150. #Unionfs layers setup by this script...
  151. #unionfs layers: RW (top) RO1 RO2 PUPMODE
  152. #full install, flash drive: tmpfs PDEV1 3
  153. #First boot (or pfix=ram): tmpfs pup_xxx.sfs 5
  154. #pup_save is a partition: PDEV1 pup_xxx.sfs 6
  155. #ditto, but flash drive: tmpfs PDEV1 pup_xxx.sfs 7
  156. #Normal running puppy: pup_save.3fs pup_xxx.sfs 12
  157. #ditto, but flash drive: tmpfs pup_save.3fs pup_xxx.sfs 13
  158. #Multisession cd/dvd: tmpfs folders(tmpfs2) pup_xxx.sfs 77 (13+64)
  159. #/bin/hotplug2stdout_notimeout > /tmp/pup_event_uevents_initrd &
  160. #120215 internationalize... (based on work by L18L)
  161. if [ ! $1 ];then
  162. mount -t proc none /proc
  163. mount -t sysfs none /sys
  164. mount -t rootfs -o remount,rw rootfs /
  165. ln -s /proc/mounts /etc/mtab #resize2fs,e2fsck need this.
  166. [ $plang ] && PLANG=$plang #boot parameter
  167. [ "`echo -n "$PLANG" | grep '_'`" = "" ] && PLANG="" #120222 PLANG must be complete, ex: de_DE.UTF-8.
  168. [ ! "$PLANG" ] && [ -f /PUPPYLANG ] && PLANG=`cat /PUPPYLANG` #so Woof can specify a default lang.
  169. #note, a running puppy could also open initrd.gz and stick PUPPYLANG inside (i plan for chooselocale to do that!)
  170. if [ "$PLANG" ];then
  171. if [ -f /locale/${PLANG%.*}/init ];then #chop off .UTF-8 if it is there.
  172. TRANSLATIONFILE="/locale/${PLANG%.*}/init"
  173. else
  174. [ -f /locale/${PLANG%_*}/init ] && TRANSLATIONFILE="/locale/${PLANG%_*}/init" #get first 2 chars of PLANG, ex: en
  175. fi
  176. if [ "$TRANSLATIONFILE" ];then
  177. sed -f $TRANSLATIONFILE /init > /init2
  178. chmod 755 /init2
  179. exec /init2 $PLANG #run translated script.
  180. fi
  181. fi
  182. else #2nd entry, running /init2
  183. PLANG=${1}
  184. fi
  185. export LANG=C #w004
  186. . /DISTRO_SPECS #v412 has DISTRO_VERSION, DISTRO_FILE_PREFIX
  187. [ ! "$DISTRO_DB_SUBNAME" ] && DISTRO_DB_SUBNAME="$DISTRO_COMPAT_VERSION" #121102 fallback if DISTRO_DB_SUBNAME not defined in file DISTRO_SPECS.
  188. PATH="/bin:/sbin"
  189. KERNELVER="`uname -r`"
  190. PUPDESKFLG=1 #130515 this may be changed to 0 by 3builddistro.
  191. ##130612 detect CONFIG_DEVTMPFS=y and CONFIG_DEVTMPFS_MOUNT=y...
  192. DEVTMPFSFLG=0 #130618 set it from 3builddistro.
  193. #100911 simple filenames specified in DISTRO_SPECS: DISTRO_ZDRVSFS, DISTRO_PUPPYSFS...
  194. ZDRVSFS="$DISTRO_ZDRVSFS"
  195. ADRVSFS="$DISTRO_ADRVSFS"
  196. YDRVSFS="$DISTRO_YDRVSFS"
  197. PUPXXXSFS="$DISTRO_PUPPYSFS"
  198. IDSTRING="$DISTRO_IDSTRING" #from DISTRO_SPECS, string appended to kernel.qky, vmlinuz, puppy.sfs, zdrv.sfs, devx.sfs (see 3builddistro).
  199. [ "`echo "$PUPXXXSFS" | grep '[0-9]\.sfs'`" != "" ] && NAMETYPE='traditional' #110422 has version info.
  200. [ $layerfs ] && LAYERFS=$layerfs
  201. [ ! $LAYERFS ] && LAYERFS=aufs #aufs or unionfs
  202. [ "`modinfo aufs 2>/dev/null`" = "" ] && LAYERFS=unionfs #precaution.
  203. [ $loglevel ] && LOGLEVEL=$loglevel #v2.22
  204. #100318 perform a f.s. check...
  205. fsckme_func() { #passed params: partition filesystem [pupsavefile]
  206. if [ ! -e /bin/e2fsck ];then #111120
  207. echo -e -n "\\033[1;31m SORRY, cannot check filesystem \\033[0;39m" > /dev/console #31=red
  208. return
  209. fi
  210. case $2 in
  211. ext2|ext3|ext4)
  212. e2fsck -y -f /dev/$1 >/tmp/chkret &
  213. echo -e "\\033[1;35m" >/dev/console #35=purple
  214. if [ "${1}" = "loop1" ];then
  215. echo -n " 'save file' filesystem check, please wait..." >/dev/console
  216. else
  217. echo -n " '${1}' filesystem check, please wait..." >/dev/console
  218. fi
  219. usleep 200000 #100604 TazOC gave me idea that delay before pidof is good.
  220. while [ "`pidof e2fsck`" != "" ];do
  221. sleep 1
  222. echo -n "." >/dev/console
  223. done
  224. echo -en "\\033[0;39m" >/dev/console
  225. ;;
  226. esac
  227. if [ $3 ];then
  228. #rc.shutdown has created /fsckme.flg with this 3rd parameter.
  229. #this is a pupsave file, which has a ext2/3/4 f.s (based on .2fs, .3fs, .4fs ext)
  230. #this flag will be set for any prior improper shutdown. if have lots of installations
  231. #of puppy on the pc, the flag may not even be for this install of puppy, however, this is
  232. #the simplest implementation...
  233. PFSCK="yes"
  234. fi
  235. }
  236. mntfunc() {
  237. MNT_T="$1" #ex: vfat
  238. MNT_DEV="$2" #ex: /dev/sda1
  239. MNT_DIR="$3" #ex: /mnt/sda1
  240. MNT_O=""
  241. [ $4 ] && MNT_O="${4}" #ex: noatime
  242. case $MNT_T in
  243. ntfs)
  244. ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,silent 2>/dev/null #default is rw. 130211 add silent.
  245. ntfsRETVAL=$?
  246. [ $ntfsRETVAL -eq 0 ] && return 0
  247. if [ $ntfsRETVAL -eq 14 ];then
  248. echo -e "\\033[1;31m" >/dev/console #31=red
  249. echo -n "ERROR: Windows NTFS hibernated partition, cannot mount" > /dev/console
  250. echo -e "\\033[0;39m" >/dev/console
  251. return 14
  252. else
  253. ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,force,silent 2>/dev/null #130211 add silent.
  254. fi
  255. ;;
  256. vfat)
  257. mount -t $MNT_T -o $VFAT_OUT_PARAM $MNT_DEV $MNT_DIR
  258. ;;
  259. *)
  260. if [ "$MNT_O" = "" ];then
  261. mount -t $MNT_T $MNT_DEV $MNT_DIR
  262. else
  263. mount -t $MNT_T -o $MNT_O $MNT_DEV $MNT_DIR
  264. fi
  265. ;;
  266. esac
  267. return $?
  268. }
  269. umntfunc() {
  270. #111120 note, this code is not needed anymore for ntfs-3g. normal 'umount' can unmount it.
  271. #warning umntfunc call must have mntpt param, not device name.
  272. LASTPARAM="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/mnt/'`"
  273. if [ "`mount | grep "$LASTPARAM" | grep -E 'ntfs|fuse'`" = "" ];then
  274. umount $@
  275. else
  276. fusermount -u $LASTPARAM
  277. fi
  278. return $?
  279. }
  280. check_status()
  281. {
  282. if [ $1 -eq 0 ]
  283. then
  284. /bin/echo -en "\\033[74G" >/dev/console #move to column 72. 110426: 74
  285. /bin/echo -en "\\033[1;32m" >/dev/console
  286. /bin/echo -en "done" >/dev/console
  287. /bin/echo -e "\\033[0;39m" >/dev/console
  288. else
  289. /bin/echo -en "\\033[72G" >/dev/console #110426 move to column 72.
  290. /bin/echo -en "\\033[1;31m" >/dev/console
  291. /bin/echo -en "failed" >/dev/console
  292. /bin/echo -e "\\033[0;39m" >/dev/console
  293. echo -en "\\033[1;35m" >/dev/console #35=purple
  294. echo -n "Dumping last lines of /tmp/bootinit.log..." >/dev/console
  295. /bin/echo -e "\\033[0;39m" >/dev/console
  296. echo -en "\\033[1;31m" >/dev/console #31=red
  297. cat /tmp/bootinit.log | tail -n 4 >/dev/console
  298. /bin/echo -en "\\033[0;39m" >/dev/console
  299. echo -en "\\033[1;35m" >/dev/console #35=purple
  300. echo -n "Dumping last lines of kernel log..." >/dev/console
  301. /bin/echo -e "\\033[0;39m" >/dev/console
  302. echo -en "\\033[1;31m" >/dev/console #31=red
  303. dmesg | tail -n 4 >/dev/console
  304. /bin/echo -en "\\033[0;39m" >/dev/console
  305. #exit to initial ramdisk shell...
  306. [ "$RDSH" != "" ] && exec /bin/sh >/dev/console 2>&1
  307. echo "Pausing for 60 seconds..." >/dev/console
  308. sleep 60
  309. fi
  310. }
  311. search_func() { #110425
  312. case $1 in
  313. ata)
  314. [ "$PMEDIA" = "usbflash" -o "$PMEDIA" = "usbhd" ] && return #only probe usb drives.
  315. LESSPARTS0="`echo "$PCPARTS0" | grep -f /tmp/ALLDRVS0`" #111003 only probe non-usb drives. need for kernels builtin usb drvr.
  316. ;;
  317. *) #usb
  318. LESSPARTS0="`echo "$PCPARTS0" | grep -v -f /tmp/ATADRIVES0`" #only probe usb drives.
  319. ;;
  320. esac
  321. if [ "$PMEDIA" ];then #kernel boot param
  322. case $PMEDIA in
  323. cd)
  324. [ "$PRAMONLY" = "yes" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep -E 'iso9660|udf'`" #do not search other drives. 130128 add udf.
  325. ;;
  326. *)
  327. #note: a mistake if have PDEV1 on usb booting, as it can change.
  328. [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
  329. ;;
  330. esac
  331. fi
  332. [ "$LESSPARTS0" = "" ] && return #nothing to search in.
  333. LESSPARTS="`echo "$LESSPARTS0" | tr '\n' ' '`"
  334. echo "$PCPARTSALL" > /tmp/PCPARTSALL_${1} #for debugging.
  335. echo "$LESSPARTS0" > /tmp/LESSPARTS0_${1} #for debugging.
  336. #130513 want to give preference to write pupdesk.flg to a linux partition...
  337. LINUXFS="$(echo "$LESSPARTS0" | grep -E 'ext2|ext3|ext4|reiserfs|minix|f2fs' | head -n 1)"
  338. #find puppy files in the pc...
  339. #vmlinuz (and optional simplified puppy.sfs (PUPXXXSFS), zdrv.sfs (ZDRVSFS)) have appended id-string (IDSTRING).
  340. IGNORE=''
  341. SEARCHDEPTH=2
  342. [ "$PSUBDIR" ] && SEARCHDEPTH=1
  343. for ONETRY in $LESSPARTS
  344. do
  345. ONEDEV="`echo -n "$ONETRY" | cut -f 1 -d '|'`"
  346. ONEFS="`echo -n "$ONETRY" | cut -f 2 -d '|'`"
  347. ONEDRV="`echo -n "$ONEDEV" | grep -o -f /tmp/ALLDRVS0`" #110205 ex: sda1 becomes sda.
  348. if [ "$IGNORE" = "optical" ];then #110126 ignore optical if boot partition found.
  349. [ "`echo -n "$ONEDRV" | grep -f /tmp/OPTICALDRIVES0`" != "" ] && continue #110205
  350. fi
  351. #v403 nasty bug: usb optical drive showing as /sys/block/sr0, but won't mount, needs more delay...
  352. mntfunc $ONEFS /dev/$ONEDEV /mnt/data #-t $ONEFS /dev/$ONEDEV /mnt/data
  353. if [ $? -ne 0 ];then
  354. echo "PAUSE 5SEC: tried to mount /dev/${ONEDEV}, ${ONEFS} f.s." #101005 boot param loglevel=7 will show this.
  355. echo -e -n " \\033[1;31mpausing\\033[0;39m" > /dev/console #31=red
  356. sleep 5 #2 wasn't enough.
  357. mntfunc $ONEFS /dev/$ONEDEV /mnt/data
  358. if [ $? -ne 0 ];then
  359. echo "RETRY FAILED: mounting /dev/${ONEDEV}, ${ONEFS} f.s." #101005
  360. continue
  361. fi
  362. fi
  363. echo "ONEDEV=$ONEDEV ONEFS=$ONEFS ONEDRV=$ONEDRV PSUBDIR=$PSUBDIR" >> /tmp/puppy-file-search.log #101127 for debugging.
  364. if [ -d /mnt/data${PSUBDIR} ];then
  365. if [ "$VMLINUZ" = "" ];then #search for kernel.qky and vmlinuz...
  366. if [ "$ONEFS" != "iso9660" -a "$PMEDIA" = "cd" -a "$ONEFS" != "udf" ];then #101021 avoid finding vmlinuz on hd. 110204. 130128 also udf.
  367. echo "Bypass looking for vmlinuz on $ONEDEV"
  368. else
  369. FND_FILES="`find /mnt/data${PSUBDIR} -maxdepth ${SEARCHDEPTH} -xdev -type f -iname kernel.qky -o -iname ${KERNELNAME} | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  370. for ONEPUPFILE in $FND_FILES #kernel.qky: see woof script 4quirkybuild.
  371. do
  372. ONEFULLSIZE=`stat -c %s /mnt/data${ONEPUPFILE}`
  373. ONEORIGSIZE=`expr $ONEFULLSIZE - 32` #110422
  374. ONEIDSTRING="`dd if=/mnt/data${ONEPUPFILE} bs=1 skip=${ONEORIGSIZE} 2>/dev/null | sed -e 's%[^a-zA-Z0-9\.]%%g'`"
  375. if [ "$ONEIDSTRING" = "$IDSTRING" ];then
  376. VMLINUZ="`basename $ONEPUPFILE`"
  377. PDEV1="$ONEDEV"
  378. DEV1FS="$ONEFS"
  379. BOOTDRV="$ONEDRV" #exs: sda sr0
  380. PSUBDIR="`dirname $ONEPUPFILE`" #ex: /puppies/wary071
  381. [ "$PSUBDIR" = "/" ] && PSUBDIR=""
  382. #SAVEMARK: BootFlash utility can create 128MB boot partition, 2nd partition for pupsave...
  383. #101020 if pup installed in a subdir, look there for SAVEMARK...
  384. [ -f /mnt/data${PSUBDIR}/SAVEMARK ] && PSAVEMARK="`cat /mnt/data${PSUBDIR}/SAVEMARK`" #partition no. that has or will-have ${DISTRO_FILE_PREFIX}save.2fs. 101020
  385. [ "$PSAVEMARK" ] && SAVEPART="${BOOTDRV}${PSAVEMARK}" #note, PSAVEMARK could also be a kernel boot param. ex: sda2
  386. [ "$PSUBDIR" = "" ] && [ -f /mnt/data/etc/DISTRO_SPECS ] && DEV1PUP='yes' #flag full installation. 101103 ignore if vmlinuz in a subdir.
  387. if [ "`echo -n "$BOOTDRV" | grep -f /tmp/OPTICALDRIVES0`" = "" ];then #110205 test not optical.
  388. IGNORE='optical' #refinement, if vmlinuz not on optical drive, don't probe it. 110126
  389. else #booting on optical, is it multisession?...
  390. FND_MULTIFOLDER="`find /mnt/data -maxdepth 1 -xdev -type d -name 20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9] | grep -v ' ' | sed -e 's%^/mnt/data%%' | head -n 1`"
  391. if [ "$FND_MULTIFOLDER" ];then #multisession cd/dvd
  392. if [ "$PRAMONLY" != "yes" ];then
  393. PUPMODE=72 #64+8, will become 77.
  394. PUPSAVE="${ONEDEV},${ONEFS},${FND_MULTIFOLDER}"
  395. fi
  396. fi
  397. fi
  398. fi
  399. done
  400. fi
  401. fi
  402. [ "$PSUBDIR" ] && SEARCHDEPTH=1
  403. if [ "$PUPSFS" = "" ];then
  404. FND_FILES="`find /mnt/data${PSUBDIR} -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${PUPXXXSFS} | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  405. for ONEPUPFILE in $FND_FILES
  406. do
  407. if [ "$NAMETYPE" = "traditional" ];then
  408. ONEIDSTRING="$IDSTRING" #found file based on it's name only.
  409. else
  410. ONEFULLSIZE=`stat -c %s /mnt/data${ONEPUPFILE}`
  411. ONEORIGSIZE=`expr $ONEFULLSIZE - 32`
  412. ONEIDSTRING="`dd if=/mnt/data${ONEPUPFILE} bs=1 skip=${ONEORIGSIZE} 2>/dev/null | sed -e 's%[^a-zA-Z0-9\.]%%g'`"
  413. fi
  414. if [ "$ONEIDSTRING" = "$IDSTRING" ];then
  415. PUPSFS="${ONEDEV},${ONEFS},${ONEPUPFILE}"
  416. break
  417. fi
  418. done
  419. fi
  420. if [ "$ZDRV" = "" ];then
  421. FND_FILES="`find /mnt/data${PSUBDIR} -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${ZDRVSFS} | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  422. for ONEPUPFILE in $FND_FILES
  423. do
  424. if [ "$NAMETYPE" = "traditional" ];then
  425. ONEIDSTRING="$IDSTRING" #found file based on it's name only.
  426. else
  427. ONEFULLSIZE=`stat -c %s /mnt/data${ONEPUPFILE}`
  428. ONEORIGSIZE=`expr $ONEFULLSIZE - 32` #110422
  429. ONEIDSTRING="`dd if=/mnt/data${ONEPUPFILE} bs=1 skip=${ONEORIGSIZE} 2>/dev/null | sed -e 's%[^a-zA-Z0-9\.]%%g'`"
  430. fi
  431. if [ "$ONEIDSTRING" = "$IDSTRING" ];then
  432. ZDRV="${ONEDEV},${ONEFS},${ONEPUPFILE}"
  433. break
  434. fi
  435. done
  436. fi
  437. if [ "$ADRV" = "" ];then
  438. FND_FILES="`find /mnt/data${PSUBDIR} -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${ADRVSFS} | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  439. for ONEPUPFILE in $FND_FILES
  440. do
  441. if [ "$NAMETYPE" = "traditional" ];then
  442. ONEIDSTRING="$IDSTRING" #found file based on it's name only.
  443. else
  444. ONEFULLSIZE=`stat -c %s /mnt/data${ONEPUPFILE}`
  445. ONEORIGSIZE=`expr $ONEFULLSIZE - 32` #110422
  446. ONEIDSTRING="`dd if=/mnt/data${ONEPUPFILE} bs=1 skip=${ONEORIGSIZE} 2>/dev/null | sed -e 's%[^a-zA-Z0-9\.]%%g'`"
  447. fi
  448. if [ "$ONEIDSTRING" = "$IDSTRING" ];then
  449. ADRV="${ONEDEV},${ONEFS},${ONEPUPFILE}"
  450. echo -n " adrive" > /dev/console
  451. break
  452. fi
  453. done
  454. fi
  455. if [ "$YDRV" = "" ];then
  456. FND_FILES="`find /mnt/data${PSUBDIR} -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${YDRVSFS} | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  457. for ONEPUPFILE in $FND_FILES
  458. do
  459. if [ "$NAMETYPE" = "traditional" ];then
  460. ONEIDSTRING="$IDSTRING" #found file based on it's name only.
  461. else
  462. ONEFULLSIZE=`stat -c %s /mnt/data${ONEPUPFILE}`
  463. ONEORIGSIZE=`expr $ONEFULLSIZE - 32` #110422
  464. ONEIDSTRING="`dd if=/mnt/data${ONEPUPFILE} bs=1 skip=${ONEORIGSIZE} 2>/dev/null | sed -e 's%[^a-zA-Z0-9\.]%%g'`"
  465. fi
  466. if [ "$ONEIDSTRING" = "$IDSTRING" ];then
  467. YDRV="${ONEDEV},${ONEFS},${ONEPUPFILE}"
  468. echo -n " ydrive" > /dev/console
  469. break
  470. fi
  471. done
  472. fi
  473. fi #101103 moved up.
  474. echo " IGNORE=$IGNORE PSUBDIR=$PSUBDIR SAVEPART=$SAVEPART VMLINUZ=$VMLINUZ PDEV1=$PDEV1 PUPSFS=$PUPSFS" >> /tmp/puppy-file-search.log #101127 for debugging.
  475. FND_PUPSAVES=""
  476. ONEFS_IS_LINUX=""
  477. case $ONEFS in
  478. ext2|ext3|ext4|reiserfs|minix|f2fs) ONEFS_IS_LINUX="Y" ;;
  479. esac
  480. if [ "$SAVEPART" ];then #see SAVEMARK above. 101103 modified logic.
  481. if [ "$SAVEPART" = "$ONEDEV" ];then
  482. if [ "$PSUBDIR" ];then
  483. #look in same subdir, then in '/' (maxdepth=1)...
  484. if [ -d /mnt/data${PSUBDIR} ]; then
  485. [ "$ONEFS_IS_LINUX" = "Y" ] && FND_PUPSAVES="`find /mnt/data${PSUBDIR} -maxdepth 1 -xdev -type d -iname ${DISTRO_FILE_PREFIX}save'*' | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  486. FND_PUPSAVES="${FND_PUPSAVES}`find /mnt/data${PSUBDIR} -maxdepth 1 -xdev -type f -iname ${DISTRO_FILE_PREFIX}save*.[234]fs | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  487. fi
  488. else
  489. [ "$ONEFS_IS_LINUX" = "Y" ] && FND_PUPSAVES="`find /mnt/data -maxdepth ${SEARCHDEPTH} -xdev -type d -iname ${DISTRO_FILE_PREFIX}save'*' | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  490. FND_PUPSAVES="${FND_PUPSAVES}`find /mnt/data -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${DISTRO_FILE_PREFIX}save*.[234]fs | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  491. [ -f /mnt/data/etc/rc.d/PUPSTATE ] && DEV2PUP="${ONEDEV}|${ONEFS}" #full save to different partition than boot. 100919 101103 ignore if installed in a subdir.
  492. fi
  493. fi
  494. else #101020
  495. if [ "$PSUBDIR" ];then
  496. #look in same subdir, then in '/' (maxdepth=1)...
  497. if [ -d /mnt/data${PSUBDIR} ]; then
  498. [ "$ONEFS_IS_LINUX" = "Y" ] && FND_PUPSAVES="`find /mnt/data${PSUBDIR} -maxdepth 1 -xdev -type d -iname ${DISTRO_FILE_PREFIX}save'*' | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  499. FND_PUPSAVES="${FND_PUPSAVES}`find /mnt/data${PSUBDIR} -maxdepth 1 -xdev -type f -iname ${DISTRO_FILE_PREFIX}save*.[234]fs | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  500. fi
  501. else
  502. [ "$ONEFS_IS_LINUX" = "Y" ] && FND_PUPSAVES="`find /mnt/data -maxdepth ${SEARCHDEPTH} -xdev -type d -iname ${DISTRO_FILE_PREFIX}save'*' | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  503. FND_PUPSAVES="${FND_PUPSAVES}`find /mnt/data -maxdepth ${SEARCHDEPTH} -xdev -type f -iname ${DISTRO_FILE_PREFIX}save*.[234]fs | grep -v ' ' | sed -e 's%^/mnt/data%%' | tr '\n' ' '`"
  504. fi
  505. fi
  506. [ "$FND_PUPSAVES" ] && echo "$ONEDEV $ONEFS $FND_PUPSAVES" >> /tmp/PUPSAVES
  507. #130513 if we find a rw f.s., create pupdesk.flg. only needed in PUPMODE=5, see /usr/sbin/quicksetup.
  508. if [ "$PRAMONLY" != "yes" -a $PUPDESKFLG -eq 1 ];then #130514 exclude. 130515
  509. if [ ! -f /tmp/RWPART ];then
  510. if [ "$LINUXFS" ];then
  511. RWPARTFLG=''
  512. case $ONEFS in
  513. ext2|ext3|ext4|reiserfs|minix|f2fs) RWPARTFLG="$(cat /proc/mounts | grep "/dev/${ONEDEV} " | grep ' rw,')" ;;
  514. esac
  515. else
  516. RWPARTFLG="$(cat /proc/mounts | grep "/dev/${ONEDEV} " | grep ' rw,')"
  517. fi
  518. [ "$RWPARTFLG" ] && echo -n "${ONEDEV}|${ONEFS}" > /tmp/RWPART #where we intend to create pupdesk.flg, see further down.
  519. fi
  520. fi
  521. #fix any improper shutdowns... fsckme.flg format: sda7,ext3,[/pupsave.2fs] (see rc.shutdown)
  522. FSCKME=""
  523. [ -f /mnt/data/fsckme.flg ] && FSCKME="`cat /mnt/data/fsckme.flg | tr ',' ' ' | tr '\n' ' '`"
  524. rm -f /mnt/data/fsckme.flg
  525. umntfunc /mnt/data
  526. [ "$FSCKME" ] && fsckme_func $FSCKME
  527. done
  528. } #search_func
  529. resize_pupsave_func() { #131225
  530. rm -f /mnt/dev_save/pupsaveresizenew.txt
  531. echo > /dev/console
  532. echo -n "Increasing $PUPSAVEFILE by $KILOBIG Kbytes, please wait..." >/dev/console
  533. dd if=/dev/zero bs=1024 count=$KILOBIG >> /mnt/dev_save$PUPSAVEFILEX #131225
  534. sync
  535. }
  536. fsck_pupsave_func() {
  537. e2fsck -y -f $1
  538. resize2fs -pf $1 #no size, will fill all of file.
  539. sync
  540. check_status 0 #note, e2fsck gives an error even though it works. v2.21 maybe okay now.
  541. echo -n "...continuing with loading $PUPSAVEFILE..." > /dev/console
  542. }
  543. mnt_enc_pupsave_func() {
  544. echo >/dev/console
  545. echo "NOTICE: As you type your password nothing will be displayed on the screen." >/dev/console
  546. echo "This is a security measure. Just type it in then press ENTER key..." >/dev/console
  547. echo -e "\\033[1;36m" >/dev/console #aqua-blue
  548. echo -n "Password: " >/dev/console
  549. echo -en "\\033[0;39m" >/dev/console
  550. if [ "$CRYPTO" = "-e aes" ];then #v3.98
  551. read -s MYPASS #< /dev/console v403
  552. echo "$MYPASS" | losetup -p 0 -e aes /dev/loop1 /mnt/dev_save$PUPSAVEFILE
  553. else
  554. #losetup does not accept -p param for xor encryption... may not work...
  555. losetup $CRYPTO /dev/loop1 /mnt/dev_save$PUPSAVEFILE
  556. fi
  557. }
  558. #pmedia= usbflash|usbhd|usbcd|ataflash|atahd|atacd|atazip|scsihd|scsicd|cd
  559. [ $pmedia ] && PMEDIA=$pmedia #boot parameter, broad category of boot media. ex: cd.
  560. [ $pdev1 ] && PDEV1=$pdev1 #boot parameter, partition have booted off. ex: hda3
  561. [ $psubdir ] && PSUBDIR=$psubdir #boot parameter, directory for puppy files. ex: puppy220
  562. [ $pkeys ] && PKEYS=$pkeys #boot parameter, keyboard layout w476
  563. [ $psavemark ] && PSAVEMARK=$psavemark #100913 partition number that has/will-have save-file.
  564. [ $PSUBDIR ] && [ "`echo -n "$PSUBDIR" | cut -c 1`" != "/" ] && PSUBDIR="/${PSUBDIR}" #add leading /.
  565. #100915 requested by technosaurus (formats get changed further down)...
  566. [ $pupsfs ] && PUPSFS=$pupsfs #format partition:<path><filename> ex: sda2:/wary071/wary_071.sfs
  567. [ $zdrv ] && ZDRV=$zdrv #ex: sda2:/wary071/zdrv_071.sfs
  568. [ $adrv ] && ADRV=$adrv
  569. [ $ydrv ] && YDRV=$ydrv
  570. [ $underdog ] && UNDERDOG=$underdog #120130 specify partition for Underdog Linux (refer also underdog.lnx).
  571. #now supporting a boot menu...
  572. RDSH=""
  573. if [ "$pfix" ];then
  574. for ONEFIX in `echo -n "$pfix" | tr ',' ' '`
  575. do
  576. case $ONEFIX in
  577. ram) PRAMONLY="yes";; #run in ram only (do not load ${DISTRO_FILE_PREFIX}save).
  578. rdsh) RDSH="yes";; #exit to shell in initial ramdisk.
  579. rdsh0) RDSH="0";; #drop out early, before loading drivers.
  580. rdsh6) RDSH="6";; #w091027 drop out just before mount layerfs.
  581. nox) PNOX="yes";; #do not start X.
  582. clean) PCLEAN="yes";; #force version upgrade and cleanup.
  583. purge) PPURGE="yes";; #radical cleanup for broken system.
  584. copy) PCOPY="yes";; #copy .sfs files into ram.
  585. nocopy) PNOCOPY="yes";; #do not copy .sfs files into ram (default is copy if enough ram).
  586. fsck) PFSCK="yes";; #do a fsck of ${DISTRO_FILE_PREFIX}save file.
  587. [0-9]*) PIGNORELAST=$ONEFIX;; #blacklist last $ONEFIX folders (multisession).
  588. esac
  589. done
  590. fi
  591. #for backwards naming compatibility... ex: idehd becomes atahd 101021: atacd,scsicd,usbcd to become just cd...
  592. PMEDIA="`echo -n "$PMEDIA" | sed -e 's%ide%ata%' -e 's%sata%ata%' -e 's%.*cd$%cd%'`"
  593. clear #clear the screen.
  594. [ ! "$LOGLEVEL" ] && exec 1>/tmp/bootinit.log 2>&1 #remove o/p from console. v2.22 loglevel added.
  595. export TZ='XXX-23' #100318 imaginary place right around the world east of Greenwich.
  596. #...i think that this will give the most delayed time, so any file operations
  597. #will not result in a future date after the correct time is set in the main puppy f.s.
  598. #ref: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
  599. #100427 crap, despite the help inside the hwclock applet, it doesn't accept long-options...
  600. /bin/hwclock -s -l #set system time (based on hw clock set to local time).
  601. #does this initrd have all the zdrv components inside it?...
  602. ZDRVINIT='no'
  603. [ `cat /lib/modules/$KERNELVER/modules.dep | wc -l` -gt 200 ] && ZDRVINIT='yes'
  604. #120216 /PUPPYKEYMAP inserted in initrd by quicksetup (in future, by Woof too)...
  605. FONTMAP=""
  606. [ -f /PUPPYKEYMAP ] && [ ! "$PKEYS" ] && PKEYS="`cat /PUPPYKEYMAP`" #allow kernel boot param to override.
  607. if [ "$PLANG" ];then
  608. if [ ! "$PKEYS" ];then
  609. #try to set PKEYS to match the language. first 2 letters of PLANG...
  610. PKEYS=${PLANG:0:2} #rough as guts, assign first 2 chars of PLANG to PKEYS.
  611. case $PLANG in
  612. en*) PKEYS=us ;;
  613. esac
  614. fi
  615. #120216 L18L suggests load these, instead of what is below...
  616. case $PLANG in
  617. en*) echo ;;
  618. ar*|iw*) #L18L no Greek
  619. setfont /lib/consolefonts/LatArCyrHeb-16.psfu.gz -C /dev/tty1
  620. FONTMAP='LatArCyrHeb-16.psfu'
  621. ;;
  622. ru*) #vkvkvk for ru
  623. zcat /lib/consolefonts/ter-u16n.psf.gz | loadfont
  624. FONTMAP='ter-u16n.psf'
  625. ;;
  626. *) #L18L All European languages; new default ?!
  627. zcat /lib/consolefonts/LatGrkCyr-8x16.psfu.gz | loadfont
  628. FONTMAP='LatGrkCyr-8x16.psfu'
  629. ;;
  630. esac
  631. fi
  632. #091122 load keyboard layout if PKEYS boot param...
  633. STATUS=0
  634. VFAT_OUT_PARAM='shortname=mixed,quiet,utf8' #140102 rodin.s: added utf8 for flash drive to be mounted with utf-8 if boot is done from flash drive
  635. CODEPAGE=""
  636. KMAP=""
  637. if [ "$PKEYS" ];then
  638. if [ ! -f /lib/keymaps/${PKEYS}.gz ];then
  639. PKEYS="`ls -1 /lib/keymaps/${PKEYS}*.gz | head -n 1 | rev | cut -f 1 -d '/' | cut -f 2 -d '.' | rev`"
  640. fi
  641. if [ -f /lib/keymaps/${PKEYS}.gz ];then
  642. echo "Loading '${PKEYS}' keyboard layout..." >/dev/console
  643. KMAP="$PKEYS"
  644. zcat /lib/keymaps/${PKEYS}.gz | loadkmap ; STATUS=$(($STATUS + $?))
  645. case $PKEYS in #note, same code in /etc/rc.d/rc.country, /usr/sbin/input-wizard and init.
  646. de*|be*|br*|dk*|es*|fi*|fr*|it*|no*|se*|pt*)
  647. modprobe nls_cp850
  648. [ ! "$PLANG" ] && FONTMAP="lat1-12.psfu" #120216
  649. CODEPAGE="850"
  650. VFAT_OUT_PARAM="$OUT_PARAM"',codepage=850'
  651. ;;
  652. cz*|hu*|pl*|ro*|sk*|croat*|slovene*)
  653. modprobe nls_cp852
  654. modprobe nls_iso8859-2
  655. [ ! "$PLANG" ] && FONTMAP="lat2-12.psfu" #120216
  656. CODEPAGE="852"
  657. VFAT_OUT_PARAM="$OUT_PARAM"',codepage=852,iocharset=iso8859-2'
  658. ;;
  659. esac
  660. if [ ! "$PLANG" ];then #120216 old behaviour.
  661. if [ "$FONTMAP" ];then #100520 fix syntax error...
  662. zcat /lib/consolefonts/${FONTMAP}.gz | loadfont
  663. STATUS=$(($STATUS + $?))
  664. fi
  665. fi
  666. else
  667. STATUS=1
  668. fi
  669. check_status $STATUS
  670. fi
  671. [ "$RDSH" = "0" ] && exec /bin/sh >/dev/console 2>&1 #w091222
  672. ###################LOAD MODULES TO ACCESS DRIVES#####################
  673. echo -n "Loading drivers needed to access disk drives" > /dev/console #STEP ONE
  674. #100214 one config of 2.6.33 has base floppy and ps/2 mouse support not builtin...
  675. [ "`modinfo floppy 2>/dev/null`" != "" ] && modprobe floppy > /dev/null 2>&1
  676. [ "`modinfo psmouse 2>/dev/null`" != "" ] && modprobe psmouse
  677. #w462 if present, load it. enables recognition of drives attached to parallel port.
  678. [ "`modinfo ppa 2>/dev/null`" != "" ] && modprobe ppa #also loads parport.ko
  679. ELSPCI="`elspci -l`" #jesses great little utility.
  680. #v403 pcmcia drive support. i think this may need extra delay though...
  681. if [ "`echo "$ELSPCI" | grep '060700'`" != "" ];then
  682. modprobe yenta_socket
  683. #...may have to add on a couple of seconds, need to test with a pcmcia drive.
  684. #v412 yeah, my pccard-usb adaptor needs delay before elspci recognises 0C0310 (ohci-hcd) interface...
  685. echo -n "." > /dev/console
  686. sleep 2
  687. fi
  688. #v423 k2.6.29.6 dmesg has warning that ehci-hcd should load before uhci-hcd and ohci-hid...
  689. [ "`echo "$ELSPCI" | grep '0C0320'`" != "" ] && modprobe ehci-hcd 2>/dev/null
  690. #121227 extra f.s. drivers may be modules (quirky6)... 130216 add f2fs...
  691. for ONEFSMOD in ext2 ext3 ext4 fat msdos vfat ntfs reiserfs udf f2fs
  692. do
  693. [ "`modinfo $ONEFSMOD 2>/dev/null`" != "" ] && modprobe $ONEFSMOD
  694. done
  695. echo -n "." > /dev/console
  696. MODALIASES="`cat /sys/bus/pci/devices/*/modalias`" #important, save to variable before loop.
  697. for ONEMODALIAS in $MODALIASES
  698. do
  699. modprobe $ONEMODALIAS 2>/dev/null #-v means verbose.
  700. #[ $? -eq 0 ] && echo -n "." > /dev/console
  701. done
  702. #091222 some mmc/sd interfaces need this...
  703. #(above code loop may have loaded sdhci/sdhci_pci or tifm_core/tifm_7xx1)
  704. [ "`lsmod | grep '^sdhci'`" != "" ] && modprobe mmc_core && modprobe mmc_block
  705. [ "`lsmod | grep '^tifm'`" != "" ] && modprobe mmc_core && modprobe mmc_block && modprobe tifm_sd
  706. modprobe squashfs
  707. modprobe sr_mod > /dev/null 2>&1 #v3.93 now built-in to kernel.
  708. #filesystems...
  709. modprobe nls_cp437 2>/dev/null #needed by windows filesystems.
  710. modprobe nls_iso8859-1 2>/dev/null #needed by linux filesystems.
  711. modprobe $LAYERFS #unionfs or aufs.
  712. modprobe fuse #for ntfs-3g driver.
  713. #110126 define ATADRIVES as all internal ide/pata/sata (and mmc) drives (not usb), except optical...
  714. #110710 rewritten to handle kernel with usb driver built-in...
  715. ALLDRVS0="`find /sys/block -maxdepth 1 -name 'mmc*' -o -name 'sd*' -o -name 'sr*' | xargs -l readlink 2>/dev/null | grep -v '/usb[0-9]' | rev | cut -f 1 -d '/' | rev`" #all *except* usb!
  716. ALLDRVS="`echo "$ALLDRVS0" | tr '\n' ' '`" #all *except* usb!
  717. [ "$ALLDRVS" = " " ] && ALLDRVS=""
  718. ATADRIVES="`echo "$ALLDRVS0" | grep -v '^sr' | tr '\n' ' '`"
  719. [ "$ATADRIVES" = " " ] && ATADRIVES=""
  720. ATAOPTICALDRIVES="`echo "$ALLDRVS0" | grep '^sr' | tr '\n' ' '`"
  721. [ "$ATAOPTICALDRIVES" = " " ] && ATAOPTICALDRIVES=""
  722. if [ -e /proc/ide ];then
  723. for ONEIDE in `ls -1 /proc/ide | grep '^hd' | tr '\n' ' '`
  724. do
  725. ALLDRVS="${ALLDRVS}${ONEIDE} "
  726. if [ "`cat /proc/ide/${ONEIDE}/media`" = "cdrom" ];then
  727. ATAOPTICALDRIVES="${ATAOPTICALDRIVES}${ONEIDE} "
  728. else
  729. ATADRIVES="${ATADRIVES}${ONEIDE} "
  730. fi
  731. done
  732. ALLDRVS0="`echo -n "$ALLDRVS" | tr ' ' '\n'`"
  733. fi
  734. ATADRIVES0="`echo -n "$ATADRIVES" | tr ' ' '\n'`"
  735. touch /tmp/ATADRIVES0 #110509 fix for LF only messes up grep later.
  736. [ "$ATADRIVES" != "" ] && echo "$ATADRIVES0" > /tmp/ATADRIVES0 #110205 broken busybox grep -F. 110509
  737. ATAOPTICALDRIVES0="`echo -n "$ATAOPTICALDRIVES" | tr ' ' '\n'`"
  738. touch /tmp/ALLDRVS0
  739. [ "$ALLDRVS" ] && echo "$ALLDRVS0" > /tmp/ALLDRVS0 #all drives *except* usb.
  740. PCPARTSALL="`probepart_init -k`"
  741. PCPARTS0="`echo "$PCPARTSALL" | grep '^/dev/' | cut -f 1-2 -d '|' | grep -E 'f2fs|udf|iso9660|ext2|ext3|ext4|reiserfs|msdos|vfat|minix|ntfs' | sed -e 's%/dev/%%'`" #ex: sda1|vfat 130128 add udf. 130216 add f2fs.
  742. LESSPARTS0="$PCPARTS0"
  743. #120328 could have iso9660 f.s. booting off a non-optical drive (see BootFlash). exclude /dev/mmc ...
  744. OPTICALDRIVES0="`echo "$PCPARTS0" | grep -E 'iso9660|udf' | grep -v '^mmc' | cut -f 1 -d '|'`" #ex: sr0 130128 add udf.
  745. touch /tmp/OPTICALDRIVES0 #110509 fix for using with grep.
  746. [ "$OPTICALDRIVES0" != "" ] && echo "$OPTICALDRIVES0" > /tmp/OPTICALDRIVES0 #110509 fix
  747. echo "ALLDRVS=$ALLDRVS " >> /tmp/puppy-file-search.log #for debugging.
  748. if [ "`lsmod | grep -E '^uhci|^ohci|^ehci'`" != "" ];then
  749. /sbin/wait4usb_classic & #110425
  750. else
  751. /sbin/wait4usb & #110710 kernel has builtin hid and usb drivers, and without or with my usb-storage patch.
  752. fi
  753. check_status 0 #END STEP ONE
  754. ##############END MODULE LOADING TO ACCESS DRIVES####################
  755. #######################FINDING PUPPY FILES###########################
  756. echo -n "Searching for Puppy files..." > /dev/console #STEP TWO
  757. PUPMODE=0
  758. touch /tmp/PUPSAVES
  759. KERNELNAME='vmlinuz'
  760. #100915 technosaurus recommendation (see above)...
  761. if [ "$PUPSFS" ];then
  762. DEV="`echo "$PUPSFS" | cut -f 1 -d ':'`"
  763. FS="`echo "$PCPARTS0" | grep "${DEV}|" | cut -f 2 -d '|'`"
  764. SPEC="`echo -n "$PUPSFS" | cut -f 2 -d ':'`"
  765. PUPXXXSFS="`basename $SPEC`"
  766. [ "$PSUBDIR" = "" ] && PSUBDIR="`dirname $SPEC`"
  767. [ "$PSUBDIR" = "/" ] && PSUBDIR=""
  768. PUPSFS="${DEV},${FS},${SPEC}"
  769. LESSPARTS0="${DEV}|${FS}" #110425
  770. fi
  771. if [ "$ZDRV" ];then
  772. DEV="`echo "$ZDRV" | cut -f 1 -d ':'`"
  773. FS="`echo "$PCPARTS0" | grep "${DEV}|" | cut -f 2 -d '|'`"
  774. SPEC="`echo -n "$ZDRV" | cut -f 2 -d ':'`"
  775. ZDRVSFS="`basename $SPEC`"
  776. ZDRV="${DEV},${FS},${SPEC}"
  777. fi
  778. if [ "$ADRV" ];then
  779. DEV="`echo "$ADRV" | cut -f 1 -d ':'`"
  780. FS="`echo "$PCPARTS0" | grep "${DEV}|" | cut -f 2 -d '|'`"
  781. SPEC="`echo -n "$ADRV" | cut -f 2 -d ':'`"
  782. ADRVSFS="`basename $SPEC`"
  783. ADRV="${DEV},${FS},${SPEC}"
  784. fi
  785. if [ "$YDRV" ];then
  786. DEV="`echo "$YDRV" | cut -f 1 -d ':'`"
  787. FS="`echo "$PCPARTS0" | grep "${DEV}|" | cut -f 2 -d '|'`"
  788. SPEC="`echo -n "$YDRV" | cut -f 2 -d ':'`"
  789. YDRVSFS="`basename $SPEC`"
  790. YDRV="${DEV},${FS},${SPEC}"
  791. fi
  792. #first look inside initrd...
  793. [ -f /${PUPXXXSFS} ] && PUPSFS="rootfs,rootfs,/${PUPXXXSFS}"
  794. [ -f /${ZDRVSFS} ] && ZDRV="rootfs,rootfs,/${ZDRVSFS}"
  795. [ -f /${ADRVSFS} ] && ADRV="rootfs,rootfs,/${ADRVSFS}"
  796. [ -f /${YDRVSFS} ] && YDRV="rootfs,rootfs,/${YDRVSFS}"
  797. search_func ata #110425
  798. while [ ! -e /tmp/flag-usb-ready ];do #110710 wait for usb process to complete.
  799. usleep 250000 #microseconds
  800. done
  801. if [ -s /tmp/flag-usb-ready ];then #110710 has stuff in it if usb drives exist.
  802. ALLDRVS="`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr' | tr '\n' ' '`" #110204
  803. [ "$ALLDRVS" = " " ] && ALLDRVS=""
  804. [ -e /proc/ide ] && ALLDRVS="${ALLDRVS}`ls -1 /proc/ide | grep '^hd' | tr '\n' ' '`" #110204 ex: sda sdb sr0 hda
  805. ALLDRVS0="`echo -n "$ALLDRVS" | tr -s ' ' | tr ' ' '\n'`" #110205
  806. echo "$ALLDRVS0" > /tmp/ALLDRVS0 #110205
  807. PCPARTSALL="`probepart_init -k`"
  808. PCPARTS0="`echo "$PCPARTSALL" | grep '^/dev/' | cut -f 1-2 -d '|' | grep -E 'f2fs|udf|iso9660|ext2|ext3|ext4|reiserfs|msdos|vfat|minix|ntfs' | sed -e 's%/dev/%%'`" #ex: sda1|vfat 130128 add udf. 130216 add f2fs.
  809. LESSPARTS0="$PCPARTS0"
  810. #120328 could have iso9660 f.s. booting off a usb flash/hard drive (see BootFlash). exclude /dev/sd and /dev/mmc ...
  811. OPTICALDRIVES0="`echo "$PCPARTS0" | grep -E 'iso9660|udf' | grep -v -E '^sd|^mmc' | cut -f 1 -d '|'`" #ex: sr0 130128 add udf.
  812. touch /tmp/OPTICALDRIVES0 #fix
  813. [ "$OPTICALDRIVES0" ] && echo "$OPTICALDRIVES0" > /tmp/OPTICALDRIVES0 #fix
  814. echo "ALLDRVS=$ALLDRVS " >> /tmp/puppy-file-search.log
  815. PUPSFS_OPT=""
  816. if [ "$PUPSFS" ]; then
  817. FS=$(echo $PUPSFS | cut -s -f2 -d',')
  818. echo $FS | grep -q -E 'iso9660|udf' && PUPSFS_OPT=$PUPSFS && PUPSFS=""
  819. fi
  820. if [ "$VMLINUZ" = "" -o "$PUPSFS" = "" -o "$SAVEPART" = "" ];then
  821. search_func usb
  822. fi
  823. [ "$PUPSFS" ] || PUPSFS=$PUPSFS_OPT
  824. fi
  825. cp -f /tmp/PUPSAVES /tmp/PUPSAVES-complete #101127 for debugging.
  826. #110116 jamesbond: for netboot, PDEV1 is empty, so don't want to fail here...
  827. [ "$PUPSFS" = "" ] && DROPOUT="${PUPXXXSFS}"
  828. if [ "$DROPOUT" ];then
  829. echo -en "\\033[1;31m" >/dev/console #31=red
  830. echo -n "${DROPOUT} not found. Dropping out to initial-ramdisk console..." >/dev/console
  831. /bin/echo -e "\\033[0;39m" >/dev/console
  832. exec /bin/sh >/dev/console 2>&1
  833. fi
  834. if [ "$VMLINUZ" = "" ];then #101103 maybe network boot, no local vmlinuz
  835. #well, to get this far, PDEV1 has been supplied.
  836. #110116 jamesbond,shinobar: no, for netboot, PDEV1 is empty, add test for $PDEV1...
  837. [ "$DEV1FS" = "" -a "$PDEV1" != "" ] && DEV1FS="`echo "$LESSPARTS0" | grep "${PDEV1}|" | cut -f 2 -d '|'`"
  838. BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #110205 ex: sda1 becomes sda.
  839. VMLINUZ='vmlinuz'
  840. fi
  841. PUPMODE=`expr $PUPMODE + 4` #puppy.sfs (PUPXXXSFS) exists.
  842. #if pupsave file not already found, choose it here...
  843. if [ ! "$PUPSAVE" ];then
  844. if [ "$PRAMONLY" != "yes" ];then
  845. if [ "$IGNORE" = "optical" ];then #narrow it down...
  846. #not booting off optical drive.
  847. grep "${PSUBDIR}/" /tmp/PUPSAVES > /tmp/PUPSAVES2 #note: need this as above probing may have got some invalid hits.
  848. if [ "$SAVEPART" ];then #set by file SAVEMARK, see above.
  849. grep "${SAVEPART} " /tmp/PUPSAVES2 > /tmp/PUPSAVES
  850. else #it must be in the boot partition...
  851. grep "${PDEV1} " /tmp/PUPSAVES2 > /tmp/PUPSAVES
  852. fi
  853. fi
  854. if [ -s /tmp/PUPSAVES ];then #100922
  855. touch /tmp/PUPSAVE2SFSS #so does not spit any erroros if not there
  856. cat /tmp/PUPSAVES |
  857. while read ONELINE
  858. do
  859. ONEDEV="`echo -n "$ONELINE" | cut -f 1 -d ' '`"
  860. ONEFS="`echo -n "$ONELINE" | cut -f 2 -d ' '`"
  861. ONEPUPSAVES="`echo -n "$ONELINE" | cut -f 3-99 -d ' '`"
  862. for ONEPUPSAVE in $ONEPUPSAVES
  863. do
  864. echo "${ONEDEV},${ONEFS},${ONEPUPSAVE}" >> /tmp/PUPSAVE2SFSS
  865. done
  866. done
  867. NUMPUPSAVES=`cat /tmp/PUPSAVE2SFSS | wc -l`
  868. if [ $NUMPUPSAVES -eq 1 ];then
  869. PUPSAVE="`cat /tmp/PUPSAVE2SFSS`"
  870. else
  871. CNTSAVE=1
  872. echo -e "\\033[1;36m" >/dev/console #36=aquablue
  873. echo "Type a number to choose which personal file to use:" > /dev/console
  874. echo "0 none" > /dev/console
  875. for ONECHOICE in `cat /tmp/PUPSAVE2SFSS | tr '\n' ' '`
  876. do
  877. ONEFILE="`echo -n "$ONECHOICE" | cut -f 3 -d ','`"
  878. ONEPART="`echo -n "$ONECHOICE" | cut -f 1 -d ','`"
  879. echo -e "${CNTSAVE} ${ONEPART}\\033[10G${ONEFILE}" > /dev/console #10 means move to that column.
  880. CNTSAVE=`expr $CNTSAVE + 1`
  881. done
  882. echo -en "\\033[0;39m" >/dev/console
  883. read NUMSAVE
  884. [ $NUMSAVE -ne 0 ] && PUPSAVE="`cat /tmp/PUPSAVE2SFSS | tr '\n' ' ' | cut -f $NUMSAVE -d ' '`"
  885. fi
  886. fi
  887. fi
  888. [ "$PUPSAVE" ] && PUPMODE=`expr $PUPMODE + 8`
  889. fi
  890. #refine the PUPMODE...
  891. #if a ${DISTRO_FILE_PREFIX}save.2fs was not found, perhaps boot partition has a full install of puppy...
  892. [ ! "$PUPSAVE" ] && [ "$DEV1PUP" = "yes" -o "$DEV2PUP" != "" ] && PUPMODE=`expr $PUPMODE + 2`
  893. #do we want a tmpfs top layered-fs layer? (set bit-0 of PUPMODE)...
  894. #only if ${DISTRO_FILE_PREFIX}save.2fs (or PDEV1 for DEV1PUP=yes, or first boot) on a flash drive, usb or internal...
  895. case $PUPMODE in
  896. 4) #so far have only got a puppy.sfs. this is first boot or pfix=ram.
  897. PUPMODE=5 #`expr $PUPMODE + 1` #yes, want tmpfs top layer (PUPMODE=5).
  898. ;;
  899. 6) #4=puppy.sfs found, 2=session saved to entire partition. total=6
  900. #note: session saved in boot partition, or other specified by SAVEMARK (DEV2PUP).
  901. DRVSAVE="`echo -n "$PDEV1" | sed -e 's/[0-9]*$//' -e 's/p$//'`" #ex: sda 110126 mmcblk0p1 becomes mmcblk0
  902. REMOVABLEDRVSAVE="`cat /sys/block/$DRVSAVE/removable`"
  903. [ "$REMOVABLEDRVSAVE" = "1" -a "$PMEDIA" != "usbhd" ] && PUPMODE=7 #110116 shinobar.
  904. #v3.96 Classmate laptop has internal usb flash, so really want the tmpfs layer...
  905. # puppyinstaller created 'pmedia=usbflash' for the extlinux full hd install...
  906. [ "$PMEDIA" = "usbflash" ] && PUPMODE=7
  907. ;;
  908. 12) #4=puppy.sfs found, 8=${DISTRO_FILE_PREFIX}save.2fs found. total=12
  909. DRVSAVE="`echo -n "$PUPSAVE" | cut -f 1 -d ',' | sed -e 's/[0-9]*$//' -e 's/p$//'`" #ex: sda 110126 mmcblk0p1 becomes mmcblk0
  910. REMOVABLEDRVSAVE="`cat /sys/block/$DRVSAVE/removable`"
  911. [ "$REMOVABLEDRVSAVE" = "1" -a "$PMEDIA" != "usbhd" ] && PUPMODE=13 #110116 shinobar.
  912. [ "$PMEDIA" = "usbflash" ] && PUPMODE=13 #v404 fix classmate, with internal usb flash.
  913. [ "$PMEDIA" = "ataflash" ] && PUPMODE=13 #w019 constrain writes to internal flash drv.
  914. ;;
  915. 76) #v3.01 64+8+4 multisession cd.
  916. PUPMODE=77 #yes, want tmpfs top layer.
  917. ;;
  918. esac
  919. check_status 0
  920. ########################END FINDING PUPPY FILES############################
  921. ##########################LOADING PUPPY FILES###########################
  922. RAMSIZE=`free | grep -o 'Mem: .*' | tr -s ' ' | cut -f 2 -d ' '` #total physical ram (less shared video). 110405
  923. CRYPTO=""
  924. STATUS=0
  925. #decide the mount-points...
  926. #unionfs layers: RW (top) RO1 RO2 PUPMODE
  927. #full install, flash drive: tmpfs PDEV1 3
  928. #First boot (or pfix=ram): tmpfs pup_xxx.sfs 5
  929. #pup_save is a partition: PDEV1 pup_xxx.sfs 6
  930. #ditto, but flash drive: tmpfs PDEV1 pup_xxx.sfs 7
  931. #Normal running puppy: pup_save.3fs pup_xxx.sfs 12
  932. #ditto, but flash drive: tmpfs pup_save.3fs pup_xxx.sfs 13
  933. #Multisession cd/dvd: tmpfs folders(tmpfs2) pup_xxx.sfs 77
  934. CREATETMPFS="";CREATEPDEV1="";CREATEPUPXXXSFS="";CREATEPUPSAVE2FS="";CREATEFOLDERS=""
  935. case $PUPMODE in #w003 changed some save-layer to 'ro+wh' so that whiteouts files are recognised...
  936. 3) CREATETMPFS="/pup_rw";CREATEPDEV1="/pup_ro1"
  937. OLDFILESMNTPT="/pup_ro1";NEWFILESMNTPT="/pup_ro1";UMNTRW="/pup_rw=rw:";UMNTRO0="/pup_ro1=ro+wh:";;
  938. 5) CREATETMPFS="/pup_rw";CREATEPUPXXXSFS="/pup_ro2"
  939. OLDFILESMNTPT="";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO1="/pup_ro2=ro";;
  940. 6) CREATEPDEV1="/pup_rw";CREATEPUPXXXSFS="/pup_ro2"
  941. OLDFILESMNTPT="/pup_rw";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO1="/pup_ro2=ro";;
  942. 7) CREATETMPFS="/pup_rw";CREATEPDEV1="/pup_ro1";CREATEPUPXXXSFS="/pup_ro2"
  943. OLDFILESMNTPT="/pup_ro1";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO0="/pup_ro1=ro+wh:";UMNTRO1="/pup_ro2=ro";;
  944. 12) CREATEPUPSAVE2FS="/pup_rw";CREATEPUPXXXSFS="/pup_ro2"
  945. OLDFILESMNTPT="/pup_rw";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO1="/pup_ro2=ro";;
  946. 13) CREATETMPFS="/pup_rw";CREATEPUPSAVE2FS="/pup_ro1";CREATEPUPXXXSFS="/pup_ro2"
  947. OLDFILESMNTPT="/pup_ro1";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO0="/pup_ro1=ro+wh:";UMNTRO1="/pup_ro2=ro";;
  948. 77) CREATETMPFS="/pup_rw";CREATEFOLDERS="/pup_ro1";CREATEPUPXXXSFS="/pup_ro2"
  949. OLDFILESMNTPT="/pup_ro1";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO0="/pup_ro1=ro+wh:";UMNTRO1="/pup_ro2=ro";;
  950. *) RDSH="yes";; #precaution.
  951. esac
  952. if [ "$CREATEPDEV1" != "" ];then
  953. if [ "$DEV2PUP" ];then #100915
  954. DEV="`echo -n "$DEV2PUP" | cut -f 1 -d '|'`"
  955. FS="`echo -n "$DEV2PUP" | cut -f 2 -d '|'`"
  956. else #session saved to boot partition.
  957. DEV="$PDEV1"
  958. FS="$DEV1FS"
  959. fi
  960. [ "`echo "$FS" | grep 'ext[234]'`" != "" ] && echo "/dev/$DEV $CREATEPDEV1 $FS defaults 1 1" >> /etc/fstab #v2.21
  961. mount -t $FS /dev/$DEV $CREATEPDEV1
  962. check_status $?
  963. #save is not a ${DISTRO_FILE_PREFIX}save file, but a partition on a layered-fs layer...
  964. if [ "$CREATEPDEV1" = "/pup_rw" -o "$CREATEPDEV1" = "/pup_ro1" ];then #v2.20b
  965. SMNTPT="$CREATEPDEV1"
  966. PUPSAVE="$DEV,$FS,/" #deliberately left last param as only /.
  967. fi
  968. fi
  969. if [ "$CREATEPUPSAVE2FS" != "" ];then
  970. PUPSAVEDEV="`echo -n "$PUPSAVE" | cut -f 1 -d ','`"
  971. PUPSAVEFS="`echo -n "$PUPSAVE" | cut -f 2 -d ','`"
  972. PUPSAVEFILE="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  973. #normal ${DISTRO_FILE_PREFIX}save.2fs file. just mount it from where it is...
  974. echo -n "Loading personal file $PUPSAVEFILE ($PUPSAVEDEV)..." > /dev/console
  975. [ "`echo "$PUPSAVEFS" | grep 'ext[234]'`" != "" ] && echo "/dev/$PUPSAVEDEV /mnt/dev_save $PUPSAVEFS defaults 1 1" >> /etc/fstab #v2.21
  976. mntfunc $PUPSAVEFS /dev/$PUPSAVEDEV /mnt/dev_save noatime #-t $PUPSAVEFS -o noatime /dev/$PUPSAVEDEV /mnt/dev_save
  977. if [ $? -eq 0 ];then
  978. SMNTPT="/mnt/dev_save"
  979. #is the ${DISTRO_FILE_PREFIX}save encrypted?...
  980. if [ ! "`echo "$PUPSAVEFILE" | grep '_crypt'`" = "" ];then
  981. case $PUPSAVEFILE in
  982. *cryptx*) #see /etc/rc.d/rc.shutdown.
  983. CRYPTO='-E 1' #v2.16final '-e xor' --bug, loads xor.ko which is something else.
  984. modprobe cryptoloop
  985. ;;
  986. *)
  987. CRYPTO='-e aes'
  988. modprobe cryptoloop
  989. modprobe aes_generic 2>/dev/null #v407 aes name change.
  990. modprobe aes 2>/dev/null #for older kernel <2.6.25
  991. modprobe crypto_blkcipher 2>/dev/null #v407 blkcipher name change.
  992. modprobe blkcipher 2>/dev/null #old kernel.
  993. modprobe cbc
  994. ;;
  995. esac
  996. fi
  997. if [ "$CRYPTO" != "" ] ; then
  998. echo "" >/dev/console
  999. echo "Mounting encrypted $PUPSAVEFILE..." > /dev/console
  1000. while true; do
  1001. #note, cryptoloop does not work with jounalled fs, hence have to use ext2 only.
  1002. # if pupsave increase requested
  1003. if [ -f /mnt/dev_save/pupsaveresizenew.txt ];then #131225 changed to function
  1004. . /mnt/dev_save/pupsaveresizenew.txt
  1005. if echo ${PUPSAVEFILEX}|grep -q ${PUPSAVEFILE##*/} ;then #131231
  1006. if [ ! -e /bin/e2fsck ];then
  1007. echo -e -n "\\033[1;31m SORRY, cannot resize ${PUPSAVEFILE} \\033[0;39m" > /dev/console #31=red
  1008. rm -f /mnt/dev_save/pupsaveresizenew.txt
  1009. else
  1010. resize_pupsave_func #131225
  1011. fi # end pupsave increase, old code removed 131225
  1012. mnt_enc_pupsave_func
  1013. fsck_pupsave_func /dev/loop1 #131225
  1014. else
  1015. mnt_enc_pupsave_func
  1016. fi #131225
  1017. else
  1018. mnt_enc_pupsave_func
  1019. fi
  1020. echo "/dev/loop1 $CREATEPUPSAVE2FS ext2 defaults 1 1" >> /etc/fstab #v2.21
  1021. [ "$PFSCK" = "yes" ] && fsckme_func loop1 ext2 #100318 however, commented out as there was an old not that f.s. check on an encrypted pupsave is broken. #140106 SFR: re-enabled
  1022. mount -t ext2 -o noatime,rw /dev/loop1 $CREATEPUPSAVE2FS #only ext2 allowed.
  1023. MNTSTAT=$?
  1024. if [ "$MNTSTAT" = "0" ] ; then
  1025. echo -n "...successfully mounted" >/dev/console
  1026. break
  1027. else
  1028. [ ! -e /bin/e2fsck ] && break #111120
  1029. echo -en "\\033[1;31m" >/dev/console #31=red
  1030. echo "Can't mount file, press ENTER key to try again." >/dev/console
  1031. echo "Or, any other char then ENTER for f.s. check then try again." > /dev/console
  1032. echo -n "Or, for developers type 'quit' to drop out to console: " > /dev/console
  1033. echo -en "\\033[0;39m" >/dev/console
  1034. read crypttryagain
  1035. echo > /dev/console
  1036. [ "$crypttryagain" = "quit" ] && exec /bin/sh >/dev/console 2>&1 #v3.98
  1037. [ "$crypttryagain" != "" ] && e2fsck -y -f /dev/loop1 >/dev/console
  1038. losetup -d /dev/loop1
  1039. fi
  1040. done
  1041. elif [ -d /mnt/dev_save$PUPSAVEFILE ]; then
  1042. mount -o bind /mnt/dev_save${PUPSAVEFILE} $CREATEPUPSAVE2FS
  1043. else #pupsave not encrypted.
  1044. # if pupsave increase requested
  1045. if [ -f /mnt/dev_save/pupsaveresizenew.txt ];then #131225 changed to function
  1046. . /mnt/dev_save/pupsaveresizenew.txt
  1047. if echo ${PUPSAVEFILEX}|grep -q ${PUPSAVEFILE##*/} ;then
  1048. if [ ! -e /bin/e2fsck ];then
  1049. echo -e -n "\\033[1;31m SORRY, cannot resize ${PUPSAVEFILE} \\033[0;39m" > /dev/console #31=red
  1050. rm -f /mnt/dev_save/pupsaveresizenew.txt
  1051. else
  1052. resize_pupsave_func #131225
  1053. fsck_pupsave_func /mnt/dev_save$PUPSAVEFILE #131225
  1054. fi
  1055. fi
  1056. fi
  1057. # end pupsave increase
  1058. losetup /dev/loop1 /mnt/dev_save${PUPSAVEFILE}
  1059. SFFS='ext'`echo -n "$PUPSAVEFILE" | rev | cut -c 3`
  1060. echo "/dev/loop1 $CREATEPUPSAVE2FS $SFFS defaults 1 1" >> /etc/fstab
  1061. [ "$PFSCK" = "yes" ] && fsckme_func loop1 $SFFS #100318
  1062. mount -t $SFFS -o noatime /dev/loop1 $CREATEPUPSAVE2FS
  1063. if [ $? -ne 0 ];then
  1064. if [ -e /bin/e2fsck ];then #111120
  1065. e2fsck -y -f /dev/loop1 > /dev/console #-y answer yes to all repair questions.
  1066. mount -t $SFFS -o noatime /dev/loop1 $CREATEPUPSAVE2FS
  1067. fi
  1068. fi
  1069. fi
  1070. fi
  1071. STATUS=$? #101028
  1072. check_status $STATUS
  1073. #101028 ask if upgrading save-file...
  1074. if [ $STATUS -eq 0 ];then
  1075. if [ $PUPMODE -eq 12 -o $PUPMODE -eq 13 ];then #4+8 or 4+8+1
  1076. OLDDISTRO_VERSION="`grep '^DISTRO_VERSION' $CREATEPUPSAVE2FS/etc/DISTRO_SPECS | cut -f 2 -d '=' | cut -f 2 -d "'" | cut -f 2 -d '"' | cut -f 1 -d ' '`" #110422
  1077. if vercmp ${DISTRO_VERSION} gt ${OLDDISTRO_VERSION} ;then #110422
  1078. if [ "$NUMPUPSAVES" != "0" ];then #save-file(s) found.
  1079. echo -e "\\033[1;36m" >/dev/console #36=aquablue
  1080. echo "This save-file was last used with version $OLDDISTRO_VERSION of Puppy." >/dev/console
  1081. echo "Hit the ENTER key only if it is okay to upgrade this file, or to not use it and boot up in RAM only type any other printable character." >/dev/console
  1082. echo -n "ENTER only to upgrade: " >/dev/console
  1083. echo -en "\\033[0;39m" >/dev/console
  1084. read noupgradesf
  1085. if [ "$noupgradesf" != "" ];then
  1086. echo -en "\\033[1;35m" >/dev/console #35=purple
  1087. echo "Backing off, not using save-file, booting in RAM only, PUPMODE=5..." >/dev/console
  1088. echo -en "\\033[0;39m" >/dev/console
  1089. sync
  1090. umount $CREATEPUPSAVE2FS #unmount the save-file.
  1091. PUPMODE=5
  1092. CREATETMPFS="";CREATEPDEV1="";CREATEPUPXXXSFS="";CREATEPUPSAVE2FS="";CREATEFOLDERS=""
  1093. CREATETMPFS="/pup_rw";CREATEPUPXXXSFS="/pup_ro2"
  1094. OLDFILESMNTPT="";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO1="/pup_ro2=ro"
  1095. fi
  1096. fi
  1097. #check if puppy.sfs copied to same place as save-file...
  1098. if [ "`echo -n "$BOOTDRV" | grep -f /tmp/OPTICALDRIVES0`" != "" ];then #110205 booting off cd.
  1099. if [ "$CREATEPUPSAVE2FS" ];then #did not do the backoff above.
  1100. xPUPSFSDEV="`echo -n "$PUPSFS" | cut -f 1 -d ','`" #checking puppy.sfs file.
  1101. xPUPSFSFS="`echo -n "$PUPSFS" | cut -f 2 -d ','`"
  1102. xPUPSFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1103. basepupsfs="`basename $xPUPSFSFILE`"
  1104. if [ "`echo -n "$xPUPSFSDEV" | grep -f /tmp/OPTICALDRIVES0`" != "" ];then #110205
  1105. #it is on the cd, so checkout copying it to hd...
  1106. echo -e "\\033[1;36m" >/dev/console #36=aquablue
  1107. echo "The main Puppy file '${basepupsfs}' is being loaded off the optical disc." >/dev/console
  1108. echo "Very slow! Type ENTER key only to copy it to the same partition as the save-file then on next boot it will load fast. Type any printable char not to copy it." >/dev/console
  1109. echo -n "ENTER key only to copy: " >/dev/console
  1110. echo -en "\\033[0;39m" >/dev/console
  1111. read nocopysfs
  1112. if [ "$nocopysfs" = "" ];then
  1113. echo -en "\\033[1;35m" >/dev/console #35=purple
  1114. echo "'${basepupsfs}' now copying to hard drive (but only available next boot)..." >/dev/console
  1115. echo -en "\\033[0;39m" >/dev/console
  1116. PPATTERN="/dev/$xPUPSFSDEV "
  1117. PUPSFSDEVMNTPT="`grep "$PPATTERN" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1118. if [ "$PUPSFSDEVMNTPT" = "" ];then
  1119. mntfunc $xPUPSFSFS /dev/$xPUPSFSDEV /mnt/dev_ro2 #-t $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2
  1120. PUPSFSDEVMNTPT="/mnt/dev_ro2"
  1121. UMOUNTME="/mnt/dev_ro2" #mark for unmounting.
  1122. fi
  1123. #110424 do not copy puppy*.sfs into a sub-dir...
  1124. cp -f ${PUPSFSDEVMNTPT}/*.sfs /mnt/dev_save/
  1125. sync
  1126. fi
  1127. fi
  1128. fi
  1129. fi
  1130. fi
  1131. fi
  1132. fi
  1133. fi
  1134. #there are technical problems with loading a swap partition/file before the union
  1135. #is created, so not doing it until rc.sysinit runs. however, if a tmpfs needs to be
  1136. #created here, set it's size in anticipation of a swap being loaded...
  1137. EXTRAALLOCK=0
  1138. SWAPPART="`echo "$PCPARTSALL" | grep '|swap|' | head -n 1`"
  1139. [ "$SWAPPART" ] && SWAPPARTSIZE=`echo -n "$SWAPPART" | cut -f 3 -d '|'`
  1140. [ $SWAPPARTSIZE ] && EXTRAALLOCK=`expr $SWAPPARTSIZE \/ 2`
  1141. if [ $EXTRAALLOCK -eq 0 ];then
  1142. [ -f ${SMNTPT}/pupswap.swp ] && SWAPFILESIZEBYTES=`stat -c %s ${SMNTPT}/pupswap.swp`
  1143. [ $SWAPFILESIZEBYTES ] && EXTRAALLOCK=`expr $SWAPFILESIZEBYTES \/ 2048` #use half. 110521 also convert bytes to kb.
  1144. fi
  1145. FREEK=0
  1146. if [ "$CREATETMPFS" != "" ];then
  1147. FREEK=`expr $RAMSIZE \/ 2` #half of physical.
  1148. [ $PUPMODE -eq 77 ] && FREEK=`expr $FREEK - 50000` #need some slack.
  1149. ALLOCK=`expr $FREEK + $EXTRAALLOCK`
  1150. mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATETMPFS
  1151. fi
  1152. #RW (top) layer now has a tmpfs, PDEV1 or ${DISTRO_FILE_PREFIX}save mounted on it. calc free space...
  1153. [ $FREEK -eq 0 ] && FREEK=`df | grep ' /pup_rw' | tr -s ' ' | cut -f 4 -d ' '`
  1154. [ ! $FREEK ] && FREEK=0
  1155. if [ "$CREATEFOLDERS" != "" ];then
  1156. PUPSAVEDEV="`echo -n "$PUPSAVE" | cut -f 1 -d ','`"
  1157. PUPSAVEFS="`echo -n "$PUPSAVE" | cut -f 2 -d ','`"
  1158. PUPSAVEFILE="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  1159. mount -o noatime -t $PUPSAVEFS /dev/$PUPSAVEDEV /mnt/dev_ro1 #mnt the cd.
  1160. #create a tmpfs to load the folders...
  1161. ALLOCK=`expr $RAMSIZE \/ 2 - 50000` #allocate half of physical ram. + leave 50M slack.
  1162. mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATEFOLDERS #/pup_ro1
  1163. #load the folders from the cd...
  1164. ####START LOAD FOLDERS####
  1165. CDMNTPT="/mnt/dev_ro1" #where the multisession cd is mounted.
  1166. DESTDIR="$CREATEFOLDERS" #dest dir has a tmpfs mntd on it, into which to copy folders.
  1167. BKFOLDERS="`ls -1 -r $CDMNTPT | grep '^20[0-9][0-9]'`"
  1168. BKLASTFOLDER="`echo "$BKFOLDERS" | head -n 1`"
  1169. #a boot option allows ignore last n sessions, also need to create a badlist...
  1170. if [ "$PIGNORELAST" ];then
  1171. BKBADLIST="`echo "$BKFOLDERS" | head -n ${PIGNORELAST}`"
  1172. if [ -f $CDMNTPT/$BKLASTFOLDER/.badfolders ];then
  1173. cp $CDMNTPT/$BKLASTFOLDER/.badfolders $DESTDIR/
  1174. if [ ! $? -eq 0 ];then
  1175. #fallback, in case last folder badly corrupted...
  1176. BKPREVFOLDER="`echo "$BKFOLDERS" | head -n 2 | tail -n 1`"
  1177. [ -f $CDMNTPT/$BKPREVFOLDER/.badfolders ] && cp $CDMNTPT/$BKPREVFOLDER/.badfolders $DESTDIR/
  1178. fi
  1179. fi
  1180. echo "$BKBADLIST" >> $DESTDIR/.badfolders
  1181. #note, rc.shutdown and savesession-dvd 'touch' this file so it will get saved.
  1182. sync
  1183. else
  1184. [ -f $CDMNTPT/$BKLASTFOLDER/.badfolders ] && cp $CDMNTPT/$BKLASTFOLDER/.badfolders $DESTDIR/
  1185. fi
  1186. [ -f $DESTDIR/.badfolders ] && BKBADLIST="`cat $DESTDIR/.badfolders | tr "\n" " "`"
  1187. BKFOLDERS="`echo -n "$BKFOLDERS" | tr "\n" " "`"
  1188. for ONEFOLDER in $BKFOLDERS
  1189. do
  1190. if [ ! "`echo -n "$BKBADLIST" | grep "$ONEFOLDER"`" = "" ];then
  1191. echo "Folder $ONEFOLDER marked bad." >/dev/console
  1192. continue #ignore bad folder.
  1193. fi
  1194. echo -n "Loading folder $ONEFOLDER from CD/DVD..." >/dev/console
  1195. #need to be careful not to overfill the ramdisk...
  1196. FREERAMDISK=`df 2>/dev/null | grep "$DESTDIR" | head -n 1 | tr -s " " | cut -f 4 -d " "`
  1197. SIZEFOLDER=`du -k -s ${CDMNTPT}/${ONEFOLDER} | cut -f 1`
  1198. if [ -d ${CDMNTPT}/${ONEFOLDER}/archive ];then
  1199. SIZEARCHIVE=`du -k -s ${CDMNTPT}/${ONEFOLDER}/archive | cut -f 1`
  1200. else
  1201. SIZEARCHIVE=0
  1202. fi
  1203. SIZESOURCE=`expr $SIZEFOLDER - $SIZEARCHIVE`
  1204. if [ $FREERAMDISK -gt $SIZESOURCE ];then
  1205. #well, -u will only copy if files newer, so less stuff may get copied than calc'd above.
  1206. #need to copy everything except archive folder...
  1207. [ -d $CDMNTPT/$ONEFOLDER/bin ] && cp -a -u $CDMNTPT/$ONEFOLDER/bin $DESTDIR/ > /dev/null 2>&1
  1208. [ -d $CDMNTPT/$ONEFOLDER/sbin ] && cp -a -u $CDMNTPT/$ONEFOLDER/sbin $DESTDIR/ > /dev/null 2>&1
  1209. [ -d $CDMNTPT/$ONEFOLDER/etc ] && cp -a -u $CDMNTPT/$ONEFOLDER/etc $DESTDIR/ > /dev/null 2>&1
  1210. [ -d $CDMNTPT/$ONEFOLDER/lib ] && cp -a -u $CDMNTPT/$ONEFOLDER/lib $DESTDIR/ > /dev/null 2>&1
  1211. [ -d $CDMNTPT/$ONEFOLDER/opt ] && cp -a -u $CDMNTPT/$ONEFOLDER/opt $DESTDIR/ > /dev/null 2>&1
  1212. if [ -d $CDMNTPT/$ONEFOLDER/root/.var_saved ];then #100820 see /etc/rc.d/functions4puppy
  1213. mkdir -p $DESTDIR/var
  1214. cp -a -u $CDMNTPT/$ONEFOLDER/root/.var_saved/* $DESTDIR/var/ > /dev/null 2>&1
  1215. fi
  1216. [ -d $CDMNTPT/$ONEFOLDER/root ] && cp -a -u $CDMNTPT/$ONEFOLDER/root $DESTDIR/ > /dev/null 2>&1
  1217. [ -d $CDMNTPT/$ONEFOLDER/root/.var_saved ] && rm -rf $DESTDIR/root/.var_saved > /dev/null 2>&1 #100820
  1218. [ -d $CDMNTPT/$ONEFOLDER/usr ] && cp -a -u $CDMNTPT/$ONEFOLDER/usr $DESTDIR/ > /dev/null 2>&1
  1219. [ $DEVTMPFSFLG -eq 0 ] && [ -d $CDMNTPT/$ONEFOLDER/dev ] && cp -a -u $CDMNTPT/$ONEFOLDER/dev $DESTDIR/ > /dev/null 2>&1 #v411 130612
  1220. cp -a -u $CDMNTPT/$ONEFOLDER/*.sfs $DESTDIR/ > /dev/null 2>&1 #v3.97
  1221. #delete deleted files (.wh.filename)... 110212 screen out .wh..wh..opq
  1222. WHITEOUTS="`find $DESTDIR -xdev -type f -name .wh.* | grep -v '__dir_opaque' | grep -v '.wh..wh.'`" #110212
  1223. echo "$WHITEOUTS" |
  1224. while read DELWHITE
  1225. do
  1226. DELFILE="`echo -n "$DELWHITE" | sed -e 's/\\.wh\\.//g'`"
  1227. if [ -e "$DELFILE" ];then
  1228. rm -rf "$DELFILE"
  1229. rm -rf "$DELWHITE"
  1230. fi
  1231. done
  1232. check_status 0 #display 'done' for each folder loaded.
  1233. else
  1234. echo -n -e "\\033[70G\\033[1;31m" >/dev/console #red text on column 70.
  1235. echo -n "RAM full" >/dev/console
  1236. echo -e "\\033[0;39m" >/dev/console
  1237. break
  1238. fi
  1239. done
  1240. sync
  1241. ####END LOAD FOLDERS####
  1242. umount /mnt/dev_ro1 #unmount the cd.
  1243. fi
  1244. OLDDISTRO_VERSION="$DISTRO_VERSION" #110422
  1245. [ -f $OLDFILESMNTPT/etc/puppyversion ] && OLDDISTRO_VERSION="`cat $OLDFILESMNTPT/etc/puppyversion`" #old pre-w464 installation. 110422
  1246. [ -f $OLDFILESMNTPT/etc/DISTRO_SPECS ] && OLDDISTRO_VERSION="`grep '^DISTRO_VERSION' $OLDFILESMNTPT/etc/DISTRO_SPECS | cut -f 2 -d '=' | cut -f 2 -d "'" | cut -f 2 -d '"' | cut -f 1 -d ' '`" #w012 w478 110422
  1247. #110801 moved up...
  1248. REASON=''
  1249. vercmp $DISTRO_VERSION gt $OLDDISTRO_VERSION && REASON='upgrade' #110422
  1250. [ $PUPMODE -eq 5 ] && REASON='firstboot'
  1251. #110810 some builds may have many scsi drivers in initrd, if needed will have already loaded, so delete them...
  1252. if [ "$REASON" != "" ];then
  1253. mkdir /tmp/scsi-keep
  1254. for ONEKEEP in imm.ko ppa.ko raid_class.ko sg.ko scsi_wait_scan.ko
  1255. do
  1256. ONEFND="`find /lib/modules/$KERNELVER/kernel/drivers/scsi -type f -name $ONEKEEP`"
  1257. [ "$ONEFND" ] && cp -a $ONEFND /tmp/scsi-keep/
  1258. done
  1259. rm -rf /lib/modules/$KERNELVER/kernel/drivers/scsi
  1260. cp -a /tmp/scsi-keep /lib/modules/$KERNELVER/kernel/drivers/scsi #restore needed.
  1261. fi
  1262. #110810 problem kernel numbering 2.6.32-40, 2.6.32-44 both in /lib/modules/2.6.32...
  1263. if [ "$REASON" = "upgrade" ];then
  1264. if [ -d /pup_rw/lib/modules/initrd ];then
  1265. rm -rf /pup_rw/lib/modules/initrd
  1266. rm -f /pup_rw/lib/modules/modules.*
  1267. fi
  1268. if [ -d /pup_ro1/lib/modules/initrd ];then
  1269. rm -rf /pup_ro1/lib/modules/initrd
  1270. rm -f /pup_ro1/lib/modules/modules.*
  1271. fi
  1272. fi
  1273. #move modules to main f.s...
  1274. #(do this before loading ${DISTRO_FILE_PREFIX}-xxx.sfs, to free up ram space)...
  1275. if [ "$ZDRVINIT" = "yes" ];then
  1276. #the entire kitchen sink of modules is in the initrd.
  1277. ZDRV='' #/sbin/modprobe needs this.
  1278. #what if deleted modules due to lack space in ${DISTRO_FILE_PREFIX}save, but now more free space?... v4.01...
  1279. [ ! -d /pup_rw/lib/modules/all-firmware ] && [ ! -d /pup_ro1/lib/modules/all-firmware ] && [ $FREEK -gt 24000 ] && REASON='restore'
  1280. if [ "$REASON" != "" ];then
  1281. [ -d /pup_rw/lib/modules ] && rm -rf /pup_rw/lib/modules
  1282. [ -d /pup_ro1/lib/modules ] && rm -rf /pup_ro1/lib/modules
  1283. mkdir -p /pup_rw/lib
  1284. mv /lib/modules /pup_rw/lib/
  1285. mkdir -p /pup_rw/initrd
  1286. cp -af /DISTRO_SPECS /pup_rw/initrd/
  1287. cp -af /init /pup_rw/initrd/
  1288. sync
  1289. fi
  1290. else
  1291. #the initrd does have some modules, move them to the main layered f.s...
  1292. #v4.02 moved this up. had it down after the the unionfs setup (just want it same place as the above code).
  1293. [ ! -d /pup_rw/lib/modules/$KERNELVER/initrd ] && [ ! -d /pup_ro1/lib/modules/$KERNELVER/initrd ] && REASON="new"
  1294. if [ "$REASON" = "new" ];then #110810 change test.
  1295. mkdir -p /pup_rw/lib/modules/$KERNELVER #PUPMODE=5, this dir not exist.
  1296. mv /lib/modules/$KERNELVER /pup_rw/lib/modules/$KERNELVER/initrd
  1297. rm -f /pup_rw/lib/modules/$KERNELVER/initrd/modules.*
  1298. sync
  1299. #note: /etc/rc.d/rc.sysinit will detect them and run depmod.
  1300. fi
  1301. fi
  1302. COPY2RAM=""
  1303. COPYMSG='copying to ram' #purple
  1304. if [ "$CREATEPUPXXXSFS" != "" ];then
  1305. #load puppy.sfs...
  1306. PUPSFSDEV="`echo -n "$PUPSFS" | cut -f 1 -d ','`"
  1307. PUPSFSFS="`echo -n "$PUPSFS" | cut -f 2 -d ','`"
  1308. PUPSFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1309. basepupsfs="`basename $PUPSFSFILE`"
  1310. echo -n "Loading the '${basepupsfs}' main file..." > /dev/console
  1311. if [ "$PUPSFSDEV" = "rootfs" ];then #humongous initrd.
  1312. PUPSFSDEVMNTPT="" #actually it's '/'.
  1313. COPY2RAM='yes' #actually it is already in ram, but code below puts it in a tmpfs.
  1314. else
  1315. PPATTERN="/dev/$PUPSFSDEV "
  1316. PUPSFSDEVMNTPT="`grep "$PPATTERN" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1317. if [ "$PUPSFSDEVMNTPT" = "" ];then
  1318. mntfunc $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2 #-t $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2
  1319. PUPSFSDEVMNTPT="/mnt/dev_ro2"
  1320. UMOUNTME="/mnt/dev_ro2" #mark for unmounting.
  1321. fi
  1322. fi
  1323. #if there's heaps of ram, copy puppy.sfs to a tmpfs...
  1324. #v405 fast media plus more than 256MB ram then definitely worth copying to ram...
  1325. SIZESFSK=`du -k ${PUPSFSDEVMNTPT}${PUPSFSFILE} | cut -f 1`
  1326. SIZESFSK=$(($SIZESFSK + 1000)) #some slack.
  1327. MINRAM2CPY=$(($SIZESFSK * 2)) #100222 technosaurus: in case of very big puppies.
  1328. #100920 decide whether to copy .sfs's to ram (see prior decision above)...
  1329. pdPATTERN="`echo "$PUPSFSDEV" | sed -e 's/[0-9]*$//'` "
  1330. if [ "$PNOCOPY" != "yes" ];then
  1331. [ "`echo -n "$ATADRIVES" | grep "$pdPATTERN"`" = "" ] && COPYCONTENDER='yes' #test if not fast internal drive.
  1332. [ $PUPMODE -eq 5 ] && COPYCONTENDER='yes'
  1333. [ "$DEV1FS" = "iso9660" ] && COPYCONTENDER='yes'
  1334. [ "$DEV1FS" = "udf" ] && COPYCONTENDER='yes' #130128
  1335. [ $RAMSIZE -gt 700000 ] && COPYCONTENDER='yes' #130728 always try to copy sfs to ram if >=700MB.
  1336. fi
  1337. [ "$PCOPY" = "yes" ] && COPYCONTENDER='yes'
  1338. #130728 bump minimum ram size... was 220000
  1339. [ "$COPYCONTENDER" = "yes" ] && [ $RAMSIZE -gt 400000 ] && [ $RAMSIZE -gt $MINRAM2CPY ] && COPY2RAM="yes"
  1340. if [ "$COPY2RAM" = "yes" ];then
  1341. mount -t tmpfs -o size=${SIZESFSK}k tmpfs /mnt/tmpfs
  1342. if [ "${PUPSFSDEVMNTPT}" = "" ];then #v403 humongous initrd.
  1343. mv -f ${PUPSFSDEVMNTPT}${PUPSFSFILE} /mnt/tmpfs/
  1344. else
  1345. echo -e -n " \\033[1;35m${COPYMSG}\\033[0;39m" > /dev/console #purple.
  1346. cp -af ${PUPSFSDEVMNTPT}${PUPSFSFILE} /mnt/tmpfs/
  1347. fi
  1348. sync
  1349. SFSBASENAME="`basename $PUPSFSFILE`"
  1350. losetup /dev/loop0 /mnt/tmpfs/${SFSBASENAME}
  1351. #101013 moved down [ "$UMOUNTME" != "" ] && umntfunc $UMOUNTME
  1352. else
  1353. losetup /dev/loop0 ${PUPSFSDEVMNTPT}${PUPSFSFILE}
  1354. fi
  1355. mount -r -t squashfs -o noatime /dev/loop0 $CREATEPUPXXXSFS #usually /pup_ro2.
  1356. fi
  1357. ###TODO: above code-block almost same as below, could probably combine###
  1358. ZLAYER='' #v4.02
  1359. ZFACTOR='' #v426
  1360. #note, traditionally, loop2 kept free for scripts to use.
  1361. if [ "$ZDRVINIT" != "yes" ];then
  1362. #v4.02 if ZDRV located, and mounted, put it into the layered-fs...
  1363. if [ "$ZDRV" != "" ];then
  1364. ZDEV="`echo "$ZDRV" | cut -f 1 -d ','`"
  1365. ZFS="`echo "$ZDRV" | cut -f 2 -d ','`"
  1366. ZFILE="`echo "$ZDRV" | cut -f 3 -d ','`"
  1367. MNT_ZFILE=""
  1368. if [ "$ZDEV" = "rootfs" ];then #101102 humongous initrd.
  1369. MNT_ZFILE="" #actually it's '/'.
  1370. COPY2RAM='yes' #actually it is already in ram, but code below puts it in a tmpfs.
  1371. else
  1372. zPATTERN="/dev/$ZDEV "
  1373. MNT_ZFILE="`grep "$zPATTERN" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1374. fi
  1375. ZBASENAME="`basename $ZFILE`" #v426 moved up.
  1376. if [ "$MNT_ZFILE" != "" ];then
  1377. if [ "$COPY2RAM" = "yes" ];then
  1378. SIZEZK=`du -k ${MNT_ZFILE}${ZFILE} | cut -f 1`
  1379. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1380. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs2
  1381. if [ "$MNT_ZFILE" = "" ];then #101101 humongous initrd.
  1382. mv -af ${MNT_ZFILE}${ZFILE} /mnt/tmpfs2/
  1383. else
  1384. cp -af ${MNT_ZFILE}${ZFILE} /mnt/tmpfs2/
  1385. fi
  1386. sync
  1387. losetup /dev/loop3 /mnt/tmpfs2/${ZBASENAME}
  1388. else
  1389. losetup /dev/loop3 ${MNT_ZFILE}${ZFILE}
  1390. fi
  1391. mount -r -t squashfs -o noatime /dev/loop3 /pup_z
  1392. if [ $? -eq 0 ];then
  1393. ZLAYER=':/pup_z=ro'
  1394. ZFACTOR="$ZBASENAME" #v426
  1395. fi
  1396. fi
  1397. fi
  1398. fi
  1399. #130513 create pupdesk.flg...
  1400. if [ $PUPMODE -eq 5 ];then
  1401. if [ -s /tmp/RWPART ];then
  1402. pdFLG=0
  1403. pdDEV="$(cat /tmp/RWPART | cut -f 1 -d '|')"
  1404. pdFS="$(cat /tmp/RWPART | cut -f 2 -d '|')"
  1405. pdMNTPT="$(cat /proc/mounts | grep "/dev/${pdDEV} " | cut -f 2 -d ' ')"
  1406. if [ ! "$pdMNTPT" ];then
  1407. mkdir -p /mnt/$pdDEV
  1408. mntfunc $pdFS /dev/$pdDEV /mnt/$pdDEV #130518
  1409. pdFLG=1
  1410. pdMNTPT="/mnt/${pdDEV}"
  1411. fi
  1412. if [ ! -f ${pdMNTPT}/pupdesk.flg ];then
  1413. touch ${pdMNTPT}/pupdesk.flg #read in quicksetup.
  1414. else
  1415. #quicksetup writes auto-selected driver into pupdesk.flg (at previous boot).
  1416. mkdir -p /pup_rw/var/local #130518
  1417. cp -f ${pdMNTPT}/pupdesk.flg /pup_rw/var/local/quicksetup-pupmode5-autodriver #xorgwizard-cli reads this.
  1418. mkdir -p /pup_rw/root #130518
  1419. touch /pup_rw/root/.xorgwizard-reenter #see /root/.profile, will cause xorgwizard to run.
  1420. #...see also /etc/rc.d/rc.sysinit
  1421. fi
  1422. [ $pdFLG -eq 1 ] && umntfunc $pdMNTPT
  1423. fi
  1424. else
  1425. [ -f /tmp/RWPART ] && rm -f /tmp/RWPART
  1426. fi
  1427. ALAYER=''
  1428. AFACTOR=''
  1429. if [ "$ADRV" != "" ];then
  1430. ADEV="`echo "$ADRV" | cut -f 1 -d ','`"
  1431. AFS="`echo "$ADRV" | cut -f 2 -d ','`"
  1432. AFILE="`echo "$ADRV" | cut -f 3 -d ','`"
  1433. MNT_AFILE=""
  1434. aPATTERN="/dev/$ADEV "
  1435. MNT_AFILE="`grep "$aPATTERN" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1436. ABASENAME="`basename $AFILE`" #v426 moved up.
  1437. if [ "$MNT_AFILE" != "" ];then
  1438. if [ "$COPY2RAM" = "yes" ];then
  1439. SIZEZK=`du -k ${MNT_AFILE}${AFILE} | cut -f 1`
  1440. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1441. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs2
  1442. cp -af ${MNT_AFILE}${AFILE} /mnt/tmpfs2/
  1443. sync
  1444. losetup /dev/loop2 /mnt/tmpfs2/${ABASENAME}
  1445. else
  1446. losetup /dev/loop2 ${MNT_AFILE}${AFILE}
  1447. fi
  1448. mount -r -t squashfs -o noatime /dev/loop2 /pup_a > /dev/console 2>&1
  1449. if [ $? -eq 0 ];then
  1450. ALAYER='/pup_a=ro:'
  1451. AFACTOR="$ABASENAME" #v426
  1452. fi
  1453. fi
  1454. fi
  1455. YLAYER=''
  1456. YFACTOR=''
  1457. if [ "$YDRV" != "" ];then
  1458. YDEV="`echo "$YDRV" | cut -f 1 -d ','`"
  1459. YFS="`echo "$YDRV" | cut -f 2 -d ','`"
  1460. YFILE="`echo "$YDRV" | cut -f 3 -d ','`"
  1461. MNT_YFILE=""
  1462. yPATTERN="/dev/$YDEV "
  1463. MNT_YFILE="`grep "$yPATTERN" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1464. YBASENAME="`basename $YFILE`" #v426 moved up.
  1465. if [ "$MNT_YFILE" != "" ];then
  1466. if [ "$COPY2RAM" = "yes" ];then
  1467. SIZEZK=`du -k ${MNT_YFILE}${YFILE} | cut -f 1`
  1468. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1469. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs3
  1470. cp -af ${MNT_YFILE}${YFILE} /mnt/tmpfs3/
  1471. sync
  1472. losetup /dev/loop3 /mnt/tmpfs3/${YBASENAME}
  1473. else
  1474. losetup /dev/loop3 ${MNT_YFILE}${YFILE}
  1475. fi
  1476. mount -r -t squashfs -o noatime /dev/loop3 /pup_y > /dev/console 2>&1
  1477. if [ $? -eq 0 ];then
  1478. YLAYER='/pup_y=ro:'
  1479. YFACTOR="$YBASENAME" #v426
  1480. fi
  1481. fi
  1482. fi
  1483. [ "$UMOUNTME" != "" ] && umntfunc $UMOUNTME #101013 puppy.sfs was copied to tmpfs so can unmount partition.
  1484. check_status 0 #$?
  1485. ########################END LOADING PUPPY FILES########################
  1486. #120215 may have PSUBDIR already, but use this method... (i want to be able to locate the initrd.gz)
  1487. zPSUBDIR=''
  1488. [ "$PUPSFS" ] && zPSUBDIR="`echo -n "$PUPSFS" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/xxx.sfs will return /pup220
  1489. [ "$zPSUBDIR" = "" -o "$zPSUBDIR" = "/" ] && zPSUBDIR="$PSUBDIR"
  1490. #...this will be written to /etc/rc.d/PUPSTATE
  1491. #/etc/PUPSTATE passes useful variables to the running puppy...
  1492. mkdir -p /pup_rw/etc/rc.d
  1493. echo "PUPMODE=$PUPMODE" > /pup_rw/etc/rc.d/PUPSTATE
  1494. echo "PDEV1='$PDEV1'" >> /pup_rw/etc/rc.d/PUPSTATE
  1495. echo "DEV1FS='$DEV1FS'" >> /pup_rw/etc/rc.d/PUPSTATE
  1496. echo "PUPSFS='$PUPSFS'" >> /pup_rw/etc/rc.d/PUPSTATE
  1497. echo "PUPSAVE='$PUPSAVE'" >> /pup_rw/etc/rc.d/PUPSTATE
  1498. echo "PMEDIA='$PMEDIA'" >> /pup_rw/etc/rc.d/PUPSTATE
  1499. echo '#ATADRIVES is all internal ide/pata/sata drives, excluding optical, excluding usb...' >> /pup_rw/etc/rc.d/PUPSTATE
  1500. echo "ATADRIVES='$ATADRIVES'" >> /pup_rw/etc/rc.d/PUPSTATE
  1501. echo '#ATAOPTICALDRIVES is list of non-usb optical drives...' >> /pup_rw/etc/rc.d/PUPSTATE #110206
  1502. echo "ATAOPTICALDRIVES='$ATAOPTICALDRIVES'" >> /pup_rw/etc/rc.d/PUPSTATE
  1503. echo '#these directories are unionfs/aufs layers in /initrd...' >> /pup_rw/etc/rc.d/PUPSTATE
  1504. echo "SAVE_LAYER='$OLDFILESMNTPT'" >> /pup_rw/etc/rc.d/PUPSTATE
  1505. echo "PUP_LAYER='$NEWFILESMNTPT'" >> /pup_rw/etc/rc.d/PUPSTATE
  1506. #if [ $SMNTPT ];then
  1507. echo "#The partition that has the ${DISTRO_FILE_PREFIX}save file is mounted here..." >> /pup_rw/etc/rc.d/PUPSTATE
  1508. echo "PUP_HOME='${SMNTPT}'" >> /pup_rw/etc/rc.d/PUPSTATE
  1509. echo '#(in /initrd) ...note, /mnt/home is a link to it.' >> /pup_rw/etc/rc.d/PUPSTATE
  1510. #fi
  1511. echo '#this file has extra kernel drivers and firmware...' >> /pup_rw/etc/rc.d/PUPSTATE
  1512. echo "ZDRV='$ZDRV'" >> /pup_rw/etc/rc.d/PUPSTATE #v2.22
  1513. echo "ADRV='$ADRV'" >> /pup_rw/etc/rc.d/PUPSTATE
  1514. echo "YDRV='$YDRV'" >> /pup_rw/etc/rc.d/PUPSTATE
  1515. echo '#complete set of modules in the initrd (moved to main f.s.)...' >> /pup_rw/etc/rc.d/PUPSTATE
  1516. echo "ZDRVINIT='$ZDRVINIT'" >> /pup_rw/etc/rc.d/PUPSTATE #v4.02
  1517. echo '#Partition no. override on boot drive to which session is (or will be) saved...' >> /pup_rw/etc/rc.d/PUPSTATE
  1518. echo "PSAVEMARK='$PSAVEMARK'" >> /pup_rw/etc/rc.d/PUPSTATE
  1519. if [ "$PLANG" ];then #120215 L18L. 120217 bring this back, seems like a good thing!
  1520. echo "#PLANG is written to LANG in /etc/profile by init script initrd...
  1521. PLANG=${PLANG}
  1522. OUTPUT_CHARSET=UTF-8
  1523. export OUTPUT_CHARSET" >> /pup_rw/etc/rc.d/PUPSTATE
  1524. fi
  1525. echo "PSUBDIR='${zPSUBDIR}'" >> /pup_rw/etc/rc.d/PUPSTATE #120215
  1526. #older ${DISTRO_FILE_PREFIX}save.2fs <v2.16 will not have this file...
  1527. [ ! -f $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG ] && touch $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG
  1528. #note, OLDFILESMNTPT can also be "" so BOOTCONFIG needs to exist in initrd also.
  1529. . $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG #can have EXTRASFSLIST variable.
  1530. #110217 very bad hack, see /etc/rc.d/rc.update, rc.shutdown.
  1531. [ ! -f $OLDFILESMNTPT/var/local/etc_profile_at_shutdown ] && cp -f $OLDFILESMNTPT/etc/profile $OLDFILESMNTPT/var/local/etc_profile_at_shutdown
  1532. ######################SETUP LAYERED FILESYSTEM########################
  1533. echo -n "Setting up the layered filesystem..." > /dev/console #STEP FIVE
  1534. #are there any other sfs files to load at bottom layers?...
  1535. NEWUNIONRECORD=""
  1536. CNTLOOP=4 ; UMNTRO=""
  1537. if [ "$PUPSAVE" != "" ];then
  1538. if [ "$SMNTPT" != "" -o $PUPMODE -eq 77 ];then #v3.97
  1539. touch /tmp/EXTRASFSS #100711
  1540. SFSSDIR="$SMNTPT"
  1541. #100711 look in top and in psubdir...
  1542. xSFSSDIRx="" #100711
  1543. xPSUBDIR="`echo -n "$PUPSAVE" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/spupsave.2fs will return /pup220
  1544. [ "$xPSUBDIR" ] && xSFSSDIRx="${SMNTPT}${xPSUBDIR}"'/*.sfs' #100711
  1545. [ $PUPMODE -eq 77 ] && SFSSDIR="$DESTDIR" #v3.97
  1546. #find all the extra sfs files...
  1547. touch /tmp/LOGONEBASES
  1548. #v424 modified to only load selection made in BootManager...
  1549. if [ "$EXTRASFSLIST" != "" ];then #in /etc/rc.d/BOOTCONFIG
  1550. #130514 shinobar: extra sfs in the order of EXTRASFSLIST, subdir first
  1551. for ONEEXTRA in $EXTRASFSLIST ; do
  1552. ONEBASE="`basename $ONEEXTRA`"
  1553. echo "$ONEBASE" | grep -qE '^z|^pup[_-]' && continue
  1554. echo "/tmp/EXTRASFSS" | grep -q "$ONEBASE" && continue # avoid loading duplicates.
  1555. [ "$xPSUBDIR" != "" ] && [ -s "$SFSSDIR$xPSUBDIR/$ONEBASE" ] && echo "$SFSSDIR$xPSUBDIR/$ONEBASE" >> /tmp/EXTRASFSS && continue
  1556. [ -s "$SFSSDIR/$ONEBASE" ] && echo "$SFSSDIR/$ONEBASE" >> /tmp/EXTRASFSS && continue
  1557. done
  1558. fi
  1559. UMNTRO="" ; EXTRASFSLIST=""
  1560. if [ -s /tmp/EXTRASFSS ];then #100711
  1561. for ONEEXTRA in `cat /tmp/EXTRASFSS | tr '\n' ' '`
  1562. do
  1563. ONEBASE="`basename $ONEEXTRA`"
  1564. EXTRASFSLIST="${EXTRASFSLIST}${ONEBASE} " #construct list of actually used.
  1565. losetup /dev/loop${CNTLOOP} $ONEEXTRA
  1566. mount -r -t squashfs -o noatime /dev/loop${CNTLOOP} /pup_ro${CNTLOOP}
  1567. [ $? -eq 0 ] && UMNTRO="${UMNTRO}:/pup_ro${CNTLOOP}=ro"
  1568. CNTLOOP=`expr $CNTLOOP + 1`
  1569. [ $CNTLOOP -eq 10 ] && break
  1570. #...only support adding 3 extra .sfs files, as performance degrades as each layer added.
  1571. #...v410 bugfix, change 6 to 7 so can have 3 sfs files.
  1572. #...w015 change 7 to 10 so can have 6 sfs files.
  1573. done
  1574. fi
  1575. #keep a record of different layer configurations...
  1576. SAVEFILE="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  1577. SAVEFILENAMEONLY="`basename $SAVEFILE`"
  1578. SFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1579. SFSFILENAMEONLY="`basename $SFSFILE`"
  1580. RECORDLIST="$SAVEFILENAMEONLY $AFACTOR $YFACTOR $SFSFILENAMEONLY $EXTRASFSLIST $ZFACTOR" #v426
  1581. NEWUNIONRECORD="`echo "$RECORDLIST" | tr -s ' ' | sed -e 's/ $//'`"
  1582. #120130 bring back Underdog Linux...
  1583. [ ! "$UNDERDOG" ] && [ "$xPSUBDIR" ] && [ -f "${SMNTPT}${xPSUBDIR}/underdog.lnx" ] && UNDERDOG="`cat "${SMNTPT}${xPSUBDIR}/underdog.lnx"`"
  1584. [ ! "$UNDERDOG" ] && [ -f $SFSSDIR/underdog.lnx ] && UNDERDOG="`cat ${SFSSDIR}/underdog.lnx`"
  1585. fi
  1586. fi
  1587. #120130 bring back Underdog Linux...
  1588. if [ "$UNDERDOG" ];then #note, 'underdog' can also be specified on kernel commandline.
  1589. udPTN1="${UNDERDOG}|"
  1590. FNDPART="`echo "$PCPARTS0" | grep "$udPTN1"`" #ex: sda1|ext3
  1591. if [ "$FNDPART" ];then
  1592. udPTN2="/dev/${UNDERDOG} "
  1593. UDMNTPT="`grep "$udPTN2" /proc/self/mountinfo | grep '/ ' | cut -f 5 -d ' '`"
  1594. if [ ! "$UDMNTPT" ];then #must not be mounted.
  1595. udFS="`echo -n "$FNDPART" | cut -f 2 -d '|'`"
  1596. mount -r -t $udFS /dev/$UNDERDOG /pup_ro${CNTLOOP}
  1597. if [ $? -eq 0 ];then
  1598. UMNTRO="${UMNTRO}:/pup_ro${CNTLOOP}=ro"
  1599. #fixes to prevent library clashes... (got out of puppy 2.x)
  1600. MNTFIX='/pup_rw'
  1601. [ "`echo -n "$UMNTRO" | grep 'pup_ro1'`" != "" ] && MNTFIX='/pup_ro1'
  1602. [ ! -f $MNTFIX/lib/.wh.i686 ] && touch /pup_rw/lib/.wh.i686 #hides /lib/i686
  1603. #puppy needs dir name /usr/lib/qt at bootup (see rc.profile)...
  1604. REALQTDIR="`find /pup_ro${CNTLOOP}/usr/lib -maxdepth 1 -type d -name 'qt*' | tail -n 1 | sed -e "s/\/pup_ro${CNTLOOP}\/usr\/lib\///"`"
  1605. if [ "$REALQTDIR" ];then
  1606. if [ ! -e $MNTFIX/usr/lib/qt ];then
  1607. [ "`find /pup_ro${CNTLOOP}/usr/lib -maxdepth 1 -xtype d -name qt`" = "" ] && ln -s $REALQTDIR /pup_rw/usr/lib/qt
  1608. fi
  1609. fi
  1610. CNTLOOP=`expr $CNTLOOP + 1`
  1611. fi
  1612. fi
  1613. fi
  1614. fi
  1615. #update /etc/rc.d/BOOTCONFIG with latest layered-fs layers configuration... #100222 fix...
  1616. xBOOTCONFIG="`grep -v '^PREVUNIONRECORD' $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG | sed -e 's/^LASTUNIONRECORD/PREVUNIONRECORD/'`"
  1617. echo "$xBOOTCONFIG" > /pup_rw/etc/rc.d/BOOTCONFIG
  1618. #sync
  1619. echo "LASTUNIONRECORD='$NEWUNIONRECORD'" >> /pup_rw/etc/rc.d/BOOTCONFIG
  1620. [ "$LASTUNIONRECORD" = "$NEWUNIONRECORD" ] && NEWUNIONRECORD="" #used below.
  1621. #...if layers changed since last boot, code further down will do whiteout files purge.
  1622. #.../etc/rc.d/rc.update reads BOOTCONFIG, updates menu (etc) if layers changed.
  1623. #after switch_root, rc.sysinit calls rc.update, but need to do pre-cleaning...
  1624. if [ "$OLDFILESMNTPT" != "" ];then
  1625. #an empty tmp is required for mounting a tmpfs onto later...
  1626. rm -rf $OLDFILESMNTPT/tmp/*
  1627. rm -rf $OLDFILESMNTPT/tmp/.[0-9a-zA-Z]*
  1628. if [ ! -L $OLDFILESMNTPT/usr/X11R6 ];then #test if a symlink.
  1629. #this is supposed to be a link to X11R7. <2.10 it won't be...
  1630. if [ -d $OLDFILESMNTPT/usr/X11R6 ];then
  1631. mkdir -p $OLDFILESMNTPT/usr/X11R7
  1632. cp -af $OLDFILESMNTPT/usr/X11R6/* $OLDFILESMNTPT/usr/X11R7/
  1633. rm -rf $OLDFILESMNTPT/usr/X11R6
  1634. fi
  1635. ln -s X11R7 $OLDFILESMNTPT/usr/X11R6
  1636. fi
  1637. rm -rf $OLDFILESMNTPT/root/tmp 2>/dev/null
  1638. rm -f $OLDFILESMNTPT/root/.wh.tmp 2>/dev/null
  1639. NEWPVERSION="$DISTRO_VERSION" #110422
  1640. if [ -f $OLDFILESMNTPT/etc/puppyversion ];then
  1641. OLDPVERSION="`cat $OLDFILESMNTPT/etc/puppyversion`" #old pre-w464 installation. 110422
  1642. rm -f $OLDFILESMNTPT/etc/puppyversion #no longer used.
  1643. fi
  1644. [ -f $OLDFILESMNTPT/etc/DISTRO_SPECS ] && OLDPVERSION="`grep '^DISTRO_VERSION' $OLDFILESMNTPT/etc/DISTRO_SPECS | cut -f 2 -d '=' | cut -f 2 -d '"' | cut -f 2 -d "'" | cut -f 1 -d ' '`" #w478 110422
  1645. [ "$OLDPVERSION" = "" ] && OLDPVERSION="$NEWPVERSION"
  1646. if vercmp ${NEWPVERSION} gt ${OLDPVERSION} ; then
  1647. #make sure that the official boot scripts will be visible at top
  1648. rm -f $OLDFILESMNTPT/etc/rc.d/functions
  1649. rm -f $OLDFILESMNTPT/etc/rc.d/functions4puppy4
  1650. rm -f $OLDFILESMNTPT/etc/rc.d/rc.country
  1651. rm -f $OLDFILESMNTPT/etc/rc.d/rc.network_basic
  1652. rm -f $OLDFILESMNTPT/etc/rc.d/rc.services
  1653. rm -f $OLDFILESMNTPT/etc/rc.d/rc.shutdown
  1654. rm -f $OLDFILESMNTPT/etc/rc.d/rc.sysinit
  1655. rm -f $OLDFILESMNTPT/etc/rc.d/rc.update
  1656. fi
  1657. #110422 decrement dotted version number. hard, just set to 0.0...
  1658. [ "$PCLEAN" = "yes" ] && xOLDPVERSION='0.0' #110422
  1659. [ "$PPURGE" = "yes" ] && xOLDPVERSION='0.0' #110422
  1660. if vercmp ${NEWPVERSION} gt ${xOLDPVERSION} ; then #110422
  1661. echo -e "\\033[1;35m" >/dev/console #35=purple.
  1662. echo "Version cleanup, restoring 'official' files, please wait..." >/dev/console
  1663. echo -en "\\033[0;39m" >/dev/console
  1664. echo "(with a slow CPU this may take sometime, please be patient)" >/dev/console
  1665. #v2.16 do not overwrite rox desktop setup, as /etc/rc.d/rc.update now handles it...
  1666. [ -f $OLDFILESMNTPT/root/Choices/ROX-Filer/PuppyPin ] && touch $OLDFILESMNTPT/root/Choices/ROX-Filer/PuppyPin
  1667. [ -f $OLDFILESMNTPT/root/Choices/ROX-Filer/globicons ] && touch $OLDFILESMNTPT/root/Choices/ROX-Filer/globicons
  1668. mkdir $OLDFILESMNTPT/tmp/versioncleanup
  1669. #make sure that the official boot scripts will be visible at top... 110722 fix...
  1670. rm -f $OLDFILESMNTPT/etc/rc.d/functions
  1671. rm -f $OLDFILESMNTPT/etc/rc.d/functions4puppy4
  1672. rm -f $OLDFILESMNTPT/etc/rc.d/rc.country
  1673. rm -f $OLDFILESMNTPT/etc/rc.d/rc.network_basic
  1674. rm -f $OLDFILESMNTPT/etc/rc.d/rc.services
  1675. rm -f $OLDFILESMNTPT/etc/rc.d/rc.shutdown
  1676. rm -f $OLDFILESMNTPT/etc/rc.d/rc.sysinit
  1677. rm -f $OLDFILESMNTPT/etc/rc.d/rc.update
  1678. #i think if a file exists both in OLDFILESMNTPT and in NEWFILESMNTPT, remove
  1679. #it from OLDFILESMNTPT (as OLDFILESMNTPT is upper layer and will hide the
  1680. #'official' file. But, only do it if 'official' file has a newer modify date...
  1681. cd $NEWFILESMNTPT
  1682. #v2.12 this while-loop has become ultra-slow... seems upx compressed execs
  1683. #responsible, recently upx-ed all the execs, now restore busybox, grep, cp.
  1684. DOTCNT=0
  1685. find ./ -noleaf -type f | sed -e 's/^\.//g' |
  1686. while read ONENEW
  1687. do
  1688. DOTCNT=`expr $DOTCNT + 1`
  1689. [ $DOTCNT -gt 100 ] && DOTCNT=0 #display a dot every time cnts to 100.
  1690. [ $DOTCNT -eq 100 ] && echo -n '*' >/dev/console #v2.12
  1691. #note, screens out spaces also...
  1692. [ ! "`echo -n "$ONENEW" | grep -E '^/dev|^/tmp|^/proc| '`" = "" ] && continue
  1693. ONEBASE="`basename $OLDFILESMNTPT$ONENEW`"
  1694. OLDDIR="`dirname $OLDFILESMNTPT$ONENEW`"
  1695. #a whiteout file 'on top' will hide the 'official' file...
  1696. [ -f $OLDDIR/.wh.$ONEBASE ] && rm -f $OLDDIR/.wh.$ONEBASE
  1697. [ -f $OLDDIR/.wh.__dir_opaque ] && rm -f $OLDDIR/.wh.__dir_opaque #v424 not needed for aufs2
  1698. [ -f $OLDDIR/.wh..wh..opq ] && rm -f $OLDDIR/.wh..wh..opq #110212 recent aufs2, but probably not needed.
  1699. #let's get paranoid and imagine upper-directories also wiped...
  1700. while [ ! "$OLDDIR" = "/" ];do
  1701. OLDDIR="`dirname $OLDDIR`"
  1702. UP1BASE="`basename $OLDDIR`"
  1703. [ -f $OLDDIR/.wh.$UP1BASE ] && rm -f $OLDDIR/.wh.$UP1BASE
  1704. [ -f $OLDDIR/.wh.__dir_opaque ] && rm -f $OLDDIR/.wh.__dir_opaque #v424 not needed for aufs2
  1705. [ -f $OLDDIR/.wh..wh..opq ] && rm -f $OLDDIR/.wh..wh..opq #110212 recent aufs2, but probably not needed.
  1706. done
  1707. #now check for 'old' files on top layer...
  1708. if [ -f $OLDFILESMNTPT$ONENEW ];then
  1709. #note, this is inaccurate due to local timezone not yet set...
  1710. #i got this 'stat' off ibiblio, v3.3. i think older version than in main puppy f.s...
  1711. MODIFOLD=`$PUPFILESDIR/bin/stat -c %Y $OLDFILESMNTPT$ONENEW`
  1712. MODIFNEW=`$PUPFILESDIR/bin/stat -c %Y $NEWFILESMNTPT$ONENEW`
  1713. [ "$PPURGE" = "yes" ] && MODIFNEW=`expr $MODIFOLD + 1` #force overwrite all.
  1714. if [ $MODIFNEW -ge $MODIFOLD ];then
  1715. echo -n " $ONENEW " >/dev/console
  1716. ONEDIR="`dirname $ONENEW`"
  1717. mkdir -p $OLDFILESMNTPT/tmp/versioncleanup$ONEDIR
  1718. cp -af $OLDFILESMNTPT$ONENEW $OLDFILESMNTPT/tmp/versioncleanup$ONEDIR/
  1719. rm -f $OLDFILESMNTPT$ONENEW
  1720. fi
  1721. fi
  1722. done
  1723. echo >/dev/console
  1724. cd /
  1725. fi
  1726. #need to cleanup whiteout files if a new .sfs layer has been added...
  1727. if [ "$NEWUNIONRECORD" != "" -o "$PPURGE" = "yes" ];then
  1728. #find all .wh.__dir_opaque files at the OLDFILESMNTPT layer... v424 bugfixes... 110212 .wh..wh..opq ...
  1729. cd $OLDFILESMNTPT
  1730. find ./ -noleaf -type f -name ".wh.*" | sed -e 's/^\.//g' |
  1731. while read ONEOPAQUE #examples: /usr/src/.wh.__dir_opaque, /usr/src/.wh.bin
  1732. do
  1733. ONEDIR="`dirname $ONEOPAQUE`" #ex: /usr/src
  1734. WHBASE="`basename $ONEOPAQUE`" #ex: .wh.bin
  1735. if [ "$WHBASE" != ".wh.__dir_opaque" -a "$WHBASE" != ".wh..wh..opq" ];then #aufs2 always enter this condition... 110212 extra test.
  1736. #example, .wh.bin alongside bin directory means it is deleted...
  1737. ONEDEL="`echo -n "$WHBASE" | sed -e 's/^\\.wh\\.//g'`" #ex: bin
  1738. ONEDIR="${ONEDIR}/${ONEDEL}" #ex: /usr/src/bin
  1739. [ ! -e ".${ONEDIR}" ] && continue
  1740. fi
  1741. #if same dir exists lower layer, then wipe the opaque file...
  1742. [ -d /pup_ro3${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1743. [ -d /pup_ro4${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1744. [ -d /pup_ro5${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1745. [ -d /pup_ro6${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1746. [ -d /pup_ro7${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1747. [ -d /pup_ro8${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1748. [ -d /pup_ro9${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1749. done
  1750. cd /
  1751. fi
  1752. if vercmp $NEWPVERSION gt $xOLDPVERSION ; then #110422
  1753. vPATTERN="s%^DISTRO_VERSION=.*%DISTRO_VERSION='${xOLDPVERSION}'%" #110122 mod 110422
  1754. sed -e "$vPATTERN" $OLDFILESMNTPT/etc/DISTRO_SPECS > /tmp/distro_specs_old
  1755. cp -f /tmp/distro_specs_old $OLDFILESMNTPT/etc/DISTRO_SPECS #so rc.update will run.
  1756. sync
  1757. OLDstr='to'
  1758. [ "$xOLDPVERSION" != "0.0" ] && OLDstr="from version $xOLDPVERSION to"
  1759. echo -e "\\033[1;35m" >/dev/console #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  1760. [ "$PCLEAN" = "yes" ] && echo "This is a simulated version upgrade, which performs a file cleanup." >/dev/console
  1761. [ "$PPURGE" = "yes" ] && echo "This is a radical file cleanup for broken systems, could alter some settings." >/dev/console
  1762. echo "You are upgrading Puppy ${OLDstr} ${NEWPVERSION}." >/dev/console #110122 mod
  1763. echo "Overwritten old files have been moved to /tmp/versioncleanup/" >/dev/console
  1764. echo "After bootup please examine this directory (before shutdown) for anything that you might like to recover. Pausing 30 secs so you can read this msg..." >/dev/console
  1765. echo -en "\\033[0;39m" >/dev/console
  1766. sleep 30 #so can see above messages.
  1767. fi
  1768. fi
  1769. [ "$RDSH" = "6" ] && exec /bin/sh >/dev/console 2>&1 #w091027
  1770. #create the layered f.s.... ***THE BIG EVENT***
  1771. if [ "$LAYERFS" = "aufs" ];then
  1772. mount -t aufs -o udba=reval,diropq=w,dirs=${UMNTRW}${UMNTRO0}${ALAYER}${YLAYER}${UMNTRO1}${ZLAYER}${UMNTRO} unionfs /pup_new
  1773. else #unionfs
  1774. UMNTRW="`echo -n "$UMNTRW" | sed -e 's/+wh//g'`" #w003 'ro+wh' not accepted by unionfs, change back to 'ro'.
  1775. mount -t unionfs -o dirs=${UMNTRW}${UMNTRO0}${ALAYER}${YLAYER}${UMNTRO1}${ZLAYER}${UMNTRO} unionfs /pup_new
  1776. fi
  1777. check_status $? #END STEP FIVE
  1778. #######################END SETUP UNIONFS LAYERED FILESYSTEM###################
  1779. #101127 pakt: code adapted from bchafy's Xin
  1780. #his description: "A precfg area for faster re-mastering, no need to regenerate a .SFS
  1781. #every time you want to change the core, and no need for a hard drive to store customizations"
  1782. if [ -d $PUPSFSDEVMNTPT/precfg ];then
  1783. echo -n "Overlaying preconfig files..." > /dev/console
  1784. SRC="$PUPSFSDEVMNTPT"/precfg
  1785. DEST="/pup_new"
  1786. cd $SRC
  1787. for i in `find . -not -type d -print`; do
  1788. BASEFILE="$i"
  1789. SRCFILE="$SRC/$BASEFILE"
  1790. DESTFILE="$DEST/$BASEFILE"
  1791. DESTDIR=`dirname $DESTFILE`
  1792. MASK="777"
  1793. if test -f "$DESTFILE"; then
  1794. MASK=`stat -c %a $DESTFILE`
  1795. fi
  1796. mkdir -p $DESTDIR
  1797. cp -f $SRCFILE $DESTFILE
  1798. chmod $MASK $DESTFILE
  1799. done
  1800. check_status 0
  1801. fi
  1802. #END PRECONFIG STEP
  1803. #######################SETUP SWITCH TO MAIN FILESYSTEM#######################
  1804. echo -n "Performing a 'switch_root' to the layered filesystem..." > /dev/console
  1805. #prepare everything for doing a switch_root...
  1806. #cpio archive does switch_root, lose the initial-ramfs, so move all mntd...
  1807. mkdir -p /pup_new/initrd
  1808. mkdir -p /pup_new/initrd/pup_ro1
  1809. mkdir -p /pup_new/initrd/pup_ro2
  1810. mkdir -p /pup_new/initrd/pup_ro3
  1811. mkdir -p /pup_new/initrd/pup_ro4
  1812. mkdir -p /pup_new/initrd/pup_ro5
  1813. mkdir -p /pup_new/initrd/pup_ro6
  1814. mkdir -p /pup_new/initrd/pup_ro7
  1815. mkdir -p /pup_new/initrd/pup_ro8
  1816. mkdir -p /pup_new/initrd/pup_ro9
  1817. mkdir -p /pup_new/initrd/pup_rw
  1818. mkdir -p /pup_new/initrd/pup_z
  1819. mkdir -p /pup_new/initrd/pup_a
  1820. mkdir -p /pup_new/initrd/pup_y
  1821. mkdir -p /pup_new/initrd/mnt
  1822. mkdir -p /pup_new/initrd/mnt/data
  1823. mkdir -p /pup_new/initrd/mnt/dev_ro1
  1824. mkdir -p /pup_new/initrd/mnt/dev_ro2
  1825. mkdir -p /pup_new/initrd/mnt/dev_save
  1826. mkdir -p /pup_new/initrd/mnt/swap
  1827. mkdir -p /pup_new/initrd/mnt/tmpfs
  1828. mkdir -p /pup_new/initrd/mnt/tmpfs2
  1829. mkdir -p /pup_new/initrd/mnt/tmpfs3
  1830. mkdir -p /pup_new/initrd/mnt/zdrv
  1831. mkdir -p /pup_new/initrd/mnt/adrv
  1832. mkdir -p /pup_new/initrd/mnt/ydrv
  1833. mkdir -p /pup_new/initrd/tmp
  1834. for ONEMNT in `mount | cut -f 3 -d ' ' | grep -v 'pup_new' | grep '^/pup_' | tr '\n' ' '`
  1835. do
  1836. mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1837. done
  1838. for ONEMNT in `mount | cut -f 3 -d ' ' | grep '^/mnt/' | tr '\n' ' '`
  1839. do
  1840. mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1841. done
  1842. #v4.02 bring back, but allocate more space (/4 instead of /8)....
  1843. #v3.97 a problem can run out of /tmp space, remove...
  1844. #to minimise writes to pup_save and to speedup, tmpfs on /tmp...
  1845. if [ "$CREATETMPFS" != "/pup_rw" ];then #test if no tmpfs on unionfs top layer.
  1846. ALLOCK=`expr $RAMSIZE \/ 4 + $EXTRAALLOCK`
  1847. #v424 don't create tmpfs if have versioncleanup dir... 100423 try again...
  1848. [ ! -e /pup_new/tmp/versioncleanup ] && mount -t tmpfs -o size=${ALLOCK}k tmpfs /pup_new/tmp
  1849. fi
  1850. #PNOX is a boot param. /etc/profile prevents X from starting if this file exists...
  1851. [ "$PNOX" = "yes" ] && touch /pup_new/tmp/bootcnt.txt
  1852. cp -a /DISTRO_SPECS /pup_new/initrd/
  1853. cp -af /tmp/* /pup_new/initrd/tmp/ #keep any log files.
  1854. #091122
  1855. mkdir -p /pup_new/lib/keymaps
  1856. cp -a -f /lib/keymaps/* /pup_new/lib/keymaps/
  1857. mkdir -p /pup_new/lib/consolefonts
  1858. cp -a -f /lib/consolefonts/* /pup_new/lib/consolefonts/
  1859. if [ "$KMAP" ];then #because PKEYS boot param was defined.
  1860. echo -n "$KMAP" > /pup_new/etc/keymap
  1861. echo -n "$FONTMAP" > /pup_new/etc/fontmap
  1862. echo -n "$CODEPAGE" > /pup_new/etc/codepage
  1863. fi
  1864. #091225 copy exes to main f.s.
  1865. if [ -f /bin/TARGETEXES ];then
  1866. for ONEEXE in `cat /bin/TARGETEXES` #ex: sbin/e2fsck
  1867. do
  1868. BASEEXE="`basename $ONEEXE`"
  1869. [ ! -e /pup_new/$ONEEXE ] && cp -f /bin/$BASEEXE /pup_new/$ONEEXE
  1870. done
  1871. cp -f /bin/TARGETEXES /pup_new/bin/ #100113 puppyinstaller needs this.
  1872. fi
  1873. #110114 if a drive unplugged in previous boot, but plugged in at bootup, device-nodes will be missing in main f.s...
  1874. if [ $DEVTMPFSFLG -eq 0 ];then #130612
  1875. cp -a -u -f /dev/* /pup_new/dev/
  1876. else
  1877. mount -t devtmpfs devtmpfs /pup_new/dev
  1878. fi
  1879. #120215 if PLANG set here, carry it over...
  1880. if [ "$PLANG" ];then
  1881. langPTN="s%^LANG=.*%LANG=${PLANG}%"
  1882. sed -i -e "$langPTN" /pup_new/etc/profile
  1883. fi
  1884. #RDSH is a boot param. exit to initial ramdisk shell...
  1885. if [ "$RDSH" = "yes" ];then
  1886. echo > /dev/console
  1887. echo "Dropped to initramfs shell. Type 'exec switch' to continue booting Puppy." > /dev/console
  1888. exec /bin/sh >/dev/console 2>&1
  1889. fi
  1890. #v3.01 a bit untidy, but cd may still be mounted when it doesn't have to be...
  1891. case $PMEDIA in
  1892. *cd)
  1893. [ "$PDEV1" ] && umount /dev/$PDEV1 2>/dev/null #okay if it fails.
  1894. ;;
  1895. esac
  1896. sync
  1897. #killall -USR1 hotplug2 #v423
  1898. umount /proc/bus/usb
  1899. umount /sys
  1900. umount /proc
  1901. #now using cpio archive for initramfs 'initial ramdisk'...
  1902. exec switch_root /pup_new /sbin/init
  1903. ###END###