init 92 KB

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