Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 610112 Details for
Bug 663986
RFE - livecd-iso-to-disk has unexpected dependency on host running it
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
livecd-iso-to-disk using chroot to run in source environment
livecd-iso-to-disk (text/plain), 62.87 KB, created by
Frederick Grose
on 2012-09-05 22:20:30 UTC
(
hide
)
Description:
livecd-iso-to-disk using chroot to run in source environment
Filename:
MIME Type:
Creator:
Frederick Grose
Created:
2012-09-05 22:20:30 UTC
Size:
62.87 KB
patch
obsolete
>#!/bin/bash ># 2012-09-05 14:48:13 ># ># Transfer a Live image so that it's bootable off of a USB/SD device. ># ># Copyright 2007 Red Hat, Inc. ># Jeremy Katz <katzj@redhat.com> ># ># overlay/persistence enhancements by Douglas McClendon <dmc@viros.org> ># GPT+MBR hybrid enhancements by Stewart Adam <s.adam@diffingo.com> ># ># This program is free software; you can redistribute it and/or modify ># it under the terms of the GNU General Public License as published by ># the Free Software Foundation; version 2 of the License. ># ># This program is distributed in the hope that it will be useful, ># but WITHOUT ANY WARRANTY; without even the implied warranty of ># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ># GNU Library General Public License for more details. ># ># You should have received a copy of the GNU General Public License ># along with this program; if not, write to the Free Software ># Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. > >export PATH=/usr/sbin:$PATH >export \ > PS4='+(${SHLVL}:${LINENO}:${BASH_SOURCE}:${EUID}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' > >shortusage() { > echo " > SYNTAX > > livecd-iso-to-disk [--help] [--noverify] [--avoidsourcescript] [--nochroot] > [--format] [--msdos] [--reset-mbr] [--efi] [--skipcopy] > [--force] [--xo] [--xo-no-home] [--timeout <time>] > [--totaltimeout <time>] [--extra-kernel-args <args>] > [--multi] [--livedir <dir>] [--compress] > [--skipcompress] [--no-overlay] [--swap-size-mb <size>] > [--overlay-size-mb <size>] [--reset-overlay] > [--home-size-mb <size>] [--delete-home] [--crypted-home] > [--unencrypted-home] [--copy-home] [--include <file s>] > <source> <target device> > > (Enter livecd-iso-to-disk --help on the command line for more information.)" >} > >usage() { > echo " > " > shortusage > echo " > livecd-iso-to-disk - Transfer a LiveOS image so that it's bootable off of > a USB/SD device. > > The script may be run in simplest form with just the two arguments: > > <source> > This may be the filesystem path to a LiveOS .iso image file, > such as from a CD-ROM, DVD, or download. It could also be the > device node reference for the mount point of another LiveOS > filesystem, including the currently-running one (such as a > booted Live CD/DVD/USB, where /run/initramfs/livedev (or > /dev/live before Fedora 17) references the booted device). > > <target device> > This should be the device partition name for the attached, > target device, such as /dev/sdb1 or /dev/sdc1. (Issue the > df -Th command to get a listing of the mounted partitions, > where you can confirm the filesystem types, available space, > and device names.) Be careful to specify the correct device, > or you may overwrite important data on another disk! > > To execute the script to completion, you will need to run it with root user > permissions. > > DESCRIPTION > > livecd-iso-to-disk installs a Live CD/DVD/USB image (LiveOS) onto a USB/SD > storage device (or any storage partition that will boot with a SYSLINUX > bootloader). The target storage device can then boot the installed > operating system on systems that support booting via the USB or the SD > interface. The script requires a LiveOS source image and a target storage > device. The source image may be either a LiveOS .iso file, the currently- > running LiveOS image, the device node reference for an attached device with > an installed LiveOS image, or a file backed by a block device with an > installed LiveOS image. If the operating system supports persistent > overlays for saving system changes, a pre-sized overlay may be included with > the installation. > > Unless you request the --format option, the installation does not destroy > data outside of the LiveOS, syslinux, & EFI folders on your target device. > This allows one to maintain other files on the target disk outside of the > LiveOS filesystem. > > LiveOS images provide embedded filesystems through the Device-mapper > component of the Linux kernel. The embedded filesystems exist within files > such as /LiveOS/squashfs.img (the default compressed storage) or > /LiveOS/ext3fs.img (an uncompressed version) on the primary volume partition > of the storage device. In use, these are read-only filesystems. Optionally, > one may specify a persistent LiveOS overlay to hold image-change snapshots > (which use write-once, difference-tracking storage) in the > /LiveOS/overlay-<device_id> file, which, *one should note*, always grows in > size due to the storage mechanism. (The fraction of allocated space that > has been consumed by system activity and changes may be displayed by issuing > the 'dmsetup status' command in a terminal session of a running LiveOS > image.) One way to conserve the unrecoverable, overlay file space, is to > specify a persistent home folder for user files, which will be saved in a > /LiveOS/home.img filesystem image file. This file space is encrypted by > default, but is not compressed. (One may bypass encryption with the > --unencrypted-home installation option.) Files in this home folder may be > erased to recover and reuse their storage space. The home.img file is also > convenient for backing up or swapping user account files. > > OPTIONS > > --help > Displays usage information and exits. > > --noverify > Disables the image validation process that occurs before the image is > installed from the original Live CD .iso image. When this option is > specified, the image is not verified before loading onto the target > storage device. > > --avoidsourcescript > The launched script will be used for installation instead of the > livecd-iso-to-disk script on the source image. > > --nochroot > Disables using the source image filesystem hierarchy with chroot as the > operating root filesystem during the installation. > > --format > Formats the target device and creates an MS-DOS partition table (or GPT > partition table, if the --efi option is passed). > > --msdos > Forces format to make an fat32 file system instead of an ext4 formatted > one. > > --reset-mbr > Sets the Master Boot Record (MBR) of the target storage device to the > mbr.bin file from the installation system's syslinux directory. This > may be helpful in recovering a damaged or corrupted device. > > --efi > Creates a GUID partition table when --format is passed, and installs a > hybrid Extensible Firmware Interface (EFI)/MBR bootloader on the disk. > This is necessary for most Intel Macs. > > --skipcopy > Skips the copying of the live image to the target device, bypassing the > actions of the --format, --overlay-size-mb, --home-size-mb, & > --swap-size-mb options, if present on the command line. (The --skipcopy > option may be used while testing the script, in order to avoid repeated > and lengthy copy commands, or to repair boot configuration files on a > previously installed device.) > > --force > This option allows the installation script to bypass a delete > confirmation dialog in the event that a pre-existing LiveOS directory > is found on the target device. > > --xo > Used to prepare an image for the OLPC XO-1 laptop with its compressed, > JFFS2 filesystem. Do not use the following options with --xo: > --overlay-size-mb <size>, home-size-mb <size>, --delete-home, > --compress > > --xo-no-home > Used together with the --xo option to prepare an image for an OLPC XO > laptop with the home folder on an SD card instead of the internal flash > storage. > > --timeout > Modifies the bootloader's timeout value, which indicates how long to > pause at the boot: prompt before booting automatically. This overrides > the value set during iso creation. Units are 1/10 s. The timeout is > canceled when any key is pressed, the assumption being that the user > will complete the command line. A timeout of zero will disable the > timeout completely. > > --totaltimeout > Adds a bootloader totaltimeout, which indicates how long to wait before > booting automatically. This is used to force an automatic boot. This > timeout cannot be canceled by the user. Units are 1/10 s. > > --extra-kernel-args <args> > Specifies additional kernel arguments, <args>, that will be inserted > into the syslinux and EFI boot configurations. Multiple arguments > should be specified in one string, i.e., > --extra-kernel-args \"arg1 arg2 ...\" > > --multi > Used when installing multiple image copies to signal configuration of > the boot files for the image in the --livedir <dir> parameter. > > --livedir <dir> > Used with multiple image installations to designate the directory <dir> > for the particular image. > > --compress (default state for the operating system files) > The default, compressed SquashFS filesystem image is copied on > installation. This option has no effect when the source filesystem is > already expanded. > > --skipcompress (default option when --xo is specified) > Expands the source SquashFS image on installation into the read-only > /LiveOS/ext3fs.img filesystem image file. > > --no-overlay (effective with skipcompress only) > Creates a linear Device-mapper target for the /LiveOS/ext3fs.img > filesystem image file. Read-write by default, unless an > --extra-kernel-args of rd.live.readonly is given. > > --swap-size-mb <size> > Sets up a swap file of <size> mebibytes (integer values only) on the > target device. A maximum <size> of 2048 MiB is permitted for > vfat-formatted devices. > > --overlay-size-mb <size> > This option sets the overlay size in mebibytes (integer values only). > The overlay makes persistent storage available to the live operating > system, if the operating system supports it. The persistent LiveOS > overlay holds image-change snapshots (using write-once, difference- > tracking storage) in the /LiveOS/overlay-<device_id> file, which, *one > should note*, always grows in size due to the storage mechanism. (The > fraction of allocated space that has been consumed may be displayed by > issuing the 'dmsetup status' command in a terminal session of a running > LiveOS installation.) One way to conserve the unrecoverable, overlay > file space, is to specify a persistent home folder for user files, see > --home-size-mb below. The target storage device must have enough free > space for the image and the overlay. A maximum <size> of 2048 MiB is > permitted for vfat-formatted devices. If there is insufficient room on > your device, you will be given information to help in adjusting your > settings. > > --reset-overlay > This option will reset the persistent overlay to an unused state. It > might be used if installing from a new or refreshed image onto a device > with an existing overlay, and avoids the writing of a large file that > the vfat format requires. > > --home-size-mb <size> > Sets the home directory size in mebibytes (integer values only). A > persistent home directory will be made in the /LiveOS/home.img > filesystem image file. This file space is encrypted by default, but not > compressed (one may bypass encryption with the --unencrypted-home > installation option). Files in this home folder may be erased to > recover and reuse their storage space. The target storage device must > have enough free space for the image, any overlay, and the home > directory. Note that the --delete-home option must also be selected to > replace an existing persistent home with a new, empty one. A maximum > <size> of 2048 MiB is permitted for vfat-formatted devices. If there is > insufficient room on your device, you will be given information to help > in adjusting your settings. > > --delete-home > To prevent unwitting deletion of user files, this option must be > explicitly selected when the option --home-size-mb <size> is selected > and there is an existing persistent home directory on the target device. > > --crypted-home (default that only applies to new home-size-mb requests) > Specifies the default option to encrypt a new persistent home directory > if --home-size-mb <size> is specified. > > --unencrypted-home > Prevents the default option to encrypt a new persistent home directory. > > --copy-home > This option allows one to copy a persistent home folder from one LiveOS > image to the target image. Changes already made in the source home > directory will be propagated to the new image. > WARNING: User-sensitive information, such as password cookies and > user and application data, will be copied to the new image! Scrub > this information before using this option. > > --include <path s> > This option allows one to copy one or more file or directory paths from > the outer source filesystem to the same path on the target. > Multiple paths should be specified in one string, i.e., > --include \"path1 path2 ...\" > > CONTRIBUTORS > > livecd-iso-to-disk: David Zeuthen, Jeremy Katz, Douglas McClendon, > Chris Curran and other contributors. > (See the AUTHORS file in the source distribution for > the complete list of credits.) > > BUGS > > Report bugs to the mailing list > http://admin.fedoraproject.org/mailman/listinfo/livecd or directly to > Bugzilla http://bugzilla.redhat.com/bugzilla/ against the Fedora product, > and the livecd-tools component. > > COPYRIGHT > > Copyright (C) Fedora Project 2008, 2009, 2010 and various contributors. > This is free software. You may redistribute copies of it under the terms of > the GNU General Public License http://www.gnu.org/licenses/gpl.html. > There is NO WARRANTY, to the extent permitted by law. > > SEE ALSO > > livecd-creator, project website http://fedoraproject.org/wiki/FedoraLiveCD > " > exit 1 >} > >set -o errexit >set -o pipefail >shopt -s extglob > >success='' > >if [[ $* =~ --help ]]; then > usage >fi > >if [[ $(id -u) != 0 ]]; then > echo ' > ALERT: You need to have root user privileges to run this script. > ' > exit 1 >fi > >if (( $# < 2 )); then > echo ' > ERROR: At minimum, a source and a target must be specified.' > shortusage > exit 1 >fi > >SRC=$(readlink -f "${@: -2:1}") >TGTDEV=$(readlink -f "${@: -1}") > >if ! [[ -f $SRC || -n $(blkid $SRC) ]]; then > echo " > ERROR: '$SRC' is not a file or a block device with a file system." > shortusage > exit 1 >fi > >if [[ ! -b $TGTDEV ]]; then > echo " > ERROR: '$TGTDEV' is not a block device." > shortusage > exit 1 >fi > >cleanup() { > if ! [[ /proc/1/root/. -ef / ]]; then > # In chroot. > if [[ -d $TGTMNT ]]; then > umount $TGTMNT > rmdir $TGTMNT > elif [[ -n $success ]]; then > echo 'Leaving chroot.' > exit 11 > fi > else > sleep 2 > if [[ -d $ROOTFSMNT ]]; then > for d in $script_mp $SRCMNT $src_p_mp \ > /media /tmp /run /dev/pts /dev /sys /proc; do > umount ${ROOTFSMNT}$d 2>/dev/null || : > done > umount $ROOTFSMNT > rmdir $ROOTFSMNT > if [[ -d $SQUASHMNT ]]; then > umount $SQUASHMNT > rmdir $SQUASHMNT > fi > fi > if mountpoint -q $SRCMNT ; then > umount $SRCMNT > rmdir $SRCMNT > fi > if [[ -d $TGTMNT ]]; then > umount $TGTMNT > rmdir $TGTMNT > fi > fi >} > >exitclean() { > RETVAL=$? > if [[ $success != passedexitclean ]]; then > if [[ -d $SRCMNT || -d $TGTMNT ]]; then > if ((RETVAL > 0 && RETVAL != 11)); then > echo 'Cleaning up to exit...' > fi > cleanup > fi > if { ((RETVAL == 11)) || [[ -n $success ]]; } && > [[ /proc/1/root/. -ef / ]]; then > printf ' > The target device is now set up with a %s image!\n\n' ${srctype^} > exit 0 > elif ! [[ /proc/1/root/. -ef / ]]; then > echo 'Leaving chroot.' > fi > success=passedexitclean > RETVAL=1 > fi > exit $RETVAL >} >trap exitclean EXIT > >isdevloop() { > [[ x${1#/dev/loop} != x$1 ]] >} > >getdisk() { > declare -g DEV=$1 > declare -g device > > if isdevloop "$DEV"; then > device="$DEV" > return > fi > > local p=$(udevadm info -q path -n $DEV) > if (( $? > 0 )); then > echo "Error getting udev path to $DEV. Aborting..." > exitclean > fi > if [[ -e /sys/$p/device ]]; then > device=$(basename /sys/$p) > else > device=$(basename $(readlink -f /sys/$p/../)) > fi > if ! [[ -e /sys/block/$device || -e /dev/$device ]]; then > echo "Error finding block device of $DEV. Aborting!" > exitclean > fi > > device="/dev/$device" > # FIXME: weird dev names could mess this up I guess > local p=/dev/$(basename $p) > declare -g partnum=${p##$device} >} > >detectsrctype() { > SRCFS=$(findmnt -o FSTYPE -n $SRCMNT || :) > if [[ -e $SRCMNT/LiveOS/squashfs.img || > -e $SRCMNT/LiveOS/ext3fs.img ]]; then > srctype=live > return > fi > if [[ -e $SRCMNT/images/install.img || > -e $SRCMNT/isolinux/initrd.img ]]; then > imgtype=install > if [[ -e $SRCMNT/Packages ]]; then > srctype=installer > else > srctype=netinst > fi > if [[ ! -e $SRCMNT/images/install.img ]]; then > echo "$SRC uses initrd.img w/o install.img" > imgtype=initrd > fi > return > fi > echo "ERROR: $SRC does not appear to be a LiveOS image or DVD installer." > exitclean >} > >loopsearch() { > # Return the loop devices or backing files for the search string. > local search="${!#}" mode=$1 recurse='' loops='' nodes='' e='' f='' > local -i i=0 j=0 k s b m=1 > if [[ ${mode:0:1} == - ]]; then > [[ $mode =~ r ]] && recurse=1 > # Search backing files. > [[ $mode =~ b ]] && m=0 > fi > loops=$(echo /sys/devices/virtual/block/loop*/loop/backing_file) > if [[ ${loops:31:1} != \* ]]; then > for f in $loops; do > looparray[$i+1]=$(< ${f}) > f=${f/sys\/devices\/virtual\/block/dev} > f=${f%/loop/backing_file} > looparray[$i]=${f} > i=$i+2 > done > fi > k=$i > loops='' > findmatch() { > if [[ -n $1 ]]; then > for ((i=k; i > 0; i=i-2)); do > if [[ ${looparray[*]:$i-1-$m:1} == $search ]]; then > loops+=${looparray[$i-2+$m]}$'\n' > j=$j+1 > fi > done > else > for ((i=k; i > 0; i=i-2)); do > if [[ ${looparray[*]:$i-1:1} =~ $search ]]; then > loops+=${looparray[$i-2]}$'\n' > j=$j+1 > fi > done > fi > } > findmatch 'exact' > [[ -n $loops && -z $recurse ]] && echo "$loops" && return > if [[ -n $recurse ]]; then > if [[ -z $loops ]]; then > m=$(( m == 0 ? 1 : 0 )) > findmatch 'exact' > fi > while ((${#loops} > 0)); do > search=${loops%%$'\n'*} > nodes+=$search' ' > m=$(( m == 0 ? 1 : 0 )) > findmatch 'exact' > m=$(( m == 0 ? 1 : 0 )) > findmatch 'exact' > for e in $nodes; do > loops=${loops//$e$'\n'/} > done > done > fi > [[ -n $nodes ]] && echo "$nodes" && return > search="${!#}" > findmatch > echo "${loops[@]}" >} > >blockdevsearch () { > # Return a block device node name from the kernel sysfs major:minor. > local devs=$(echo /sys/class/block/*/dev) f='' > for f in $devs; do > m_m=$(< ${f}) > if [[ $m_m == $1 ]]; then > f=${f/sys\/class\/block/dev} > f=${f%/dev} > echo $f ; break > fi > done >} > >dev_mount_points() { > # Find the mount point paths for a device. > declare -g srcdevs='' > local tgtdevs='' devs="$1"' ' d='' mounts='' > local -a _info=() > local -i i=-1 > a_d_mp=() > devs+=$(loopsearch -r "$1") > for d in $devs; do > [[ ${d:0:5} == /dev/ ]] && srcdevs+=$(mountpoint -q -x $d)',' > done > while read -r -a _info; do > if [[ $srcdevs =~ ${_info[2]}',' ]]; then > mounts+="${_info[2]} ${_info[4]}"$'\n' > fi > done < /proc/self/mountinfo > tgtdevs=$(sort -r <<< "$mounts") > for d in $tgtdevs; do > i+=1; a_d_mp[i]=$(printf '%b' "$d") > done >} > >try_unmount () { > # Attempt to unmount a block device. > local d='' e='' mp='' dev='' tdev='' > local -i i > dev_mount_points "$1" > if [[ -n $a_d_mp ]]; then > echo -e "\nDevice '$1' is mounted at these locations: > \rdisk - mount point" > for ((i=0, c=${#a_d_mp[@]}; i < c; i+=2)); do > d=${a_d_mp[i]} > printf '%2s:%-2s - %s\n' ${d%:*} ${d#*:} "${a_d_mp[i+1]}" > done > echo " > Press Enter to unmount '$1', or Ctrl C to exit." > read > echo "Attempting to unmount these mount points:" > for ((i=0, c=${#a_d_mp[@]}; i < c; i+=2)); do > d=${a_d_mp[i]}; mp=${a_d_mp[i+1]} > printf '%2s:%-2s - %s' ${d%:*} ${d#*:} "${a_d_mp[i+1]}" > dev=$(mountpoint -d "$mp") > if [[ $dev == $d ]]; then > e=$(umount "$mp" 2>&1) || printf ' -- ERROR: %s\n' "$e" > else > tdev=$(blockdevsearch $dev) > printf ' -- FAILED: %s (%s) is the topmost mount.\n' $tdev $dev > e=FAILED > fi > [[ -n $e ]] && findmnt -R "$mp" && echo && continue > if [[ $(mountpoint -q "$mp") == 0 ]]; then > echo ' -- FAILED' > umount "$mp" > if [[ $(mountpoint -q "$mp") == 0 ]]; then > echo ' -- FAILED again. Exiting...' > exitclean > else > echo ' -- succeeded.' > fi > else > echo ' -- success' > fi > done > if [[ -n $e ]]; then exitclean ; fi > fi > a_d_mp=() >} > >mountsrcroot() { > SQUASHMNT=$(mktemp -d /media/XXXXXX) > mount -o ro ${SRCMNT}/LiveOS/squashfs.img $SQUASHMNT || exitclean > ROOTFSMNT=$(mktemp -d /media/XXXXXX) > ROOTFS=${SQUASHMNT}/LiveOS/ext3fs.img > [[ -e $ROOTFS ]] || ROOTFS=${SQUASHMNT}/LiveOS/rootfs.img > mount -o loop,ro $ROOTFS $ROOTFSMNT || exitclean > for d in /proc /sys /dev /dev/pts /run /tmp /media; do > mount --bind $d ${ROOTFSMNT}$d > done > mount --bind $SRCMNT ${ROOTFSMNT}$SRCMNT || exitclean > mount --bind "$src_p_mp" ${ROOTFSMNT}"$src_p_mp" || exitclean > if [[ $* =~ --avoidsourcescript ]]; then > mount --bind "$script_mp" ${ROOTFSMNT}"$script_mp" || exitclean > fi >} > ># do some basic sanity checks. >if [[ -z $(blkid $TGTDEV) ]]; then > echo "ERROR: '$TGTDEV' is not a file system available to this system. > Exiting..." > exitclean >fi >declare -a a_d_mp=() >try_unmount $TGTDEV > >if [[ $(swapon -s) =~ \ ${TGTDEV}\ ]]; then > echo "Your chosen target device, $TGTDEV, is in use as a swap device. > Please disable swap if you want to use this device. > Exiting..." > exitclean >fi > >if [[ /proc/1/root/. -ef / ]]; then > # Not in chroot. > # FIXME: would be better if we had better mountpoints > export saved_umask=$(umask -p) > # Secure the mount point for privacy. > umask 0077 > export SRCMNT=$(mktemp -d /media/srctmp.XXXXXX) > dev_mount_points $SRC > script_mp=$(stat -c %m "$0") > mp_d=$(mountpoint -d "$script_mp") > if [[ $srcdevs =~ ${mp_d}, ]]; then > MP=$script_mp > elif [[ -n $a_d_mp ]]; then > MP=${a_d_mp[1]} > fi > mntsrc=$SRC > mntopt='-o ro' > if [[ $SRC == $(readlink -f /run/initramfs/livedev) ]] || > [[ $SRC == $(readlink -f /dev/live) ]]; then > mntsrc=$MP > src_p_mp=$MP > imgtype=liveboot > mntopt+=,loop\ --bind > elif [[ -n $MP ]]; then > mntsrc=$MP > mntopt+=\ --bind > src_p_mp=$(stat -c %m "$SRC") > else > src_p_mp=$(stat -c %m "$mntsrc") > fi > mount $mntopt "$mntsrc" $SRCMNT || exitclean > trap exitclean SIGINT SIGTERM >fi > >srctype='' >imgtype='' >detectsrctype > >Installscript=$(readlink -f "$0") >if ! [[ /proc/1/root/. -ef / ]]; then > echo 'In chroot.' >elif ! [[ $* =~ --nochroot ]]; then > mountsrcroot $* > ! [[ $* =~ --avoidsourcescript ]] && > Installscript=${SRCMNT}/LiveOS/livecd-iso-to-disk > chroot $ROOTFSMNT bash "$Installscript" "$@" > echo 'Out of chroot.' > cleanup > exit >elif [[ liveboot == $imgtype ]]; then > echo 'Replicating a booted LiveOS image.' >elif [[ install\ initrd =~ $imgtype ]]; then > if [[ netinst == $srctype ]]; then > echo 'Beginning network install.' > elif [[ installer == $srctype ]]; then > echo 'Installing from DVD image.' > fi >fi > >checkFilesystem() { > local dev=$1 > > TGTFS=$(blkid -s TYPE -o value $dev || :) > if ! [[ ,vfat,msdos,ext2,ext3,ext4,btrfs, =~ ,${TGTFS}, ]]; then > printf '\n ALERT: > The target filesystem must have a vfat, ext[234], or btrfs format. > Exiting...\n' > exitclean > fi > > TGTLABEL=$(blkid -s UUID -o value $dev) > if [[ -n $TGTLABEL ]]; then > TGTLABEL="UUID=$TGTLABEL" > else > TGTLABEL=$(blkid -s LABEL -o value $dev) > if [[ -n $TGTLABEL ]]; then > TGTLABEL="LABEL=$TGTLABEL" > else > printf '\n ALERT: > You need to have a filesystem label or > UUID for your target device.\n' > if [[ ,vfat,msdos, =~ ,${TGTFS}, ]]; then > printf ' > A label can be set with the dosfslabel command.' > elif [[ ,ext2,ext3,ext4, =~ ,$TGTFS, ]]; then > printf ' > A label can be set with the e2label command.' > elif [[ btrfs == $TGTFS ]]; then > printf ' > A label can be set with the btrfs filesystem label command.' > fi > exitclean > fi > fi > > if [[ ,vfat,msdos, =~ ,$TGTFS, ]]; then > mountopts='-o shortname=winnt,umask=0077' > fi >} > >checkFilesystem $TGTDEV > >if [[ ,ext2,ext3,ext4,btrfs, =~ ,${TGTFS}, && > $(extlinux 2>&1) =~ 'extlinux: command not found' ]]; then > printf "\n ERROR: > This system does not have the EXTLINUX bootloader installed as required > by the '%s' filesystem on the target device, %s.\n > EXTLINUX is available in the syslinux-extlinux & livecd-tools packages. > Exiting...\n\n" $TGTFS $TGTDEV > exitclean >fi > >checkint() { > if ! (( $1 > 0 )); then > shortusage > echo " > ERROR: There is a problem with option '$1'." > exit 1 > fi >} > >cryptedhome=1 >keephome=1 >copyhome='' >copyhomesize=0 >homesizemb=0 >swapsizemb=0 >overlaysizemb=0 >resetoverlay='' >overlay='' >LIVEOS=LiveOS >HOMEFILE=home.img >includes='' > >while (( $# > 2 )); do > case $1 in > --help) > ;; > --noverify) > noverify=noverify > ;; > --avoidsourcescript) > ;; > --nochroot) > ;; > --format) > format=format > ;; > --msdos) > usemsdos=usemsdos > ;; > --reset-mbr|--resetmbr) > resetmbr=resetmbr > ;; > --efi|--mactel) > efi=efi > ;; > --skipcopy) > skipcopy=skipcopy > ;; > --force) > force=force > ;; > --xo) > xo=1 > skipcompress=skipcompress > ;; > --xo-no-home) > xonohome=xonohome > ;; > --timeout) > checkint $2 > timeout=$2 > shift > ;; > --totaltimeout) > checkint $2 > totaltimeout=$2 > shift > ;; > --extra-kernel-args) > kernelargs=$2 > shift > ;; > --multi) > multi=multi > ;; > --livedir) > LIVEOS=$2 > shift > ;; > --compress) > skipcompress='' > ;; > --skipcompress) > skipcompress=skipcompress > ;; > --no-overlay) > overlay=none > ;; > --swap-size-mb) > checkint $2 > swapsizemb=$2 > shift > ;; > --overlay-size-mb) > checkint $2 > overlaysizemb=$2 > shift > ;; > --reset-overlay) > resetoverlay=resetoverlay > ;; > --home-size-mb) > checkint $2 > homesizemb=$2 > shift > ;; > --crypted-home) > cryptedhome=cryptedhome > ;; > --unencrypted-home) > cryptedhome='' > ;; > --delete-home) > keephome='' > ;; > --copy-home) > copyhome=1 > cryptedhome='' > ;; > --include) > includes=($2) > shift > ;; > *) > echo "Invalid arg -- $1" > shortusage > exit 1 > ;; > esac > shift >done > >getpartition() { > local DEV=$1 > local pa=$( < /proc/partitions ) > pa=${pa##*$DEV} > partnum=${pa%% *} >} > >resetMBR() { > if isdevloop "$DEV"; then > return > fi > getdisk $1 > # if efi, we need to use the hybrid MBR > if [[ -n $efi ]]; then > if [[ -f /usr/lib/syslinux/gptmbr.bin ]]; then > cat /usr/lib/syslinux/gptmbr.bin > $device > elif [[ -f /usr/share/syslinux/gptmbr.bin ]]; then > cat /usr/share/syslinux/gptmbr.bin > $device > else > echo 'Could not find gptmbr.bin (SYSLINUX).' > exitclean > fi > else > if [[ -f /usr/lib/syslinux/mbr.bin ]]; then > cat /usr/lib/syslinux/mbr.bin > $device > elif [[ -f /usr/share/syslinux/mbr.bin ]]; then > cat /usr/share/syslinux/mbr.bin > $device > else > echo 'Could not find mbr.bin (SYSLINUX).' > exitclean > fi > fi >} > >checkMBR() { > if isdevloop "$DEV"; then > return 0 > fi > getdisk $1 > > mbrword=($(hexdump -n 2 <<< \ > "$(dd if=$device bs=2 count=1)")) 2>/dev/null || exit 2 > if [[ ${mbrword[1]} == 0000 ]]; then > printf ' > The Master Boot Record, MBR, appears to be blank. > Do you want to replace the MBR on this device? > Press Enter to continue, or Ctrl C to abort.' > read > resetMBR $1 > fi > return 0 >} > >checkPartActive() { > local dev=$1 > getdisk $dev > > # If we're installing to whole-disk and not a partition, then we > # don't need to worry about being active. > if [[ $dev = $device ]]; then > return > fi > if isdevloop "$DEV"; then > return > fi > > local partinfo=$(fdisk -l $device) 2>/dev/null > partinfo=${partinfo##*$dev+( )} > > if [[ ${partinfo:0:1} != * ]]; then > printf "\n ATTENTION: > The partition isn't marked bootable!\n > You can mark the partition as bootable with the following commands:\n > # parted %s > (parted) toggle <N> boot > (parted) quit\n\n" $device > exitclean > fi >} > >checkLVM() { > local dev=$1 > > if [[ -x /sbin/pvs && > "$(/sbin/pvs -o vg_name --noheadings $dev* 2>/dev/null || :)" ]]; then > printf "\n ATTENTION: > Device '$dev' contains a volume group and cannot be formated!\n\n > You can remove the volume group using vgremove.\n" > exitclean > fi > return 0 >} > >createGPTLayout() { > local dev=$1 > getdisk $dev > > printf '\n WARNING: This will DESTROY All DATA on: %s !!\n > Press Enter to continue, or Ctrl C to abort.\n' $device > read > umount ${device}* &> /dev/null || : > parted --script $device mklabel gpt > local sizeinfo=$(LC_ALL=C parted --script -m $device 'unit b print') > sizeinfo=${sizeinfo#*${device}:} > sizeinfo=${sizeinfo%%B*} > parted --script $device unit b mkpart '"EFI System Partition"' fat32 \ > 1048576 $((sizeinfo - 1048576)) set 1 boot on > # Sometimes automount can be _really_ annoying. > echo 'Waiting for devices to settle...' > udevadm settle > sleep 5 > getpartition ${device#/dev/} > TGTDEV=${device}${partnum} > umount $TGTDEV &> /dev/null || : > mkdosfs -n LIVE $TGTDEV > TGTLABEL="UUID=$(blkid -s UUID -o value $TGTDEV)" >} > >createMSDOSLayout() { > local dev=$1 > getdisk $dev > > printf '\n WARNING: This will DESTROY ALL DATA on: %s !!\n > Press Enter to continue, or Ctrl C to abort.\n' $device > read > umount ${device}* &> /dev/null || : > /sbin/parted --script $device mklabel msdos > local sizeinfo=$(LC_ALL=C parted --script -m $device 'unit b print') > sizeinfo=${sizeinfo#*${device}:} > sizeinfo=${sizeinfo%%B*} > parted --script $device unit b mkpart primary fat32 \ > 1048576 $((sizeinfo - 1048576)) set 1 boot on > # Sometimes automount can be _really_ annoying. > echo 'Waiting for devices to settle...' > udevadm settle > sleep 5 > if ! isdevloop "$DEV"; then > getpartition ${device#/dev/} > TGTDEV=${device}${partnum} > else > TGTDEV=${device} > fi > umount $TGTDEV &> /dev/null || : > mkdosfs -n LIVE $TGTDEV > TGTLABEL="UUID=$(blkid -s UUID -o value $TGTDEV)" >} > >createEXTFSLayout() { > local dev=$1 > getdisk $dev > > printf '\n WARNING: This will DESTROY ALL DATA on: %s !!\n > Press Enter to continue, or Ctrl C to abort.\n' $device > read > umount ${device}* &> /dev/null || : > parted --script $device mklabel msdos > local sizeinfo=$(LC_ALL=C parted --script -m $device 'unit b print') > sizeinfo=${sizeinfo#*${device}:} > sizeinfo=${sizeinfo%%B*} > parted --script $device unit b mkpart primary ext2 \ > 1048576 $((sizeinfo - 1048576)) set 1 boot on > # Sometimes automount can be _really_ annoying. > echo 'Waiting for devices to settle...' > udevadm settle > sleep 5 > getpartition ${device#/dev/} > TGTDEV=${device}${partnum} > umount $TGTDEV &> /dev/null || : > > # Check extlinux version > if [[ $(extlinux -v 2>&1) =~ extlinux\ 3 ]]; then > mkfs.ext3 -L LIVE $TGTDEV > else > mkfs.ext4 -L LIVE $TGTDEV > fi > TGTLABEL="UUID=$(blkid -s UUID -o value $TGTDEV)" >} > >checkGPT() { > local dev=$1 > getdisk $dev > local partinfo=$(fdisk -l $device 2>/dev/null) > if ! [[ ${partinfo} =~ \ GPT\ ]]; then > printf '\n ATTENTION: > EFI booting requires a GPT partition table on the boot disk.\n > This can be set up manually, or you can reformat your disk > by running livecd-iso-to-disk with the --format option.' > exitclean > fi > > partinfo=$(LC_ALL=C parted --script -m $device 'print') > while IFS=: read -r -a _info; do > if [[ $partnum == ${_info[0]} ]]; then > volname=${_info[5]} > flags=${_info[6]} > break > fi > done <<< "$partinfo" > > if [[ $volname != 'EFI System Partition' ]]; then > printf "\n ALERT: > The partition name must be 'EFI System Partition'.\n > This can be set with a partition editor, such as parted, > or you can run livecd-iso-to-disk with the --reset-mbr option." > exitclean > fi > if ! [[ $flags =~ boot ]]; then > printf "\n ATTENTION: > The partition isn't marked bootable!\n > You can mark the partition as bootable with the following commands:\n > # parted %s > (parted) toggle <N> boot > (parted) quit\n\n" $device > exitclean > fi >} > >checkSyslinuxVersion() { > if [[ ! -x /usr/bin/syslinux ]]; then > printf '\n ALERT: > You need to have the SYSLINUX package installed to run this script. > Exiting...\n' > exit 1 > fi > local check=($(syslinux --version 2>&1)) || : > if [[ $check != syslinux ]]; then > SYSLINUXPATH='' > elif [[ -n $multi ]]; then > SYSLINUXPATH=$LIVEOS/syslinux > else > SYSLINUXPATH=syslinux > fi >} > >cp_p() { > strace -q -ewrite cp -- "${1}" "${2}" 2>&1 | > awk '{ > count += $NF > if (count % 10 == 0) { > percent = count / total_size * 100 > printf "%3d%% [", percent > for (i=0;i<=percent;i++) > printf "=" > printf ">" > for (i=percent;i<100;i++) > printf " " > printf "]\r" > } > } > END { print "" }' total_size=$(stat -c '%s' "${1}") count=0 >} > >copyFile() { > if [[ -x /usr/bin/rsync ]]; then > rsync --inplace --8-bit-output --progress "$1" "$2" > return > fi > if [[ -x /usr/bin/gvfs-copy ]]; then > gvfs-copy -p "$1" "$2" > return > fi > if [[ -x /usr/bin/strace && -x /bin/awk ]]; then > cp_p "$1" "$2" > return > fi > cp "$1" "$2" >} > >if [[ -z $noverify && $SRCFS == iso9660 ]]; then > # verify the image > echo 'Verifying image...' > if ! checkisomd5 --verbose "$SRC"; then > printf ' > Are you SURE you want to continue?\n > Press Enter to continue, or Ctrl C to abort.\n' > read > fi >fi > ># Format the device >if [[ -n $format && -z $skipcopy ]]; then > checkLVM $TGTDEV > > if [[ -n $efi ]]; then > createGPTLayout $TGTDEV > elif [[ -n $usemsdos || ! -x /sbin/extlinux ]]; then > createMSDOSLayout $TGTDEV > else > createEXTFSLayout $TGTDEV > fi >fi > >if [[ -n $efi ]]; then > checkGPT $TGTDEV >fi > >checkSyslinuxVersion > ># Because we can't set boot flag for EFI Protective on msdos partition tables >[[ -z $efi ]] && checkPartActive $TGTDEV >[[ -n $resetmbr ]] && resetMBR $TGTDEV > >checkMBR $TGTDEV > >if ((overlaysizemb > 0)); then > if [[ ,vfat,msdos, =~ ,$TGTFS, ]] && ((overlaysizemb > 2048)); then > printf '\n ALERT: > An overlay size greater than 2048 MiB > is not allowed on VFAT formatted filesystems.\n' > exitclean > fi > LABEL=$(blkid -s LABEL -o value $TGTDEV) || : > if [[ $LABEL =~ ( ) ]]; then > printf '\n ALERT: > The LABEL (%s) on %s has spaces in it. > Spaces do not work with the overlay.\n\n > Use dosfslabel or e2fslabel to change the label.\n' $LABEL $TGTDEV > exitclean > fi > OVERFILE="overlay-$LABEL-$(blkid -s UUID -o value $TGTDEV)" || : >fi > >if [[ ,vfat,msdos, =~ ,$TGTFS, ]] && ((homesizemb > 2048)); then > printf '\n ALERT: > A home.img size greater than 2048 MiB > is not allowed on VFAT formatted filesystems.\n' > exitclean >fi > >if [[ ,vfat,msdos, =~ ,$TGTFS, ]] && ((swapsizemb > 2048)); then > printf '\n ALERT: > A swap file size greater than 2048 MiB > is not allowed on VFAT formatted filesystems.\n' > exitclean >fi > >TGTMNT=$(mktemp -d /media/tgttmp.XXXXXX) >eval $saved_umask >mount $mountopts $TGTDEV $TGTMNT || exitclean > >if [[ -d $SRCMNT/LiveOS ]]; then > SRCLIVEOSDIR=$SRCMNT/LiveOS >else > SRCLIVEOSDIR=$SRCMNT >fi >if [[ ! -f $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome ]]; then > printf '\n ERROR: > There appears to be no persistent /home.img on the source. > Please check your inputs. Exiting...\n' > exitclean >fi >if [[ $SRCFS == iso9660 && -f $SRCMNT/$LIVEOS/$HOMEFILE && > -z $copyhome ]]; then > printf '\n NOTICE: > The source has a persistent home.img intended for installation. > If there is an existing home.img on the target device, > you will be asked to approve its deletion.\n > Press Enter to continue, or Ctrl C to abort.\n' > read > copyhome=1 >fi >if [[ -f $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome && -n $cryptedhome ]]; then > printf '\n ATTENTION: > The default --encrypted-home option is only available for newly-created > home.img filesystems. If the home.img on the source is encrypted, > that feature will carry over to the new installation.\n > Press Enter to continue, or Ctrl C to abort.\n' > read >fi >if [[ -f $TGTMNT/$LIVEOS/$HOMEFILE && -n $keephome && > $homesizemb -gt 0 ]]; then > printf '\n ERROR: > The target has an existing home.img and you requested that a new > home.img be created. To remove an existing home.img on the target, > you must explicitly specify --delete-home as an installation option.\n > Please adjust your home options. Exiting...\n' > exitclean >fi >if [[ -f $TGTMNT/$LIVEOS/$HOMEFILE && -n $keephome && -n $copyhome && > -s $SRCMNT/$LIVEOS/$HOMEFILE ]]; then > printf '\n ERROR: > The target has an existing home.img, and you requested that one from > the from the source be copied to the target device. > To remove an existing home.img on the target, you must explicitly > specify the --delete-home option.\n > Please adjust your home options. Exiting...\n' > exitclean >fi >if [[ -s $SRCMNT/$LIVEOS/$HOMEFILE && -n $copyhome && > $homesizemb -gt 0 ]]; then > printf '\n ERROR: > You requested a new home AND to copy one from the source.\n > Please request only one of these options. Exiting...\n' > exitclean >fi >if [[ ! -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome && > $overlaysizemb -gt 0 ]]; then > printf '\n NOTICE: > There appears to be no persistent home.img on this source.\n > Would you LIKE to continue with just the persistent overlay?\n > Press Enter to continue, or Ctrl C to abort.\n' > read > copyhome='' >fi >if [[ -n $resetoverlay ]]; then > OVERFILE="overlay-$(blkid -s LABEL -o value $TGTDEV)-$( > blkid -s UUID -o value $TGTDEV)" > if [[ ! -s $TGTMNT/$LIVEOS/$OVERFILE ]]; then > printf '\n NOTICE: > There is no persistent overlay on the target device to reset.\n > Exiting...\n' > exitclean > elif ((overlaysizemb > 0)); then > printf '\n ERROR: > You requested a new persistent overlay AND to reset the current one.\n > Please select only one of these options. Exiting...\n' > exitclean > fi >fi >if [[ -n $efi ]]; then > if [[ -d $SRCMNT/EFI/BOOT ]]; then > EFI_BOOT=/EFI/BOOT > elif [[ -d $SRCMNT/EFI/boot ]]; then > EFI_BOOT=/EFI/boot > else > printf '\n ATTENTION: > You requested EFI booting, but this source image lacks support > for EFI booting. Exiting...\n' > exitclean > fi >fi > ># Let's try to make sure that there's enough room on the target device. >if [[ -d $TGTMNT/$LIVEOS ]]; then > tbd=($(du -B 1M $TGTMNT/$LIVEOS)) > if [[ -s $TGTMNT/$LIVEOS/$HOMEFILE ]] && [[ -n $keephome ]]; then > homesize=($(du -B 1M $TGTMNT/$LIVEOS/$HOMEFILE)) > tbd=$((tbd - homesize)) > fi >else > tbd=0 >fi > >if [[ live == $srctype ]]; then > targets=$TGTMNT/$SYSLINUXPATH > [[ -n $efi ]] && targets+=\ $TGTMNT$EFI_BOOT > [[ -n $xo ]] && targets+=\ $TGTMNT/boot/olpc.fth > duTable=($(du -c -B 1M $targets 2> /dev/null || :)) > tbd=$((tbd + ${duTable[*]: -2:1})) >fi > >if [[ -n $skipcompress ]] && [[ -s $SRCMNT/LiveOS/squashfs.img ]]; then > if mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT; then > livesize=($(du -B 1M --apparent-size $SRCMNT/LiveOS/ext3fs.img)) > umount $SRCMNT > if ((livesize > 2048)) && [[ ,vfat,msdos, =~ ,$TGTFS, ]]; then > printf '\n ATTENTION: > An uncompressed image size greater than 2048 MiB is not suitable > for a VFAT-formatted device. The compressed SquashFS will be > copied to the target device.\n > Press Enter to continue, or Ctrl C to abort.\n' > read > skipcompress='' > livesize=0 > fi > else > printf '\n ATTENTION: > --skipcompress or --xo was specified, but the currently running > kernel can not mount the SquashFS from the source file to extract it.\n > Instead, the compressed SquashFS will be copied to the target device.\n > Press Enter to continue, or Ctrl C to abort.\n' > read > skipcompress='' > fi >fi > >if [[ live == $srctype ]]; then > sources=$SRCMNT/LiveOS/ext3fs.img\ $SRCMNT/LiveOS/osmin.img > [[ -z $skipcompress ]] && sources+=\ $SRCMNT/LiveOS/squashfs.img > sources+=\ $SRCMNT/isolinux\ $SRCMNT/syslinux > [[ -n $efi ]] && sources+=\ $SRCMNT$EFI_BOOT > [[ -n $xo ]] && sources+=\ $SRCMNT/boot/olpc.fth > duTable=($(du -c -B 1M "$Installscript" $sources 2> /dev/null || :)) > livesize=$((livesize + ${duTable[*]: -2:1} + 1)) > [[ -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome ]] && \ > copyhomesize=($(du -s -B 1M $SRCLIVEOSDIR/$HOMEFILE)) > if [[ $SRCFS == iso9660 ]]; then > # Add supplementary .iso content. > [[ -e $SRCMNT/boot ]] && findargs=$SRCMNT/boot > findargs+=\ $SRCMNT' -xdev -mindepth 1 -maxdepth 1 > ( -type d -o -type f ) > ! ( -name isolinux -o -name LiveOS -o -name EFI -o -name olpc.fth ) > -print0' > fi > if [[ -n $includes ]]; then > includes=(${includes[@]/#/$SRCMNT}) > missing='' > for i in ${!includes[*]}; do > if [[ ! -e ${includes[i]} ]]; then > missing+=' '${includes[i]#$SRCMNT}$'\n' > fi > done > if [[ -n $missing ]]; then > printf '\n ERROR: > You requested inclusion of these files that were not found:\n > Please check your input. Exiting...\n > %s ' "$missing" > exitclean > fi > fi > includes_size=0 > if [[ -n $includes || -n $findargs ]]; then > duTable=($(find ${includes[*]} $findargs | \ > du -cs -B 1M --files0-from=-)) > includes_size=${duTable[*]: -2:1} > fi >fi >freespace=($(df -B 1M --total $TGTDEV)) >freespace=${freespace[*]: -2:1} > >if [[ live == $srctype ]]; then > tba=$((overlaysizemb + homesizemb + copyhomesize + includes_size + > livesize + swapsizemb)) > if ((tba > freespace + tbd)); then > needed=$((tba - freespace - tbd)) > printf '\n The live image + overlay, home, includes, & swap space, > \r if requested, will NOT fit in the space available on the > \r target device.\n > \r + Size of live image: %10s MiB\n' $livesize > (($overlaysizemb > 0)) && > printf ' + Overlay size: %16s\n' $overlaysizemb > (($homesizemb > 0)) && > printf ' + Home directory size: %9s\n' $homesizemb > (($copyhomesize > 0)) && > printf ' + Copy home directory size: %4s\n' $copyhomesize > (($includes_size > 0)) && > printf ' + Included files size: %9s\n' $includes_size > (($swapsizemb > 0)) && > printf ' + Swap overlay size: %11s\n' $swapsizemb > printf '\r = Total requested space: %6s MiB\n > \r - Space available: %12s > \r ============================== > \r Space needed: %15s MiB\n > \r To fit the installation on this device, > \r free storage on the target, or decrease the > \r requested size total by: %6s MiB\n\n' $tba\ > $((freespace + tbd)) $needed $needed > exitclean > fi >fi > ># Verify available space for DVD installer >if [[ $srctype = installer ]]; then > if [[ -z $skipcopy ]]; then > duTable=($(du -s -B 1M $SRC)) > srcsize=${duTable[0]} > else > srcsize=0 > fi > if [[ $imgtype == install ]]; then > imgpath=images/install.img > else > imgpath=isolinux/initrd.img > fi > duTable=($(du -s -B 1M $SRCMNT/$imgpath)) > instimgsize=${duTable[0]} > > tbd=0 > if [[ -e $TGTMNT/$imgpath ]]; then > duTable=($(du -s -B 1M $TGTMNT/$imgpath)) > tbd=${duTable[0]} > fi > if [[ -e $TGTMNT/$(basename $SRC) ]]; then > duTable=($(du -s -B 1M $TGTMNT/$(basename $SRC))) > tbd=$((tbd + ${duTable[0]})) > fi > printf '\n Size of DVD image: %s\n > Size of %s: %s\n > Available space: %s\n' $srcsize $imgpath $instimgsize $((freespace + tbd)) > if (( ((srcsize + instimgsize)) > ((freespace + tbd)) )); then > printf '\n ERROR: > Unable to fit the DVD image + the install.img on the available space > of the target device. Exiting...' > exitclean > fi >fi > >if [[ -z $skipcopy && $srctype == live ]]; then > if [[ -d $TGTMNT/$LIVEOS && -z $force ]]; then > echo 'The target device is already set up with a LiveOS image.' > if [[ -z $keephome && -e $TGTMNT/$LIVEOS/$HOMEFILE ]]; then > printf '\n WARNING: > \r The old persistent home.img will be deleted!\n > \r Press Enter to continue, or Ctrl C to abort.' > read > else > echo 'Deleting old OS in fifteen seconds...' > sleep 15 > [[ -e $TGTMNT/$LIVEOS/$HOMEFILE && -n $keephome ]] && > mv $TGTMNT/$LIVEOS/$HOMEFILE $TGTMNT/$HOMEFILE > fi > rm -rf $TGTMNT/$LIVEOS > fi >fi > ># Bootloader is always reconfigured, so keep these out of the if skipcopy code. >[[ ! -d $TGTMNT/$SYSLINUXPATH ]] && mkdir -p $TGTMNT/$SYSLINUXPATH >[[ -n $efi && ! -d $TGTMNT$EFI_BOOT ]] && mkdir -p $TGTMNT$EFI_BOOT > ># Live image copy >if [[ $srctype == live && -z $skipcopy ]]; then > echo 'Copying LiveOS image to target device...' > [[ ! -d $TGTMNT/$LIVEOS ]] && mkdir $TGTMNT/$LIVEOS > [[ -n $keephome && -f $TGTMNT/$HOMEFILE ]] && > mv $TGTMNT/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE > if [[ -n $skipcompress && -f $SRCMNT/LiveOS/squashfs.img ]]; then > mount -o loop $SRCMNT/LiveOS/squashfs.img $SRCMNT || exitclean > copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || { > umount $SRCMNT ; exitclean ; } > umount $SRCMNT > elif [[ -f $SRCMNT/LiveOS/squashfs.img ]]; then > copyFile $SRCMNT/LiveOS/squashfs.img $TGTMNT/$LIVEOS/squashfs.img || > exitclean > elif [[ -f $SRCMNT/LiveOS/ext3fs.img ]]; then > copyFile $SRCMNT/LiveOS/ext3fs.img $TGTMNT/$LIVEOS/ext3fs.img || > exitclean > fi > if [[ -f $SRCMNT/LiveOS/osmin.img ]]; then > copyFile $SRCMNT/LiveOS/osmin.img $TGTMNT/$LIVEOS/osmin.img || > exitclean > fi > if [[ -s $SRCLIVEOSDIR/$HOMEFILE && -n $copyhome ]]; then > copyFile $SRCLIVEOSDIR/$HOMEFILE $TGTMNT/$LIVEOS/$HOMEFILE || > exitclean > fi > cp_mode='-ax' > [[ ,vfat,msdos, =~ ,$TGTFS, ]] && cp_mode='-dRx' > if [[ $SRCFS == iso9660 ]]; then > # Add supplementary .iso content. > find $findargs -exec cp $cp_mode -t $TGTMNT {} + 1> /dev/null || > exitclean > fi > if [[ -n $includes ]]; then > cp $cp_mode -t $TGTMNT ${includes[*]} || exitclean > fi > sync >fi > ># DVD installer copy >if [[ $srctype == installer || $srctype == netinst ]]; then > echo 'Copying DVD image to target device.' > mkdir -p $TGTMNT/images/ > if [[ $imgtype == install ]]; then > copyFile $SRCMNT/images/install.img $TGTMNT/images/install.img || > exitclean > fi > if [[ $srctype == installer && -z $skipcopy ]]; then > cp $SRC $TGTMNT/ > fi > sync >fi > ># Adjust syslinux sources for replication of installed images ># between filesystem types. >if [[ -z $skipcopy ]]; then > if [[ -d $SRCMNT/isolinux/ ]]; then > cp $SRCMNT/isolinux/* $TGTMNT/$SYSLINUXPATH > elif [[ -d $SRCMNT/syslinux/ ]]; then > cp $SRCMNT/syslinux/* $TGTMNT/$SYSLINUXPATH > if [[ -f $SRCMNT/syslinux/extlinux.conf ]]; then > mv $TGTMNT/$SYSLINUXPATH/extlinux.conf \ > $TGTMNT/$SYSLINUXPATH/isolinux.cfg > elif [[ -f $SRCMNT/syslinux/syslinux.cfg ]]; then > mv $TGTMNT/$SYSLINUXPATH/syslinux.cfg \ > $TGTMNT/$SYSLINUXPATH/isolinux.cfg > fi > fi >fi >BOOTCONFIG=$TGTMNT/$SYSLINUXPATH/isolinux.cfg ># Set this to nothing so sed doesn't care. >BOOTCONFIG_EFI='' >if [[ -n $efi ]]; then > cp $SRCMNT$EFI_BOOT/* $TGTMNT$EFI_BOOT > > # FIXME > # There is a problem here. On older LiveCD's the files are boot?*.conf > # They really should be renamed to BOOT?*.conf > > # this is a little ugly, but it gets the "interesting" named config file > BOOTCONFIG_EFI=$TGTMNT$EFI_BOOT/+(BOOT|boot)?*.conf > rm -f $TGTMNT$EFI_BOOT/grub.conf > > # On some images (RHEL) the BOOT*.efi file isn't in $EFI_BOOT, but is in > # the eltorito image, so try to extract it, if it is missing. > > # test for presence of *.efi grub binary > if [[ ! -f $TGTMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]]; then > if [[ ! -x /usr/bin/dumpet ]]; then > printf '\n ALERT: > \r As no /usr/bin/dumpet tool was found, > \r an EFI image will not boot. The source media is missing > \r the grub binary in /EFI/BOOT/*efi.\n' > exitclean > else > # dump the eltorito image with dumpet, output is $SRC.1 > dumpet -i $SRC -d > EFIMNT=$(mktemp -d /media/srctmp.XXXXXX) > mount -o loop $SRC.1 $EFIMNT > > if [[ -f $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi ]]; then > cp $EFIMNT$EFI_BOOT/+(BOOT|boot)?*.efi $TGTMNT$EFI_BOOT > else > printf '\n ALERT: > \r No BOOT*.efi was found in the eltorito image. > \r EFI boot is not available with this source.\n' > umount $EFIMNT > rm $SRC.1 > exitclean > fi > umount $EFIMNT > rm $SRC.1 > fi > fi >fi > >if [[ live == $srctype ]]; then > # Copy this installer script. > cp -fT "$Installscript" $TGTMNT/$LIVEOS/livecd-iso-to-disk > chmod +x $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null || : > > # If the source is an installed Live USB/SD image, restore the boot config > # file to a base state before updating. > if [[ -d $SRCMNT/syslinux/ ]]; then > echo 'Preparing boot config file.' > sedscript='s/\(r*d*.*live.*ima*ge*\) .* \(rd.luks=0\|rd_NO_LUKS\)/\1' > sedscript+=' quiet rhgb \2/' > sed -i "s/root=live:[^ ]*/root=live:CDLABEL=name/; t more > s/root=[^ ]*/root=CDLABEL=name/ > :more; s/rootfstype=[^ ]* [^ ]*/rootfstype=auto ro/ > $sedscript > s/\(r*d*.*live.*ima*ge*\) .* quiet/\1 quiet/" \ > $BOOTCONFIG $BOOTCONFIG_EFI > sed -i 's/^timeout.*$/timeout\ 100/ > /^totaltimeout.*$/d' $BOOTCONFIG > fi >fi >echo 'Updating boot config file.' ># adjust label and fstype >if [[ -n $LANG ]]; then > kernelargs=$kernelargs\ LANG=$LANG >fi >sed -i "s/CDLABEL=[^ ]*/$TGTLABEL/ > s/rootfstype=[^ ]*/rootfstype=$TGTFS/ > s/LABEL=[^ ]*/$TGTLABEL/" $BOOTCONFIG $BOOTCONFIG_EFI >if [[ -n $kernelargs ]]; then > sed -i "s;initrd0.img;& ${kernelargs};" $BOOTCONFIG $BOOTCONFIG_EFI >fi >if [[ $LIVEOS != LiveOS ]]; then > sed -i "s/r*d*.*live.*ima*ge*/& live_dir=$LIVEOS/"\ > $BOOTCONFIG $BOOTCONFIG_EFI >fi > ># DVD Installer >if [[ $srctype == installer ]]; then > sedscript="s;initrd=initrd.img;initrd=initrd.img ${LANG:+LANG=$LANG}" > sedscript+=" repo=hd:$TGTLABEL:/;g" > sed -i "$sedscript" -e 's;stage2=\S*;;g' $BOOTCONFIG > if [[ -n $efi ]]; then > # Images are in $SYSLINUXPATH now > sed -i "s;/images/pxeboot/;/$SYSLINUXPATH/;g > s;vmlinuz;vmlinuz ${LANG:+LANG=$LANG} repo=hd:$TGTLABEL:/;g"\ > $BOOTCONFIG_EFI > fi >fi > ># DVD Installer for netinst. >if [[ $srctype == netinst ]]; then > if [[ $imgtype == install ]]; then > sed -i "s;stage2=\S*;stage2=hd:$TGTLABEL:/images/install.img;g"\ > $BOOTCONFIG > else > # The initrd has everything, so no stage2 > sed -i 's;stage2=\S*;;g' $BOOTCONFIG > fi > if [[ -n $efi ]]; then > # Images are in $SYSLINUXPATH now > sed -i "s;/images/pxeboot/;/$SYSLINUXPATH/;g" $BOOTCONFIG_EFI > fi >fi > ># Adjust the boot timeouts. >if [[ -n $timeout ]]; then > sed -i "s/^timeout.*$/timeout\ $timeout/" $BOOTCONFIG >fi >if [[ -n $totaltimeout ]]; then > sed -i "/^timeout.*$/a\totaltimeout\ $totaltimeout" $BOOTCONFIG >fi > ># Use repo if the .iso has the repository on it, otherwise use stage2, which ># will default to using the network mirror. >if [[ -e $SRCMNT/.discinfo ]]; then > METHODSTR=repo >else > METHODSTR=stage2 >fi > >if [[ $overlay == none ]]; then > sed -i "s/r*d*.*live.*ima*ge*/& overlay=none/ > s/ ro / rw /" $BOOTCONFIG $BOOTCONFIG_EFI >fi > >if ((overlaysizemb > 0)); then > echo 'Initializing persistent overlay file...' > if [[ -z $skipcopy ]]; then > if [[ ,vfat,msdos, =~ ,$TGTFS, ]]; then > # vfat can't handle sparse files. > dd if=/dev/zero of=$TGTMNT/$LIVEOS/$OVERFILE \ > count=$overlaysizemb bs=1M > else > dd if=/dev/null of=$TGTMNT/$LIVEOS/$OVERFILE \ > count=1 bs=1M seek=$overlaysizemb > fi > fi > sed -i "s/r*d*.*live.*ima*ge*/& overlay=${TGTLABEL}/ > s/ ro / rw /" $BOOTCONFIG $BOOTCONFIG_EFI >fi > >if [[ -n $resetoverlay && -z $skipcopy ]]; then > dd if=/dev/zero of=$TGTMNT/$LIVEOS/$OVERFILE bs=64k count=1 conv=notrunc >fi > >if ((swapsizemb > 0)) && [[ -z $skipcopy ]]; then > echo 'Initializing swap file...' > dd if=/dev/zero of=$TGTMNT/$LIVEOS/swap.img count=$swapsizemb bs=1M > mkswap -f $TGTMNT/$LIVEOS/swap.img >fi > >if ((homesizemb > 0)) && [[ -z $skipcopy ]]; then > echo 'Initializing persistent home filesystem...' > homesource=/dev/zero > [[ -n $cryptedhome ]] && homesource=/dev/urandom > if [[ ,vfat,msdos, =~ ,$TGTFS, ]]; then > # vfat can't handle sparse files. > dd if=${homesource} of=$TGTMNT/$LIVEOS/$HOMEFILE \ > count=$homesizemb bs=1M > else > dd if=/dev/null of=$TGTMNT/$LIVEOS/$HOMEFILE \ > count=1 bs=1M seek=$homesizemb > fi > if [[ -n $cryptedhome ]]; then > loop=$(losetup -f) > losetup $loop $TGTMNT/$LIVEOS/$HOMEFILE > > echo 'Encrypting persistent home filesystem...' > while ! cryptsetup luksFormat -y -q $loop; do :; done; > > echo 'Please enter the password again to unlock the device.' > while ! cryptsetup luksOpen $loop EncHomeFoo; do :; done; > > mkfs.ext4 -j /dev/mapper/EncHomeFoo > tune2fs -c0 -i0 -ouser_xattr,acl /dev/mapper/EncHomeFoo > sleep 2 > cryptsetup luksClose EncHomeFoo > losetup -d $loop > else > echo 'Formatting unencrypted home filesystem...' > mkfs.ext4 -F -j $TGTMNT/$LIVEOS/$HOMEFILE > tune2fs -c0 -i0 -ouser_xattr,acl $TGTMNT/$LIVEOS/$HOMEFILE > fi >fi > ># Create the forth files for booting on the XO, if requested. ># We'd do this unconditionally, but you have to have a kernel that will ># boot on the XO anyway. >if [[ -n $xo ]]; then > echo 'Setting up /boot/olpc.fth file.' > while read -r args; do > if [[ $args =~ ^append ]]; then > args=${args:6} > args=${args/ initrd=+([^ ])/} > break > fi > done < $TGTMNT/$SYSLINUXPATH/isolinux.cfg > if [[ -z $xonohome && ! -f $TGTMNT/$LIVEOS/$HOMEFILE ]]; then > args=$args\ persistenthome=mtd0 > fi > args=$args\ reset_overlay > xosyspath=${SYSLINUXPATH//\//\\} > if [[ ! -d $TGTMNT/boot ]]; then > mkdir -p $TGTMNT/boot > fi > cat > $TGTMNT/boot/olpc.fth <<EOF >\ Boot script for USB boot >hex rom-pa fffc7 + 4 \$number drop h# 2e19 < [if] > patch 2drop erase claim-params > : high-ramdisk ( -- ) > cv-load-ramdisk > h# 22c +lp l@ 1+ memory-limit umin /ramdisk - ffff.f000 and ( new-ramdisk-adr ) > ramdisk-adr over /ramdisk move ( new-ramdisk-adr ) > to ramdisk-adr > ; > ' high-ramdisk to load-ramdisk >[then] > >: set-bootpath-dev ( -- ) > " /chosen" find-package if ( phandle ) > " bootpath" rot get-package-property 0= if ( propval$ ) > get-encoded-string ( bootpath$ ) > [char] \ left-parse-string 2nip ( dn$ ) > dn-buf place ( ) > then > then > > " /sd" dn-buf count sindex 0>= if > " sd:" > else > " u:" > then > " BOOTPATHDEV" \$set-macro >; > >set-bootpath-dev >" $args" to boot-file >" \${BOOTPATHDEV}$xosyspath\initrd0.img" expand$ to ramdisk >" \${BOOTPATHDEV}$xosyspath\vmlinuz0" expand$ to boot-device >unfreeze >boot >EOF >fi > >if [[ -z $multi ]]; then > echo 'Installing boot loader.' > if [[ -n $efi ]]; then > # Replace the ia32 hack. > if [[ -f $TGTMNT$EFI_BOOT/boot.conf ]]; then > cp -f $TGTMNT$EFI_BOOT/BOOTia32.conf $TGTMNT$EFI_BOOT/BOOT.conf > fi > fi > > # This is a bit of a kludge, but SYSLINUX doesn't guarantee the API > # for its com32 modules. :/ > if [[ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 && > -f /usr/share/syslinux/vesamenu.c32 ]]; then > cp /usr/share/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32 > elif [[ -f $TGTMNT/$SYSLINUXPATH/vesamenu.c32 && > -f /usr/lib/syslinux/vesamenu.c32 ]]; then > cp /usr/lib/syslinux/vesamenu.c32 $TGTMNT/$SYSLINUXPATH/vesamenu.c32 > elif [[ -f $TGTMNT/$SYSLINUXPATH/menu.c32 && > -f /usr/share/syslinux/menu.c32 ]]; then > cp /usr/share/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32 > elif [[ -f $TGTMNT/$SYSLINUXPATH/menu.c32 && > -f /usr/lib/syslinux/menu.c32 ]]; then > cp /usr/lib/syslinux/menu.c32 $TGTMNT/$SYSLINUXPATH/menu.c32 > fi > > if [[ ,vfat,msdos, =~ ,$TGTFS, ]]; then > # SYSLINUX expects the config to be named syslinux.cfg, > # and has to run with the file system unmounted. > mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg \ > $TGTMNT/$SYSLINUXPATH/syslinux.cfg > # Deal with mtools complaining about ldlinux.sys > if [[ -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys ]]; then > rm -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys > fi > chmod -R go+r $TGTMNT/$SYSLINUXPATH $TGTMNT/$LIVEOS > cleanup $? > if [[ -n $SYSLINUXPATH ]]; then > syslinux -d $SYSLINUXPATH $TGTDEV > else > syslinux $TGTDEV > fi > elif [[ ,ext2,ext3,ext4,btrfs, =~ ,${TGTFS}, ]]; then > # extlinux expects the config to be named extlinux.conf, > # and has to be run with the file system mounted. > mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg \ > $TGTMNT/$SYSLINUXPATH/extlinux.conf > extlinux -i $TGTMNT/$SYSLINUXPATH > # Starting with SYSLINUX 4, ldlinux.sys is used on all file systems. > if [[ -f $TGTMNT/$SYSLINUXPATH/extlinux.sys ]]; then > chattr -i $TGTMNT/$SYSLINUXPATH/extlinux.sys > elif [[ -f $TGTMNT/$SYSLINUXPATH/ldlinux.sys ]]; then > chattr -i $TGTMNT/$SYSLINUXPATH/ldlinux.sys > fi > chmod -R go+r $TGTMNT/$SYSLINUXPATH $TGTMNT/$LIVEOS > cleanup > fi >else > # We need to do some more config file tweaks for multi-image mode. > sed -i "s;kernel vm;kernel /$LIVEOS/syslinux/vm; > s;initrd=i;initrd=/$LIVEOS/syslinux/i;" \ > $TGTMNT/$SYSLINUXPATH/isolinux.cfg > mv $TGTMNT/$SYSLINUXPATH/isolinux.cfg $TGTMNT/$SYSLINUXPATH/syslinux.cfg > chmod -R go+r $TGTMNT/$SYSLINUXPATH $TGTMNT/$LIVEOS > cleanup >fi >success=success
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 663986
:
610112
|
610337