init 93 KB

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