init 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101
  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. PUPPY_FOLDER="`grep '^PUPSAVE' $CREATEPUPSAVE2FS/etc/rc.d/PUPSTATE | cut -f 3 -d ','`"
  1099. if vercmp ${DISTRO_VERSION} gt ${OLDDISTRO_VERSION} ;then #110422
  1100. if [ "$NUMPUPSAVES" != "0" ];then #save-file(s) found.
  1101. echo -e "\\033[1;36m" >/dev/console #36=aquablue
  1102. echo "This save-file was last used with version $OLDDISTRO_VERSION of Puppy." >/dev/console
  1103. 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
  1104. echo -n "ENTER only to upgrade: " >/dev/console
  1105. echo -en "\\033[0;39m" >/dev/console
  1106. read noupgradesf
  1107. if [ "$noupgradesf" != "" ];then
  1108. echo -en "\\033[1;35m" >/dev/console #35=purple
  1109. echo "Backing off, not using save-file, booting in RAM only, PUPMODE=5..." >/dev/console
  1110. echo -en "\\033[0;39m" >/dev/console
  1111. sync
  1112. if [ -L "$CREATEPUPSAVE2FS" ]; then
  1113. rm -f "$CREATEPUPSAVE2FS" #get rid of save-folder
  1114. mkdir $CREATEPUPSAVE2FS
  1115. else
  1116. umount $CREATEPUPSAVE2FS #unmount the save-file.
  1117. fi
  1118. PUPMODE=5
  1119. CREATETMPFS="";CREATEPDEV1="";CREATEPUPXXXSFS="";CREATEPUPSAVE2FS="";CREATEFOLDERS=""
  1120. CREATETMPFS="/pup_rw";CREATEPUPXXXSFS="/pup_ro2"
  1121. OLDFILESMNTPT="";NEWFILESMNTPT="/pup_ro2";UMNTRW="/pup_rw=rw:";UMNTRO1="/pup_ro2=ro"
  1122. fi
  1123. fi
  1124. #check if puppy.sfs copied to same place as save-file...
  1125. if [ "`echo -n "$BOOTDRV" | grep -f /tmp/OPTICALDRIVES0`" != "" ];then #110205 booting off cd.
  1126. if [ "$CREATEPUPSAVE2FS" ];then #did not do the backoff above.
  1127. xPUPSFSDEV="`echo -n "$PUPSFS" | cut -f 1 -d ','`" #checking puppy.sfs file.
  1128. xPUPSFSFS="`echo -n "$PUPSFS" | cut -f 2 -d ','`"
  1129. xPUPSFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1130. basepupsfs="`basename $xPUPSFSFILE`"
  1131. [ "`echo $PUPPY_FOLDER | cut -f 3 -d '/'`" = "" ] && dirpupsfs="/" || dirpupsfs="`dirname $PUPPY_FOLDER`"
  1132. #set update flag
  1133. touch /tmp/version_update_flag
  1134. if [ "`echo -n "$xPUPSFSDEV" | grep -f /tmp/OPTICALDRIVES0`" != "" ];then #110205
  1135. #it is on the cd, so checkout copying it to hd...
  1136. echo -e "\\033[1;36m" >/dev/console #36=aquablue
  1137. echo "The main Puppy file '${basepupsfs}' is being loaded off an optical" >/dev/console
  1138. echo "disc. Very slow!" >/dev/console
  1139. echo "If you are updating an older version in your hard disk, type the" >/dev/console
  1140. echo "ENTER key only to update all the files in your installation." >/dev/console
  1141. echo "Or type \"s\" to copy only the SFS(s) at the root of the partition" >/dev/console
  1142. echo "of your save-file. Then on next boot from the CD puppy will load" >/dev/console
  1143. echo "the puppy SFSs from there." >/dev/console
  1144. echo "Type any other printable character not to copy anything." >/dev/console
  1145. echo -n "ENTER key only to update: " >/dev/console
  1146. echo -en "\\033[0;39m" >/dev/console
  1147. read nocopysfs
  1148. if [ "$nocopysfs" = "" -o "$nocopysfs" = "s" ];then
  1149. echo -en "\\033[1;35m" >/dev/console #35=purple
  1150. echo "'${basepupsfs}' now copying to hard drive (but only available next boot)..." >/dev/console
  1151. echo -en "\\033[0;39m" >/dev/console
  1152. PPATTERN="/dev/$xPUPSFSDEV "
  1153. PUPSFSDEVMNTPT="`mount | grep -m1 "$PPATTERN" | cut -f 3 -d ' '`"
  1154. if [ "$PUPSFSDEVMNTPT" = "" ];then
  1155. mntfunc $xPUPSFSFS /dev/$xPUPSFSDEV /mnt/dev_ro2 #-t $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2
  1156. PUPSFSDEVMNTPT="/mnt/dev_ro2"
  1157. UMOUNTME="/mnt/dev_ro2" #mark for unmounting.
  1158. fi
  1159. #110424 do not copy puppy*.sfs into a sub-dir...
  1160. if [ "$nocopysfs" = "s" ];then
  1161. cp -f ${PUPSFSDEVMNTPT}/*.sfs /mnt/dev_save
  1162. else
  1163. if [ -f /mnt/dev_save/"$dirpupsfs"/initrd.gz ]; then # make sure
  1164. cp -f ${PUPSFSDEVMNTPT}/*.sfs /mnt/dev_save/"$dirpupsfs"
  1165. mv /mnt/dev_save/"$dirpupsfs"/initrd.gz /mnt/dev_save/"$dirpupsfs"/initrd.gz.OLD
  1166. mv /mnt/dev_save/"$dirpupsfs"/vmlinuz /mnt/dev_save/"$dirpupsfs"/vmlinuz.OLD
  1167. cp -f ${PUPSFSDEVMNTPT}/initrd.gz /mnt/dev_save/"$dirpupsfs"
  1168. cp -f ${PUPSFSDEVMNTPT}/vmlinuz /mnt/dev_save/"$dirpupsfs"
  1169. else
  1170. cp -f ${PUPSFSDEVMNTPT}/*.sfs /mnt/dev_save
  1171. fi
  1172. fi
  1173. sync
  1174. fi
  1175. fi
  1176. fi
  1177. fi
  1178. fi
  1179. fi
  1180. fi
  1181. fi
  1182. #there are technical problems with loading a swap partition/file before the union
  1183. #is created, so not doing it until rc.sysinit runs. however, if a tmpfs needs to be
  1184. #created here, set it's size in anticipation of a swap being loaded...
  1185. EXTRAALLOCK=0
  1186. SWAPPART="`echo "$PCPARTSALL" | grep '|swap|' | head -n 1`"
  1187. [ "$SWAPPART" ] && SWAPPARTSIZE=`echo -n "$SWAPPART" | cut -f 3 -d '|'`
  1188. [ $SWAPPARTSIZE ] && EXTRAALLOCK=`expr $SWAPPARTSIZE \/ 2`
  1189. if [ $EXTRAALLOCK -eq 0 ];then
  1190. [ -f ${SMNTPT}/pupswap.swp ] && SWAPFILESIZEBYTES=`stat -c %s ${SMNTPT}/pupswap.swp`
  1191. [ $SWAPFILESIZEBYTES ] && EXTRAALLOCK=`expr $SWAPFILESIZEBYTES \/ 2048` #use half. 110521 also convert bytes to kb.
  1192. fi
  1193. FREEK=0
  1194. if [ "$CREATETMPFS" != "" ];then
  1195. FREEK=`expr $RAMSIZE \/ 2` #half of physical.
  1196. [ $PUPMODE -eq 77 ] && FREEK=`expr $FREEK - 50000` #need some slack.
  1197. ALLOCK=`expr $FREEK + $EXTRAALLOCK`
  1198. mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATETMPFS
  1199. fi
  1200. #RW (top) layer now has a tmpfs, PDEV1 or ${DISTRO_FILE_PREFIX}save mounted on it. calc free space...
  1201. [ $FREEK -eq 0 ] && FREEK=`df | grep ' /pup_rw' | tr -s ' ' | cut -f 4 -d ' '`
  1202. [ ! $FREEK ] && FREEK=0
  1203. if [ "$CREATEFOLDERS" != "" ];then
  1204. PUPSAVEDEV="`echo -n "$PUPSAVE" | cut -f 1 -d ','`"
  1205. PUPSAVEFS="`echo -n "$PUPSAVE" | cut -f 2 -d ','`"
  1206. PUPSAVEFILE="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  1207. mount -o noatime -t $PUPSAVEFS /dev/$PUPSAVEDEV /mnt/dev_ro1 #mnt the cd.
  1208. #create a tmpfs to load the folders...
  1209. ALLOCK=`expr $RAMSIZE \/ 2 - 50000` #allocate half of physical ram. + leave 50M slack.
  1210. mount -t tmpfs -o size=${ALLOCK}k tmpfs $CREATEFOLDERS #/pup_ro1
  1211. #load the folders from the cd...
  1212. ####START LOAD FOLDERS####
  1213. CDMNTPT="/mnt/dev_ro1" #where the multisession cd is mounted.
  1214. DESTDIR="$CREATEFOLDERS" #dest dir has a tmpfs mntd on it, into which to copy folders.
  1215. BKFOLDERS="`ls -1 -r $CDMNTPT | grep '^20[0-9][0-9]'`"
  1216. BKLASTFOLDER="`echo "$BKFOLDERS" | head -n 1`"
  1217. #a boot option allows ignore last n sessions, also need to create a badlist...
  1218. if [ "$PIGNORELAST" ];then
  1219. BKBADLIST="`echo "$BKFOLDERS" | head -n ${PIGNORELAST}`"
  1220. if [ -f $CDMNTPT/$BKLASTFOLDER/.badfolders ];then
  1221. cp $CDMNTPT/$BKLASTFOLDER/.badfolders $DESTDIR/
  1222. if [ ! $? -eq 0 ];then
  1223. #fallback, in case last folder badly corrupted...
  1224. BKPREVFOLDER="`echo "$BKFOLDERS" | head -n 2 | tail -n 1`"
  1225. [ -f $CDMNTPT/$BKPREVFOLDER/.badfolders ] && cp $CDMNTPT/$BKPREVFOLDER/.badfolders $DESTDIR/
  1226. fi
  1227. fi
  1228. echo "$BKBADLIST" >> $DESTDIR/.badfolders
  1229. #note, rc.shutdown and savesession-dvd 'touch' this file so it will get saved.
  1230. sync
  1231. else
  1232. [ -f $CDMNTPT/$BKLASTFOLDER/.badfolders ] && cp $CDMNTPT/$BKLASTFOLDER/.badfolders $DESTDIR/
  1233. fi
  1234. [ -f $DESTDIR/.badfolders ] && BKBADLIST="`cat $DESTDIR/.badfolders | tr "\n" " "`"
  1235. BKFOLDERS="`echo -n "$BKFOLDERS" | tr "\n" " "`"
  1236. for ONEFOLDER in $BKFOLDERS
  1237. do
  1238. if [ ! "`echo -n "$BKBADLIST" | grep "$ONEFOLDER"`" = "" ];then
  1239. echo "Folder $ONEFOLDER marked bad." >/dev/console
  1240. continue #ignore bad folder.
  1241. fi
  1242. echo -n "Loading folder $ONEFOLDER from CD/DVD..." >/dev/console
  1243. #need to be careful not to overfill the ramdisk...
  1244. FREERAMDISK=`df 2>/dev/null | grep "$DESTDIR" | head -n 1 | tr -s " " | cut -f 4 -d " "`
  1245. SIZEFOLDER=`du -k -s ${CDMNTPT}/${ONEFOLDER} | cut -f 1`
  1246. if [ -d ${CDMNTPT}/${ONEFOLDER}/archive ];then
  1247. SIZEARCHIVE=`du -k -s ${CDMNTPT}/${ONEFOLDER}/archive | cut -f 1`
  1248. else
  1249. SIZEARCHIVE=0
  1250. fi
  1251. SIZESOURCE=`expr $SIZEFOLDER - $SIZEARCHIVE`
  1252. if [ $FREERAMDISK -gt $SIZESOURCE ];then
  1253. #well, -u will only copy if files newer, so less stuff may get copied than calc'd above.
  1254. #need to copy everything except archive folder...
  1255. [ -d $CDMNTPT/$ONEFOLDER/bin ] && cp -a -u $CDMNTPT/$ONEFOLDER/bin $DESTDIR/ > /dev/null 2>&1
  1256. [ -d $CDMNTPT/$ONEFOLDER/sbin ] && cp -a -u $CDMNTPT/$ONEFOLDER/sbin $DESTDIR/ > /dev/null 2>&1
  1257. [ -d $CDMNTPT/$ONEFOLDER/etc ] && cp -a -u $CDMNTPT/$ONEFOLDER/etc $DESTDIR/ > /dev/null 2>&1
  1258. [ -d $CDMNTPT/$ONEFOLDER/lib ] && cp -a -u $CDMNTPT/$ONEFOLDER/lib $DESTDIR/ > /dev/null 2>&1
  1259. [ -d $CDMNTPT/$ONEFOLDER/opt ] && cp -a -u $CDMNTPT/$ONEFOLDER/opt $DESTDIR/ > /dev/null 2>&1
  1260. if [ -d $CDMNTPT/$ONEFOLDER/root/.var_saved ];then #100820 see /etc/rc.d/functions4puppy
  1261. mkdir -p $DESTDIR/var
  1262. cp -a -u $CDMNTPT/$ONEFOLDER/root/.var_saved/* $DESTDIR/var/ > /dev/null 2>&1
  1263. fi
  1264. [ -d $CDMNTPT/$ONEFOLDER/root ] && cp -a -u $CDMNTPT/$ONEFOLDER/root $DESTDIR/ > /dev/null 2>&1
  1265. [ -d $CDMNTPT/$ONEFOLDER/root/.var_saved ] && rm -rf $DESTDIR/root/.var_saved > /dev/null 2>&1 #100820
  1266. [ -d $CDMNTPT/$ONEFOLDER/usr ] && cp -a -u $CDMNTPT/$ONEFOLDER/usr $DESTDIR/ > /dev/null 2>&1
  1267. [ $DEVTMPFSFLG -eq 0 ] && [ -d $CDMNTPT/$ONEFOLDER/dev ] && cp -a -u $CDMNTPT/$ONEFOLDER/dev $DESTDIR/ > /dev/null 2>&1 #v411 130612
  1268. cp -a -u $CDMNTPT/$ONEFOLDER/*.sfs $DESTDIR/ > /dev/null 2>&1 #v3.97
  1269. #delete deleted files (.wh.filename)... 110212 screen out .wh..wh..opq
  1270. WHITEOUTS="`find $DESTDIR -xdev -type f -name .wh.* | grep -v '__dir_opaque' | grep -v '.wh..wh.'`" #110212
  1271. echo "$WHITEOUTS" |
  1272. while read DELWHITE
  1273. do
  1274. DELFILE="`echo -n "$DELWHITE" | sed -e 's/\\.wh\\.//g'`"
  1275. if [ -e "$DELFILE" ];then
  1276. rm -rf "$DELFILE"
  1277. rm -rf "$DELWHITE"
  1278. fi
  1279. done
  1280. check_status 0 #display 'done' for each folder loaded.
  1281. else
  1282. echo -n -e "\\033[70G\\033[1;31m" >/dev/console #red text on column 70.
  1283. echo -n "RAM full" >/dev/console
  1284. echo -e "\\033[0;39m" >/dev/console
  1285. break
  1286. fi
  1287. done
  1288. sync
  1289. ####END LOAD FOLDERS####
  1290. umount /mnt/dev_ro1 #unmount the cd.
  1291. fi
  1292. OLDDISTRO_VERSION="$DISTRO_VERSION" #110422
  1293. [ -f $OLDFILESMNTPT/etc/puppyversion ] && OLDDISTRO_VERSION="`cat $OLDFILESMNTPT/etc/puppyversion`" #old pre-w464 installation. 110422
  1294. [ -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
  1295. #110801 moved up...
  1296. REASON=''
  1297. vercmp $DISTRO_VERSION gt $OLDDISTRO_VERSION && REASON='upgrade' #110422
  1298. [ $PUPMODE -eq 5 ] && REASON='firstboot'
  1299. #110810 some builds may have many scsi drivers in initrd, if needed will have already loaded, so delete them...
  1300. if [ "$REASON" != "" ];then
  1301. mkdir /tmp/scsi-keep
  1302. for ONEKEEP in imm.ko ppa.ko raid_class.ko sg.ko scsi_wait_scan.ko
  1303. do
  1304. ONEFND="`find /lib/modules/$KERNELVER/kernel/drivers/scsi -type f -name $ONEKEEP`"
  1305. [ "$ONEFND" ] && cp -a $ONEFND /tmp/scsi-keep/
  1306. done
  1307. rm -rf /lib/modules/$KERNELVER/kernel/drivers/scsi
  1308. cp -a /tmp/scsi-keep /lib/modules/$KERNELVER/kernel/drivers/scsi #restore needed.
  1309. fi
  1310. #110810 problem kernel numbering 2.6.32-40, 2.6.32-44 both in /lib/modules/2.6.32...
  1311. if [ "$REASON" = "upgrade" ];then
  1312. if [ -d /pup_rw/lib/modules/initrd ];then
  1313. rm -rf /pup_rw/lib/modules/initrd
  1314. rm -f /pup_rw/lib/modules/modules.*
  1315. fi
  1316. if [ -d /pup_ro1/lib/modules/initrd ];then
  1317. rm -rf /pup_ro1/lib/modules/initrd
  1318. rm -f /pup_ro1/lib/modules/modules.*
  1319. fi
  1320. fi
  1321. #move modules to main f.s...
  1322. #(do this before loading ${DISTRO_FILE_PREFIX}-xxx.sfs, to free up ram space)...
  1323. if [ "$ZDRVINIT" = "yes" ];then
  1324. #the entire kitchen sink of modules is in the initrd.
  1325. ZDRV='' #/sbin/modprobe needs this.
  1326. #what if deleted modules due to lack space in ${DISTRO_FILE_PREFIX}save, but now more free space?... v4.01...
  1327. [ ! -d /pup_rw/lib/modules/all-firmware ] && [ ! -d /pup_ro1/lib/modules/all-firmware ] && [ $FREEK -gt 24000 ] && REASON='restore'
  1328. if [ "$REASON" != "" ];then
  1329. [ -d /pup_rw/lib/modules ] && rm -rf /pup_rw/lib/modules
  1330. [ -d /pup_ro1/lib/modules ] && rm -rf /pup_ro1/lib/modules
  1331. mkdir -p /pup_rw/lib
  1332. mv /lib/modules /pup_rw/lib/
  1333. mkdir -p /pup_rw/initrd
  1334. cp -af /DISTRO_SPECS /pup_rw/initrd/
  1335. cp -af /init /pup_rw/initrd/
  1336. sync
  1337. fi
  1338. else
  1339. #the initrd does have some modules, move them to the main layered f.s...
  1340. #v4.02 moved this up. had it down after the the unionfs setup (just want it same place as the above code).
  1341. [ ! -d /pup_rw/lib/modules/$KERNELVER/initrd ] && [ ! -d /pup_ro1/lib/modules/$KERNELVER/initrd ] && REASON="new"
  1342. if [ "$REASON" = "new" ];then #110810 change test.
  1343. mkdir -p /pup_rw/lib/modules/$KERNELVER #PUPMODE=5, this dir not exist.
  1344. mv /lib/modules/$KERNELVER /pup_rw/lib/modules/$KERNELVER/initrd
  1345. rm -f /pup_rw/lib/modules/$KERNELVER/initrd/modules.*
  1346. sync
  1347. #note: /etc/rc.d/rc.sysinit will detect them and run depmod.
  1348. fi
  1349. fi
  1350. COPY2RAM=""
  1351. COPYMSG='copying to ram' #purple
  1352. if [ "$CREATEPUPXXXSFS" != "" ];then
  1353. #load puppy.sfs...
  1354. PUPSFSDEV="`echo -n "$PUPSFS" | cut -f 1 -d ','`"
  1355. PUPSFSFS="`echo -n "$PUPSFS" | cut -f 2 -d ','`"
  1356. PUPSFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1357. basepupsfs="`basename $PUPSFSFILE`"
  1358. echo -n "Loading the '${basepupsfs}' main file..." > /dev/console
  1359. if [ "$PUPSFSDEV" = "rootfs" ];then #humongous initrd.
  1360. PUPSFSDEVMNTPT="" #actually it's '/'.
  1361. COPY2RAM='yes' #actually it is already in ram, but code below puts it in a tmpfs.
  1362. else
  1363. PPATTERN="/dev/$PUPSFSDEV "
  1364. PUPSFSDEVMNTPT="`mount | grep -m1 "$PPATTERN" | cut -f 3 -d ' '`"
  1365. if [ "$PUPSFSDEVMNTPT" = "" ];then
  1366. mntfunc $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2 #-t $PUPSFSFS /dev/$PUPSFSDEV /mnt/dev_ro2
  1367. PUPSFSDEVMNTPT="/mnt/dev_ro2"
  1368. UMOUNTME="/mnt/dev_ro2" #mark for unmounting.
  1369. fi
  1370. fi
  1371. #if there's heaps of ram, copy puppy.sfs to a tmpfs...
  1372. #v405 fast media plus more than 256MB ram then definitely worth copying to ram...
  1373. SIZESFSK=`du -k ${PUPSFSDEVMNTPT}${PUPSFSFILE} | cut -f 1`
  1374. SIZESFSK=$(($SIZESFSK + 1000)) #some slack.
  1375. MINRAM2CPY=$(($SIZESFSK * 2)) #100222 technosaurus: in case of very big puppies.
  1376. #100920 decide whether to copy .sfs's to ram (see prior decision above)...
  1377. pdPATTERN="`echo "$PUPSFSDEV" | sed -e 's/[0-9]*$//'` "
  1378. if [ "$PNOCOPY" != "yes" ];then
  1379. [ "`echo -n "$ATADRIVES" | grep "$pdPATTERN"`" = "" ] && COPYCONTENDER='yes' #test if not fast internal drive.
  1380. [ $PUPMODE -eq 5 ] && COPYCONTENDER='yes'
  1381. [ "$DEV1FS" = "iso9660" ] && COPYCONTENDER='yes'
  1382. [ "$DEV1FS" = "udf" ] && COPYCONTENDER='yes' #130128
  1383. [ $RAMSIZE -gt 700000 ] && COPYCONTENDER='yes' #130728 always try to copy sfs to ram if >=700MB.
  1384. fi
  1385. [ "$PCOPY" = "yes" ] && COPYCONTENDER='yes'
  1386. #130728 bump minimum ram size... was 220000
  1387. [ "$COPYCONTENDER" = "yes" ] && [ $RAMSIZE -gt 400000 ] && [ $RAMSIZE -gt $MINRAM2CPY ] && COPY2RAM="yes"
  1388. if [ "$COPY2RAM" = "yes" ];then
  1389. mount -t tmpfs -o size=${SIZESFSK}k tmpfs /mnt/tmpfs
  1390. if [ "${PUPSFSDEVMNTPT}" = "" ];then #v403 humongous initrd.
  1391. mv -f ${PUPSFSDEVMNTPT}${PUPSFSFILE} /mnt/tmpfs/
  1392. else
  1393. echo -e -n " \\033[1;35m${COPYMSG}\\033[0;39m" > /dev/console #purple.
  1394. cp -af ${PUPSFSDEVMNTPT}${PUPSFSFILE} /mnt/tmpfs/
  1395. fi
  1396. sync
  1397. SFSBASENAME="`basename $PUPSFSFILE`"
  1398. losetup /dev/loop0 /mnt/tmpfs/${SFSBASENAME}
  1399. #101013 moved down [ "$UMOUNTME" != "" ] && umntfunc $UMOUNTME
  1400. else
  1401. losetup /dev/loop0 ${PUPSFSDEVMNTPT}${PUPSFSFILE}
  1402. fi
  1403. mount -r -t squashfs -o noatime /dev/loop0 $CREATEPUPXXXSFS #usually /pup_ro2.
  1404. fi
  1405. ###TODO: above code-block almost same as below, could probably combine###
  1406. ZLAYER='' #v4.02
  1407. ZFACTOR='' #v426
  1408. #note, traditionally, loop2 kept free for scripts to use.
  1409. if [ "$ZDRVINIT" != "yes" ];then
  1410. #v4.02 if ZDRV located, and mounted, put it into the layered-fs...
  1411. if [ "$ZDRV" != "" ];then
  1412. ZDEV="`echo "$ZDRV" | cut -f 1 -d ','`"
  1413. ZFS="`echo "$ZDRV" | cut -f 2 -d ','`"
  1414. ZFILE="`echo "$ZDRV" | cut -f 3 -d ','`"
  1415. MNT_ZFILE=""
  1416. if [ "$ZDEV" = "rootfs" ];then #101102 humongous initrd.
  1417. MNT_ZFILE="" #actually it's '/'.
  1418. COPY2RAM='yes' #actually it is already in ram, but code below puts it in a tmpfs.
  1419. else
  1420. zPATTERN="/dev/$ZDEV "
  1421. MNT_ZFILE="`mount | grep -m1 "$zPATTERN" | cut -f 3 -d ' '`"
  1422. fi
  1423. ZBASENAME="`basename $ZFILE`" #v426 moved up.
  1424. if [ "$MNT_ZFILE" != "" ];then
  1425. if [ "$COPY2RAM" = "yes" ];then
  1426. SIZEZK=`du -k ${MNT_ZFILE}${ZFILE} | cut -f 1`
  1427. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1428. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs4
  1429. if [ "$MNT_ZFILE" = "" ];then #101101 humongous initrd.
  1430. mv -af ${MNT_ZFILE}${ZFILE} /mnt/tmpfs4/
  1431. else
  1432. cp -af ${MNT_ZFILE}${ZFILE} /mnt/tmpfs4/
  1433. fi
  1434. sync
  1435. losetup /dev/loop4 /mnt/tmpfs4/${ZBASENAME}
  1436. else
  1437. losetup /dev/loop4 ${MNT_ZFILE}${ZFILE}
  1438. fi
  1439. mount -r -t squashfs -o noatime /dev/loop4 /pup_z
  1440. if [ $? -eq 0 ];then
  1441. ZLAYER=':/pup_z=ro'
  1442. ZFACTOR="$ZBASENAME" #v426
  1443. fi
  1444. fi
  1445. fi
  1446. fi
  1447. #130513 create pupdesk.flg...
  1448. if [ $PUPMODE -eq 5 ];then
  1449. if [ -s /tmp/RWPART ];then
  1450. pdFLG=0
  1451. pdDEV="$(cat /tmp/RWPART | cut -f 1 -d '|')"
  1452. pdFS="$(cat /tmp/RWPART | cut -f 2 -d '|')"
  1453. pdMNTPT="$(cat /proc/mounts | grep "/dev/${pdDEV} " | cut -f 2 -d ' ')"
  1454. if [ ! "$pdMNTPT" ];then
  1455. mkdir -p /mnt/$pdDEV
  1456. mntfunc $pdFS /dev/$pdDEV /mnt/$pdDEV #130518
  1457. pdFLG=1
  1458. pdMNTPT="/mnt/${pdDEV}"
  1459. fi
  1460. if [ ! -f ${pdMNTPT}/pupdesk.flg ];then
  1461. touch ${pdMNTPT}/pupdesk.flg #read in quicksetup.
  1462. else
  1463. #quicksetup writes auto-selected driver into pupdesk.flg (at previous boot).
  1464. mkdir -p /pup_rw/var/local #130518
  1465. cp -f ${pdMNTPT}/pupdesk.flg /pup_rw/var/local/quicksetup-pupmode5-autodriver #xorgwizard-cli reads this.
  1466. mkdir -p /pup_rw/root #130518
  1467. touch /pup_rw/root/.xorgwizard-reenter #see /root/.profile, will cause xorgwizard to run.
  1468. #...see also /etc/rc.d/rc.sysinit
  1469. fi
  1470. [ $pdFLG -eq 1 ] && umntfunc $pdMNTPT
  1471. fi
  1472. else
  1473. [ -f /tmp/RWPART ] && rm -f /tmp/RWPART
  1474. fi
  1475. ALAYER=''
  1476. AFACTOR=''
  1477. if [ "$ADRV" != "" ];then
  1478. ADEV="`echo "$ADRV" | cut -f 1 -d ','`"
  1479. AFS="`echo "$ADRV" | cut -f 2 -d ','`"
  1480. AFILE="`echo "$ADRV" | cut -f 3 -d ','`"
  1481. MNT_AFILE=""
  1482. aPATTERN="/dev/$ADEV "
  1483. MNT_AFILE="`mount | grep -m1 "$aPATTERN" | cut -f 3 -d ' '`"
  1484. ABASENAME="`basename $AFILE`" #v426 moved up.
  1485. if [ "$MNT_AFILE" != "" ];then
  1486. if [ "$COPY2RAM" = "yes" ];then
  1487. SIZEZK=`du -k ${MNT_AFILE}${AFILE} | cut -f 1`
  1488. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1489. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs2
  1490. cp -af ${MNT_AFILE}${AFILE} /mnt/tmpfs2/
  1491. sync
  1492. losetup /dev/loop2 /mnt/tmpfs2/${ABASENAME}
  1493. else
  1494. losetup /dev/loop2 ${MNT_AFILE}${AFILE}
  1495. fi
  1496. mount -r -t squashfs -o noatime /dev/loop2 /pup_a > /dev/console 2>&1
  1497. if [ $? -eq 0 ];then
  1498. ALAYER='/pup_a=ro:'
  1499. AFACTOR="$ABASENAME" #v426
  1500. fi
  1501. fi
  1502. fi
  1503. YLAYER=''
  1504. YFACTOR=''
  1505. if [ "$YDRV" != "" ];then
  1506. YDEV="`echo "$YDRV" | cut -f 1 -d ','`"
  1507. YFS="`echo "$YDRV" | cut -f 2 -d ','`"
  1508. YFILE="`echo "$YDRV" | cut -f 3 -d ','`"
  1509. MNT_YFILE=""
  1510. yPATTERN="/dev/$YDEV "
  1511. MNT_YFILE="`mount | grep -m1 "$yPATTERN" | cut -f 3 -d ' '`"
  1512. YBASENAME="`basename $YFILE`" #v426 moved up.
  1513. if [ "$MNT_YFILE" != "" ];then
  1514. if [ "$COPY2RAM" = "yes" ];then
  1515. SIZEZK=`du -k ${MNT_YFILE}${YFILE} | cut -f 1`
  1516. SIZEZK=`expr $SIZEZK + 1000` #some slack.
  1517. mount -t tmpfs -o size=${SIZEZK}k tmpfs /mnt/tmpfs3
  1518. cp -af ${MNT_YFILE}${YFILE} /mnt/tmpfs3/
  1519. sync
  1520. losetup /dev/loop3 /mnt/tmpfs3/${YBASENAME}
  1521. else
  1522. losetup /dev/loop3 ${MNT_YFILE}${YFILE}
  1523. fi
  1524. mount -r -t squashfs -o noatime /dev/loop3 /pup_y > /dev/console 2>&1
  1525. if [ $? -eq 0 ];then
  1526. YLAYER='/pup_y=ro:'
  1527. YFACTOR="$YBASENAME" #v426
  1528. fi
  1529. fi
  1530. fi
  1531. [ "$UMOUNTME" != "" ] && umntfunc $UMOUNTME #101013 puppy.sfs was copied to tmpfs so can unmount partition.
  1532. check_status 0 #$?
  1533. ########################END LOADING PUPPY FILES########################
  1534. #120215 may have PSUBDIR already, but use this method... (i want to be able to locate the initrd.gz)
  1535. zPSUBDIR=''
  1536. [ "$PUPSFS" ] && zPSUBDIR="`echo -n "$PUPSFS" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/xxx.sfs will return /pup220
  1537. [ "$zPSUBDIR" = "" -o "$zPSUBDIR" = "/" ] && zPSUBDIR="$PSUBDIR"
  1538. #...this will be written to /etc/rc.d/PUPSTATE
  1539. #/etc/PUPSTATE passes useful variables to the running puppy...
  1540. mkdir -p /pup_rw/etc/rc.d
  1541. echo "PUPMODE=$PUPMODE" > /pup_rw/etc/rc.d/PUPSTATE
  1542. echo "PDEV1='$PDEV1'" >> /pup_rw/etc/rc.d/PUPSTATE
  1543. echo "DEV1FS='$DEV1FS'" >> /pup_rw/etc/rc.d/PUPSTATE
  1544. echo "PUPSFS='$PUPSFS'" >> /pup_rw/etc/rc.d/PUPSTATE
  1545. echo "PUPSAVE='$PUPSAVE'" >> /pup_rw/etc/rc.d/PUPSTATE
  1546. echo "PMEDIA='$PMEDIA'" >> /pup_rw/etc/rc.d/PUPSTATE
  1547. echo '#ATADRIVES is all internal ide/pata/sata drives, excluding optical, excluding usb...' >> /pup_rw/etc/rc.d/PUPSTATE
  1548. echo "ATADRIVES='$ATADRIVES'" >> /pup_rw/etc/rc.d/PUPSTATE
  1549. echo '#ATAOPTICALDRIVES is list of non-usb optical drives...' >> /pup_rw/etc/rc.d/PUPSTATE #110206
  1550. echo "ATAOPTICALDRIVES='$ATAOPTICALDRIVES'" >> /pup_rw/etc/rc.d/PUPSTATE
  1551. echo '#these directories are unionfs/aufs layers in /initrd...' >> /pup_rw/etc/rc.d/PUPSTATE
  1552. echo "SAVE_LAYER='$OLDFILESMNTPT'" >> /pup_rw/etc/rc.d/PUPSTATE
  1553. echo "PUP_LAYER='$NEWFILESMNTPT'" >> /pup_rw/etc/rc.d/PUPSTATE
  1554. #if [ $SMNTPT ];then
  1555. echo "#The partition that has the ${DISTRO_FILE_PREFIX}save file is mounted here..." >> /pup_rw/etc/rc.d/PUPSTATE
  1556. echo "PUP_HOME='${SMNTPT}'" >> /pup_rw/etc/rc.d/PUPSTATE
  1557. echo '#(in /initrd) ...note, /mnt/home is a link to it.' >> /pup_rw/etc/rc.d/PUPSTATE
  1558. #fi
  1559. echo '#this file has extra kernel drivers and firmware...' >> /pup_rw/etc/rc.d/PUPSTATE
  1560. echo "ZDRV='$ZDRV'" >> /pup_rw/etc/rc.d/PUPSTATE #v2.22
  1561. echo "ADRV='$ADRV'" >> /pup_rw/etc/rc.d/PUPSTATE
  1562. echo "YDRV='$YDRV'" >> /pup_rw/etc/rc.d/PUPSTATE
  1563. echo '#complete set of modules in the initrd (moved to main f.s.)...' >> /pup_rw/etc/rc.d/PUPSTATE
  1564. echo "ZDRVINIT='$ZDRVINIT'" >> /pup_rw/etc/rc.d/PUPSTATE #v4.02
  1565. echo '#Partition no. override on boot drive to which session is (or will be) saved...' >> /pup_rw/etc/rc.d/PUPSTATE
  1566. echo "PSAVEMARK='$PSAVEMARK'" >> /pup_rw/etc/rc.d/PUPSTATE
  1567. if [ "$PLANG" ];then #120215 L18L. 120217 bring this back, seems like a good thing!
  1568. echo "#PLANG is written to LANG in /etc/profile by init script initrd...
  1569. PLANG=${PLANG}
  1570. OUTPUT_CHARSET=UTF-8
  1571. export OUTPUT_CHARSET" >> /pup_rw/etc/rc.d/PUPSTATE
  1572. fi
  1573. echo "PSUBDIR='${zPSUBDIR}'" >> /pup_rw/etc/rc.d/PUPSTATE #120215
  1574. #older ${DISTRO_FILE_PREFIX}save.2fs <v2.16 will not have this file...
  1575. [ ! -f $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG ] && touch $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG
  1576. #note, OLDFILESMNTPT can also be "" so BOOTCONFIG needs to exist in initrd also.
  1577. . $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG #can have EXTRASFSLIST variable.
  1578. #110217 very bad hack, see /etc/rc.d/rc.update, rc.shutdown.
  1579. [ ! -f $OLDFILESMNTPT/var/local/etc_profile_at_shutdown ] && cp -f $OLDFILESMNTPT/etc/profile $OLDFILESMNTPT/var/local/etc_profile_at_shutdown
  1580. ######################SETUP LAYERED FILESYSTEM########################
  1581. echo -n "Setting up the layered filesystem..." > /dev/console #STEP FIVE
  1582. #are there any other sfs files to load at bottom layers?...
  1583. NEWUNIONRECORD=""
  1584. CNTLOOP=5 ; UMNTRO=""
  1585. if [ "$PUPSAVE" != "" ];then
  1586. if [ "$SMNTPT" != "" -o $PUPMODE -eq 77 ];then #v3.97
  1587. touch /tmp/EXTRASFSS #100711
  1588. SFSSDIR="$SMNTPT"
  1589. #100711 look in top and in psubdir...
  1590. xSFSSDIRx="" #100711
  1591. xPSUBDIR="`echo -n "$PUPSAVE" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/spupsave.2fs will return /pup220
  1592. [ "$xPSUBDIR" ] && xSFSSDIRx="${SMNTPT}${xPSUBDIR}"'/*.sfs' #100711
  1593. [ $PUPMODE -eq 77 ] && SFSSDIR="$DESTDIR" #v3.97
  1594. #find all the extra sfs files...
  1595. touch /tmp/LOGONEBASES
  1596. #v424 modified to only load selection made in BootManager...
  1597. if [ "$EXTRASFSLIST" != "" ];then #in /etc/rc.d/BOOTCONFIG
  1598. #130514 shinobar: extra sfs in the order of EXTRASFSLIST, subdir first
  1599. for ONEEXTRA in $EXTRASFSLIST ; do
  1600. ONEBASE="`basename $ONEEXTRA`"
  1601. echo "$ONEBASE" | grep -qE '^z|^pup[_-]' && continue
  1602. echo "/tmp/EXTRASFSS" | grep -q "$ONEBASE" && continue # avoid loading duplicates.
  1603. [ "$xPSUBDIR" != "" ] && [ -s "$SFSSDIR$xPSUBDIR/$ONEBASE" ] && echo "$SFSSDIR$xPSUBDIR/$ONEBASE" >> /tmp/EXTRASFSS && continue
  1604. [ -s "$SFSSDIR/$ONEBASE" ] && echo "$SFSSDIR/$ONEBASE" >> /tmp/EXTRASFSS && continue
  1605. done
  1606. fi
  1607. UMNTRO="" ; EXTRASFSLIST=""
  1608. if [ -s /tmp/EXTRASFSS ];then #100711
  1609. for ONEEXTRA in `cat /tmp/EXTRASFSS | tr '\n' ' '`
  1610. do
  1611. ONEBASE="`basename $ONEEXTRA`"
  1612. EXTRASFSLIST="${EXTRASFSLIST}${ONEBASE} " #construct list of actually used.
  1613. losetup /dev/loop${CNTLOOP} $ONEEXTRA
  1614. mount -r -t squashfs -o noatime /dev/loop${CNTLOOP} /pup_ro${CNTLOOP}
  1615. [ $? -eq 0 ] && UMNTRO="${UMNTRO}:/pup_ro${CNTLOOP}=ro"
  1616. CNTLOOP=`expr $CNTLOOP + 1`
  1617. [ $CNTLOOP -eq 10 ] && break
  1618. #...only support adding 3 extra .sfs files, as performance degrades as each layer added.
  1619. #...v410 bugfix, change 6 to 7 so can have 3 sfs files.
  1620. #...w015 change 7 to 10 so can have 6 sfs files.
  1621. done
  1622. fi
  1623. #keep a record of different layer configurations...
  1624. SAVEFILE="`echo -n "$PUPSAVE" | cut -f 3 -d ','`"
  1625. SAVEFILENAMEONLY="`basename $SAVEFILE`"
  1626. SFSFILE="`echo -n "$PUPSFS" | cut -f 3 -d ','`"
  1627. SFSFILENAMEONLY="`basename $SFSFILE`"
  1628. RECORDLIST="$SAVEFILENAMEONLY $AFACTOR $YFACTOR $SFSFILENAMEONLY $ZFACTOR $EXTRASFSLIST" #v426
  1629. NEWUNIONRECORD="`echo "$RECORDLIST" | tr -s ' ' | sed -e 's/ $//'`"
  1630. #120130 bring back Underdog Linux...
  1631. [ ! "$UNDERDOG" ] && [ "$xPSUBDIR" ] && [ -f "${SMNTPT}${xPSUBDIR}/underdog.lnx" ] && UNDERDOG="`cat "${SMNTPT}${xPSUBDIR}/underdog.lnx"`"
  1632. [ ! "$UNDERDOG" ] && [ -f $SFSSDIR/underdog.lnx ] && UNDERDOG="`cat ${SFSSDIR}/underdog.lnx`"
  1633. fi
  1634. fi
  1635. #120130 bring back Underdog Linux...
  1636. if [ "$UNDERDOG" ];then #note, 'underdog' can also be specified on kernel commandline.
  1637. udPTN1="${UNDERDOG}|"
  1638. FNDPART="`echo "$PCPARTS0" | grep "$udPTN1"`" #ex: sda1|ext3
  1639. if [ "$FNDPART" ];then
  1640. udPTN2="/dev/${UNDERDOG} "
  1641. UDMNTPT="`mount | grep -m1 "$udPTN2" | cut -f 3 -d ' '`"
  1642. if [ ! "$UDMNTPT" ];then #must not be mounted.
  1643. udFS="`echo -n "$FNDPART" | cut -f 2 -d '|'`"
  1644. mount -r -t $udFS /dev/$UNDERDOG /pup_ro${CNTLOOP}
  1645. if [ $? -eq 0 ];then
  1646. UMNTRO="${UMNTRO}:/pup_ro${CNTLOOP}=ro"
  1647. #fixes to prevent library clashes... (got out of puppy 2.x)
  1648. MNTFIX='/pup_rw'
  1649. [ "`echo -n "$UMNTRO" | grep 'pup_ro1'`" != "" ] && MNTFIX='/pup_ro1'
  1650. [ ! -f $MNTFIX/lib/.wh.i686 ] && touch /pup_rw/lib/.wh.i686 #hides /lib/i686
  1651. #puppy needs dir name /usr/lib/qt at bootup (see rc.profile)...
  1652. REALQTDIR="`find /pup_ro${CNTLOOP}/usr/lib -maxdepth 1 -type d -name 'qt*' | tail -n 1 | sed -e "s/\/pup_ro${CNTLOOP}\/usr\/lib\///"`"
  1653. if [ "$REALQTDIR" ];then
  1654. if [ ! -e $MNTFIX/usr/lib/qt ];then
  1655. [ "`find /pup_ro${CNTLOOP}/usr/lib -maxdepth 1 -xtype d -name qt`" = "" ] && ln -s $REALQTDIR /pup_rw/usr/lib/qt
  1656. fi
  1657. fi
  1658. CNTLOOP=`expr $CNTLOOP + 1`
  1659. fi
  1660. fi
  1661. fi
  1662. fi
  1663. #update /etc/rc.d/BOOTCONFIG with latest layered-fs layers configuration... #100222 fix...
  1664. xBOOTCONFIG="`grep -v '^PREVUNIONRECORD' $OLDFILESMNTPT/etc/rc.d/BOOTCONFIG | sed -e 's/^LASTUNIONRECORD/PREVUNIONRECORD/'`"
  1665. echo "$xBOOTCONFIG" > /pup_rw/etc/rc.d/BOOTCONFIG
  1666. #sync
  1667. echo "LASTUNIONRECORD='$NEWUNIONRECORD'" >> /pup_rw/etc/rc.d/BOOTCONFIG
  1668. [ "$LASTUNIONRECORD" = "$NEWUNIONRECORD" ] && NEWUNIONRECORD="" #used below.
  1669. #...if layers changed since last boot, code further down will do whiteout files purge.
  1670. #.../etc/rc.d/rc.update reads BOOTCONFIG, updates menu (etc) if layers changed.
  1671. #after switch_root, rc.sysinit calls rc.update, but need to do pre-cleaning...
  1672. if [ "$OLDFILESMNTPT" != "" ];then
  1673. #an empty tmp is required for mounting a tmpfs onto later...
  1674. rm -rf $OLDFILESMNTPT/tmp/*
  1675. rm -rf $OLDFILESMNTPT/tmp/.[0-9a-zA-Z]*
  1676. if [ ! -L $OLDFILESMNTPT/usr/X11R6 ];then #test if a symlink.
  1677. #this is supposed to be a link to X11R7. <2.10 it won't be...
  1678. if [ -d $OLDFILESMNTPT/usr/X11R6 ];then
  1679. mkdir -p $OLDFILESMNTPT/usr/X11R7
  1680. cp -af $OLDFILESMNTPT/usr/X11R6/* $OLDFILESMNTPT/usr/X11R7/
  1681. rm -rf $OLDFILESMNTPT/usr/X11R6
  1682. fi
  1683. [ -d X11R7 ] && ln -s X11R7 $OLDFILESMNTPT/usr/X11R6
  1684. fi
  1685. rm -rf $OLDFILESMNTPT/root/tmp 2>/dev/null
  1686. rm -f $OLDFILESMNTPT/root/.wh.tmp 2>/dev/null
  1687. NEWPVERSION="$DISTRO_VERSION" #110422
  1688. if [ -f $OLDFILESMNTPT/etc/puppyversion ];then
  1689. OLDPVERSION="`cat $OLDFILESMNTPT/etc/puppyversion`" #old pre-w464 installation. 110422
  1690. rm -f $OLDFILESMNTPT/etc/puppyversion #no longer used.
  1691. fi
  1692. [ -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
  1693. [ "$OLDPVERSION" = "" ] && OLDPVERSION="$NEWPVERSION"
  1694. if vercmp ${NEWPVERSION} gt ${OLDPVERSION} ; then
  1695. #make sure that the official boot scripts will be visible at top
  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. #set update flag
  1705. touch /tmp/version_update_flag
  1706. fi
  1707. #110422 decrement dotted version number. hard, just set to 0.0...
  1708. [ "$PCLEAN" = "yes" ] && xOLDPVERSION='0.0' #110422
  1709. [ "$PPURGE" = "yes" ] && xOLDPVERSION='0.0' #110422
  1710. if vercmp ${NEWPVERSION} gt ${xOLDPVERSION} ; then #110422
  1711. echo -e "\\033[1;35m" >/dev/console #35=purple.
  1712. echo "Version cleanup, restoring 'official' files, please wait..." >/dev/console
  1713. echo -en "\\033[0;39m" >/dev/console
  1714. echo "(with a slow CPU this may take sometime, please be patient)" >/dev/console
  1715. #v2.16 do not overwrite rox desktop setup, as /etc/rc.d/rc.update now handles it...
  1716. [ -f $OLDFILESMNTPT/root/Choices/ROX-Filer/PuppyPin ] && touch $OLDFILESMNTPT/root/Choices/ROX-Filer/PuppyPin
  1717. [ -f $OLDFILESMNTPT/root/Choices/ROX-Filer/globicons ] && touch $OLDFILESMNTPT/root/Choices/ROX-Filer/globicons
  1718. mkdir $OLDFILESMNTPT/tmp/versioncleanup
  1719. #make sure that the official boot scripts will be visible at top... 110722 fix...
  1720. rm -f $OLDFILESMNTPT/etc/rc.d/functions
  1721. rm -f $OLDFILESMNTPT/etc/rc.d/functions4puppy4
  1722. rm -f $OLDFILESMNTPT/etc/rc.d/rc.country
  1723. rm -f $OLDFILESMNTPT/etc/rc.d/rc.network_basic
  1724. rm -f $OLDFILESMNTPT/etc/rc.d/rc.services
  1725. rm -f $OLDFILESMNTPT/etc/rc.d/rc.shutdown
  1726. rm -f $OLDFILESMNTPT/etc/rc.d/rc.sysinit
  1727. rm -f $OLDFILESMNTPT/etc/rc.d/rc.update
  1728. #set update flag
  1729. touch /tmp/version_update_flag
  1730. #i think if a file exists both in OLDFILESMNTPT and in NEWFILESMNTPT, remove
  1731. #it from OLDFILESMNTPT (as OLDFILESMNTPT is upper layer and will hide the
  1732. #'official' file. But, only do it if 'official' file has a newer modify date...
  1733. cd $NEWFILESMNTPT
  1734. #v2.12 this while-loop has become ultra-slow... seems upx compressed execs
  1735. #responsible, recently upx-ed all the execs, now restore busybox, grep, cp.
  1736. DOTCNT=0
  1737. find ./ -noleaf -type f | sed -e 's/^\.//g' |
  1738. while read ONENEW
  1739. do
  1740. DOTCNT=`expr $DOTCNT + 1`
  1741. [ $DOTCNT -gt 100 ] && DOTCNT=0 #display a dot every time cnts to 100.
  1742. [ $DOTCNT -eq 100 ] && echo -n '*' >/dev/console #v2.12
  1743. #note, screens out spaces also...
  1744. [ ! "`echo -n "$ONENEW" | grep -E '^/dev|^/tmp|^/proc| '`" = "" ] && continue
  1745. ONEBASE="`basename $OLDFILESMNTPT$ONENEW`"
  1746. OLDDIR="`dirname $OLDFILESMNTPT$ONENEW`"
  1747. #a whiteout file 'on top' will hide the 'official' file...
  1748. [ -f $OLDDIR/.wh.$ONEBASE ] && rm -f $OLDDIR/.wh.$ONEBASE
  1749. [ -f $OLDDIR/.wh.__dir_opaque ] && rm -f $OLDDIR/.wh.__dir_opaque #v424 not needed for aufs2
  1750. [ -f $OLDDIR/.wh..wh..opq ] && rm -f $OLDDIR/.wh..wh..opq #110212 recent aufs2, but probably not needed.
  1751. #let's get paranoid and imagine upper-directories also wiped...
  1752. while [ ! "$OLDDIR" = "/" ];do
  1753. OLDDIR="`dirname $OLDDIR`"
  1754. UP1BASE="`basename $OLDDIR`"
  1755. [ -f $OLDDIR/.wh.$UP1BASE ] && rm -f $OLDDIR/.wh.$UP1BASE
  1756. [ -f $OLDDIR/.wh.__dir_opaque ] && rm -f $OLDDIR/.wh.__dir_opaque #v424 not needed for aufs2
  1757. [ -f $OLDDIR/.wh..wh..opq ] && rm -f $OLDDIR/.wh..wh..opq #110212 recent aufs2, but probably not needed.
  1758. done
  1759. #now check for 'old' files on top layer...
  1760. if [ -f $OLDFILESMNTPT$ONENEW ];then
  1761. #note, this is inaccurate due to local timezone not yet set...
  1762. #i got this 'stat' off ibiblio, v3.3. i think older version than in main puppy f.s...
  1763. MODIFOLD=`$PUPFILESDIR/bin/stat -c %Y $OLDFILESMNTPT$ONENEW`
  1764. MODIFNEW=`$PUPFILESDIR/bin/stat -c %Y $NEWFILESMNTPT$ONENEW`
  1765. [ "$PPURGE" = "yes" ] && MODIFNEW=`expr $MODIFOLD + 1` #force overwrite all.
  1766. if [ $MODIFNEW -ge $MODIFOLD ];then
  1767. echo -n " $ONENEW " >/dev/console
  1768. ONEDIR="`dirname $ONENEW`"
  1769. mkdir -p $OLDFILESMNTPT/tmp/versioncleanup$ONEDIR
  1770. cp -af $OLDFILESMNTPT$ONENEW $OLDFILESMNTPT/tmp/versioncleanup$ONEDIR/
  1771. rm -f $OLDFILESMNTPT$ONENEW
  1772. fi
  1773. fi
  1774. done
  1775. echo >/dev/console
  1776. cd /
  1777. fi
  1778. #need to cleanup whiteout files if a new .sfs layer has been added...
  1779. if [ "$NEWUNIONRECORD" != "" -o "$PPURGE" = "yes" ];then
  1780. #find all .wh.__dir_opaque files at the OLDFILESMNTPT layer... v424 bugfixes... 110212 .wh..wh..opq ...
  1781. cd $OLDFILESMNTPT
  1782. find ./ -noleaf -type f -name ".wh.*" | sed -e 's/^\.//g' |
  1783. while read ONEOPAQUE #examples: /usr/src/.wh.__dir_opaque, /usr/src/.wh.bin
  1784. do
  1785. ONEDIR="`dirname $ONEOPAQUE`" #ex: /usr/src
  1786. WHBASE="`basename $ONEOPAQUE`" #ex: .wh.bin
  1787. if [ "$WHBASE" != ".wh.__dir_opaque" -a "$WHBASE" != ".wh..wh..opq" ];then #aufs2 always enter this condition... 110212 extra test.
  1788. #example, .wh.bin alongside bin directory means it is deleted...
  1789. ONEDEL="`echo -n "$WHBASE" | sed -e 's/^\\.wh\\.//g'`" #ex: bin
  1790. ONEDIR="${ONEDIR}/${ONEDEL}" #ex: /usr/src/bin
  1791. [ ! -e ".${ONEDIR}" ] && continue
  1792. fi
  1793. #if same dir exists lower layer, then wipe the opaque file...
  1794. [ -d /pup_ro3${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1795. [ -d /pup_ro4${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1796. [ -d /pup_ro5${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1797. [ -d /pup_ro6${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1798. [ -d /pup_ro7${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1799. [ -d /pup_ro8${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1800. [ -d /pup_ro9${ONEDIR} ] && rm -f ${OLDFILESMNTPT}${ONEOPAQUE}
  1801. done
  1802. cd /
  1803. fi
  1804. if vercmp $NEWPVERSION gt $xOLDPVERSION ; then #110422
  1805. vPATTERN="s%^DISTRO_VERSION=.*%DISTRO_VERSION='${xOLDPVERSION}'%" #110122 mod 110422
  1806. sed -e "$vPATTERN" $OLDFILESMNTPT/etc/DISTRO_SPECS > /tmp/distro_specs_old
  1807. cp -f /tmp/distro_specs_old $OLDFILESMNTPT/etc/DISTRO_SPECS #so rc.update will run.
  1808. sync
  1809. OLDstr='to'
  1810. [ "$xOLDPVERSION" != "0.0" ] && OLDstr="from version $xOLDPVERSION to"
  1811. echo -e "\\033[1;35m" >/dev/console #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  1812. [ "$PCLEAN" = "yes" ] && echo "This is a simulated version upgrade, which performs a file cleanup." >/dev/console
  1813. [ "$PPURGE" = "yes" ] && echo "This is a radical file cleanup for broken systems, could alter some settings." >/dev/console
  1814. echo "You are upgrading Puppy ${OLDstr} ${NEWPVERSION}." >/dev/console #110122 mod
  1815. echo "Overwritten old files have been moved to /tmp/versioncleanup/" >/dev/console
  1816. 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
  1817. echo -en "\\033[0;39m" >/dev/console
  1818. sleep 30 #so can see above messages.
  1819. fi
  1820. fi
  1821. [ "$RDSH" = "6" ] && exec /bin/sh >/dev/console 2>&1 #w091027
  1822. #create the layered f.s.... ***THE BIG EVENT***
  1823. if [ "$LAYERFS" = "aufs" ];then
  1824. mount -t aufs -o udba=reval,diropq=w,dirs=${UMNTRW}${UMNTRO0}${ALAYER}${YLAYER}${UMNTRO1}${ZLAYER}${UMNTRO} unionfs /pup_new
  1825. else #unionfs
  1826. UMNTRW="`echo -n "$UMNTRW" | sed -e 's/+wh//g'`" #w003 'ro+wh' not accepted by unionfs, change back to 'ro'.
  1827. mount -t unionfs -o dirs=${UMNTRW}${UMNTRO0}${ALAYER}${YLAYER}${UMNTRO1}${ZLAYER}${UMNTRO} unionfs /pup_new
  1828. fi
  1829. check_status $? #END STEP FIVE
  1830. #######################END SETUP UNIONFS LAYERED FILESYSTEM###################
  1831. #101127 pakt: code adapted from bchafy's Xin
  1832. #his description: "A precfg area for faster re-mastering, no need to regenerate a .SFS
  1833. #every time you want to change the core, and no need for a hard drive to store customizations"
  1834. if [ -d $PUPSFSDEVMNTPT/precfg ];then
  1835. echo -n "Overlaying preconfig files..." > /dev/console
  1836. SRC="$PUPSFSDEVMNTPT"/precfg
  1837. DEST="/pup_new"
  1838. cd $SRC
  1839. for i in `find . -not -type d -print`; do
  1840. BASEFILE="$i"
  1841. SRCFILE="$SRC/$BASEFILE"
  1842. DESTFILE="$DEST/$BASEFILE"
  1843. DESTDIR=`dirname $DESTFILE`
  1844. MASK="777"
  1845. if test -f "$DESTFILE"; then
  1846. MASK=`stat -c %a $DESTFILE`
  1847. fi
  1848. mkdir -p $DESTDIR
  1849. cp -f $SRCFILE $DESTFILE
  1850. chmod $MASK $DESTFILE
  1851. done
  1852. check_status 0
  1853. fi
  1854. #END PRECONFIG STEP
  1855. #######################SETUP SWITCH TO MAIN FILESYSTEM#######################
  1856. echo -n "Performing a 'switch_root' to the layered filesystem..." > /dev/console
  1857. #prepare everything for doing a switch_root...
  1858. #cpio archive does switch_root, lose the initial-ramfs, so move all mntd...
  1859. mkdir -p /pup_new/initrd
  1860. mkdir -p /pup_new/initrd/pup_ro1
  1861. mkdir -p /pup_new/initrd/pup_ro2
  1862. mkdir -p /pup_new/initrd/pup_ro3
  1863. mkdir -p /pup_new/initrd/pup_ro4
  1864. mkdir -p /pup_new/initrd/pup_ro5
  1865. mkdir -p /pup_new/initrd/pup_ro6
  1866. mkdir -p /pup_new/initrd/pup_ro7
  1867. mkdir -p /pup_new/initrd/pup_ro8
  1868. mkdir -p /pup_new/initrd/pup_ro9
  1869. mkdir -p /pup_new/initrd/pup_rw
  1870. mkdir -p /pup_new/initrd/pup_z
  1871. mkdir -p /pup_new/initrd/pup_a
  1872. mkdir -p /pup_new/initrd/pup_y
  1873. mkdir -p /pup_new/initrd/mnt
  1874. mkdir -p /pup_new/initrd/mnt/data
  1875. mkdir -p /pup_new/initrd/mnt/dev_ro1
  1876. mkdir -p /pup_new/initrd/mnt/dev_ro2
  1877. mkdir -p /pup_new/initrd/mnt/dev_save
  1878. mkdir -p /pup_new/initrd/mnt/swap
  1879. mkdir -p /pup_new/initrd/mnt/tmpfs
  1880. mkdir -p /pup_new/initrd/mnt/tmpfs2
  1881. mkdir -p /pup_new/initrd/mnt/tmpfs3
  1882. mkdir -p /pup_new/initrd/mnt/tmpfs4
  1883. mkdir -p /pup_new/initrd/mnt/zdrv
  1884. mkdir -p /pup_new/initrd/mnt/adrv
  1885. mkdir -p /pup_new/initrd/mnt/ydrv
  1886. mkdir -p /pup_new/initrd/tmp
  1887. for ONEMNT in `mount | cut -f 3 -d ' ' | grep -v 'pup_new' | grep '^/pup_' | tr '\n' ' '`
  1888. do
  1889. mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1890. done
  1891. for ONEMNT in `mount | cut -f 3 -d ' ' | grep '^/mnt/' | tr '\n' ' '`
  1892. do
  1893. mount -o move $ONEMNT /pup_new/initrd${ONEMNT}
  1894. done
  1895. if [ "${PUPSAVEFILE}" -a -d /pup_new/initrd/mnt/dev_save${PUPSAVEFILE} ]; then
  1896. if [ "${CREATEPUPSAVE2FS}" -a -L "${CREATEPUPSAVE2FS}" ]; then
  1897. rm -r -f "/pup_new/initrd${CREATEPUPSAVE2FS}"
  1898. ln -s /initrd/mnt/dev_save${PUPSAVEFILE} /pup_new/initrd${CREATEPUPSAVE2FS} #for after the switch root
  1899. fi
  1900. fi
  1901. #v4.02 bring back, but allocate more space (/4 instead of /8)....
  1902. #v3.97 a problem can run out of /tmp space, remove...
  1903. #to minimise writes to pup_save and to speedup, tmpfs on /tmp...
  1904. if [ "$CREATETMPFS" != "/pup_rw" ];then #test if no tmpfs on unionfs top layer.
  1905. ALLOCK=`expr $RAMSIZE \/ 4 + $EXTRAALLOCK`
  1906. #v424 don't create tmpfs if have versioncleanup dir... 100423 try again...
  1907. [ ! -e /pup_new/tmp/versioncleanup ] && mount -t tmpfs -o size=${ALLOCK}k tmpfs /pup_new/tmp
  1908. fi
  1909. #PNOX is a boot param. /etc/profile prevents X from starting if this file exists...
  1910. [ "$PNOX" = "yes" ] && touch /pup_new/tmp/bootcnt.txt
  1911. cp -a /DISTRO_SPECS /pup_new/initrd/
  1912. cp -af /tmp/* /pup_new/initrd/tmp/ #keep any log files.
  1913. #091122
  1914. mkdir -p /pup_new/lib/keymaps
  1915. cp -a -f /lib/keymaps/* /pup_new/lib/keymaps/
  1916. mkdir -p /pup_new/lib/consolefonts
  1917. cp -a -f /lib/consolefonts/* /pup_new/lib/consolefonts/
  1918. if [ "$KMAP" ];then #because PKEYS boot param was defined.
  1919. echo -n "$KMAP" > /pup_new/etc/keymap
  1920. echo -n "$FONTMAP" > /pup_new/etc/fontmap
  1921. echo -n "$CODEPAGE" > /pup_new/etc/codepage
  1922. fi
  1923. #091225 copy exes to main f.s.
  1924. if [ -f /bin/TARGETEXES ];then
  1925. for ONEEXE in `cat /bin/TARGETEXES` #ex: sbin/e2fsck
  1926. do
  1927. BASEEXE="`basename $ONEEXE`"
  1928. [ ! -e /pup_new/$ONEEXE ] && cp -f /bin/$BASEEXE /pup_new/$ONEEXE
  1929. done
  1930. cp -f /bin/TARGETEXES /pup_new/bin/ #100113 puppyinstaller needs this.
  1931. fi
  1932. #110114 if a drive unplugged in previous boot, but plugged in at bootup, device-nodes will be missing in main f.s...
  1933. if [ $DEVTMPFSFLG -eq 0 ];then #130612
  1934. cp -a -u -f /dev/* /pup_new/dev/
  1935. else
  1936. mount -t devtmpfs devtmpfs /pup_new/dev
  1937. fi
  1938. #120215 if PLANG set here, carry it over...
  1939. if [ "$PLANG" ];then
  1940. langPTN="s%^LANG=.*%LANG=${PLANG}%"
  1941. sed -i -e "$langPTN" /pup_new/etc/profile
  1942. fi
  1943. #RDSH is a boot param. exit to initial ramdisk shell...
  1944. if [ "$RDSH" = "yes" ];then
  1945. echo > /dev/console
  1946. echo "Dropped to initramfs shell. Type 'exec switch' to continue booting Puppy." > /dev/console
  1947. exec /bin/sh >/dev/console 2>&1
  1948. fi
  1949. #v3.01 a bit untidy, but cd may still be mounted when it doesn't have to be...
  1950. case $PMEDIA in
  1951. *cd)
  1952. [ "$PDEV1" ] && umount /dev/$PDEV1 2>/dev/null #okay if it fails.
  1953. ;;
  1954. esac
  1955. sync
  1956. #killall -USR1 hotplug2 #v423
  1957. umount /proc/bus/usb
  1958. umount /sys
  1959. umount /proc
  1960. #now using cpio archive for initramfs 'initial ramdisk'...
  1961. exec switch_root /pup_new /sbin/init
  1962. ###END###