Change vfat limit from 2047 to 4095 (#995552)
[livecd.git] / tools / livecd-iso-to-disk.sh
blobb38e3b20c4b3d267c81337aef9e041d242c3ed3c
1 #!/bin/bash
2 # Transfer a Live image so that it's bootable off of a USB/SD device.
3 # Copyright 2007-2012 Red Hat, Inc.
5 # Jeremy Katz <katzj@redhat.com>
6 # Brian C. Lane <bcl@redhat.com>
8 # overlay/persistence enhancements by Douglas McClendon <dmc@viros.org>
9 # GPT+MBR hybrid enhancements by Stewart Adam <s.adam@diffingo.com>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; version 2 of the License.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Library General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 export PATH=/sbin:/usr/sbin:$PATH
27 shortusage() {
28 echo "
29 SYNTAX
31 livecd-iso-to-disk [--help] [--noverify] [--format] [--msdos] [--reset-mbr]
32 [--efi] [--skipcopy] [--force] [--xo] [--xo-no-home]
33 [--timeout <time>] [--totaltimeout <time>]
34 [--extra-kernel-args <args>] [--multi] [--livedir <dir>]
35 [--compress] [--skipcompress] [--swap-size-mb <size>]
36 [--overlay-size-mb <size>] [--home-size-mb <size>]
37 [--delete-home] [--crypted-home] [--unencrypted-home]
38 [--updates updates.img] [--ks kickstart]
39 <source> <target device>
41 (Enter livecd-iso-to-disk --help on the command line for more information.)"
44 usage() {
45 echo "
47 shortusage
48 echo "
49 livecd-iso-to-disk - Transfer a LiveOS image so that it's bootable off of
50 a USB/SD device.
52 The script may be run in simplest form with just the two arguments:
54 <source>
55 This may be the filesystem path to a LiveOS .iso image file,
56 such as from a CD-ROM, DVD, or download. It could also be the
57 device node reference for the mount point of another LiveOS
58 filesystem, including the currently-running one (such as a
59 booted Live CD/DVD/USB, where /dev/live references the running
60 image device).
62 <target device>
63 This should be the device partition name for the attached,
64 target device, such as /dev/sdb1 or /dev/sdc1. (Issue the
65 df -Th command to get a listing of the mounted partitions,
66 where you can confirm the filesystem types, available space,
67 and device names.) Be careful to specify the correct device,
68 or you may overwrite important data on another disk!
70 To execute the script to completion, you will need to run it with root user
71 permissions.
72 SYSLINUX must be installed on the computer running the installation script.
74 DESCRIPTION
76 livecd-iso-to-disk installs a Live CD/DVD/USB image (LiveOS) onto a USB/SD
77 storage device (or any storage partition that will boot with a SYSLINUX
78 bootloader). The target storage device can then boot the installed
79 operating system on systems that support booting via the USB or the SD
80 interface. The script requires a LiveOS source image and a target storage
81 device. The source image may be either a LiveOS .iso file, the currently-
82 running LiveOS image, the device node reference for an attached device with
83 an installed LiveOS image, or a file backed by a block device with an
84 installed LiveOS image. If the operating system supports persistent
85 overlays for saving system changes, a pre-sized overlay may be included with
86 the installation.
88 Unless you request the --format option, the installation does not destroy
89 data outside of the LiveOS, syslinux, & EFI folders on your target device.
90 This allows one to maintain other files on the target disk outside of the
91 LiveOS filesystem.
93 LiveOS images provide embedded filesystems through the Device-mapper
94 component of the Linux kernel. The embedded filesystems exist within files
95 such as /LiveOS/squashfs.img (the default compressed storage) or
96 /LiveOS/ext3fs.img (an uncompressed version) on the primary volume partition
97 of the storage device. In use, these are read-only filesystems. Optionally,
98 one may specify a persistent LiveOS overlay to hold image-change snapshots
99 (that use write-once, difference-tracking storage) in the
100 /LiveOS/overlay-<device_id> file, which, *one should note*, always grows in
101 size due to the storage mechanism. (The fraction of allocated space that
102 has been consumed by system activity and changes may be displayed by issuing
103 the 'dmsetup status' command in a terminal session of a running LiveOS
104 image.) One way to conserve the unrecoverable, overlay file space, is to
105 specify a persistent home folder for user files, which will be saved in a
106 /LiveOS/home.img filesystem image file. This file space is encrypted by
107 default, but is not compressed. (One may bypass encryption with the
108 --unencrypted-home installation option.) Files in this home folder may be
109 erased to recover and reuse their storage space. The home.img file is also
110 convenient for backing up or swapping user account files.
112 OPTIONS
114 --help
115 Displays usage information and exits.
117 --noverify
118 Disables the image validation process that occurs before the image is
119 installed from the original Live CD .iso image. When this option is
120 specified, the image is not verified before loading onto the target
121 storage device.
123 --format
124 Formats the target device and creates an MS-DOS partition table (or GPT
125 partition table, if the --efi option is passed).
127 --msdos
128 Forces format to use msdos instead of ext4.
130 --reset-mbr
131 Sets the Master Boot Record (MBR) of the target storage device to the
132 mbr.bin file from the installation system's syslinux directory. This
133 may be helpful in recovering a damaged or corrupted device.
135 --efi
136 Creates a GUID partition table when --format is passed, and installs a
137 hybrid Extensible Firmware Interface (EFI)/MBR bootloader on the disk.
138 This is necessary for most Intel Macs.
140 --skipcopy
141 Skips the copying of the live image to the target device, bypassing the
142 actions of the --format, --overlay-size-mb, --home-size-mb, &
143 --swap-size-mb options, if present on the command line. (The --skipcopy
144 option may be used while testing the script, in order to avoid repeated
145 and lengthy copy commands, or to repair boot configuration files on a
146 previously installed device.)
148 --force
149 This option allows the installation script to bypass a delete
150 confirmation dialog in the event that a pre-existing LiveOS directory
151 is found on the target device.
153 --xo
154 Used to prepare an image for the OLPC XO-1 laptop with its compressed,
155 JFFS2 filesystem. Do not use the following options with --xo:
156 --overlay-size-mb <size>, home-size-mb <size>, --delete-home,
157 --compress
159 --xo-no-home
160 Used together with the --xo option to prepare an image for an OLPC XO
161 laptop with the home folder on an SD card instead of the internal flash
162 storage.
164 --timeout
165 Modifies the bootloader's timeout value, which indicates how long to
166 pause at the boot: prompt before booting automatically. This overrides
167 the value set during iso creation. Units are 1/10 s. The timeout is
168 canceled when any key is pressed, the assumption being that the user
169 will complete the command line. A timeout of zero will disable the
170 timeout completely.
172 --totaltimeout
173 Adds a bootloader totaltimeout, which indicates how long to wait before
174 booting automatically. This is used to force an automatic boot. This
175 timeout cannot be canceled by the user. Units are 1/10 s.
177 --extra-kernel-args <args>
178 Specifies additional kernel arguments, <args>, that will be inserted
179 into the syslinux and EFI boot configurations. Multiple arguments
180 should be specified in one string, i.e.,
181 --extra-kernel-args \"arg1 arg2 ...\"
183 --multi
184 Used when installing multiple image copies to signal configuration of
185 the boot files for the image in the --livedir <dir> parameter.
188 --livedir <dir>
189 Used with multiple image installations to designate the directory <dir>
190 for the particular image.
192 --compress (default state for the operating system files)
193 The default, compressed SquashFS filesystem image is copied on
194 installation. This option has no effect when the source filesystem is
195 already expanded.
197 --skipcompress (default option when --xo is specified)
198 Expands the source SquashFS image on installation into the read-only
199 /LiveOS/ext3fs.img filesystem image file.
201 --swap-size-mb <size>
202 Sets up a swap file of <size> mebibytes (integer values only) on the
203 target device.
205 --overlay-size-mb <size>
206 This option sets the overlay size in mebibytes (integer values only).
207 The overlay makes persistent storage available to the live operating
208 system, if the operating system supports it. The persistent LiveOS
209 overlay holds image-change snapshots (using write-once, difference-
210 tracking storage) in the /LiveOS/overlay-<device_id> file, which, *one
211 should note*, always grows in size due to the storage mechanism. (The
212 fraction of allocated space that has been consumed may be displayed by
213 issuing the 'dmsetup status' command in a terminal session of a running
214 LiveOS installation.) One way to conserve the unrecoverable, overlay
215 file space, is to specify a persistent home folder for user files, see
216 --home-size-mb below. The target storage device must have enough free
217 space for the image and the overlay. A maximum <size> of 4095 MiB is
218 permitted for vfat-formatted devices. If there is insufficient room on
219 your device, you will be given information to help in adjusting your
220 settings.
222 --home-size-mb <size>
223 Sets the home directory size in mebibytes (integer values only). A
224 persistent home directory will be made in the /LiveOS/home.img
225 filesystem image file. This file space is encrypted by default, but not
226 compressed (one may bypass encryption with the --unencrypted-home
227 installation option). Files in this home folder may be erased to
228 recover and reuse their storage space. The target storage device must
229 have enough free space for the image, any overlay, and the home
230 directory. Note that the --delete-home option must also be selected to
231 replace an existing persistent home with a new, empty one. A maximum
232 <size> of 4095 MiB is permitted for vfat-formatted devices. If there is
233 insufficient room on your device, you will be given information to help
234 in adjusting your settings.
236 --delete-home
237 To prevent unwitting deletion of user files, this option must be
238 explicitly selected when the option --home-size-mb <size> is selected
239 and there is an existing persistent home directory on the target device.
241 --crypted-home (default that only applies to new home-size-mb requests)
242 Specifies the default option to encrypt a new persistent home directory
243 if --home-size-mb <size> is specified.
245 --unencrypted-home
246 Prevents the default option to encrypt a new persistent home directory.
248 --updates updates.img
249 Setup inst.updates to point to an updates image on the device. Anaconda
250 uses this for testing updates to an iso without needing to make a new iso.
252 --ks kickstart
253 Setup inst.ks to point to an kickstart file on the device. Use this for
254 automating installs on boot.
256 CONTRIBUTORS
258 livecd-iso-to-disk: David Zeuthen, Jeremy Katz, Douglas McClendon,
259 Chris Curran and other contributors.
260 (See the AUTHORS file in the source distribution for
261 the complete list of credits.)
263 BUGS
265 Report bugs to the mailing list
266 http://admin.fedoraproject.org/mailman/listinfo/livecd or directly to
267 Bugzilla http://bugzilla.redhat.com/bugzilla/ against the Fedora product,
268 and the livecd-tools component.
270 COPYRIGHT
272 Copyright (C) Fedora Project 2008, 2009, 2010 and various contributors.
273 This is free software. You may redistribute copies of it under the terms of
274 the GNU General Public License http://www.gnu.org/licenses/gpl.html.
275 There is NO WARRANTY, to the extent permitted by law.
277 SEE ALSO
279 livecd-creator, project website http://fedoraproject.org/wiki/FedoraLiveCD
281 exit 1
284 cleanup() {
285 sleep 2
286 [ -d "$SRCMNT" ] && umount $SRCMNT && rmdir $SRCMNT
287 [ -d "$TGTMNT" ] && umount $TGTMNT && rmdir $TGTMNT
290 exitclean() {
291 RETVAL=$?
292 if [ -d "$SRCMNT" ] || [ -d "$TGTMNT" ];
293 then
294 [ "$RETVAL" = 0 ] || echo "Cleaning up to exit..."
295 cleanup
297 exit $RETVAL
300 isdevloop() {
301 [ x"${1#/dev/loop}" != x"$1" ]
304 getdisk() {
305 DEV=$1
307 if isdevloop "$DEV"; then
308 device="$DEV"
309 return
312 p=$(udevadm info -q path -n $DEV)
313 if [ $? -gt 0 ]; then
314 echo "Error getting udev path to $DEV"
315 exitclean
317 if [ -e /sys/$p/device ]; then
318 device=$(basename /sys/$p)
319 else
320 device=$(basename $(readlink -f /sys/$p/../))
322 if [ ! -e /sys/block/$device -o ! -e /dev/$device ]; then
323 echo "Error finding block device of $DEV. Aborting!"
324 exitclean
327 device="/dev/$device"
328 # FIXME: weird dev names could mess this up I guess
329 p=/dev/$(basename $p)
330 partnum=${p##$device}
333 resetMBR() {
334 if isdevloop "$DEV"; then
335 return
337 getdisk $1
338 # if efi, we need to use the hybrid MBR
339 if [ -n "$efi" ]; then
340 if [ -f /usr/lib/syslinux/gptmbr.bin ]; then
341 cat /usr/lib/syslinux/gptmbr.bin > $device
342 elif [ -f /usr/share/syslinux/gptmbr.bin ]; then
343 cat /usr/share/syslinux/gptmbr.bin > $device
344 else
345 echo "Could not find gptmbr.bin (syslinux)"
346 exitclean
348 # Make it bootable on EFI and BIOS
349 parted -s $device set $partnum legacy_boot on
350 else
351 if [ -f /usr/lib/syslinux/mbr.bin ]; then
352 cat /usr/lib/syslinux/mbr.bin > $device
353 elif [ -f /usr/share/syslinux/mbr.bin ]; then
354 cat /usr/share/syslinux/mbr.bin > $device
355 else
356 echo "Could not find mbr.bin (syslinux)"
357 exitclean
362 checkMBR() {
363 if isdevloop "$DEV"; then
364 return 0
366 getdisk $1
368 bs=$(mktemp /tmp/bs.XXXXXX)
369 dd if=$device of=$bs bs=512 count=1 2>/dev/null || exit 2
371 mbrword=$(hexdump -n 2 $bs |head -n 1|awk {'print $2;'})
372 rm -f $bs
373 if [ "$mbrword" = "0000" ]; then
374 if [ -z "$format" ]; then
375 echo "MBR appears to be blank."
376 echo "Press Enter to replace the MBR and continue or ctrl-c to abort"
377 read
379 resetMBR $1
382 return 0
385 checkPartActive() {
386 dev=$1
387 getdisk $dev
389 # if we're installing to whole-disk and not a partition, then we
390 # don't need to worry about being active
391 if [ "$dev" = "$device" ]; then
392 return
394 if isdevloop "$DEV"; then
395 return
398 if [ "$(/sbin/fdisk -l $device 2>/dev/null |grep -m1 $dev |awk {'print $2;'})" != "*" ]; then
399 echo "Partition isn't marked bootable!"
400 echo "You can mark the partition as bootable with "
401 echo " # /sbin/parted $device"
402 echo " (parted) toggle N boot"
403 echo " (parted) quit"
404 exitclean
408 checkLVM() {
409 dev=$1
411 if [ -x /sbin/pvs -a \
412 "$(/sbin/pvs -o vg_name --noheadings $dev* 2>/dev/null || :)" ]; then
413 echo "Device, $dev, contains a volume group and cannot be formated!"
414 echo "You can remove the volume group using vgremove."
415 exitclean
417 return 0
420 createGPTLayout() {
421 dev=$1
422 getdisk $dev
424 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
425 echo "Press Enter to continue or ctrl-c to abort"
426 read
427 umount ${device}* &> /dev/null || :
428 wipefs -a ${device}
429 /sbin/parted --script $device mklabel gpt
430 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit MB print" |grep ^$device:)
431 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
432 p1_size=$(($dev_size - 3))
434 if [ $p1_size -le 0 ]; then
435 echo "Your device isn't big enough to hold $SRC"
436 echo "It is $(($p1_size * -1)) MB too small"
437 exitclean
439 p1_start=1
440 p1_end=$(($p1_size + 1))
441 /sbin/parted -s $device u MB mkpart '"EFI System Partition"' fat32 $p1_start $p1_end set 1 boot on
442 # Sometimes automount can be _really_ annoying.
443 echo "Waiting for devices to settle..."
444 /sbin/udevadm settle
445 sleep 5
446 TGTDEV=${device}1
447 umount $TGTDEV &> /dev/null || :
448 /sbin/mkdosfs -n LIVE $TGTDEV
449 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
452 createMSDOSLayout() {
453 dev=$1
454 getdisk $dev
456 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
457 echo "Press Enter to continue or ctrl-c to abort"
458 read
459 umount ${device}* &> /dev/null || :
460 wipefs -a ${device}
461 /sbin/parted --script $device mklabel msdos
462 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit MB print" |grep ^$device:)
463 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
464 p1_size=$(($dev_size - 3))
466 if [ $p1_size -le 0 ]; then
467 echo "Your device isn't big enough to hold $SRC"
468 echo "It is $(($p1_size * -1)) MB too small"
469 exitclean
471 p1_start=1
472 p1_end=$(($p1_size + 1))
473 /sbin/parted -s $device u MB mkpart primary fat32 $p1_start $p1_end set 1 boot on
474 # Sometimes automount can be _really_ annoying.
475 echo "Waiting for devices to settle..."
476 /sbin/udevadm settle
477 sleep 5
478 if ! isdevloop "$DEV"; then
479 TGTDEV=${device}1
480 else
481 TGTDEV=${device}
483 umount $TGTDEV &> /dev/null || :
484 /sbin/mkdosfs -n LIVE $TGTDEV
485 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
488 createEXTFSLayout() {
489 dev=$1
490 getdisk $dev
492 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
493 echo "Press Enter to continue or ctrl-c to abort"
494 read
495 umount ${device}* &> /dev/null || :
496 wipefs -a ${device}
497 /sbin/parted -s $device mklabel msdos
498 partinfo=$(LC_ALL=C /sbin/parted -s -m $device "u MB print" |grep ^$device:)
499 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
500 p1_size=$(($dev_size - 3))
502 if [ $p1_size -le 0 ]; then
503 echo "Your device isn't big enough to hold $SRC"
504 echo "It is $(($p1_size * -1)) MB too small"
505 exitclean
507 p1_start=1
508 p1_end=$(($p1_size + 1))
509 /sbin/parted -s $device u MB mkpart primary ext2 $p1_start $p1_end set 1 boot on
510 # Sometimes automount can be _really_ annoying.
511 echo "Waiting for devices to settle..."
512 /sbin/udevadm settle
513 sleep 5
514 TGTDEV=${device}1
515 umount $TGTDEV &> /dev/null || :
517 # Check extlinux version
518 if extlinux -v 2>&1 | grep -q 'extlinux 3'; then
519 mkfs=/sbin/mkfs.ext3
520 else
521 mkfs=/sbin/mkfs.ext4
523 $mkfs -L LIVE $TGTDEV
524 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
527 checkGPT() {
528 dev=$1
529 getdisk $dev
531 if [ "$(/sbin/parted -m $device p 2>/dev/null |grep -ic :gpt:)" -eq "0" ]; then
532 echo "EFI boot requires a GPT partition table."
533 echo "This can be done manually or you can run with --format"
534 exitclean
537 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "print" |grep ^$partnum:)
538 volname=$(echo $partinfo |cut -d : -f 6)
539 flags=$(echo $partinfo |cut -d : -f 7)
540 if [ "$volname" != "EFI System Partition" ]; then
541 echo "Partition name must be 'EFI System Partition'"
542 echo "This can be set in parted or you can run with --reset-mbr"
543 exitclean
545 if [ "$(echo $flags |grep -c boot)" = "0" ]; then
546 echo "Partition isn't marked bootable!"
547 echo "You can mark the partition as bootable with "
548 echo " # /sbin/parted $device"
549 echo " (parted) toggle N boot"
550 echo " (parted) quit"
551 exitclean
555 checkFilesystem() {
556 dev=$1
558 TGTFS=$(/sbin/blkid -s TYPE -o value $dev || :)
559 if [ "$TGTFS" != "vfat" ] && [ "$TGTFS" != "msdos" ]; then
560 if [ "$TGTFS" != "ext2" ] && [ "$TGTFS" != "ext3" ] && [ "$TGTFS" != "ext4" ] && [ "$TGTFS" != "btrfs" ]; then
561 echo "Target filesystem ($dev:$TGTFS) must be vfat, ext[234] or btrfs"
562 exitclean
566 TGTLABEL=$(/sbin/blkid -s LABEL -o value $dev)
567 if [ "$TGTLABEL" != "LIVE" ]; then
568 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
569 /sbin/dosfslabel $dev LIVE
570 if [ $? -gt 0 ]; then
571 echo "dosfslabel failed on $dev, device not setup"
572 exitclean
574 elif [ "$TGTFS" = "ext2" -o "$TGTFS" = "ext3" -o "$TGTFS" = "ext4" ]; then
575 /sbin/e2label $dev LIVE
576 if [ $? -gt 0 ]; then
577 echo "e2label failed on $dev, device not setup"
578 exitclean
580 else
581 echo "Unknown filesystem type. Try setting its label to LIVE and re-running"
582 exitclean
586 # Use UUID if available
587 TGTUUID=$(/sbin/blkid -s UUID -o value $dev)
588 if [ -n "$TGTUUID" ]; then
589 TGTLABEL="UUID=$TGTUUID"
590 else
591 TGTLABEL="LABEL=LIVE"
594 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
595 mountopts="-o shortname=winnt,umask=0077"
599 checkSyslinuxVersion() {
600 if [ ! -x /usr/bin/syslinux ]; then
601 echo "You need to have syslinux installed to run this script"
602 exit 1
604 check=($(syslinux --version 2>&1)) || :
605 if [[ 'syslinux' != $check ]]; then
606 SYSLINUXPATH=""
607 elif [ -n "$multi" ]; then
608 SYSLINUXPATH="$LIVEOS/syslinux"
609 else
610 SYSLINUXPATH="syslinux"
614 checkMounted() {
615 dev=$1
616 if grep -q "^$dev " /proc/mounts ; then
617 echo "$dev is mounted, please unmount for safety"
618 exitclean
620 if grep -q "^$dev " /proc/swaps; then
621 echo "$dev is in use as a swap device, please disable swap"
622 exitclean
626 checkint() {
627 if ! test $1 -gt 0 2>/dev/null ; then
628 shortusage
629 exit 1
633 if [ $(id -u) != 0 ]; then
634 echo "You need to be root to run this script"
635 exit 1
638 detectsrctype() {
639 if [[ -e "$SRCMNT/Packages" ]]; then
640 echo "/Packages found, will copy source packages to target"
641 packages=1
643 if [[ -e "$SRCMNT/LiveOS/squashfs.img" ]]; then
644 # LiveOS style boot image
645 srctype=live
646 return
648 if [ -e $SRCMNT/images/install.img -o -e $SRCMNT/isolinux/initrd.img ]; then
649 if [ -n "$packages" ]; then
650 srctype=installer
651 else
652 srctype=netinst
654 imgtype=install
655 if [ ! -e $SRCMNT/images/install.img ]; then
656 echo "$SRC uses initrd.img w/o install.img"
657 imgtype=initrd
659 return
661 echo "ERROR: $SRC does not appear to be a Live image or DVD installer."
662 exitclean
665 cp_p() {
666 strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
667 | awk '{
668 count += $NF
669 if (count % 10 == 0) {
670 percent = count / total_size * 100
671 printf "%3d%% [", percent
672 for (i=0;i<=percent;i++)
673 printf "="
674 printf ">"
675 for (i=percent;i<100;i++)
676 printf " "
677 printf "]\r"
680 END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
683 copyFile() {
684 if [ -x /usr/bin/rsync ]; then
685 rsync --inplace -P "$1" "$2"
686 return
688 if [ -x /usr/bin/gvfs-copy ]; then
689 gvfs-copy -p "$1" "$2"
690 return
692 if [ -x /usr/bin/strace -a -x /bin/awk ]; then
693 cp_p "$1" "$2"
694 return
696 cp "$1" "$2"
699 set -e
700 set -o pipefail
701 trap exitclean EXIT
702 shopt -s extglob
704 cryptedhome=1
705 keephome=1
706 homesizemb=0
707 swapsizemb=0
708 overlaysizemb=0
709 srctype=
710 imgtype=
711 packages=
712 LIVEOS=LiveOS
713 HOMEFILE="home.img"
714 updates=
717 if [[ "$*" =~ "--help" ]]; then
718 usage
720 while [ $# -gt 2 ]; do
721 case $1 in
722 --help)
723 usage
725 --noverify)
726 noverify=1
728 --format)
729 format=1
731 --msdos)
732 usemsdos=1
734 --reset-mbr|--resetmbr)
735 resetmbr=1
737 --efi|--mactel)
738 efi=1
740 --skipcopy)
741 skipcopy=1
743 --force)
744 force=1
746 --xo)
747 xo=1
748 skipcompress=1
750 --xo-no-home)
751 xonohome=1
753 --timeout)
754 checkint $2
755 timeout=$2
756 shift
758 --totaltimeout)
759 checkint $2
760 totaltimeout=$2
761 shift
763 --extra-kernel-args)
764 kernelargs=$2
765 shift
767 --multi)
768 multi=1
770 --livedir)
771 LIVEOS=$2
772 shift
774 --compress)
775 skipcompress=""
777 --skipcompress)
778 skipcompress=1
780 --swap-size-mb)
781 checkint $2
782 swapsizemb=$2
783 shift
785 --overlay-size-mb)
786 checkint $2
787 overlaysizemb=$2
788 shift
790 --home-size-mb)
791 checkint $2
792 homesizemb=$2
793 shift
795 --crypted-home)
796 cryptedhome=1
798 --unencrypted-home)
799 cryptedhome=""
801 --delete-home)
802 keephome=""
804 --updates)
805 updates=$2
806 shift
808 --ks)
809 ks=$2
810 shift
813 echo "invalid arg -- $1"
814 shortusage
815 exit 1
817 esac
818 shift
819 done
821 SRC=$(readlink -f "$1")
822 TGTDEV=$(readlink -f "$2")
824 if [ -z "$SRC" ]; then
825 echo "Missing source"
826 shortusage
827 exit 1
830 if [ ! -b "$SRC" -a ! -f "$SRC" ]; then
831 echo "$SRC is not a file or block device"
832 shortusage
833 exit 1
836 if [ -z "$TGTDEV" ]; then
837 echo "Missing target device"
838 shortusage
839 exit 1
842 if [ ! -b "$TGTDEV" ]; then
843 echo "$TGTDEV is not a block device"
844 shortusage
845 exit 1
848 if [ -z "$noverify" ]; then
849 # verify the image
850 echo "Verifying image..."
851 if ! checkisomd5 --verbose "$SRC"; then
852 echo "Are you SURE you want to continue?"
853 echo "Press Enter to continue or ctrl-c to abort"
854 read
858 # do some basic sanity checks.
859 checkMounted $TGTDEV
861 # FIXME: would be better if we had better mountpoints
862 SRCMNT=$(mktemp -d /media/srctmp.XXXXXX)
863 if [ -b "$SRC" ]; then
864 mount -o ro "$SRC" $SRCMNT || exitclean
865 elif [ -f "$SRC" ]; then
866 mount -o loop,ro "$SRC" $SRCMNT || exitclean
867 else
868 echo "$SRC is not a file or block device."
869 exitclean
871 # Figure out what needs to be done based on the source image
872 detectsrctype
874 # Format the device
875 if [ -n "$format" -a -z "$skipcopy" ]; then
876 checkLVM $TGTDEV
878 if [ -n "$efi" ]; then
879 createGPTLayout $TGTDEV
880 elif [ -n "$usemsdos" -o ! -x /sbin/extlinux ]; then
881 createMSDOSLayout $TGTDEV
882 else
883 createEXTFSLayout $TGTDEV
887 checkFilesystem $TGTDEV
888 if [ -n "$efi" ]; then
889 checkGPT $TGTDEV
892 checkSyslinuxVersion
893 # Because we can't set boot flag for EFI Protective on msdos partition tables
894 [ -z "$efi" ] && checkPartActive $TGTDEV
895 [ -n "$resetmbr" ] && resetMBR $TGTDEV
896 checkMBR $TGTDEV
899 if [ "$overlaysizemb" -gt 0 ]; then
900 if [ "$TGTFS" = "vfat" -a "$overlaysizemb" -gt 4095 ]; then
901 echo "Can't have an overlay of 4095MB or greater on VFAT"
902 exitclean
904 LABEL=$(/sbin/blkid -s LABEL -o value $TGTDEV)
905 if [[ "$LABEL" =~ ( ) ]]; then
906 echo "The LABEL($LABEL) on $TGTDEV has spaces in it, which do not work with the overlay"
907 echo "You can re-format or use dosfslabel/e2fslabel to change it"
908 exitclean
912 if [ "$homesizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
913 if [ "$homesizemb" -gt 4095 ]; then
914 echo "Can't have a home overlay greater than 4095MB on VFAT"
915 exitclean
919 if [ "$swapsizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
920 if [ "$swapsizemb" -gt 4095 ]; then
921 echo "Can't have a swap file greater than 4095MB on VFAT"
922 exitclean
926 TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX)
927 mount $mountopts $TGTDEV $TGTMNT || exitclean
929 trap exitclean SIGINT SIGTERM
931 if [ -f "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" -a "$homesizemb" -gt 0 ]; then
932 echo "ERROR: Requested keeping existing /home and specified a size for /home"
933 echo "Please either don't specify a size or specify --delete-home"
934 exitclean
937 if [ -n "$efi" ]; then
938 if [ -d $SRCMNT/EFI/BOOT ]; then
939 EFI_BOOT="/EFI/BOOT"
940 elif [ -d $SRCMNT/EFI/boot ]; then
941 EFI_BOOT="/EFI/boot"
942 else
943 echo "ERROR: This live image does not support EFI booting"
944 exitclean
948 # let's try to make sure there's enough room on the target device
949 if [[ -d $TGTMNT/$LIVEOS ]]; then
950 tbd=($(du -B 1M $TGTMNT/$LIVEOS))
951 if [[ -s $TGTMNT/$LIVEOS/$HOMEFILE ]] && [[ -n $keephome ]]; then
952 homesize=($(du -B 1M $TGTMNT/$LIVEOS/$HOMEFILE))
953 tbd=$((tbd - homesize))
955 else
956 tbd=0
959 if [[ live == $srctype ]]; then
960 targets="$TGTMNT/$SYSLINUXPATH"
961 [[ -n $efi ]] && targets+=" $TGTMNT$EFI_BOOT"
962 [[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"
963 target_size=$(du -s -c -B 1M $targets 2> /dev/null | awk '/total$/ {print $1;}') || :
964 tbd=$((tbd + target_size))
967 if [[ -n $skipcompress ]] && [[ -s $SRCMNT/LiveOS/squashfs.img ]]; then
968 if mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT; then
969 livesize=($(du -B 1M --apparent-size $SRCMNT/LiveOS/ext3fs.img))
970 umount $SRCMNT
971 if ((livesize > 4095)) && [[ vfat == $TGTFS ]]; then
972 echo "
973 An uncompressed image size greater than 4095 MB is not suitable
974 for a VFAT-formatted device. The compressed SquashFS will be
975 copied to the target device.
977 skipcompress=""
978 livesize=0
980 else
981 echo "WARNING: --skipcompress or --xo was specified but the
982 currently-running kernel can not mount the SquashFS from the source
983 file to extract it. Instead, the compressed SquashFS will be copied
984 to the target device."
985 skipcompress=""
988 if [[ live == $srctype ]]; then
989 thisScriptpath=$(readlink -f "$0")
990 sources="$SRCMNT/LiveOS/ext3fs.img $SRCMNT/LiveOS/osmin.img"
991 [[ -z $skipcompress ]] && sources+=" $SRCMNT/LiveOS/squashfs.img"
992 sources+=" $SRCMNT/isolinux $SRCMNT/syslinux"
993 [[ -n $efi ]] && sources+=" $SRCMNT$EFI_BOOT"
994 [[ -n $xo ]] && sources+=" $SRCMNT/boot/olpc.fth"
995 source_size=$(du -s -c -B 1M "$thisScriptpath" $sources 2> /dev/null | awk '/total$/ {print $1;}') || :
996 livesize=$((livesize + source_size))
999 freespace=$(df -B 1M --total $TGTDEV | awk '/^total/ {print $4;}')
1001 if [[ live == $srctype ]]; then
1002 tba=$((overlaysizemb + homesizemb + livesize + swapsizemb))
1003 if ((tba > freespace + tbd)); then
1004 needed=$((tba - freespace - tbd))
1005 printf "\n The live image + overlay, home, & swap space, if requested,
1006 \r will NOT fit in the space available on the target device.\n
1007 \r + Size of live image: %10s MiB\n" $livesize
1008 (($overlaysizemb > 0)) && \
1009 printf " + Overlay size: %16s\n" $overlaysizemb
1010 (($homesizemb > 0)) && \
1011 printf " + Home directory size: %9s\n" $homesizemb
1012 (($swapsizemb > 0)) && \
1013 printf " + Swap overlay size: %11s\n" $swapsizemb
1014 printf " = Total requested space: %6s MiB\n" $tba
1015 printf " - Space available: %12s\n" $((freespace + tbd))
1016 printf " ==============================\n"
1017 printf " Space needed: %15s MiB\n\n" $needed
1018 printf " To fit the installation on this device,
1019 \r free space on the target, or decrease the
1020 \r requested size total by: %6s MiB\n\n" $needed
1021 exitclean
1025 # Verify available space for DVD installer
1026 if [ "$srctype" = "installer" ]; then
1027 if [ "$imgtype" = "install" ]; then
1028 imgpath=images/install.img
1029 else
1030 imgpath=isolinux/initrd.img
1032 installimgsize=$(du -s -B 1M $SRCMNT/$imgpath | awk {'print $1;'})
1034 tbd=0
1035 if [ -e $TGTMNT/$imgpath ]; then
1036 tbd=$(du -s -B 1M $TGTMNT/$imgpath | awk {'print $1;'})
1038 if [ -e "$TGTMNT/$(basename "$SRC")" ]; then
1039 tbd=$(($tbd + $(du -s -B 1M "$TGTMNT/$(basename "$SRC")" | awk {'print $1;'})))
1041 echo "Size of $imgpath: $installimgsize"
1042 echo "Available space: $((freespace + tbd))"
1043 if (( installimgsize > ((freespace + tbd)) )); then
1044 echo "ERROR: Unable to fit DVD image + install.img on available space on the target device."
1045 exitclean
1049 if [ -z "$skipcopy" ] && [ "$srctype" = "live" ]; then
1050 if [ -d $TGTMNT/$LIVEOS -a -z "$force" ]; then
1051 echo "Already set up as live image."
1052 if [ -z "$keephome" -a -e $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1053 echo "WARNING: Persistent /home will be deleted!!!"
1054 echo "Press Enter to continue or ctrl-c to abort"
1055 read
1056 else
1057 echo "Deleting old OS in fifteen seconds..."
1058 sleep 15
1060 [ -e "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" ] && mv $TGTMNT/$LIVEOS/$HOMEFILE $TGTMNT/$HOMEFILE
1063 rm -rf $TGTMNT/$LIVEOS
1067 # Bootloader is always reconfigured, so keep these out of the if skipcopy stuff.
1068 [ ! -d $TGTMNT/$SYSLINUXPATH ] && mkdir -p $TGTMNT/$SYSLINUXPATH
1069 [ -n "$efi" -a ! -d $TGTMNT$EFI_BOOT ] && mkdir -p $TGTMNT$EFI_BOOT
1071 # Live image copy
1072 if [ "$srctype" = "live" -a -z "$skipcopy" ]; then
1073 echo "Copying live image to target device."
1074 [ ! -d $TGTMNT/$LIVEOS ] && mkdir $TGTMNT/$LIVEOS
1075 [ -n "$keephome" -a -f "$TGTMNT/$HOMEFILE" ] && mv $TGTMNT/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE
1076 if [ -n "$skipcompress" -a -f $SRCMNT/LiveOS/squashfs.img ]; then
1077 mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT || exitclean
1078 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || {
1079 umount $SRCMNT ; exitclean ; }
1080 umount $SRCMNT
1081 elif [ -f $SRCMNT/LiveOS/squashfs.img ]; then
1082 copyFile $SRCMNT/LiveOS/squashfs.img $TGTMNT/$LIVEOS/squashfs.img || exitclean
1083 elif [ -f $SRCMNT/LiveOS/ext3fs.img ]; then
1084 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || exitclean
1086 if [ -f $SRCMNT/LiveOS/osmin.img ]; then
1087 copyFile $SRCMNT/LiveOS/osmin.img $TGTMNT/$LIVEOS/osmin.img || exitclean
1089 sync
1092 # Adjust syslinux sources for replication of installed images
1093 # between filesystem types.
1094 if [[ -d $SRCMNT/isolinux/ ]]; then
1095 cp $SRCMNT/isolinux/* $TGTMNT/$SYSLINUXPATH
1096 elif [[ -d $SRCMNT/syslinux/ ]]; then
1097 cp $SRCMNT/syslinux/* $TGTMNT/$SYSLINUXPATH
1098 if [[ -f $SRCMNT/syslinux/extlinux.conf ]]; then
1099 mv $TGTMNT/$SYSLINUXPATH/extlinux.conf \
1100 $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1101 elif [[ -f $SRCMNT/syslinux/syslinux.cfg ]]; then
1102 mv $TGTMNT/$SYSLINUXPATH/syslinux.cfg $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1105 BOOTCONFIG=$TGTMNT/$SYSLINUXPATH/isolinux.cfg
1106 # Set this to nothing so sed doesn't care
1107 BOOTCONFIG_EFI=
1108 if [ -n "$efi" ]; then
1109 echo "Setting up $EFI_BOOT"
1110 cp -r $SRCMNT$EFI_BOOT/* $TGTMNT$EFI_BOOT
1112 # The GRUB EFI config file can be one of:
1113 # boot?*.conf
1114 # BOOT?*.conf
1115 # grub.cfg
1116 if [ -e $TGTMNT$EFI_BOOT/grub.cfg ]; then
1117 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/grub.cfg
1118 elif [ -e $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf ]; then
1119 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf
1120 else
1121 echo "Unable to find EFI config file."
1122 exitclean
1124 rm -f $TGTMNT$EFI_BOOT/grub.conf
1126 # On some images (RHEL) the BOOT*.efi file isn't in $EFI_BOOT, but is in
1127 # the eltorito image, so try to extract it if it is missing
1129 # test for presence of *.efi grub binary
1130 if [ ! -f $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1131 if [ ! -x /usr/bin/dumpet ]; then
1132 echo "No /usr/bin/dumpet tool found. EFI image will not boot."
1133 echo "Source media is missing grub binary in /EFI/BOOT/*efi"
1134 exitclean
1135 else
1136 # dump the eltorito image with dumpet, output is $SRC.1
1137 dumpet -i "$SRC" -d
1138 EFIMNT=$(mktemp -d /media/srctmp.XXXXXX)
1139 mount -o loop "$SRC".1 $EFIMNT
1141 if [ -f $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1142 cp $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi $TGTMNT$EFI_BOOT
1143 else
1144 echo "No BOOT*.efi found in eltorito image. EFI will not boot"
1145 umount $EFIMNT
1146 rm "$SRC".1
1147 exitclean
1149 umount $EFIMNT
1150 rm "$SRC".1
1155 # DVD installer copy
1156 if [ -z "$skipcopy" -a \( "$srctype" = "installer" -o "$srctype" = "netinst" \) ]; then
1157 echo "Copying DVD image to target device."
1158 mkdir -p $TGTMNT/images/
1159 if [ "$imgtype" = "install" ]; then
1160 for img in install.img updates.img product.img; do
1161 if [ -e $SRCMNT/images/$img ]; then
1162 copyFile $SRCMNT/images/$img $TGTMNT/images/$img || exitclean
1164 done
1168 # Copy packages over.
1169 # Before Fedora17 we could copy the .iso and setup a repo=
1170 # F17 and later look for repodata on the source media.
1171 # The presence of packages and LiveOS indicates F17 or later.
1172 if [ -n "$packages" -a -z "$skipcopy" ]; then
1173 if [ "$srctype" != "live" ]; then
1174 echo "Copying $SRC to device"
1175 copyFile "$SRC" "$TGTMNT/"
1177 # Setup a repo= to point to the .iso
1178 sed -i -e "s;initrd.img;initrd.img repo=hd:$TGTLABEL:/;g" $BOOTCONFIG
1179 if [ -n "$efi" ]; then
1180 sed -i -e "s;vmlinuz;vmlinuz repo=hd:$TGTLABEL:/;g" $BOOTCONFIG_EFI
1182 else
1183 echo "Copying package data from $SRC to device"
1184 rsync --inplace -rLDP --exclude EFI/ --exclude images/ --exclude isolinux/ \
1185 --exclude TRANS.TBL --exclude LiveOS/ "$SRCMNT/" "$TGTMNT/"
1187 echo "Waiting for device to finish writing"
1188 sync
1191 if [ "$srctype" = "live" ]; then
1192 # Copy this installer script.
1193 cp -fT "$thisScriptpath" $TGTMNT/$LIVEOS/livecd-iso-to-disk
1194 chmod +x $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null || :
1196 # When the source is an installed Live USB/SD image, restore the boot config
1197 # file to a base state before updating.
1198 if [[ -d $SRCMNT/syslinux/ ]]; then
1199 echo "Preparing boot config file."
1200 sed -i -e "s/root=live:[^ ]*/root=live:CDLABEL=name/"\
1201 -e "s/\(r*d*.*live.*ima*ge*\) .* quiet/\1 quiet/"\
1202 $BOOTCONFIG $BOOTCONFIG_EFI
1203 sed -i -e "s/^timeout.*$/timeout\ 100/"\
1204 -e "/^totaltimeout.*$/d" $BOOTCONFIG
1208 # Setup the updates.img
1209 if [ -n "$updates" ]; then
1210 copyFile "$updates" "$TGTMNT/updates.img"
1211 kernelargs+=" inst.updates=hd:$TGTLABEL:/updates.img"
1214 # Setup the kickstart
1215 if [ -n "$ks" ]; then
1216 copyFile "$ks" "$TGTMNT/ks.cfg"
1217 kernelargs+=" inst.ks=hd:$TGTLABEL:/ks.cfg"
1220 echo "Updating boot config file"
1221 # adjust label and fstype
1222 sed -i -e "s/CDLABEL=[^ ]*/$TGTLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$TGTFS/" -e "s/LABEL=[^ ]*/$TGTLABEL/" $BOOTCONFIG $BOOTCONFIG_EFI
1223 if [ -n "$kernelargs" ]; then
1224 sed -i -e "s;initrd.\?\.img;& ${kernelargs};" $BOOTCONFIG
1225 if [ -n "$efi" ]; then
1226 sed -i -e "s;vmlinuz.\?;& ${kernelargs} ;" $BOOTCONFIG_EFI
1229 if [ "$LIVEOS" != "LiveOS" ]; then
1230 sed -i -e "s;r*d*.*live.*ima*ge*;& live_dir=$LIVEOS;"\
1231 $BOOTCONFIG $BOOTCONFIG_EFI
1234 # EFI images are in $SYSLINUXPATH now
1235 if [ -n "$efi" ]; then
1236 sed -i -e "s;/isolinux/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1237 sed -i -e "s;/images/pxeboot/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1238 sed -i -e "s;findiso;;g" $BOOTCONFIG_EFI
1241 # DVD Installer for netinst
1242 if [ "$srctype" != "live" ]; then
1243 if [ "$imgtype" = "install" ]; then
1244 sed -i -e "s;initrd.img;initrd.img stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG
1245 if [ -n "$efi" ]; then
1246 sed -i -e "s;vmlinuz;vmlinuz stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG_EFI
1248 else
1249 # The initrd has everything, so no stage2
1250 sed -i -e "s;stage2=\S*;;g" $BOOTCONFIG $BOOTCONFIG_EFI
1254 # Adjust the boot timeouts
1255 if [ -n "$timeout" ]; then
1256 sed -i -e "s/^timeout.*$/timeout\ $timeout/" $BOOTCONFIG
1258 if [ -n "$totaltimeout" ]; then
1259 sed -i -e "/^timeout.*$/a\totaltimeout\ $totaltimeout" $BOOTCONFIG
1262 if [ "$overlaysizemb" -gt 0 ]; then
1263 echo "Initializing persistent overlay file"
1264 OVERFILE="overlay-$( /sbin/blkid -s LABEL -o value $TGTDEV )-$( /sbin/blkid -s UUID -o value $TGTDEV )"
1265 if [ -z "$skipcopy" ]; then
1266 if [ "$TGTFS" = "vfat" ]; then
1267 # vfat can't handle sparse files
1268 dd if=/dev/zero of=$TGTMNT/$LIVEOS/$OVERFILE count=$overlaysizemb bs=1M
1269 else
1270 dd if=/dev/null of=$TGTMNT/$LIVEOS/$OVERFILE count=1 bs=1M seek=$overlaysizemb
1273 sed -i -e "s/r*d*.*live.*ima*ge*/& overlay=${TGTLABEL}/"\
1274 $BOOTCONFIG $BOOTCONFIG_EFI
1275 sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG $BOOTCONFIG_EFI
1278 if [ "$swapsizemb" -gt 0 -a -z "$skipcopy" ]; then
1279 echo "Initializing swap file"
1280 dd if=/dev/zero of=$TGTMNT/$LIVEOS/swap.img count=$swapsizemb bs=1M
1281 mkswap -f $TGTMNT/$LIVEOS/swap.img
1284 if [ "$homesizemb" -gt 0 -a -z "$skipcopy" ]; then
1285 echo "Initializing persistent /home"
1286 homesource=/dev/zero
1287 [ -n "$cryptedhome" ] && homesource=/dev/urandom
1288 if [ "$TGTFS" = "vfat" ]; then
1289 # vfat can't handle sparse files
1290 dd if=${homesource} of=$TGTMNT/$LIVEOS/$HOMEFILE count=$homesizemb bs=1M
1291 else
1292 dd if=/dev/null of=$TGTMNT/$LIVEOS/$HOMEFILE count=1 bs=1M seek=$homesizemb
1294 if [ -n "$cryptedhome" ]; then
1295 loop=$(losetup -f)
1296 losetup $loop $TGTMNT/$LIVEOS/$HOMEFILE
1298 echo "Encrypting persistent /home"
1299 while ! cryptsetup luksFormat -y -q $loop; do :; done;
1301 echo "Please enter the password again to unlock the device"
1302 while ! cryptsetup luksOpen $loop EncHomeFoo; do :; done;
1304 mkfs.ext4 -j /dev/mapper/EncHomeFoo
1305 tune2fs -c0 -i0 -ouser_xattr,acl /dev/mapper/EncHomeFoo
1306 sleep 2
1307 cryptsetup luksClose EncHomeFoo
1308 losetup -d $loop
1309 else
1310 echo "Formatting unencrypted /home"
1311 mkfs.ext4 -F -j $TGTMNT/$LIVEOS/$HOMEFILE
1312 tune2fs -c0 -i0 -ouser_xattr,acl $TGTMNT/$LIVEOS/$HOMEFILE
1316 # create the forth files for booting on the XO if requested
1317 # we'd do this unconditionally, but you have to have a kernel that will
1318 # boot on the XO anyway.
1319 if [ -n "$xo" ]; then
1320 echo "Setting up /boot/olpc.fth file"
1321 args=$(grep "^ *append" $TGTMNT/$SYSLINUXPATH/isolinux.cfg |head -n1 |sed -e 's/.*initrd=[^ ]*//')
1322 if [ -z "$xonohome" -a ! -f $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1323 args="$args persistenthome=mtd0"
1325 args="$args reset_overlay"
1326 xosyspath=$(echo $SYSLINUXPATH | sed -e 's;/;\\;')
1327 if [ ! -d $TGTMNT/boot ]; then
1328 mkdir -p $TGTMNT/boot
1330 cat > $TGTMNT/boot/olpc.fth <<EOF
1331 \ Boot script for USB boot
1332 hex rom-pa fffc7 + 4 \$number drop h# 2e19 < [if]
1333 patch 2drop erase claim-params
1334 : high-ramdisk ( -- )
1335 cv-load-ramdisk
1336 h# 22c +lp l@ 1+ memory-limit umin /ramdisk - ffff.f000 and ( new-ramdisk-adr )
1337 ramdisk-adr over /ramdisk move ( new-ramdisk-adr )
1338 to ramdisk-adr
1340 ' high-ramdisk to load-ramdisk
1341 [then]
1343 : set-bootpath-dev ( -- )
1344 " /chosen" find-package if ( phandle )
1345 " bootpath" rot get-package-property 0= if ( propval$ )
1346 get-encoded-string ( bootpath$ )
1347 [char] \ left-parse-string 2nip ( dn$ )
1348 dn-buf place ( )
1349 then
1350 then
1352 " /sd" dn-buf count sindex 0>= if
1353 " sd:"
1354 else
1355 " u:"
1356 then
1357 " BOOTPATHDEV" \$set-macro
1360 set-bootpath-dev
1361 " $args" to boot-file
1362 " \${BOOTPATHDEV}$xosyspath\initrd0.img" expand$ to ramdisk
1363 " \${BOOTPATHDEV}$xosyspath\vmlinuz0" expand$ to boot-device
1364 unfreeze
1365 boot
1370 if [ -z "$multi" ]; then
1371 echo "Installing boot loader"
1372 if [ -n "$efi" ]; then
1373 # replace the ia32 hack
1374 if [ -f "$TGTMNT$EFI_BOOT/BOOT.conf" ]; then
1375 cp -f $TGTMNT$EFI_BOOT/BOOTia32.conf $TGTMNT$EFI_BOOT/BOOT.conf
1379 # this is a bit of a kludge, but syslinux doesn't guarantee the API for its com32 modules :/
1380 if [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/share/syslinux/vesamenu.c32 ]; then
1381 cp /usr/share/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1382 elif [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/lib/syslinux/vesamenu.c32 ]; then
1383 cp /usr/lib/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1384 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/share/syslinux/menu.c32 ]; then
1385 cp /usr/share/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1386 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/lib/syslinux/menu.c32 ]; then
1387 cp /usr/lib/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1390 if [ "$TGTFS" == "vfat" -o "$TGTFS" == "msdos" ]; then
1391 # syslinux expects the config to be named syslinux.cfg
1392 # and has to run with the file system unmounted
1393 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1394 # deal with mtools complaining about ldlinux.sys
1395 if [ -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys ]; then
1396 rm -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1398 cleanup
1399 if [ -n "$SYSLINUXPATH" ]; then
1400 syslinux -d $SYSLINUXPATH $TGTDEV
1401 else
1402 syslinux $TGTDEV
1404 elif [ "$TGTFS" == "ext2" -o "$TGTFS" == "ext3" -o "$TGTFS" == "ext4" -o "$TGTFS" == "btrfs" ]; then
1405 # extlinux expects the config to be named extlinux.conf
1406 # and has to be run with the file system mounted
1407 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/extlinux.conf
1408 extlinux -i $TGTMNT/$SYSLINUXPATH
1409 # Starting with syslinux 4 ldlinux.sys is used on all file systems.
1410 if [ -f "$TGTMNT/$SYSLINUXPATH/extlinux.sys" ]; then
1411 chattr -i $TGTMNT/$SYSLINUXPATH/extlinux.sys
1412 elif [ -f "$TGTMNT/$SYSLINUXPATH/ldlinux.sys" ]; then
1413 chattr -i $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1415 cleanup
1417 else
1418 # we need to do some more config file tweaks for multi-image mode
1419 sed -i -e "s;kernel vm;kernel /$LIVEOS/syslinux/vm;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1420 sed -i -e "s;initrd=i;initrd=/$LIVEOS/syslinux/i;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1421 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1422 cleanup
1425 echo "Target device is now set up with a Live image!"