bootflash 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
  4. #a gui for makebootfat and syslinux, to make a usb drive bootable, then install puppy.
  5. #optional drive name passed in, ex: 'sdc'.
  6. #100913 new simplified puppy filenames.
  7. #101026 .sfs was not getting copied off cd. various improvements.
  8. #110130 fix for ldlinux.sys deleted, see jinx100 http://murga-linux.com/puppy/viewtopic.php?t=63719&start=165
  9. #110505 support sudo for non-root user.
  10. #120201 rodin.s: internationalized.
  11. #120311 ComboFormat, 128M first partition not big enough for some puppies, change to 256M.
  12. #120323 replace 'xmessage' with 'pupmessage'.
  13. #130203 change probedisk2 to probedisk.
  14. #130722 new method to update desktop drive icons. see also /usr/sbin/gparted_shell, puppyinstaller.
  15. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  16. export TEXTDOMAIN=bootflash
  17. export TEXTDOMAINDIR=/usr/share/locale
  18. export OUTPUT_CHARSET=UTF-8
  19. eval_gettext () {
  20. local myMESSAGE=$(gettext "$1")
  21. eval echo \"$myMESSAGE\"
  22. }
  23. export LANGORG=$LANG
  24. PARAM1=""
  25. [ $1 ] && PARAM1="$1"
  26. USBDRV="$PARAM1"
  27. #export LANG=C # turn off for gettext rodin.s
  28. . /etc/rc.d/PUPSTATE
  29. . /etc/DISTRO_SPECS #100913
  30. echo '#!/bin/sh' > /tmp/bootme-morehelp
  31. echo 'export HELP_DIALOG="<window title=\"'$(gettext 'BootFlash: Help')'\" icon-name=\"gtk-info\">
  32. <hbox>
  33. <vbox>
  34. <text use-markup=\"true\"><label>\"<b>'$(gettext 'BIOS-setup</b>')'
  35. '$(gettext 'When the computer is just starting to power up, pressing the DEL or F1 key usually enters the BIOS-setup. If you had plugged in the USB drive beforehand, you would be able to see whether the BIOS has auto-detected it. Or, you will be able to see whether the BIOS has manual choices of USB-HDD, USB-ZIP or USB-FDD. It is recommended that you do this before running BootFlash.')'
  36. '$(gettext '<b>Windows compatibility</b>')'
  37. '$(gettext 'BootFlash creates one or two partitions on the USB drive, or in the case of USB-FDD formats the drive without any partitions (what is called <i>SuperFloppy</i> mode). Whatever, the filesystem created on the drive is FAT16 or FAT32, which is compatible with Microsoft Windows. This means that you can read and write files from Windows.')'
  38. <b>ISO9660</b>
  39. '$(gettext 'This one has had less testing, and I got it to work on 2 out of 4 PCs that I tested. For a BIOS with manual choices, choose USB-HDD. However, unlike the USB-HDD choice in BootFlash which formats the drive with one FAT partition, this creates two partitons, the first one ISO9660 and the second FAT -- the first is the filesystem used in CDs. It is not normal to have a ISO9660 filesystem in a Flash memory or hard drive, so I am not surprised that some BIOSes do not like it! -- but on the otherhand it may work where other choices do not. However, there is one big caveat: it has the disadvantage that to upgrade Puppy the drive has to be reformatted using BootFlash, so you would have to copy-off the pupsave.2fs file (the file that has all your personal stuff) then copy it back afterward -- a bit more involved than the usual super-simple upgrade process.')'\"</label></text>
  40. </vbox>
  41. <vbox>
  42. <text use-markup=\"true\"><label>\"<b>'$(gettext 'Installing Puppy</b>')'
  43. '$(gettext 'BootFlash will format the USB drive so that it is bootable, then will offer to install Puppy Linux. Obviously, as this erases whatever was on the drive, it is for doing a new installation of Puppy.')'
  44. '$(gettext '<b>Upgrading Puppy</b>')'
  45. '$(gettext 'You could use the Puppy Universal Installer, however it is a piece of cake to do it manually. When a new version of Puppy is released, download the live-CD iso file, then just click on it to open it. Drag the files vmlinuz, initrd.gz and puppy.sfs (and ardv, ydrf and zdrv.sfs if they exist) (some builds of Puppy have different names for these files, for example: wary_092.sfs and zw092345.sfs) to the USB drive, and that is it, you have upgraded!
  46. It is super-simple, but just a warning: if there are files of an old installation, for example wary_091.2fs and zw091346.sfs, just delete those.')'
  47. '$(gettext 'WARNING: There is one caveat to the above. Be careful before deleting the old puppy.sfs that it is not in use by Puppy. If the PC has 256MB or more of RAM, Puppy will normally copy puppy.sfs into RAM, so the original is not being used and can be deleted. To find out, open a terminal and type <i>losetup</i> -- if you see something like /mnt/tmpfs/puppy.sfs then it is in RAM. If not, or uncertain, boot another Puppy from a different drive/CD.')'
  48. '$(gettext '<b>Puppy Universal Installer</b>')'
  49. '$(gettext 'This is a tool for installing Puppy to any media, including USB. BootFlash is an alternative tool specific to USB and for new installations only. You might want to try the Universal Installer first, and if you cannot get the drive to boot then try BootFlash.')'\"</label></text>
  50. </vbox>
  51. </hbox>
  52. </window>"
  53. gtkdialog3 --center --program=HELP_DIALOG' >> /tmp/bootme-morehelp
  54. chmod 777 /tmp/bootme-morehelp
  55. #About dlg...
  56. echo '#!/bin/sh' > /tmp/bootme-about
  57. echo 'export ABOUT_DIALOG="<window title=\"'$(gettext 'BootFlash: About')'\" icon-name=\"gtk-info\">
  58. <vbox>
  59. <text use-markup=\"true\"><label>\"<b>'$(gettext 'BootFlash</b>
  60. Is a GUI application written by Barry Kauler, March 2009. (c) copyright Barry Kauler 2009, licenced under the Lesser GPL licence v2, http://www.fsf.org/licensing/licenses/lgpl.html.
  61. BootFlash uses excellent applications under-the-hood, in particular I would like to acknowledge Makebootfat created by Andrea Mazzoleni, and Syslinux created by Peter Anvin.
  62. Note, Makebootfat has been patched by me to optimise the number of heads and sectors/track to suit BootFlash. Note also, Syslinux version 3.72 or greater is required for the ISO9660 mode of BootFlash.')'\"</label></text>
  63. </vbox>
  64. </window>"
  65. gtkdialog3 --center --program=ABOUT_DIALOG' >> /tmp/bootme-about
  66. chmod 777 /tmp/bootme-about
  67. export MAIN_DIALOG="<window title=\"$(gettext 'BootFlash: make USB drive bootable')\" icon-name=\"gtk-preferences\">
  68. <vbox>
  69. <hbox>
  70. <vbox>
  71. <text><label>\" \"</label></text>
  72. <text use-markup=\"true\"><label>\"<b>$(gettext 'Welcome! The intention of BootFlash is to get a USB memory stick (Flash drive) or USB hard drive to boot off any computer that has options in its BIOS setup for booting from USB ...then to install Puppy on it')</b>\"</label></text>
  73. <text><label>`gettext \"Your PC's BIOS setup has choices for booting from various types of drives. Modern BIOSes will autodetect whatever USB drives are plugged in, but older BIOSes have fixed choices such as 'USB-HDD' (hard drive), 'USB-ZIP' (zip drive) or 'USB-FDD' (floppy drive). For modern auto-detecting BIOSes or an older one that offers 'USB-HDD', I suggest you make that your preferred choice and tick the 'USB-HDD' radiobutton below. However, it may not work, even on modern computers.\"`</label></text>
  74. <text use-markup=\"true\"><label>\"<b>$(gettext 'Please be aware that running this program will erase anything currently on the USB drive')</b>\"</label></text>
  75. <frame>
  76. <radiobutton><label>$(gettext 'USB-HDD (hard drive) PREFERRED CHOICE')</label><variable>RADIO_HDD</variable></radiobutton>
  77. <radiobutton><label>$(gettext 'USB-ZIP (zip drive)')</label><variable>RADIO_ZIP</variable></radiobutton>
  78. <radiobutton><label>$(gettext "USB-FDD ('SuperFloppy' drive)")</label><variable>RADIO_FDD</variable></radiobutton>
  79. <radiobutton><label>$(gettext 'ComboFormat (hard/zip/floppy chameleon)')</label><variable>RADIO_ALL</variable></radiobutton>
  80. <radiobutton><label>$(gettext 'ISO9660 (CD filesystem)')</label><variable>RADIO_ISO</variable></radiobutton>
  81. </frame>
  82. <hbox>
  83. <button><label>$(gettext 'More help')</label><action>/tmp/bootme-morehelp & </action></button>
  84. <button><label>$(gettext 'About')</label><action>/tmp/bootme-about & </action></button>
  85. <text><label>\" \"</label></text>
  86. <button ok></button>
  87. <button cancel></button>
  88. </hbox>
  89. </vbox>
  90. <vbox>
  91. <frame $(gettext 'Help')>
  92. <text use-markup=\"true\"><label>\"<b>USB-HDD</b>
  93. `gettext \"This is the preferred choice for modern PCs, whether the USB drive is an actual hard drive or a Flash 'memory stick'. The BIOS in modern PCs will auto-detect whatever is plugged in, and slightly older BIOSes may have a 'USB-HDD' choice in the BIOS-setup -- if so, choose that. Note though, even modern PCs may not boot the USB drive, and you may need to look at one of the following choices.
  94. <b>USB-ZIP</b>
  95. This will make the USB drive seem like a Zip drive. A slightly older BIOS may offer a 'USB-ZIP' boot option, so if you set that in the BIOS then format the USB drive to seem like a Zip drive, it may succeed. You can even do this with a USB hard drive.
  96. <b>USB-FDD</b>
  97. This is also known as <b>SuperFloppy</b> mode and will make the USB drive seem like a floppy drive. The drive is formatted without any partitions -- just like a floppy, the entire disk is used for the filesystem.
  98. <b>ComboFormat</b>
  99. This one is very cunning. It makes the drive seem like a HDD, ZIP <i>and</i> FDD. This is the one to choose if you want to be able to take your USB memory stick to just about any PC and it will boot.\"`\"</label></text>
  100. </frame>
  101. </vbox>
  102. </hbox>
  103. </vbox>
  104. </window>"
  105. RETPARAMS="`gtkdialog3 --center --program=MAIN_DIALOG`"
  106. #ex:
  107. #RADIO_ALL="false"
  108. #RADIO_FDD="false"
  109. #RADIO_HDD="true"
  110. #RADIO_ZIP="false"
  111. #EXIT="OK"
  112. eval "$RETPARAMS"
  113. [ "$EXIT" != "OK" ] && exit
  114. #decide what drive...
  115. if [ "$USBDRV" = "" ];then
  116. export PLUGIN_DIALOG="<window title=\"BootFlash\" icon-name=\"gtk-preferences\">
  117. <vbox>
  118. <pixmap><input file>/usr/local/lib/X11/pixmaps/question.xpm</input></pixmap>
  119. <text use-markup=\"true\"><label>\"<b>$(gettext 'Please plugin the USB drive right now. If it is already plugged in, make absolutely sure that it is unmounted before continuing')</b>\"</label></text>
  120. <text><label>$(gettext 'Note, it does not matter if you have other USB drives or devices plugged in, as the next dialog window will present them all and ask you to choose one.')</label></text>
  121. <hbox>
  122. <text><label>`gettext \"Click 'OK' to continue, 'Cancel' to quit:\"`</label></text>
  123. <button ok></button>
  124. <button cancel></button>
  125. </hbox>
  126. </vbox>
  127. </window>"
  128. RETPARAMS="`gtkdialog3 --center --program=PLUGIN_DIALOG`"
  129. eval "$RETPARAMS"
  130. [ "$EXIT" != "OK" ] && exit
  131. sleep 2
  132. PROBEDISK="`probedisk 2> /tmp/probediskerr.txt`"
  133. USBDRIVES="`echo "$PROBEDISK" | grep '|usbdrv|' | cut -f 3 -d '/' | cut -f 1 -d '|' | tr "\n" " "`"
  134. SELECTIONS=""
  135. for ONEUSB in $USBDRIVES
  136. do
  137. [ "$ATADRIVES" != "" ] && [ "`echo "$ATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #eliminate ide/sata drives.
  138. [ "$SATADRIVES" != "" ] && [ "`echo "$SATADRIVES" | grep "$ONEUSB"`" != "" ] && continue #for old kernel.
  139. USBMEMTYPE="Flash memory"
  140. [ "`cat /sys/block/$ONEUSB/removable`" != "1" ] && USBMEMTYPE="hard drive"
  141. USBINFO="`echo "$PROBEDISK" | grep "/dev/$ONEUSB" | head -n 1 | cut -f 3 -d '|' | tr '$' " " | tr ',' ' ' | tr -s " " | sed -e 's/ $//'`"
  142. USBSIZE="`disktype /dev/$ONEUSB | grep "Block device" | cut -f 2 -d ',' | tr -s " " | cut -f 1-4 -d " "`"
  143. SELECTIONS="${SELECTIONS}
  144. $ONEUSB \"${USBMEMTYPE}, ${USBINFO}, ${USBSIZE}\""
  145. done
  146. xSELECTIONS="`echo "$SELECTIONS" | tr '\n' ' ' | tr -s ' '`"
  147. if [ "$SELECTIONS" = "" ];then
  148. pupmessage -bg red -center -title "$(gettext 'ERROR')" "$(gettext 'No USB drive plugged in!')"
  149. exit
  150. fi
  151. CHOOSEDLG="Xdialog --wmclass \"gtkdialog2\" --title \"$(gettext 'BootFlash: choose drive')\" --no-cancel --stdout --menubox \"$(gettext 'Choose which drive to format:')\" 10 60 0 ${xSELECTIONS}"
  152. DRVSEL="`eval "$CHOOSEDLG"`"
  153. [ $? -ne 0 ] && exit
  154. [ "$DRVSEL" = "" ] && exit #precaution.
  155. [ "`echo -n "$DRVSEL" | cut -c 1,2`" != "sd" ] && exit #precaution.
  156. USBDRV="$DRVSEL"
  157. #reconfirm correct drv choice...
  158. MYSELECTION="`echo "$SELECTIONS" | grep "^${USBDRV} " | tr '"' ' ' | tr -s ' '`" #'geany
  159. export RECONFIRM_DIALOG="<window title=\"BootFlash\" icon-name=\"gtk-preferences\">
  160. <vbox>
  161. <pixmap><input file>/usr/local/lib/X11/pixmaps/question.xpm</input></pixmap>
  162. <text><label>$(gettext 'Please reconfirm that this is the USB drive that you want to format:')</label></text>
  163. <text use-markup=\"true\"><label>\"<b>${MYSELECTION}</b>\"</label></text>
  164. <text><label>`gettext \"Please also reconfirm that you want to use BootFlash to reformat the drive (and install Puppy). If you have a new USB drive, it is normally recommended that you use the Puppy Universal Installer first, as that will attempt to make the drive bootable as-is, that is, without reformatting it. If you haven't tried the Universal Installer yet, recommend that you hit Cancel here, and run the Universal Installer from the Setup menu.\"`</label></text>
  165. <hbox>
  166. <text><label>`gettext \"Click 'OK' to continue, 'Cancel' to quit:\"`</label></text>
  167. <button ok></button>
  168. <button cancel></button>
  169. </hbox>
  170. </vbox>
  171. </window>"
  172. RETPARAMS="`gtkdialog3 --center --program=RECONFIRM_DIALOG`"
  173. eval "$RETPARAMS"
  174. [ "$EXIT" != "OK" ] && exit
  175. fi
  176. #make sure not mounted...
  177. while [ "`mount | grep "^/dev/$DRVSEL"`" != "" ];do
  178. export PLUGIN_DIALOG="<window title=\"BootFlash\" icon-name=\"gtk-preferences\">
  179. <vbox>
  180. <pixmap><input file>/usr/local/lib/X11/pixmaps/error.xpm</input></pixmap>
  181. <text use-markup=\"true\"><label>\"<b>`eval_gettext \"Drive \\\${DRVSEL} is still mounted. Please unmount it before continuing. If the drive has multiple partitions, are they all unmounted?\"`</b>\"</label></text>
  182. <text><label>$(gettext 'Note: click on the appropriate mounted desktop drive icon, and you will receive an offer to unmount it.')</label></text>
  183. <hbox>
  184. <text><label>`gettext \"Click 'OK' to continue, 'Cancel' to quit:\"`</label></text>
  185. <button ok></button>
  186. <button cancel></button>
  187. </hbox>
  188. </vbox>
  189. </window>"
  190. RETPARAMS="`gtkdialog3 --center --program=PLUGIN_DIALOG`"
  191. eval "$RETPARAMS"
  192. [ "$EXIT" != "OK" ] && exit
  193. sleep 1
  194. done
  195. #gather the files together...
  196. rm -rf /tmp/makebootfat 2>/dev/null
  197. mkdir /tmp/makebootfat
  198. cd /tmp/makebootfat
  199. cp -a /usr/lib/syslinux/ldlinux.bss ./
  200. cp -a /usr/lib/syslinux/mbrfat.bin ./
  201. cp -a /usr/lib/syslinux/mbr.bin ./
  202. cp -a /usr/lib/syslinux/ldlinux.sys ./
  203. mkdir tempdir
  204. /usr/lib/gtkdialog/box_splash -close never -text "`eval_gettext \"Please wait, formatting \\\${USBDRV} drive...\"`" &
  205. X1PID=$!
  206. if [ "$RADIO_HDD" = "true" ];then #hard drive.
  207. #weird code here...
  208. dd if=/dev/zero of=/dev/$USBDRV bs=512 count=1
  209. sync
  210. #fdisk cannot be used to create a partition table, it won't boot, use makebootfat...
  211. makebootfat --output /dev/$USBDRV --syslinux3 --boot ldlinux.bss --mbr mbr.bin --copy ldlinux.sys tempdir
  212. #...but drive broken, fix as follows...
  213. #also optional...
  214. dd if=/dev/zero of=/dev/${USBDRV}1 bs=512 count=1 #zeroise first 512 bytes of partition. some apps need this.
  215. DRVSIZEB=`fdisk -l /dev/${USBDRV} | grep '^Disk /dev/' | cut -f 5 -d ' '` #in bytes.
  216. DRVSIZEK=`expr $DRVSIZEB \/ 1024`
  217. DRVSIZEM=`expr $DRVSIZEK \/ 1024`
  218. sync
  219. if [ $DRVSIZEM -gt 1024 ];then #1GB
  220. #set partition-id to fat32 (0b=fat32, oc=fat32-lba)...
  221. echo -e 't\n0b\nw' | fdisk /dev/$USBDRV
  222. mkdosfs -F 32 /dev/${USBDRV}1 #FAT32. -n puppysave
  223. else
  224. #set partition-id to fat16 (06=fat16, 0e=fat16-lba)...
  225. echo -e 't\n06\nw' | fdisk /dev/$USBDRV
  226. mkdosfs -F 16 /dev/${USBDRV}1 #FAT16. -n puppysave
  227. fi
  228. sync
  229. #110130 fix for ldlinux.sys wiped... note, i am uncertain how this hack makes any difference...
  230. makebootfat --output /dev/$USBDRV --syslinux3 --boot ldlinux.bss --mbr mbr.bin --copy ldlinux.sys tempdir
  231. sync
  232. syslinux /dev/${USBDRV}1
  233. #um, it may still need to have the boot flag set...
  234. [ "`fdisk -l /dev/$USBDRV | grep '/dev/.* \\* '`" = "" ] && echo -e 'a\n1\nw' | fdisk /dev/$USBDRV
  235. #one big fat partition, pup_save will be in it too...
  236. PUPSAVEPART="${USBDRV}1"
  237. PUPBOOTPART="${USBDRV}1"
  238. else
  239. if [ "$RADIO_FDD" = "true" ];then #only choose this for drives no greater than 1GB.
  240. #take out '--mbrfat' has partition but makes look like floppy drive.
  241. #take out '--mbr mbrfat.com' as there are no partitions.
  242. #take out '--zip' as that forces 32 sector 64 head zip disk architecture.
  243. #add '--disk' to ensure operate on disk not a partition.
  244. makebootfat --output /dev/$USBDRV --syslinux3 --disk --boot ldlinux.bss --copy ldlinux.sys tempdir
  245. PUPSAVEPART="${USBDRV}"
  246. PUPBOOTPART="${USBDRV}"
  247. else
  248. #need space for 256MB image...
  249. WKGPATH="/tmp"
  250. FREEM=`df -m | grep ' /tmp$' | tr -s ' ' | cut -f 4 -d ' '`
  251. [ ! $FREEM ] && FREEM=0
  252. if [ $FREEM -lt 300 ];then
  253. WKGPATH="/root"
  254. FREEM=`df -m | grep ' /$' | tr -s ' ' | cut -f 4 -d ' '`
  255. if [ $FREEM -lt 300 ];then
  256. WKGPATH="`readlink /mnt/home`"
  257. mhPATTERN=' '"$WKGPATH"'$'
  258. FREEM=`df -m | grep "$mhPATTERN" | tr -s ' ' | cut -f 4 -d ' '`
  259. fi
  260. fi
  261. if [ $FREEM -lt 300 ];then
  262. kill $X1PID
  263. pupmessage -bg red -title "$(gettext 'ERROR')" "$(gettext 'SORRY, cannot find 256MB free working space!')"
  264. exit
  265. fi
  266. if [ "$RADIO_ISO" = "true" ];then
  267. #need puppy.iso to copy to usb drive...
  268. kill $X1PID
  269. SRCFPATH="`Xdialog --wrap --wmclass "gtkdialog2" --left --backtitle "$(gettext "The 'ISO9660' choice requires the Puppy .iso file to be written directly into the USB drive. Please select it then click 'OK':")" --title "BootFlash: ISO9660 format" --stdout --no-buttons --no-cancel --fselect "*.iso" 0 0`"
  270. [ $? -ne 0 ] && exit
  271. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, copying .iso file...')" &
  272. X1PID=$!
  273. rm -f $WKGPATH/image256m 2>/dev/null
  274. cp -f "$SRCFPATH" $WKGPATH/image256m
  275. sync
  276. isohybrid $WKGPATH/image256m
  277. sync
  278. PUPSAVEPART="${USBDRV}2"
  279. PUPBOOTPART="${USBDRV}1"
  280. else
  281. #create 256M empty file...
  282. dd if=/dev/zero of=${WKGPATH}/image256m bs=1024 count=262144 #256MB 131072=128MB
  283. sync
  284. LOOPDEV="`losetup -f`"
  285. losetup $LOOPDEV ${WKGPATH}/image256m
  286. if [ "$RADIO_ALL" = "true" ];then #ComboFormat
  287. makebootfat --output $LOOPDEV --syslinux3 --zip --boot ldlinux.bss --mbr mbrfat.bin --mbrfat --copy ldlinux.sys tempdir
  288. #'--zip' sets partition-4 as bootable, so pup_save will go into partition-1...
  289. PUPSAVEPART="${USBDRV}1"
  290. PUPBOOTPART="${USBDRV}4"
  291. fi
  292. if [ "$RADIO_ZIP" = "true" ];then
  293. #take out '--mbrfat' has partition but makes look like floppy drive.
  294. makebootfat --output $LOOPDEV --syslinux3 --zip --boot ldlinux.bss --mbr mbrfat.bin --copy ldlinux.sys tempdir
  295. #'--zip' sets partition-4 as bootable, so pup_save will go into partition-1...
  296. PUPSAVEPART="${USBDRV}1"
  297. PUPBOOTPART="${USBDRV}4"
  298. fi
  299. sync
  300. losetup -d $LOOPDEV
  301. fi
  302. #write bootable f.s. to drive...
  303. dd if=${WKGPATH}/image256m of=/dev/$USBDRV
  304. sync
  305. rm -f ${WKGPATH}/image256m
  306. #now create partition to fill remaining space on usb drive...
  307. if [ "$RADIO_ISO" = "true" ];then
  308. echo -e 'n\np\n2\n\n\nw' | fdisk /dev/$USBDRV #create partition-2
  309. PARTNUM="2"
  310. else
  311. echo -e 'n\np\n1\n\n\nw' | fdisk /dev/$USBDRV #create partition-1
  312. PARTNUM="1"
  313. fi
  314. DRVSIZEB=`fdisk -l /dev/${USBDRV} | grep '^Disk /dev/' | cut -f 5 -d ' '` #in bytes.
  315. DRVSIZEK=`expr $DRVSIZEB \/ 1024`
  316. DRVSIZEM=`expr $DRVSIZEK \/ 1024`
  317. if [ $DRVSIZEM -gt 1024 ];then #1GB
  318. #set partition-id to fat32 (0b=fat32, oc=fat32-lba)...
  319. echo -e "t\n${PARTNUM}\n0b\nw" | fdisk /dev/${USBDRV}
  320. sync
  321. mkdosfs -F 32 -n puppysave /dev/${PUPSAVEPART} #FAT32.
  322. else
  323. #set partition-id to fat16 (06=fat16, 0e=fat16-lba)...
  324. echo -e "t\n${PARTNUM}\n06\nw" | fdisk /dev/${USBDRV}
  325. mkdosfs -n puppysave /dev/${PUPSAVEPART} #FAT16.
  326. fi
  327. fi
  328. fi
  329. #need to refresh desktop drive icons(s)...
  330. ##/tmp/pup_event_frontend_block_request is used in /sbin/pup_event_frontend_d to refresh drv...
  331. #echo "$USBDRV" > /tmp/pup_event_frontend_block_request
  332. #130722 ...this file was read by the old /sbin/pup_event_frontend_d big script.
  333. #now have a binary daemon, send this uevent to it, then /usr/local/pup_event/frontend_change will be called...
  334. echo change > /sys/block/${USBDRV}/uevent
  335. kill $X1PID
  336. #announce finished, offer to install Puppy...
  337. if [ "$RADIO_ISO" = "true" ];then
  338. export FINISHED_DIALOG="<window title=\"$(gettext 'BootFlash: ISO9660 format finished')\" icon-name=\"gtk-preferences\">
  339. <vbox>
  340. <pixmap><input file>/usr/local/lib/X11/pixmaps/ok.xpm</input></pixmap>
  341. <text use-markup=\"true\"><label>\"<b>$(gettext 'All done!')</b>\"</label></text>
  342. <text><label>$(gettext 'The drive now has two partitions, ISO9660 and the rest of the drive a FAT partition. Puppy will offer to create a pup-save file in the latter, at the first shutdown after successfully booting from the USB drive.')</label></text>
  343. <hbox>
  344. <button ok></button>
  345. </hbox>
  346. </vbox>
  347. </window>"
  348. gtkdialog3 --center --program=FINISHED_DIALOG
  349. exit
  350. fi
  351. export FINISHED_DIALOG="<window title=\"$(gettext 'BootFlash: install Puppy')\" icon-name=\"gtk-preferences\">
  352. <vbox>
  353. <pixmap><input file>/usr/local/lib/X11/pixmaps/question.xpm</input></pixmap>
  354. <text use-markup=\"true\"><label>\"<b>$(gettext 'USB drive now (hopefully) bootable!')</b>\"</label></text>
  355. <text><label>$(gettext 'Now, if you wish, you may install Puppy Linux on the drive. If you decline, it can be done later using the Puppy Universal Installer. If you choose to install Puppy now, you must have a Puppy live-CD .iso file available locally (that you had previously downloaded)').</label></text>
  356. <hbox>
  357. <button type=\"exit\">
  358. <label>$(gettext 'Install Puppy')</label>
  359. </button>
  360. <button type=\"exit\">
  361. <input file icon=\"gtk-close\"></input>
  362. <label>$(gettext 'Exit, finished')</label>
  363. </button>
  364. </hbox>
  365. </vbox>
  366. </window>"
  367. RETPARAMS="`gtkdialog3 --center --program=FINISHED_DIALOG`"
  368. eval "$RETPARAMS"
  369. [ "$EXIT" != "$(gettext 'Install Puppy')" ] && exit
  370. cd /root
  371. SRCFPATH="`Xdialog --wrap --wmclass "gtkdialog2" --left --backtitle "$(gettext "Please select a Puppy live-CD .iso file, then click 'OK':")" --title "$(gettext 'BootFlash: Choose .iso')" --stdout --no-buttons --no-cancel --fselect "*.iso" 0 0`"
  372. [ $? -ne 0 ] && exit
  373. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, copying files from .iso file...')" &
  374. X1PID=$!
  375. mkdir -p /tmp/bootflash_iso
  376. mount -t iso9660 -o loop ${SRCFPATH} /tmp/bootflash_iso
  377. if [ $? -ne 0 -o ! -f /tmp/bootflash_iso/initrd.gz ];then
  378. pupmessage -bg red -center -title "$(gettext 'ERROR')" "$(gettext 'Sorry error accessing .iso file')"
  379. exit
  380. fi
  381. mkdir -p /mnt/${PUPBOOTPART}
  382. mount -t vfat /dev/${PUPBOOTPART} /mnt/${PUPBOOTPART}
  383. if [ "`mount | grep "/dev/${PUPBOOTPART}"`" = "" ];then
  384. pupmessage -bg red -center -title "$(gettext 'ERROR')" "$(gettext 'Sorry error mounting USB drive')"
  385. exit
  386. fi
  387. rm -f /mnt/${PUPBOOTPART}/*-[0-9][0-9][0-9].sfs 2>/dev/null
  388. rm -f /mnt/${PUPBOOTPART}/*_[0-9][0-9][0-9].sfs 2>/dev/null #101026
  389. [ -f /mnt/${PUPBOOTPART}/${DISTRO_PUPPYSFS} ] && rm -f /mnt/${PUPBOOTPART}/${DISTRO_PUPPYSFS} #100913
  390. [ -f /mnt/${PUPBOOTPART}/${DISTRO_ADRVSFS} ] && rm -f /mnt/${PUPBOOTPART}/${DISTRO_ADRVSFS}
  391. [ -f /mnt/${PUPBOOTPART}/${DISTRO_YDRVSFS} ] && rm -f /mnt/${PUPBOOTPART}/${DISTRO_YDRVSFS}
  392. [ -f /mnt/${PUPBOOTPART}/${DISTRO_ZDRVSFS} ] && rm -f /mnt/${PUPBOOTPART}/${DISTRO_ZDRVSFS} #100913
  393. #[ -f /mnt/${PUPBOOTPART}/${DISTRO_DEVXSFS} ] && rm -f /mnt/${PUPBOOTPART}/${DISTRO_DEVXSFS} #100913
  394. #create a syslinux.cfg file...
  395. PMEDIA="usbflash"
  396. [ "`cat /sys/block/$USBDRV/removable`" != "1" ] && PMEDIA="usbhd" #101026 bugfix.
  397. echo "default vmlinuz initrd=initrd.gz pmedia=${PMEDIA}" > /mnt/${PUPBOOTPART}/syslinux.cfg
  398. cp -f /tmp/bootflash_iso/vmlinuz /mnt/${PUPBOOTPART}/
  399. cp -f /tmp/bootflash_iso/initrd.gz /mnt/${PUPBOOTPART}/
  400. cp -f /tmp/bootflash_iso/*.sfs /mnt/${PUPBOOTPART}/ 2>/dev/null #101026
  401. sync
  402. umount /mnt/${PUPBOOTPART}
  403. umount /tmp/bootflash_iso
  404. kill $X1PID
  405. export DONE_DIALOG="<window title=\"$(gettext 'BootFlash: Puppy installed')\" icon-name=\"gtk-preferences\">
  406. <vbox>
  407. <pixmap><input file>/usr/local/lib/X11/pixmaps/ok.xpm</input></pixmap>
  408. <text use-markup=\"true\"><label>\"<b>$(gettext 'Puppy installed!')</b>\"</label></text>
  409. <text><label>$(gettext 'The desktop drive icons should have been updated, so you can click on them to check that everything looks right. Then reboot and find out for sure...')</label></text>
  410. <hbox>
  411. <button ok></button>
  412. </hbox>
  413. </vbox>
  414. </window>"
  415. gtkdialog3 --center --program=DONE_DIALOG
  416. ###END###