drop 'xdriver=vesa' from basic graphics mode parameters (per ajax)
[livecd.git] / tools / livecd-iso-to-disk.sh
blob0759dee1ebc078da692a42c0b2e126c0f7c92dfe
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] [--label label]
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 --label label
257 Specifies a specific label instead of default LIVE. Useful when you do
258 unattended installs which pas a label to inst.ks
260 CONTRIBUTORS
262 livecd-iso-to-disk: David Zeuthen, Jeremy Katz, Douglas McClendon,
263 Chris Curran and other contributors.
264 (See the AUTHORS file in the source distribution for
265 the complete list of credits.)
267 BUGS
269 Report bugs to the mailing list
270 http://admin.fedoraproject.org/mailman/listinfo/livecd or directly to
271 Bugzilla http://bugzilla.redhat.com/bugzilla/ against the Fedora product,
272 and the livecd-tools component.
274 COPYRIGHT
276 Copyright (C) Fedora Project 2008, 2009, 2010 and various contributors.
277 This is free software. You may redistribute copies of it under the terms of
278 the GNU General Public License http://www.gnu.org/licenses/gpl.html.
279 There is NO WARRANTY, to the extent permitted by law.
281 SEE ALSO
283 livecd-creator, project website http://fedoraproject.org/wiki/FedoraLiveCD
285 exit 1
288 cleanup() {
289 sleep 2
290 [ -d "$SRCMNT" ] && umount $SRCMNT && rmdir $SRCMNT
291 [ -d "$TGTMNT" ] && umount $TGTMNT && rmdir $TGTMNT
294 exitclean() {
295 RETVAL=$?
296 if [ -d "$SRCMNT" ] || [ -d "$TGTMNT" ];
297 then
298 [ "$RETVAL" = 0 ] || echo "Cleaning up to exit..."
299 cleanup
301 exit $RETVAL
304 isdevloop() {
305 [ x"${1#/dev/loop}" != x"$1" ]
308 getdisk() {
309 DEV=$1
311 if isdevloop "$DEV"; then
312 device="$DEV"
313 return
316 p=$(udevadm info -q path -n $DEV)
317 if [ $? -gt 0 ]; then
318 echo "Error getting udev path to $DEV"
319 exitclean
321 if [ -e /sys/$p/device ]; then
322 device=$(basename /sys/$p)
323 else
324 device=$(basename $(readlink -f /sys/$p/../))
326 if [ ! -e /sys/block/$device -o ! -e /dev/$device ]; then
327 echo "Error finding block device of $DEV. Aborting!"
328 exitclean
331 device="/dev/$device"
332 # FIXME: weird dev names could mess this up I guess
333 p=/dev/$(basename $p)
334 partnum=${p##$device}
337 resetMBR() {
338 if isdevloop "$DEV"; then
339 return
341 getdisk $1
342 # if efi, we need to use the hybrid MBR
343 if [ -n "$efi" ]; then
344 if [ -f /usr/lib/syslinux/gptmbr.bin ]; then
345 cat /usr/lib/syslinux/gptmbr.bin > $device
346 elif [ -f /usr/share/syslinux/gptmbr.bin ]; then
347 cat /usr/share/syslinux/gptmbr.bin > $device
348 else
349 echo "Could not find gptmbr.bin (syslinux)"
350 exitclean
352 # Make it bootable on EFI and BIOS
353 parted -s $device set $partnum legacy_boot on
354 else
355 if [ -f /usr/lib/syslinux/mbr.bin ]; then
356 cat /usr/lib/syslinux/mbr.bin > $device
357 elif [ -f /usr/share/syslinux/mbr.bin ]; then
358 cat /usr/share/syslinux/mbr.bin > $device
359 else
360 echo "Could not find mbr.bin (syslinux)"
361 exitclean
366 checkMBR() {
367 if isdevloop "$DEV"; then
368 return 0
370 getdisk $1
372 bs=$(mktemp /tmp/bs.XXXXXX)
373 dd if=$device of=$bs bs=512 count=1 2>/dev/null || exit 2
375 mbrword=$(hexdump -n 2 $bs |head -n 1|awk {'print $2;'})
376 rm -f $bs
377 if [ "$mbrword" = "0000" ]; then
378 if [ -z "$format" ]; then
379 echo "MBR appears to be blank."
380 echo "Press Enter to replace the MBR and continue or ctrl-c to abort"
381 read
383 resetMBR $1
386 return 0
389 checkPartActive() {
390 dev=$1
391 getdisk $dev
393 # if we're installing to whole-disk and not a partition, then we
394 # don't need to worry about being active
395 if [ "$dev" = "$device" ]; then
396 return
398 if isdevloop "$DEV"; then
399 return
402 if [ "$(/sbin/fdisk -l $device 2>/dev/null |grep -m1 $dev |awk {'print $2;'})" != "*" ]; then
403 echo "Partition isn't marked bootable!"
404 echo "You can mark the partition as bootable with "
405 echo " # /sbin/parted $device"
406 echo " (parted) toggle N boot"
407 echo " (parted) quit"
408 exitclean
412 checkLVM() {
413 dev=$1
415 if [ -x /sbin/pvs -a \
416 "$(/sbin/pvs -o vg_name --noheadings $dev* 2>/dev/null || :)" ]; then
417 echo "Device, $dev, contains a volume group and cannot be formated!"
418 echo "You can remove the volume group using vgremove."
419 exitclean
421 return 0
424 createGPTLayout() {
425 dev=$1
426 getdisk $dev
428 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
429 echo "Press Enter to continue or ctrl-c to abort"
430 read
431 umount ${device}* &> /dev/null || :
432 wipefs -a ${device}
433 /sbin/parted --script $device mklabel gpt
434 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit MB print" |grep ^$device:)
435 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
436 p1_size=$(($dev_size - 3))
438 if [ $p1_size -le 0 ]; then
439 echo "Your device isn't big enough to hold $SRC"
440 echo "It is $(($p1_size * -1)) MB too small"
441 exitclean
443 p1_start=1
444 p1_end=$(($p1_size + 1))
445 /sbin/parted -s $device u MB mkpart '"EFI System Partition"' fat32 $p1_start $p1_end set 1 boot on
446 # Sometimes automount can be _really_ annoying.
447 echo "Waiting for devices to settle..."
448 /sbin/udevadm settle
449 sleep 5
450 TGTDEV=${device}1
451 umount $TGTDEV &> /dev/null || :
452 /sbin/mkdosfs -n $label $TGTDEV
453 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
456 createMSDOSLayout() {
457 dev=$1
458 getdisk $dev
460 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
461 echo "Press Enter to continue or ctrl-c to abort"
462 read
463 umount ${device}* &> /dev/null || :
464 wipefs -a ${device}
465 /sbin/parted --script $device mklabel msdos
466 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit MB print" |grep ^$device:)
467 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
468 p1_size=$(($dev_size - 3))
470 if [ $p1_size -le 0 ]; then
471 echo "Your device isn't big enough to hold $SRC"
472 echo "It is $(($p1_size * -1)) MB too small"
473 exitclean
475 p1_start=1
476 p1_end=$(($p1_size + 1))
477 /sbin/parted -s $device u MB mkpart primary fat32 $p1_start $p1_end set 1 boot on
478 # Sometimes automount can be _really_ annoying.
479 echo "Waiting for devices to settle..."
480 /sbin/udevadm settle
481 sleep 5
482 if ! isdevloop "$DEV"; then
483 TGTDEV=${device}1
484 else
485 TGTDEV=${device}
487 umount $TGTDEV &> /dev/null || :
488 /sbin/mkdosfs -n LIVE $TGTDEV
489 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
492 createEXTFSLayout() {
493 dev=$1
494 getdisk $dev
496 echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
497 echo "Press Enter to continue or ctrl-c to abort"
498 read
499 umount ${device}* &> /dev/null || :
500 wipefs -a ${device}
501 /sbin/parted -s $device mklabel msdos
502 partinfo=$(LC_ALL=C /sbin/parted -s -m $device "u MB print" |grep ^$device:)
503 dev_size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/MB$//')
504 p1_size=$(($dev_size - 3))
506 if [ $p1_size -le 0 ]; then
507 echo "Your device isn't big enough to hold $SRC"
508 echo "It is $(($p1_size * -1)) MB too small"
509 exitclean
511 p1_start=1
512 p1_end=$(($p1_size + 1))
513 /sbin/parted -s $device u MB mkpart primary ext2 $p1_start $p1_end set 1 boot on
514 # Sometimes automount can be _really_ annoying.
515 echo "Waiting for devices to settle..."
516 /sbin/udevadm settle
517 sleep 5
518 TGTDEV=${device}1
519 umount $TGTDEV &> /dev/null || :
521 # Check extlinux version
522 if extlinux -v 2>&1 | grep -q 'extlinux 3'; then
523 mkfs=/sbin/mkfs.ext3
524 else
525 mkfs=/sbin/mkfs.ext4
527 $mkfs -L $label $TGTDEV
528 TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
531 checkGPT() {
532 dev=$1
533 getdisk $dev
535 if [ "$(/sbin/parted -m $device p 2>/dev/null |grep -ic :gpt:)" -eq "0" ]; then
536 echo "EFI boot requires a GPT partition table."
537 echo "This can be done manually or you can run with --format"
538 exitclean
541 partinfo=$(LC_ALL=C /sbin/parted --script -m $device "print" |grep ^$partnum:)
542 volname=$(echo $partinfo |cut -d : -f 6)
543 flags=$(echo $partinfo |cut -d : -f 7)
544 if [ "$volname" != "EFI System Partition" ]; then
545 echo "Partition name must be 'EFI System Partition'"
546 echo "This can be set in parted or you can run with --reset-mbr"
547 exitclean
549 if [ "$(echo $flags |grep -c boot)" = "0" ]; then
550 echo "Partition isn't marked bootable!"
551 echo "You can mark the partition as bootable with "
552 echo " # /sbin/parted $device"
553 echo " (parted) toggle N boot"
554 echo " (parted) quit"
555 exitclean
559 checkFilesystem() {
560 dev=$1
562 TGTFS=$(/sbin/blkid -s TYPE -o value $dev || :)
563 if [ "$TGTFS" != "vfat" ] && [ "$TGTFS" != "msdos" ]; then
564 if [ "$TGTFS" != "ext2" ] && [ "$TGTFS" != "ext3" ] && [ "$TGTFS" != "ext4" ] && [ "$TGTFS" != "btrfs" ]; then
565 echo "Target filesystem ($dev:$TGTFS) must be vfat, ext[234] or btrfs"
566 exitclean
570 TGTLABEL=$(/sbin/blkid -s LABEL -o value $dev)
571 if [ "$TGTLABEL" != "$label" ]; then
572 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
573 /sbin/dosfslabel $dev $label
574 if [ $? -gt 0 ]; then
575 echo "dosfslabel failed on $dev, device not setup"
576 exitclean
578 elif [ "$TGTFS" = "ext2" -o "$TGTFS" = "ext3" -o "$TGTFS" = "ext4" ]; then
579 /sbin/e2label $dev $label
580 if [ $? -gt 0 ]; then
581 echo "e2label failed on $dev, device not setup"
582 exitclean
584 else
585 echo "Unknown filesystem type. Try setting its label to $label and re-running"
586 exitclean
590 # Use UUID if available
591 TGTUUID=$(/sbin/blkid -s UUID -o value $dev)
592 if [ -n "$TGTUUID" ]; then
593 TGTLABEL="UUID=$TGTUUID"
594 else
595 TGTLABEL="LABEL=$label"
598 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
599 mountopts="-o shortname=winnt,umask=0077"
603 checkSyslinuxVersion() {
604 if [ ! -x /usr/bin/syslinux ]; then
605 echo "You need to have syslinux installed to run this script"
606 exit 1
608 check=($(syslinux --version 2>&1)) || :
609 if [[ 'syslinux' != $check ]]; then
610 SYSLINUXPATH=""
611 elif [ -n "$multi" ]; then
612 SYSLINUXPATH="$LIVEOS/syslinux"
613 else
614 SYSLINUXPATH="syslinux"
618 checkMounted() {
619 dev=$1
620 if grep -q "^$dev " /proc/mounts ; then
621 echo "$dev is mounted, please unmount for safety"
622 exitclean
624 if grep -q "^$dev " /proc/swaps; then
625 echo "$dev is in use as a swap device, please disable swap"
626 exitclean
630 checkint() {
631 if ! test $1 -gt 0 2>/dev/null ; then
632 shortusage
633 exit 1
637 if [ $(id -u) != 0 ]; then
638 echo "You need to be root to run this script"
639 exit 1
642 detectsrctype() {
643 if [[ -e "$SRCMNT/Packages" ]]; then
644 echo "/Packages found, will copy source packages to target"
645 packages=1
647 if [[ -e "$SRCMNT/LiveOS/squashfs.img" ]]; then
648 # LiveOS style boot image
649 srctype=live
650 return
652 if [ -e $SRCMNT/images/install.img -o -e $SRCMNT/isolinux/initrd.img ]; then
653 if [ -n "$packages" ]; then
654 srctype=installer
655 else
656 srctype=netinst
658 imgtype=install
659 if [ ! -e $SRCMNT/images/install.img ]; then
660 echo "$SRC uses initrd.img w/o install.img"
661 imgtype=initrd
663 return
665 echo "ERROR: $SRC does not appear to be a Live image or DVD installer."
666 exitclean
669 cp_p() {
670 strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
671 | awk '{
672 count += $NF
673 if (count % 10 == 0) {
674 percent = count / total_size * 100
675 printf "%3d%% [", percent
676 for (i=0;i<=percent;i++)
677 printf "="
678 printf ">"
679 for (i=percent;i<100;i++)
680 printf " "
681 printf "]\r"
684 END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
687 copyFile() {
688 if [ -x /usr/bin/rsync ]; then
689 rsync --inplace -P "$1" "$2"
690 return
692 if [ -x /usr/bin/gvfs-copy ]; then
693 gvfs-copy -p "$1" "$2"
694 return
696 if [ -x /usr/bin/strace -a -x /bin/awk ]; then
697 cp_p "$1" "$2"
698 return
700 cp "$1" "$2"
703 set -e
704 set -o pipefail
705 trap exitclean EXIT
706 shopt -s extglob
708 cryptedhome=1
709 keephome=1
710 homesizemb=0
711 swapsizemb=0
712 overlaysizemb=0
713 srctype=
714 imgtype=
715 packages=
716 LIVEOS=LiveOS
717 HOMEFILE="home.img"
718 updates=
720 label="LIVE"
722 if [[ "$*" =~ "--help" ]]; then
723 usage
725 while [ $# -gt 2 ]; do
726 case $1 in
727 --help)
728 usage
730 --noverify)
731 noverify=1
733 --format)
734 format=1
736 --msdos)
737 usemsdos=1
739 --reset-mbr|--resetmbr)
740 resetmbr=1
742 --efi|--mactel)
743 efi=1
745 --skipcopy)
746 skipcopy=1
748 --force)
749 force=1
751 --xo)
752 xo=1
753 skipcompress=1
755 --xo-no-home)
756 xonohome=1
758 --timeout)
759 checkint $2
760 timeout=$2
761 shift
763 --totaltimeout)
764 checkint $2
765 totaltimeout=$2
766 shift
768 --extra-kernel-args)
769 kernelargs=$2
770 shift
772 --multi)
773 multi=1
775 --livedir)
776 LIVEOS=$2
777 shift
779 --compress)
780 skipcompress=""
782 --skipcompress)
783 skipcompress=1
785 --swap-size-mb)
786 checkint $2
787 swapsizemb=$2
788 shift
790 --overlay-size-mb)
791 checkint $2
792 overlaysizemb=$2
793 shift
795 --home-size-mb)
796 checkint $2
797 homesizemb=$2
798 shift
800 --crypted-home)
801 cryptedhome=1
803 --unencrypted-home)
804 cryptedhome=""
806 --delete-home)
807 keephome=""
809 --updates)
810 updates=$2
811 shift
813 --ks)
814 ks=$2
815 shift
817 --label)
818 label=$2
819 shift
822 echo "invalid arg -- $1"
823 shortusage
824 exit 1
826 esac
827 shift
828 done
830 SRC=$(readlink -f "$1")
831 TGTDEV=$(readlink -f "$2")
833 if [ -z "$SRC" ]; then
834 echo "Missing source"
835 shortusage
836 exit 1
839 if [ ! -b "$SRC" -a ! -f "$SRC" ]; then
840 echo "$SRC is not a file or block device"
841 shortusage
842 exit 1
845 if [ -z "$TGTDEV" ]; then
846 echo "Missing target device"
847 shortusage
848 exit 1
851 if [ ! -b "$TGTDEV" ]; then
852 echo "$TGTDEV is not a block device"
853 shortusage
854 exit 1
857 if [ -z "$noverify" ]; then
858 # verify the image
859 echo "Verifying image..."
860 if ! checkisomd5 --verbose "$SRC"; then
861 echo "Are you SURE you want to continue?"
862 echo "Press Enter to continue or ctrl-c to abort"
863 read
867 # do some basic sanity checks.
868 checkMounted $TGTDEV
870 # FIXME: would be better if we had better mountpoints
871 SRCMNT=$(mktemp -d /media/srctmp.XXXXXX)
872 if [ -b "$SRC" ]; then
873 mount -o ro "$SRC" $SRCMNT || exitclean
874 elif [ -f "$SRC" ]; then
875 mount -o loop,ro "$SRC" $SRCMNT || exitclean
876 else
877 echo "$SRC is not a file or block device."
878 exitclean
880 # Figure out what needs to be done based on the source image
881 detectsrctype
883 # Format the device
884 if [ -n "$format" -a -z "$skipcopy" ]; then
885 checkLVM $TGTDEV
887 if [ -n "$efi" ]; then
888 createGPTLayout $TGTDEV
889 elif [ -n "$usemsdos" -o ! -x /sbin/extlinux ]; then
890 createMSDOSLayout $TGTDEV
891 else
892 createEXTFSLayout $TGTDEV
896 checkFilesystem $TGTDEV
897 if [ -n "$efi" ]; then
898 checkGPT $TGTDEV
901 checkSyslinuxVersion
902 # Because we can't set boot flag for EFI Protective on msdos partition tables
903 [ -z "$efi" ] && checkPartActive $TGTDEV
904 [ -n "$resetmbr" ] && resetMBR $TGTDEV
905 checkMBR $TGTDEV
908 if [ "$overlaysizemb" -gt 0 ]; then
909 if [ "$TGTFS" = "vfat" -a "$overlaysizemb" -gt 4095 ]; then
910 echo "Can't have an overlay of 4095MB or greater on VFAT"
911 exitclean
913 LABEL=$(/sbin/blkid -s LABEL -o value $TGTDEV)
914 if [[ "$LABEL" =~ ( ) ]]; then
915 echo "The LABEL($LABEL) on $TGTDEV has spaces in it, which do not work with the overlay"
916 echo "You can re-format or use dosfslabel/e2fslabel to change it"
917 exitclean
921 if [ "$homesizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
922 if [ "$homesizemb" -gt 4095 ]; then
923 echo "Can't have a home overlay greater than 4095MB on VFAT"
924 exitclean
928 if [ "$swapsizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
929 if [ "$swapsizemb" -gt 4095 ]; then
930 echo "Can't have a swap file greater than 4095MB on VFAT"
931 exitclean
935 TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX)
936 mount $mountopts $TGTDEV $TGTMNT || exitclean
938 trap exitclean SIGINT SIGTERM
940 if [ -f "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" -a "$homesizemb" -gt 0 ]; then
941 echo "ERROR: Requested keeping existing /home and specified a size for /home"
942 echo "Please either don't specify a size or specify --delete-home"
943 exitclean
946 if [ -n "$efi" ]; then
947 if [ -d $SRCMNT/EFI/BOOT ]; then
948 EFI_BOOT="/EFI/BOOT"
949 elif [ -d $SRCMNT/EFI/boot ]; then
950 EFI_BOOT="/EFI/boot"
951 else
952 echo "ERROR: This live image does not support EFI booting"
953 exitclean
957 # let's try to make sure there's enough room on the target device
958 if [[ -d $TGTMNT/$LIVEOS ]]; then
959 tbd=($(du -B 1M $TGTMNT/$LIVEOS))
960 if [[ -s $TGTMNT/$LIVEOS/$HOMEFILE ]] && [[ -n $keephome ]]; then
961 homesize=($(du -B 1M $TGTMNT/$LIVEOS/$HOMEFILE))
962 tbd=$((tbd - homesize))
964 else
965 tbd=0
968 if [[ live == $srctype ]]; then
969 targets="$TGTMNT/$SYSLINUXPATH"
970 [[ -n $efi ]] && targets+=" $TGTMNT$EFI_BOOT"
971 [[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"
972 target_size=$(du -s -c -B 1M $targets 2> /dev/null | awk '/total$/ {print $1;}') || :
973 tbd=$((tbd + target_size))
976 if [[ -n $skipcompress ]] && [[ -s $SRCMNT/LiveOS/squashfs.img ]]; then
977 if mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT; then
978 livesize=($(du -B 1M --apparent-size $SRCMNT/LiveOS/ext3fs.img))
979 umount $SRCMNT
980 if ((livesize > 4095)) && [[ vfat == $TGTFS ]]; then
981 echo "
982 An uncompressed image size greater than 4095 MB is not suitable
983 for a VFAT-formatted device. The compressed SquashFS will be
984 copied to the target device.
986 skipcompress=""
987 livesize=0
989 else
990 echo "WARNING: --skipcompress or --xo was specified but the
991 currently-running kernel can not mount the SquashFS from the source
992 file to extract it. Instead, the compressed SquashFS will be copied
993 to the target device."
994 skipcompress=""
997 if [[ live == $srctype ]]; then
998 thisScriptpath=$(readlink -f "$0")
999 sources="$SRCMNT/LiveOS/ext3fs.img $SRCMNT/LiveOS/osmin.img"
1000 [[ -z $skipcompress ]] && sources+=" $SRCMNT/LiveOS/squashfs.img"
1001 sources+=" $SRCMNT/isolinux $SRCMNT/syslinux"
1002 [[ -n $efi ]] && sources+=" $SRCMNT$EFI_BOOT"
1003 [[ -n $xo ]] && sources+=" $SRCMNT/boot/olpc.fth"
1004 source_size=$(du -s -c -B 1M "$thisScriptpath" $sources 2> /dev/null | awk '/total$/ {print $1;}') || :
1005 livesize=$((livesize + source_size))
1008 freespace=$(df -B 1M --total $TGTDEV | awk '/^total/ {print $4;}')
1010 if [[ live == $srctype ]]; then
1011 tba=$((overlaysizemb + homesizemb + livesize + swapsizemb))
1012 if ((tba > freespace + tbd)); then
1013 needed=$((tba - freespace - tbd))
1014 printf "\n The live image + overlay, home, & swap space, if requested,
1015 \r will NOT fit in the space available on the target device.\n
1016 \r + Size of live image: %10s MiB\n" $livesize
1017 (($overlaysizemb > 0)) && \
1018 printf " + Overlay size: %16s\n" $overlaysizemb
1019 (($homesizemb > 0)) && \
1020 printf " + Home directory size: %9s\n" $homesizemb
1021 (($swapsizemb > 0)) && \
1022 printf " + Swap overlay size: %11s\n" $swapsizemb
1023 printf " = Total requested space: %6s MiB\n" $tba
1024 printf " - Space available: %12s\n" $((freespace + tbd))
1025 printf " ==============================\n"
1026 printf " Space needed: %15s MiB\n\n" $needed
1027 printf " To fit the installation on this device,
1028 \r free space on the target, or decrease the
1029 \r requested size total by: %6s MiB\n\n" $needed
1030 exitclean
1034 # Verify available space for DVD installer
1035 if [ "$srctype" = "installer" ]; then
1036 if [ "$imgtype" = "install" ]; then
1037 imgpath=images/install.img
1038 else
1039 imgpath=isolinux/initrd.img
1041 installimgsize=$(du -s -B 1M $SRCMNT/$imgpath | awk {'print $1;'})
1043 tbd=0
1044 if [ -e $TGTMNT/$imgpath ]; then
1045 tbd=$(du -s -B 1M $TGTMNT/$imgpath | awk {'print $1;'})
1047 if [ -e "$TGTMNT/$(basename "$SRC")" ]; then
1048 tbd=$(($tbd + $(du -s -B 1M "$TGTMNT/$(basename "$SRC")" | awk {'print $1;'})))
1050 echo "Size of $imgpath: $installimgsize"
1051 echo "Available space: $((freespace + tbd))"
1052 if (( installimgsize > ((freespace + tbd)) )); then
1053 echo "ERROR: Unable to fit DVD image + install.img on available space on the target device."
1054 exitclean
1058 if [ -z "$skipcopy" ] && [ "$srctype" = "live" ]; then
1059 if [ -d $TGTMNT/$LIVEOS -a -z "$force" ]; then
1060 echo "Already set up as live image."
1061 if [ -z "$keephome" -a -e $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1062 echo "WARNING: Persistent /home will be deleted!!!"
1063 echo "Press Enter to continue or ctrl-c to abort"
1064 read
1065 else
1066 echo "Deleting old OS in fifteen seconds..."
1067 sleep 15
1069 [ -e "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" ] && mv $TGTMNT/$LIVEOS/$HOMEFILE $TGTMNT/$HOMEFILE
1072 rm -rf $TGTMNT/$LIVEOS
1076 # Bootloader is always reconfigured, so keep these out of the if skipcopy stuff.
1077 [ ! -d $TGTMNT/$SYSLINUXPATH ] && mkdir -p $TGTMNT/$SYSLINUXPATH
1078 [ -n "$efi" -a ! -d $TGTMNT$EFI_BOOT ] && mkdir -p $TGTMNT$EFI_BOOT
1080 # Live image copy
1081 if [ "$srctype" = "live" -a -z "$skipcopy" ]; then
1082 echo "Copying live image to target device."
1083 [ ! -d $TGTMNT/$LIVEOS ] && mkdir $TGTMNT/$LIVEOS
1084 [ -n "$keephome" -a -f "$TGTMNT/$HOMEFILE" ] && mv $TGTMNT/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE
1085 if [ -n "$skipcompress" -a -f $SRCMNT/LiveOS/squashfs.img ]; then
1086 mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT || exitclean
1087 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || {
1088 umount $SRCMNT ; exitclean ; }
1089 umount $SRCMNT
1090 elif [ -f $SRCMNT/LiveOS/squashfs.img ]; then
1091 copyFile $SRCMNT/LiveOS/squashfs.img $TGTMNT/$LIVEOS/squashfs.img || exitclean
1092 elif [ -f $SRCMNT/LiveOS/ext3fs.img ]; then
1093 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || exitclean
1095 if [ -f $SRCMNT/LiveOS/osmin.img ]; then
1096 copyFile $SRCMNT/LiveOS/osmin.img $TGTMNT/$LIVEOS/osmin.img || exitclean
1098 sync
1101 # Adjust syslinux sources for replication of installed images
1102 # between filesystem types.
1103 if [[ -d $SRCMNT/isolinux/ ]]; then
1104 cp $SRCMNT/isolinux/* $TGTMNT/$SYSLINUXPATH
1105 elif [[ -d $SRCMNT/syslinux/ ]]; then
1106 cp $SRCMNT/syslinux/* $TGTMNT/$SYSLINUXPATH
1107 if [[ -f $SRCMNT/syslinux/extlinux.conf ]]; then
1108 mv $TGTMNT/$SYSLINUXPATH/extlinux.conf \
1109 $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1110 elif [[ -f $SRCMNT/syslinux/syslinux.cfg ]]; then
1111 mv $TGTMNT/$SYSLINUXPATH/syslinux.cfg $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1114 BOOTCONFIG=$TGTMNT/$SYSLINUXPATH/isolinux.cfg
1115 # Set this to nothing so sed doesn't care
1116 BOOTCONFIG_EFI=
1117 if [ -n "$efi" ]; then
1118 echo "Setting up $EFI_BOOT"
1119 cp -r $SRCMNT$EFI_BOOT/* $TGTMNT$EFI_BOOT
1121 # The GRUB EFI config file can be one of:
1122 # boot?*.conf
1123 # BOOT?*.conf
1124 # grub.cfg
1125 if [ -e $TGTMNT$EFI_BOOT/grub.cfg ]; then
1126 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/grub.cfg
1127 elif [ -e $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf ]; then
1128 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf
1129 else
1130 echo "Unable to find EFI config file."
1131 exitclean
1133 rm -f $TGTMNT$EFI_BOOT/grub.conf
1135 # On some images (RHEL) the BOOT*.efi file isn't in $EFI_BOOT, but is in
1136 # the eltorito image, so try to extract it if it is missing
1138 # test for presence of *.efi grub binary
1139 if [ ! -f $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1140 if [ ! -x /usr/bin/dumpet ]; then
1141 echo "No /usr/bin/dumpet tool found. EFI image will not boot."
1142 echo "Source media is missing grub binary in /EFI/BOOT/*efi"
1143 exitclean
1144 else
1145 # dump the eltorito image with dumpet, output is $SRC.1
1146 dumpet -i "$SRC" -d
1147 EFIMNT=$(mktemp -d /media/srctmp.XXXXXX)
1148 mount -o loop "$SRC".1 $EFIMNT
1150 if [ -f $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1151 cp $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi $TGTMNT$EFI_BOOT
1152 else
1153 echo "No BOOT*.efi found in eltorito image. EFI will not boot"
1154 umount $EFIMNT
1155 rm "$SRC".1
1156 exitclean
1158 umount $EFIMNT
1159 rm "$SRC".1
1164 # DVD installer copy
1165 if [ -z "$skipcopy" -a \( "$srctype" = "installer" -o "$srctype" = "netinst" \) ]; then
1166 echo "Copying DVD image to target device."
1167 mkdir -p $TGTMNT/images/
1168 if [ "$imgtype" = "install" ]; then
1169 for img in install.img updates.img product.img; do
1170 if [ -e $SRCMNT/images/$img ]; then
1171 copyFile $SRCMNT/images/$img $TGTMNT/images/$img || exitclean
1173 done
1177 # Copy packages over.
1178 # Before Fedora17 we could copy the .iso and setup a repo=
1179 # F17 and later look for repodata on the source media.
1180 # The presence of packages and LiveOS indicates F17 or later.
1181 if [ -n "$packages" -a -z "$skipcopy" ]; then
1182 if [ "$srctype" != "live" ]; then
1183 echo "Copying $SRC to device"
1184 copyFile "$SRC" "$TGTMNT/"
1186 # Setup a repo= to point to the .iso
1187 sed -i -e "s;initrd.img;initrd.img repo=hd:$TGTLABEL:/;g" $BOOTCONFIG
1188 if [ -n "$efi" ]; then
1189 sed -i -e "s;vmlinuz;vmlinuz repo=hd:$TGTLABEL:/;g" $BOOTCONFIG_EFI
1191 else
1192 echo "Copying package data from $SRC to device"
1193 rsync --inplace -rLDP --exclude EFI/ --exclude images/ --exclude isolinux/ \
1194 --exclude TRANS.TBL --exclude LiveOS/ "$SRCMNT/" "$TGTMNT/"
1196 echo "Waiting for device to finish writing"
1197 sync
1200 if [ "$srctype" = "live" ]; then
1201 # Copy this installer script.
1202 cp -fT "$thisScriptpath" $TGTMNT/$LIVEOS/livecd-iso-to-disk
1203 chmod +x $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null || :
1205 # When the source is an installed Live USB/SD image, restore the boot config
1206 # file to a base state before updating.
1207 if [[ -d $SRCMNT/syslinux/ ]]; then
1208 echo "Preparing boot config file."
1209 sed -i -e "s/root=live:[^ ]*/root=live:CDLABEL=name/"\
1210 -e "s/\(r*d*.*live.*ima*ge*\) .* quiet/\1 quiet/"\
1211 $BOOTCONFIG $BOOTCONFIG_EFI
1212 sed -i -e "s/^timeout.*$/timeout\ 100/"\
1213 -e "/^totaltimeout.*$/d" $BOOTCONFIG
1217 # Setup the updates.img
1218 if [ -n "$updates" ]; then
1219 copyFile "$updates" "$TGTMNT/updates.img"
1220 kernelargs+=" inst.updates=hd:$TGTLABEL:/updates.img"
1223 # Setup the kickstart
1224 if [ -n "$ks" ]; then
1225 copyFile "$ks" "$TGTMNT/ks.cfg"
1226 kernelargs+=" inst.ks=hd:$TGTLABEL:/ks.cfg"
1229 echo "Updating boot config file"
1230 # adjust label and fstype
1231 sed -i -e "s/CDLABEL=[^ ]*/$TGTLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$TGTFS/" -e "s/LABEL=[^ :]*/$TGTLABEL/" $BOOTCONFIG $BOOTCONFIG_EFI
1232 if [ -n "$kernelargs" ]; then
1233 sed -i -e "s;initrd.\?\.img;& ${kernelargs};" $BOOTCONFIG
1234 if [ -n "$efi" ]; then
1235 sed -i -e "s;vmlinuz.\?;& ${kernelargs} ;" $BOOTCONFIG_EFI
1238 if [ "$LIVEOS" != "LiveOS" ]; then
1239 sed -i -e "s;r*d*.*live.*ima*ge*;& live_dir=$LIVEOS;"\
1240 $BOOTCONFIG $BOOTCONFIG_EFI
1243 # EFI images are in $SYSLINUXPATH now
1244 if [ -n "$efi" ]; then
1245 sed -i -e "s;/isolinux/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1246 sed -i -e "s;/images/pxeboot/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1247 sed -i -e "s;findiso;;g" $BOOTCONFIG_EFI
1250 # DVD Installer for netinst
1251 if [ "$srctype" != "live" ]; then
1252 if [ "$imgtype" = "install" ]; then
1253 sed -i -e "s;initrd.img;initrd.img stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG
1254 if [ -n "$efi" ]; then
1255 sed -i -e "s;vmlinuz;vmlinuz stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG_EFI
1257 else
1258 # The initrd has everything, so no stage2
1259 sed -i -e "s;stage2=\S*;;g" $BOOTCONFIG $BOOTCONFIG_EFI
1263 # Adjust the boot timeouts
1264 if [ -n "$timeout" ]; then
1265 sed -i -e "s/^timeout.*$/timeout\ $timeout/" $BOOTCONFIG
1267 if [ -n "$totaltimeout" ]; then
1268 sed -i -e "/^timeout.*$/a\totaltimeout\ $totaltimeout" $BOOTCONFIG
1271 if [ "$overlaysizemb" -gt 0 ]; then
1272 echo "Initializing persistent overlay file"
1273 OVERFILE="overlay-$( /sbin/blkid -s LABEL -o value $TGTDEV )-$( /sbin/blkid -s UUID -o value $TGTDEV )"
1274 if [ -z "$skipcopy" ]; then
1275 if [ "$TGTFS" = "vfat" ]; then
1276 # vfat can't handle sparse files
1277 dd if=/dev/zero of=$TGTMNT/$LIVEOS/$OVERFILE count=$overlaysizemb bs=1M
1278 else
1279 dd if=/dev/null of=$TGTMNT/$LIVEOS/$OVERFILE count=1 bs=1M seek=$overlaysizemb
1282 sed -i -e "s/r*d*.*live.*ima*ge*/& overlay=${TGTLABEL}/"\
1283 $BOOTCONFIG $BOOTCONFIG_EFI
1284 sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG $BOOTCONFIG_EFI
1287 if [ "$swapsizemb" -gt 0 -a -z "$skipcopy" ]; then
1288 echo "Initializing swap file"
1289 dd if=/dev/zero of=$TGTMNT/$LIVEOS/swap.img count=$swapsizemb bs=1M
1290 mkswap -f $TGTMNT/$LIVEOS/swap.img
1293 if [ "$homesizemb" -gt 0 -a -z "$skipcopy" ]; then
1294 echo "Initializing persistent /home"
1295 homesource=/dev/zero
1296 [ -n "$cryptedhome" ] && homesource=/dev/urandom
1297 if [ "$TGTFS" = "vfat" ]; then
1298 # vfat can't handle sparse files
1299 dd if=${homesource} of=$TGTMNT/$LIVEOS/$HOMEFILE count=$homesizemb bs=1M
1300 else
1301 dd if=/dev/null of=$TGTMNT/$LIVEOS/$HOMEFILE count=1 bs=1M seek=$homesizemb
1303 if [ -n "$cryptedhome" ]; then
1304 loop=$(losetup -f)
1305 losetup $loop $TGTMNT/$LIVEOS/$HOMEFILE
1307 echo "Encrypting persistent /home"
1308 while ! cryptsetup luksFormat -y -q $loop; do :; done;
1310 echo "Please enter the password again to unlock the device"
1311 while ! cryptsetup luksOpen $loop EncHomeFoo; do :; done;
1313 mkfs.ext4 -j /dev/mapper/EncHomeFoo
1314 tune2fs -c0 -i0 -ouser_xattr,acl /dev/mapper/EncHomeFoo
1315 sleep 2
1316 cryptsetup luksClose EncHomeFoo
1317 losetup -d $loop
1318 else
1319 echo "Formatting unencrypted /home"
1320 mkfs.ext4 -F -j $TGTMNT/$LIVEOS/$HOMEFILE
1321 tune2fs -c0 -i0 -ouser_xattr,acl $TGTMNT/$LIVEOS/$HOMEFILE
1325 # create the forth files for booting on the XO if requested
1326 # we'd do this unconditionally, but you have to have a kernel that will
1327 # boot on the XO anyway.
1328 if [ -n "$xo" ]; then
1329 echo "Setting up /boot/olpc.fth file"
1330 args=$(grep "^ *append" $TGTMNT/$SYSLINUXPATH/isolinux.cfg |head -n1 |sed -e 's/.*initrd=[^ ]*//')
1331 if [ -z "$xonohome" -a ! -f $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1332 args="$args persistenthome=mtd0"
1334 args="$args reset_overlay"
1335 xosyspath=$(echo $SYSLINUXPATH | sed -e 's;/;\\;')
1336 if [ ! -d $TGTMNT/boot ]; then
1337 mkdir -p $TGTMNT/boot
1339 cat > $TGTMNT/boot/olpc.fth <<EOF
1340 \ Boot script for USB boot
1341 hex rom-pa fffc7 + 4 \$number drop h# 2e19 < [if]
1342 patch 2drop erase claim-params
1343 : high-ramdisk ( -- )
1344 cv-load-ramdisk
1345 h# 22c +lp l@ 1+ memory-limit umin /ramdisk - ffff.f000 and ( new-ramdisk-adr )
1346 ramdisk-adr over /ramdisk move ( new-ramdisk-adr )
1347 to ramdisk-adr
1349 ' high-ramdisk to load-ramdisk
1350 [then]
1352 : set-bootpath-dev ( -- )
1353 " /chosen" find-package if ( phandle )
1354 " bootpath" rot get-package-property 0= if ( propval$ )
1355 get-encoded-string ( bootpath$ )
1356 [char] \ left-parse-string 2nip ( dn$ )
1357 dn-buf place ( )
1358 then
1359 then
1361 " /sd" dn-buf count sindex 0>= if
1362 " sd:"
1363 else
1364 " u:"
1365 then
1366 " BOOTPATHDEV" \$set-macro
1369 set-bootpath-dev
1370 " $args" to boot-file
1371 " \${BOOTPATHDEV}$xosyspath\initrd0.img" expand$ to ramdisk
1372 " \${BOOTPATHDEV}$xosyspath\vmlinuz0" expand$ to boot-device
1373 unfreeze
1374 boot
1379 if [ -z "$multi" ]; then
1380 echo "Installing boot loader"
1381 if [ -n "$efi" ]; then
1382 # replace the ia32 hack
1383 if [ -f "$TGTMNT$EFI_BOOT/BOOT.conf" ]; then
1384 cp -f $TGTMNT$EFI_BOOT/BOOTia32.conf $TGTMNT$EFI_BOOT/BOOT.conf
1388 # this is a bit of a kludge, but syslinux doesn't guarantee the API for its com32 modules :/
1389 if [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/share/syslinux/vesamenu.c32 ]; then
1390 cp /usr/share/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1391 elif [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/lib/syslinux/vesamenu.c32 ]; then
1392 cp /usr/lib/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1393 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/share/syslinux/menu.c32 ]; then
1394 cp /usr/share/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1395 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/lib/syslinux/menu.c32 ]; then
1396 cp /usr/lib/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1399 if [ "$TGTFS" == "vfat" -o "$TGTFS" == "msdos" ]; then
1400 # syslinux expects the config to be named syslinux.cfg
1401 # and has to run with the file system unmounted
1402 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1403 # deal with mtools complaining about ldlinux.sys
1404 if [ -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys ]; then
1405 rm -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1407 cleanup
1408 if [ -n "$SYSLINUXPATH" ]; then
1409 syslinux -d $SYSLINUXPATH $TGTDEV
1410 else
1411 syslinux $TGTDEV
1413 elif [ "$TGTFS" == "ext2" -o "$TGTFS" == "ext3" -o "$TGTFS" == "ext4" -o "$TGTFS" == "btrfs" ]; then
1414 # extlinux expects the config to be named extlinux.conf
1415 # and has to be run with the file system mounted
1416 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/extlinux.conf
1417 extlinux -i $TGTMNT/$SYSLINUXPATH
1418 # Starting with syslinux 4 ldlinux.sys is used on all file systems.
1419 if [ -f "$TGTMNT/$SYSLINUXPATH/extlinux.sys" ]; then
1420 chattr -i $TGTMNT/$SYSLINUXPATH/extlinux.sys
1421 elif [ -f "$TGTMNT/$SYSLINUXPATH/ldlinux.sys" ]; then
1422 chattr -i $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1424 cleanup
1426 else
1427 # we need to do some more config file tweaks for multi-image mode
1428 sed -i -e "s;kernel vm;kernel /$LIVEOS/syslinux/vm;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1429 sed -i -e "s;initrd=i;initrd=/$LIVEOS/syslinux/i;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1430 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1431 cleanup
1434 echo "Target device is now set up with a Live image!"