Use LC_ALL=C for parted calls (#1045854)
[livecd.git] / tools / livecd-iso-to-disk.sh
blobcccb225a352550ddcf935fdd53aad3b74ed4ac81
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 [ "$(LC_ALL=C /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 if [ "$TGTFS" = "ext2" -o "$TGTFS" = "ext3" -o "$TGTFS" = "ext4" -a ! -x /sbin/extlinux ]; then
571 echo "Target filesystem ($TGTFS) requires syslinux-extlinux to be installed."
572 exitclean
576 TGTLABEL=$(/sbin/blkid -s LABEL -o value $dev)
577 if [ "$TGTLABEL" != "$label" ]; then
578 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
579 /sbin/dosfslabel $dev $label
580 if [ $? -gt 0 ]; then
581 echo "dosfslabel failed on $dev, device not setup"
582 exitclean
584 elif [ "$TGTFS" = "ext2" -o "$TGTFS" = "ext3" -o "$TGTFS" = "ext4" ]; then
585 /sbin/e2label $dev $label
586 if [ $? -gt 0 ]; then
587 echo "e2label failed on $dev, device not setup"
588 exitclean
590 else
591 echo "Unknown filesystem type. Try setting its label to $label and re-running"
592 exitclean
596 # Use UUID if available
597 TGTUUID=$(/sbin/blkid -s UUID -o value $dev)
598 if [ -n "$TGTUUID" ]; then
599 TGTLABEL="UUID=$TGTUUID"
600 else
601 TGTLABEL="LABEL=$label"
604 if [ "$TGTFS" = "vfat" -o "$TGTFS" = "msdos" ]; then
605 mountopts="-o shortname=winnt,umask=0077"
609 checkSyslinuxVersion() {
610 if [ ! -x /usr/bin/syslinux ]; then
611 echo "You need to have syslinux installed to run this script"
612 exit 1
614 check=($(syslinux --version 2>&1)) || :
615 if [[ 'syslinux' != $check ]]; then
616 SYSLINUXPATH=""
617 elif [ -n "$multi" ]; then
618 SYSLINUXPATH="$LIVEOS/syslinux"
619 else
620 SYSLINUXPATH="syslinux"
624 checkMounted() {
625 dev=$1
626 if grep -q "^$dev " /proc/mounts ; then
627 echo "$dev is mounted, please unmount for safety"
628 exitclean
630 if grep -q "^$dev " /proc/swaps; then
631 echo "$dev is in use as a swap device, please disable swap"
632 exitclean
636 checkint() {
637 if ! test $1 -gt 0 2>/dev/null ; then
638 shortusage
639 exit 1
643 if [ $(id -u) != 0 ]; then
644 echo "You need to be root to run this script"
645 exit 1
648 detectsrctype() {
649 if [[ -e "$SRCMNT/Packages" ]]; then
650 echo "/Packages found, will copy source packages to target"
651 packages=1
653 if [[ -e "$SRCMNT/LiveOS/squashfs.img" ]]; then
654 # LiveOS style boot image
655 srctype=live
656 return
658 if [ -e $SRCMNT/images/install.img -o -e $SRCMNT/isolinux/initrd.img ]; then
659 if [ -n "$packages" ]; then
660 srctype=installer
661 else
662 srctype=netinst
664 imgtype=install
665 if [ ! -e $SRCMNT/images/install.img ]; then
666 echo "$SRC uses initrd.img w/o install.img"
667 imgtype=initrd
669 return
671 echo "ERROR: $SRC does not appear to be a Live image or DVD installer."
672 exitclean
675 cp_p() {
676 strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
677 | awk '{
678 count += $NF
679 if (count % 10 == 0) {
680 percent = count / total_size * 100
681 printf "%3d%% [", percent
682 for (i=0;i<=percent;i++)
683 printf "="
684 printf ">"
685 for (i=percent;i<100;i++)
686 printf " "
687 printf "]\r"
690 END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
693 copyFile() {
694 if [ -x /usr/bin/rsync ]; then
695 rsync --inplace -P "$1" "$2"
696 return
698 if [ -x /usr/bin/gvfs-copy ]; then
699 gvfs-copy -p "$1" "$2"
700 return
702 if [ -x /usr/bin/strace -a -x /bin/awk ]; then
703 cp_p "$1" "$2"
704 return
706 cp "$1" "$2"
709 set -e
710 set -o pipefail
711 trap exitclean EXIT
712 shopt -s extglob
714 cryptedhome=1
715 keephome=1
716 homesizemb=0
717 swapsizemb=0
718 overlaysizemb=0
719 srctype=
720 imgtype=
721 packages=
722 LIVEOS=LiveOS
723 HOMEFILE="home.img"
724 updates=
726 label="LIVE"
728 while true ; do
729 case $1 in
730 --help | -h | -?)
731 usage
733 --noverify)
734 noverify=1
736 --format)
737 format=1
739 --msdos)
740 usemsdos=1
742 --reset-mbr|--resetmbr)
743 resetmbr=1
745 --efi|--mactel)
746 efi=1
748 --skipcopy)
749 skipcopy=1
751 --force)
752 force=1
754 --xo)
755 xo=1
756 skipcompress=1
758 --xo-no-home)
759 xonohome=1
761 --timeout)
762 checkint $2
763 timeout=$2
764 shift
766 --totaltimeout)
767 checkint $2
768 totaltimeout=$2
769 shift
771 --extra-kernel-args)
772 kernelargs=$2
773 shift
775 --multi)
776 multi=1
778 --livedir)
779 LIVEOS=$2
780 shift
782 --compress)
783 skipcompress=""
785 --skipcompress)
786 skipcompress=1
788 --swap-size-mb)
789 checkint $2
790 swapsizemb=$2
791 shift
793 --overlay-size-mb)
794 checkint $2
795 overlaysizemb=$2
796 shift
798 --home-size-mb)
799 checkint $2
800 homesizemb=$2
801 shift
803 --crypted-home)
804 cryptedhome=1
806 --unencrypted-home)
807 cryptedhome=""
809 --delete-home)
810 keephome=""
812 --updates)
813 updates=$2
814 shift
816 --ks)
817 ks=$2
818 shift
820 --label)
821 label=$2
822 shift
824 --*)
825 echo "invalid arg -- $1"
826 shortusage
827 exit 1
830 break
832 esac
833 shift
834 done
836 if [ $# -ne 2 ]; then
837 echo "Missing arguments"
838 shortusage
839 exit 1
842 SRC=$(readlink -f "$1") || :
843 TGTDEV=$(readlink -f "$2") || :
845 if [ -z "$SRC" ]; then
846 echo "Missing source"
847 shortusage
848 exit 1
851 if [ ! -b "$SRC" -a ! -f "$SRC" ]; then
852 echo "$SRC is not a file or block device"
853 shortusage
854 exit 1
857 if [ -z "$TGTDEV" ]; then
858 echo "Missing target device"
859 shortusage
860 exit 1
863 if [ ! -b "$TGTDEV" ]; then
864 echo "$TGTDEV is not a block device"
865 shortusage
866 exit 1
869 if [ -z "$noverify" ]; then
870 # verify the image
871 echo "Verifying image..."
872 if ! checkisomd5 --verbose "$SRC"; then
873 echo "Are you SURE you want to continue?"
874 echo "Press Enter to continue or ctrl-c to abort"
875 read
879 # do some basic sanity checks.
880 checkMounted $TGTDEV
882 # FIXME: would be better if we had better mountpoints
883 SRCMNT=$(mktemp -d /media/srctmp.XXXXXX)
884 if [ -b "$SRC" ]; then
885 mount -o ro "$SRC" $SRCMNT || exitclean
886 elif [ -f "$SRC" ]; then
887 mount -o loop,ro "$SRC" $SRCMNT || exitclean
888 else
889 echo "$SRC is not a file or block device."
890 exitclean
892 # Figure out what needs to be done based on the source image
893 detectsrctype
895 # Format the device
896 if [ -n "$format" -a -z "$skipcopy" ]; then
897 checkLVM $TGTDEV
899 if [ -n "$efi" ]; then
900 createGPTLayout $TGTDEV
901 elif [ -n "$usemsdos" -o ! -x /sbin/extlinux ]; then
902 createMSDOSLayout $TGTDEV
903 else
904 createEXTFSLayout $TGTDEV
908 checkFilesystem $TGTDEV
909 if [ -n "$efi" ]; then
910 checkGPT $TGTDEV
913 checkSyslinuxVersion
914 # Because we can't set boot flag for EFI Protective on msdos partition tables
915 [ -z "$efi" ] && checkPartActive $TGTDEV
916 [ -n "$resetmbr" ] && resetMBR $TGTDEV
917 checkMBR $TGTDEV
920 if [ "$overlaysizemb" -gt 0 ]; then
921 if [ "$TGTFS" = "vfat" -a "$overlaysizemb" -gt 4095 ]; then
922 echo "Can't have an overlay of 4095MB or greater on VFAT"
923 exitclean
925 LABEL=$(/sbin/blkid -s LABEL -o value $TGTDEV)
926 if [[ "$LABEL" =~ ( ) ]]; then
927 echo "The LABEL($LABEL) on $TGTDEV has spaces in it, which do not work with the overlay"
928 echo "You can re-format or use dosfslabel/e2fslabel to change it"
929 exitclean
933 if [ "$homesizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
934 if [ "$homesizemb" -gt 4095 ]; then
935 echo "Can't have a home overlay greater than 4095MB on VFAT"
936 exitclean
940 if [ "$swapsizemb" -gt 0 -a "$TGTFS" = "vfat" ]; then
941 if [ "$swapsizemb" -gt 4095 ]; then
942 echo "Can't have a swap file greater than 4095MB on VFAT"
943 exitclean
947 TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX)
948 mount $mountopts $TGTDEV $TGTMNT || exitclean
950 trap exitclean SIGINT SIGTERM
952 if [ -f "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" -a "$homesizemb" -gt 0 ]; then
953 echo "ERROR: Requested keeping existing /home and specified a size for /home"
954 echo "Please either don't specify a size or specify --delete-home"
955 exitclean
958 if [ -n "$efi" ]; then
959 if [ -d $SRCMNT/EFI/BOOT ]; then
960 EFI_BOOT="/EFI/BOOT"
961 elif [ -d $SRCMNT/EFI/boot ]; then
962 EFI_BOOT="/EFI/boot"
963 else
964 echo "ERROR: This live image does not support EFI booting"
965 exitclean
969 # let's try to make sure there's enough room on the target device
970 if [[ -d $TGTMNT/$LIVEOS ]]; then
971 tbd=($(du -B 1M $TGTMNT/$LIVEOS))
972 if [[ -s $TGTMNT/$LIVEOS/$HOMEFILE ]] && [[ -n $keephome ]]; then
973 homesize=($(du -B 1M $TGTMNT/$LIVEOS/$HOMEFILE))
974 tbd=$((tbd - homesize))
976 else
977 tbd=0
980 if [[ live == $srctype ]]; then
981 targets="$TGTMNT/$SYSLINUXPATH"
982 [[ -n $efi ]] && targets+=" $TGTMNT$EFI_BOOT"
983 [[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"
984 target_size=$(du -s -c -B 1M $targets 2> /dev/null | awk '/total$/ {print $1;}') || :
985 tbd=$((tbd + target_size))
988 if [[ -n $skipcompress ]] && [[ -s $SRCMNT/LiveOS/squashfs.img ]]; then
989 if mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT; then
990 livesize=($(du -B 1M --apparent-size $SRCMNT/LiveOS/ext3fs.img))
991 umount $SRCMNT
992 if ((livesize > 4095)) && [[ vfat == $TGTFS ]]; then
993 echo "
994 An uncompressed image size greater than 4095 MB is not suitable
995 for a VFAT-formatted device. The compressed SquashFS will be
996 copied to the target device.
998 skipcompress=""
999 livesize=0
1001 else
1002 echo "WARNING: --skipcompress or --xo was specified but the
1003 currently-running kernel can not mount the SquashFS from the source
1004 file to extract it. Instead, the compressed SquashFS will be copied
1005 to the target device."
1006 skipcompress=""
1009 if [[ live == $srctype ]]; then
1010 thisScriptpath=$(readlink -f "$0")
1011 sources="$SRCMNT/LiveOS/ext3fs.img $SRCMNT/LiveOS/osmin.img"
1012 [[ -z $skipcompress ]] && sources+=" $SRCMNT/LiveOS/squashfs.img"
1013 sources+=" $SRCMNT/isolinux $SRCMNT/syslinux"
1014 [[ -n $efi ]] && sources+=" $SRCMNT$EFI_BOOT"
1015 [[ -n $xo ]] && sources+=" $SRCMNT/boot/olpc.fth"
1016 source_size=$(du -s -c -B 1M "$thisScriptpath" $sources 2> /dev/null | awk '/total$/ {print $1;}') || :
1017 livesize=$((livesize + source_size))
1020 freespace=$(df -B 1M --total $TGTDEV | awk '/^total/ {print $4;}')
1022 if [[ live == $srctype ]]; then
1023 tba=$((overlaysizemb + homesizemb + livesize + swapsizemb))
1024 if ((tba > freespace + tbd)); then
1025 needed=$((tba - freespace - tbd))
1026 printf "\n The live image + overlay, home, & swap space, if requested,
1027 \r will NOT fit in the space available on the target device.\n
1028 \r + Size of live image: %10s MiB\n" $livesize
1029 (($overlaysizemb > 0)) && \
1030 printf " + Overlay size: %16s\n" $overlaysizemb
1031 (($homesizemb > 0)) && \
1032 printf " + Home directory size: %9s\n" $homesizemb
1033 (($swapsizemb > 0)) && \
1034 printf " + Swap overlay size: %11s\n" $swapsizemb
1035 printf " = Total requested space: %6s MiB\n" $tba
1036 printf " - Space available: %12s\n" $((freespace + tbd))
1037 printf " ==============================\n"
1038 printf " Space needed: %15s MiB\n\n" $needed
1039 printf " To fit the installation on this device,
1040 \r free space on the target, or decrease the
1041 \r requested size total by: %6s MiB\n\n" $needed
1042 exitclean
1046 # Verify available space for DVD installer
1047 if [ "$srctype" = "installer" ]; then
1048 if [ "$imgtype" = "install" ]; then
1049 imgpath=images/install.img
1050 else
1051 imgpath=isolinux/initrd.img
1053 installimgsize=$(du -s -B 1M $SRCMNT/$imgpath | awk {'print $1;'})
1055 tbd=0
1056 if [ -e $TGTMNT/$imgpath ]; then
1057 tbd=$(du -s -B 1M $TGTMNT/$imgpath | awk {'print $1;'})
1059 if [ -e "$TGTMNT/$(basename "$SRC")" ]; then
1060 tbd=$(($tbd + $(du -s -B 1M "$TGTMNT/$(basename "$SRC")" | awk {'print $1;'})))
1062 echo "Size of $imgpath: $installimgsize"
1063 echo "Available space: $((freespace + tbd))"
1064 if (( installimgsize > ((freespace + tbd)) )); then
1065 echo "ERROR: Unable to fit DVD image + install.img on available space on the target device."
1066 exitclean
1070 if [ -z "$skipcopy" ] && [ "$srctype" = "live" ]; then
1071 if [ -d $TGTMNT/$LIVEOS -a -z "$force" ]; then
1072 echo "Already set up as live image."
1073 if [ -z "$keephome" -a -e $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1074 echo "WARNING: Persistent /home will be deleted!!!"
1075 echo "Press Enter to continue or ctrl-c to abort"
1076 read
1077 else
1078 echo "Deleting old OS in fifteen seconds..."
1079 sleep 15
1081 [ -e "$TGTMNT/$LIVEOS/$HOMEFILE" -a -n "$keephome" ] && mv $TGTMNT/$LIVEOS/$HOMEFILE $TGTMNT/$HOMEFILE
1084 rm -rf $TGTMNT/$LIVEOS
1088 # Bootloader is always reconfigured, so keep these out of the if skipcopy stuff.
1089 [ ! -d $TGTMNT/$SYSLINUXPATH ] && mkdir -p $TGTMNT/$SYSLINUXPATH
1090 [ -n "$efi" -a ! -d $TGTMNT$EFI_BOOT ] && mkdir -p $TGTMNT$EFI_BOOT
1092 # Live image copy
1093 if [ "$srctype" = "live" -a -z "$skipcopy" ]; then
1094 echo "Copying live image to target device."
1095 [ ! -d $TGTMNT/$LIVEOS ] && mkdir $TGTMNT/$LIVEOS
1096 [ -n "$keephome" -a -f "$TGTMNT/$HOMEFILE" ] && mv $TGTMNT/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE
1097 if [ -n "$skipcompress" -a -f $SRCMNT/LiveOS/squashfs.img ]; then
1098 mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT || exitclean
1099 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || {
1100 umount $SRCMNT ; exitclean ; }
1101 umount $SRCMNT
1102 elif [ -f $SRCMNT/LiveOS/squashfs.img ]; then
1103 copyFile $SRCMNT/LiveOS/squashfs.img $TGTMNT/$LIVEOS/squashfs.img || exitclean
1104 elif [ -f $SRCMNT/LiveOS/ext3fs.img ]; then
1105 copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || exitclean
1107 if [ -f $SRCMNT/LiveOS/osmin.img ]; then
1108 copyFile $SRCMNT/LiveOS/osmin.img $TGTMNT/$LIVEOS/osmin.img || exitclean
1110 sync
1113 # Adjust syslinux sources for replication of installed images
1114 # between filesystem types.
1115 if [[ -d $SRCMNT/isolinux/ ]]; then
1116 cp $SRCMNT/isolinux/* $TGTMNT/$SYSLINUXPATH
1117 elif [[ -d $SRCMNT/syslinux/ ]]; then
1118 cp $SRCMNT/syslinux/* $TGTMNT/$SYSLINUXPATH
1119 if [[ -f $SRCMNT/syslinux/extlinux.conf ]]; then
1120 mv $TGTMNT/$SYSLINUXPATH/extlinux.conf \
1121 $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1122 elif [[ -f $SRCMNT/syslinux/syslinux.cfg ]]; then
1123 mv $TGTMNT/$SYSLINUXPATH/syslinux.cfg $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1126 BOOTCONFIG=$TGTMNT/$SYSLINUXPATH/isolinux.cfg
1127 # Set this to nothing so sed doesn't care
1128 BOOTCONFIG_EFI=
1129 if [ -n "$efi" ]; then
1130 echo "Setting up $EFI_BOOT"
1131 cp -r $SRCMNT$EFI_BOOT/* $TGTMNT$EFI_BOOT
1133 # The GRUB EFI config file can be one of:
1134 # boot?*.conf
1135 # BOOT?*.conf
1136 # grub.cfg
1137 if [ -e $TGTMNT$EFI_BOOT/grub.cfg ]; then
1138 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/grub.cfg
1139 elif [ -e $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf ]; then
1140 BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf
1141 else
1142 echo "Unable to find EFI config file."
1143 exitclean
1145 rm -f $TGTMNT$EFI_BOOT/grub.conf
1147 # On some images (RHEL) the BOOT*.efi file isn't in $EFI_BOOT, but is in
1148 # the eltorito image, so try to extract it if it is missing
1150 # test for presence of *.efi grub binary
1151 if [ ! -f $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1152 if [ ! -x /usr/bin/dumpet ]; then
1153 echo "No /usr/bin/dumpet tool found. EFI image will not boot."
1154 echo "Source media is missing grub binary in /EFI/BOOT/*efi"
1155 exitclean
1156 else
1157 # dump the eltorito image with dumpet, output is $SRC.1
1158 dumpet -i "$SRC" -d
1159 EFIMNT=$(mktemp -d /media/srctmp.XXXXXX)
1160 mount -o loop "$SRC".1 $EFIMNT
1162 if [ -f $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]; then
1163 cp $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi $TGTMNT$EFI_BOOT
1164 else
1165 echo "No BOOT*.efi found in eltorito image. EFI will not boot"
1166 umount $EFIMNT
1167 rm "$SRC".1
1168 exitclean
1170 umount $EFIMNT
1171 rm "$SRC".1
1176 # DVD installer copy
1177 if [ -z "$skipcopy" -a \( "$srctype" = "installer" -o "$srctype" = "netinst" \) ]; then
1178 echo "Copying DVD image to target device."
1179 mkdir -p $TGTMNT/images/
1180 if [ "$imgtype" = "install" ]; then
1181 for img in install.img updates.img product.img; do
1182 if [ -e $SRCMNT/images/$img ]; then
1183 copyFile $SRCMNT/images/$img $TGTMNT/images/$img || exitclean
1185 done
1189 # Copy packages over.
1190 # Before Fedora17 we could copy the .iso and setup a repo=
1191 # F17 and later look for repodata on the source media.
1192 # The presence of packages and LiveOS indicates F17 or later.
1193 if [ -n "$packages" -a -z "$skipcopy" ]; then
1194 if [ "$srctype" != "live" ]; then
1195 echo "Copying $SRC to device"
1196 copyFile "$SRC" "$TGTMNT/"
1198 # Setup a repo= to point to the .iso
1199 sed -i -e "s;initrd.img;initrd.img repo=hd:$TGTLABEL:/;g" $BOOTCONFIG
1200 if [ -n "$efi" ]; then
1201 sed -i -e "s;vmlinuz;vmlinuz repo=hd:$TGTLABEL:/;g" $BOOTCONFIG_EFI
1203 else
1204 echo "Copying package data from $SRC to device"
1205 rsync --inplace -rLDP --exclude EFI/ --exclude images/ --exclude isolinux/ \
1206 --exclude TRANS.TBL --exclude LiveOS/ "$SRCMNT/" "$TGTMNT/"
1208 echo "Waiting for device to finish writing"
1209 sync
1212 if [ "$srctype" = "live" ]; then
1213 # Copy this installer script.
1214 cp -fT "$thisScriptpath" $TGTMNT/$LIVEOS/livecd-iso-to-disk
1215 chmod +x $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null || :
1217 # When the source is an installed Live USB/SD image, restore the boot config
1218 # file to a base state before updating.
1219 if [[ -d $SRCMNT/syslinux/ ]]; then
1220 echo "Preparing boot config file."
1221 sed -i -e "s/root=live:[^ ]*/root=live:CDLABEL=name/"\
1222 -e "s/\(r*d*.*live.*ima*ge*\) .* quiet/\1 quiet/"\
1223 $BOOTCONFIG $BOOTCONFIG_EFI
1224 sed -i -e "s/^timeout.*$/timeout\ 100/"\
1225 -e "/^totaltimeout.*$/d" $BOOTCONFIG
1229 # Setup the updates.img
1230 if [ -n "$updates" ]; then
1231 copyFile "$updates" "$TGTMNT/updates.img"
1232 kernelargs+=" inst.updates=hd:$TGTLABEL:/updates.img"
1235 # Setup the kickstart
1236 if [ -n "$ks" ]; then
1237 copyFile "$ks" "$TGTMNT/ks.cfg"
1238 kernelargs+=" inst.ks=hd:$TGTLABEL:/ks.cfg"
1241 echo "Updating boot config file"
1242 # adjust label and fstype
1243 sed -i -e "s/CDLABEL=[^ ]*/$TGTLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$TGTFS/" -e "s/LABEL=[^ :]*/$TGTLABEL/" $BOOTCONFIG $BOOTCONFIG_EFI
1244 if [ -n "$kernelargs" ]; then
1245 sed -i -e "s;initrd.\?\.img;& ${kernelargs};" $BOOTCONFIG
1246 if [ -n "$efi" ]; then
1247 sed -i -e "s;vmlinuz.\?;& ${kernelargs} ;" $BOOTCONFIG_EFI
1250 if [ "$LIVEOS" != "LiveOS" ]; then
1251 sed -i -e "s;r*d*.*live.*ima*ge*;& live_dir=$LIVEOS;"\
1252 $BOOTCONFIG $BOOTCONFIG_EFI
1255 # EFI images are in $SYSLINUXPATH now
1256 if [ -n "$efi" ]; then
1257 sed -i -e "s;/isolinux/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1258 sed -i -e "s;/images/pxeboot/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI
1259 sed -i -e "s;findiso;;g" $BOOTCONFIG_EFI
1262 # DVD Installer for netinst
1263 if [ "$srctype" != "live" ]; then
1264 if [ "$imgtype" = "install" ]; then
1265 sed -i -e "s;initrd.img;initrd.img stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG
1266 if [ -n "$efi" ]; then
1267 sed -i -e "s;vmlinuz;vmlinuz stage2=hd:$TGTLABEL:/images/install.img;g" $BOOTCONFIG_EFI
1269 else
1270 # The initrd has everything, so no stage2
1271 sed -i -e "s;stage2=\S*;;g" $BOOTCONFIG $BOOTCONFIG_EFI
1275 # Adjust the boot timeouts
1276 if [ -n "$timeout" ]; then
1277 sed -i -e "s/^timeout.*$/timeout\ $timeout/" $BOOTCONFIG
1279 if [ -n "$totaltimeout" ]; then
1280 sed -i -e "/^timeout.*$/a\totaltimeout\ $totaltimeout" $BOOTCONFIG
1283 if [ "$overlaysizemb" -gt 0 ]; then
1284 echo "Initializing persistent overlay file"
1285 OVERFILE="overlay-$( /sbin/blkid -s LABEL -o value $TGTDEV )-$( /sbin/blkid -s UUID -o value $TGTDEV )"
1286 if [ -z "$skipcopy" ]; then
1287 if [ "$TGTFS" = "vfat" ]; then
1288 # vfat can't handle sparse files
1289 dd if=/dev/zero of=$TGTMNT/$LIVEOS/$OVERFILE count=$overlaysizemb bs=1M
1290 else
1291 dd if=/dev/null of=$TGTMNT/$LIVEOS/$OVERFILE count=1 bs=1M seek=$overlaysizemb
1294 sed -i -e "s/r*d*.*live.*ima*ge*/& overlay=${TGTLABEL}/"\
1295 $BOOTCONFIG $BOOTCONFIG_EFI
1296 sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG $BOOTCONFIG_EFI
1299 if [ "$swapsizemb" -gt 0 -a -z "$skipcopy" ]; then
1300 echo "Initializing swap file"
1301 dd if=/dev/zero of=$TGTMNT/$LIVEOS/swap.img count=$swapsizemb bs=1M
1302 mkswap -f $TGTMNT/$LIVEOS/swap.img
1305 if [ "$homesizemb" -gt 0 -a -z "$skipcopy" ]; then
1306 echo "Initializing persistent /home"
1307 homesource=/dev/zero
1308 [ -n "$cryptedhome" ] && homesource=/dev/urandom
1309 if [ "$TGTFS" = "vfat" ]; then
1310 # vfat can't handle sparse files
1311 dd if=${homesource} of=$TGTMNT/$LIVEOS/$HOMEFILE count=$homesizemb bs=1M
1312 else
1313 dd if=/dev/null of=$TGTMNT/$LIVEOS/$HOMEFILE count=1 bs=1M seek=$homesizemb
1315 if [ -n "$cryptedhome" ]; then
1316 loop=$(losetup -f)
1317 losetup $loop $TGTMNT/$LIVEOS/$HOMEFILE
1319 echo "Encrypting persistent /home"
1320 while ! cryptsetup luksFormat -y -q $loop; do :; done;
1322 echo "Please enter the password again to unlock the device"
1323 while ! cryptsetup luksOpen $loop EncHomeFoo; do :; done;
1325 mkfs.ext4 -j /dev/mapper/EncHomeFoo
1326 tune2fs -c0 -i0 -ouser_xattr,acl /dev/mapper/EncHomeFoo
1327 sleep 2
1328 cryptsetup luksClose EncHomeFoo
1329 losetup -d $loop
1330 else
1331 echo "Formatting unencrypted /home"
1332 mkfs.ext4 -F -j $TGTMNT/$LIVEOS/$HOMEFILE
1333 tune2fs -c0 -i0 -ouser_xattr,acl $TGTMNT/$LIVEOS/$HOMEFILE
1337 # create the forth files for booting on the XO if requested
1338 # we'd do this unconditionally, but you have to have a kernel that will
1339 # boot on the XO anyway.
1340 if [ -n "$xo" ]; then
1341 echo "Setting up /boot/olpc.fth file"
1342 args=$(grep "^ *append" $TGTMNT/$SYSLINUXPATH/isolinux.cfg |head -n1 |sed -e 's/.*initrd=[^ ]*//')
1343 if [ -z "$xonohome" -a ! -f $TGTMNT/$LIVEOS/$HOMEFILE ]; then
1344 args="$args persistenthome=mtd0"
1346 args="$args reset_overlay"
1347 xosyspath=$(echo $SYSLINUXPATH | sed -e 's;/;\\;')
1348 if [ ! -d $TGTMNT/boot ]; then
1349 mkdir -p $TGTMNT/boot
1351 cat > $TGTMNT/boot/olpc.fth <<EOF
1352 \ Boot script for USB boot
1353 hex rom-pa fffc7 + 4 \$number drop h# 2e19 < [if]
1354 patch 2drop erase claim-params
1355 : high-ramdisk ( -- )
1356 cv-load-ramdisk
1357 h# 22c +lp l@ 1+ memory-limit umin /ramdisk - ffff.f000 and ( new-ramdisk-adr )
1358 ramdisk-adr over /ramdisk move ( new-ramdisk-adr )
1359 to ramdisk-adr
1361 ' high-ramdisk to load-ramdisk
1362 [then]
1364 : set-bootpath-dev ( -- )
1365 " /chosen" find-package if ( phandle )
1366 " bootpath" rot get-package-property 0= if ( propval$ )
1367 get-encoded-string ( bootpath$ )
1368 [char] \ left-parse-string 2nip ( dn$ )
1369 dn-buf place ( )
1370 then
1371 then
1373 " /sd" dn-buf count sindex 0>= if
1374 " sd:"
1375 else
1376 " u:"
1377 then
1378 " BOOTPATHDEV" \$set-macro
1381 set-bootpath-dev
1382 " $args" to boot-file
1383 " \${BOOTPATHDEV}$xosyspath\initrd0.img" expand$ to ramdisk
1384 " \${BOOTPATHDEV}$xosyspath\vmlinuz0" expand$ to boot-device
1385 unfreeze
1386 boot
1391 if [ -z "$multi" ]; then
1392 echo "Installing boot loader"
1393 if [ -n "$efi" ]; then
1394 # replace the ia32 hack
1395 if [ -f "$TGTMNT$EFI_BOOT/BOOT.conf" ]; then
1396 cp -f $TGTMNT$EFI_BOOT/BOOTia32.conf $TGTMNT$EFI_BOOT/BOOT.conf
1400 # this is a bit of a kludge, but syslinux doesn't guarantee the API for its com32 modules :/
1401 if [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/share/syslinux/vesamenu.c32 ]; then
1402 cp /usr/share/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1403 elif [ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 -a -f /usr/lib/syslinux/vesamenu.c32 ]; then
1404 cp /usr/lib/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32
1405 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/share/syslinux/menu.c32 ]; then
1406 cp /usr/share/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1407 elif [ -f $TGTMNT/$SYSLINUXPATH/menu.c32 -a -f /usr/lib/syslinux/menu.c32 ]; then
1408 cp /usr/lib/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32
1411 if [ "$TGTFS" == "vfat" -o "$TGTFS" == "msdos" ]; then
1412 # syslinux expects the config to be named syslinux.cfg
1413 # and has to run with the file system unmounted
1414 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1415 # deal with mtools complaining about ldlinux.sys
1416 if [ -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys ]; then
1417 rm -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1419 cleanup
1420 if [ -n "$SYSLINUXPATH" ]; then
1421 syslinux -d $SYSLINUXPATH $TGTDEV
1422 else
1423 syslinux $TGTDEV
1425 elif [ "$TGTFS" == "ext2" -o "$TGTFS" == "ext3" -o "$TGTFS" == "ext4" -o "$TGTFS" == "btrfs" ]; then
1426 # extlinux expects the config to be named extlinux.conf
1427 # and has to be run with the file system mounted
1428 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/extlinux.conf
1429 extlinux -i $TGTMNT/$SYSLINUXPATH
1430 # Starting with syslinux 4 ldlinux.sys is used on all file systems.
1431 if [ -f "$TGTMNT/$SYSLINUXPATH/extlinux.sys" ]; then
1432 chattr -i $TGTMNT/$SYSLINUXPATH/extlinux.sys
1433 elif [ -f "$TGTMNT/$SYSLINUXPATH/ldlinux.sys" ]; then
1434 chattr -i $TGTMNT/$SYSLINUXPATH/ldlinux.sys
1436 cleanup
1438 else
1439 # we need to do some more config file tweaks for multi-image mode
1440 sed -i -e "s;kernel vm;kernel /$LIVEOS/syslinux/vm;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1441 sed -i -e "s;initrd=i;initrd=/$LIVEOS/syslinux/i;" $TGTMNT/$SYSLINUXPATH/isolinux.cfg
1442 mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg
1443 cleanup
1446 echo "Target device is now set up with a Live image!"