X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=scripts%2Flive;h=db1d355d0ccd38fe3c0c0c0987e4cd7dc5ab14c6;hb=08244e9b0c9b4be3c841fcc7d54f9b940ab4ec1c;hp=73a965e0b947af8fd69eb760b8390e05969fc45f;hpb=cdb98bbbdc41b29c6b94dc5aed36393daec84cf8;p=live-boot-grml.git diff --git a/scripts/live b/scripts/live index 73a965e..db1d355 100755 --- a/scripts/live +++ b/scripts/live @@ -2,669 +2,1655 @@ # set -e -export PATH=/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin +export PATH="/root/usr/bin:/root/usr/sbin:/root/bin:/root/sbin:/usr/bin:/usr/sbin:/bin:/sbin" echo "/root/lib" >> /etc/ld.so.conf echo "/root/usr/lib" >> /etc/ld.so.conf -mountpoint=/live_media +mountpoint="/live/image" +LIVE_MEDIA_PATH="live" root_persistence="live-rw" home_persistence="home-rw" root_snapshot_label="live-sn" home_snapshot_label="home-sn" -USERNAME=user +USERNAME="user" USERFULLNAME="Live user" -HOSTNAME=host -BUILD_SYSTEM=Custom +HOSTNAME="host" -mkdir -p $mountpoint +mkdir -p "${mountpoint}" + +# Create /etc/mtab for debug purpose and future syncs +if [ ! -d /etc ] +then + mkdir /etc/ +fi + +if [ ! -f /etc/mtab ] +then + touch /etc/mtab +fi [ -f /etc/live.conf ] && . /etc/live.conf -export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM +export USERNAME USERFULLNAME HOSTNAME . /scripts/live-helpers -if [ ! -f /live.vars ]; then - touch /live.vars +if [ ! -f /live.vars ] +then + touch /live.vars fi -parse_cmdline () +Arguments () { - PRESEEDS= - # looking for live-initramfs specifics options as kernel parameters - for x in $(cat /proc/cmdline); do - case $x in - userfullname=*) - export USERFULLNAME=${x#userfullname=} - export LIVECONF="changed" - ;; - hostname=*) - export HOSTNAME=${x#hostname=} - export LIVECONF="changed" - ;; - username=*) - export USERNAME=${x#username=} - export LIVECONF="changed" - ;; - netboot*) - export NETBOOT=${x#netboot=} ;; - access=*) - export ACCESS=${x#access=} ;; - xdebconf) - export XDEBCONF="Yes" ;; - xvideomode=*) - export XVIDEOMODE="${x#xvideomode=}" ;; - toram) - export TORAM="Yes" ;; - todisk=*) - export TODISK=${x#todisk=} ;; - noswap) - export NOSWAP="Yes" ;; - noautologin) - export NOAUTOLOGIN="Yes" ;; - noxautologin) - export NOXAUTOLOGIN="Yes" ;; - nosudo) - export NOSUDO="Yes" ;; - showmounts) - export SHOWMOUNTS="Yes" ;; - persistent) - export PERSISTENT="Yes" ;; - nopersistent) - export PERSISTENT="" ;; - ip*) - STATICIP=${x#ip=} - if [ "${STATICIP}" == "" ]; then - STATICIP="frommedia" - fi - export STATICIP ;; - live-getty) - export LIVE_GETTY=1 ;; - bootfrom=*|live-media=*) - export LIVE_MEDIA=${x#*=} ;; - live-media-encryption=*|encryption=*) - export LIVE_MEDIA_ENCRYPTION=${x#*=} ;; - live-media-timeout=*) - export LIVE_MEDIA_TIMEOUT=${x#live-media-timeout=} ;; - live-media-offset=*) - export LIVE_MEDIA_OFFSET=${x#live-media-offset=} ;; - locale=*|debian-installer/locale=*) - export LOCALE=${x#*=} ;; - keyb=*|kbd-chooser/method=*) - export KBD=${x#*=} ;; - klayout=*|console-setup/layoutcode=*) - export KLAYOUT=${x#*=} ;; - koptions=*) - export KOPTIONS=${x#koptions=} ;; - kvariant=*|console-setup/variantcode=*) - export KVARIANT=${x#*=} ;; - kmodel=*|console-setup/modelcode=*) - export KMODEL=${x#*=} ;; - module=*) - export MODULE=${x#module=} ;; - preseed/file=*|file=*) - export LOCATION="${x#*=}" ;; - */*=*) - question="${x%%=*}" - value="${x#*=}" - PRESEEDS="${PRESEEDS}\"${question}=${value}\" " - ;; - console=*) - export DEFCONSOLE="${x#*=}" ;; - esac - done - - # sort of compatibility with netboot.h from linux docs - if [ -z "${NETBOOT}" ]; then - if [ "${ROOT}" == "/dev/nfs" ]; then - NETBOOT="nfs" - export NETBOOT - elif [ "${ROOT}" == "/dev/cifs" ]; then - NETBOOT="cifs" - export NETBOOT - fi - fi - - if [ -z "${MODULE}" ]; then - MODULE=order - fi + PRESEEDS="" + + for ARGUMENT in $(cat /proc/cmdline) + do + case "${ARGUMENT}" in + access=*) + ACCESS="${ARGUMENT#access=}" + export ACCESS + ;; + + console=*) + DEFCONSOLE="${ARGUMENT#*=}" + export DEFCONSOLE + ;; + + debug) + DEBUG="Yes" + export DEBUG + + set -x + ;; + + fetch=*) + FETCH="${ARGUMENT#fetch=}" + export FETCH + ;; + + hook=*) + HOOK="${ARGUMENT#hook=}" + export HOOK + ;; + + ftpfs=*) + FTPFS="${ARGUMENT#ftpfs=}" + export FTPFS + ;; + + httpfs=*) + HTTPFS="${ARGUMENT#httpfs=}" + export HTTPFS + ;; + + hostname=*) + HOSTNAME="${ARGUMENT#hostname=}" + LIVECONF="changed" + export HOSTNAME LIVECONF + ;; + + username=*) + USERNAME="${ARGUMENT#username=}" + LIVECONF="changed" + export USERNAME LIVECONF + ;; + + userfullname=*) + USERFULLNAME="${ARGUMENT#userfullname=}" + LIVECONF="changed" + export USERFULLNAME LIVECONF + ;; + + ignore_uuid) + IGNORE_UUID="Yes" + export IGNORE_UUID + ;; + + integrity-check) + INTEGRITY_CHECK="Yes" + export INTEGRITY_CHECK + ;; + + ip=*) + STATICIP="${ARGUMENT#ip=}" + + if [ -z "${STATICIP}" ] + then + STATICIP="frommedia" + fi + + export STATICIP + ;; + + keyb=*|kbd-chooser/method=*) + KBD="${ARGUMENT#*=}" + export KBD + ;; + + klayout=*|console-setup/layoutcode=*) + KLAYOUT="${ARGUMENT#*=}" + export KLAYOUT + ;; + + kvariant=*|console-setup/variantcode=*) + KVARIANT="${ARGUMENT#*=}" + export KVARIANT + ;; + + kmodel=*|console-setup/modelcode=*) + KMODEL="${ARGUMENT#*=}" + export KMODEL + ;; + + koptions=*) + KOPTIONS="${ARGUMENT#koptions=}" + export KOPTIONS + ;; + + live-getty) + LIVE_GETTY="1" + export LIVE_GETTY + ;; + + live-media=*|bootfrom=*) + LIVE_MEDIA="${ARGUMENT#*=}" + export LIVE_MEDIA + ;; + + live-media-encryption=*|encryption=*) + LIVE_MEDIA_ENCRYPTION="${ARGUMENT#*=}" + export LIVE_MEDIA_ENCRYPTION + ;; + + live-media-offset=*) + LIVE_MEDIA_OFFSET="${ARGUMENT#live-media-offset=}" + export LIVE_MEDIA_OFFSET + ;; + + live-media-path=*) + LIVE_MEDIA_PATH="${ARGUMENT#live-media-path=}" + export LIVE_MEDIA_PATH + ;; + + live-media-timeout=*) + LIVE_MEDIA_TIMEOUT="${ARGUMENT#live-media-timeout=}" + export LIVE_MEDIA_TIMEOUT + ;; + + language=*|debian-installer/language=*) + language=${x#debian-installer/language=} + locale="$(lang2locale "$language")" + set_locale="true" + ;; + + locale=*|debian-installer/locale=*) + LOCALE="${ARGUMENT#*=}" + export LOCALE + ;; + + module=*) + MODULE="${ARGUMENT#module=}" + export MODULE + ;; + + netboot=*) + NETBOOT="${ARGUMENT#netboot=}" + export NETBOOT + ;; + + nfsopts=*) + NFSOPTS="${ARGUMENT#nfsopts=}" + export NFSOPTS + ;; + + nfscow=*) + NFS_COW="${ARGUMENT#nfscow=}" + export NFS_COW + ;; + + noaccessibility) + NOACCESSIBILITY="Yes" + export NOACCESSIBILITY + ;; + + noapparmor) + NOAPPARMOR="Yes" + export NOAPPARMOR + ;; + + noaptcdrom) + NOAPTCDROM="Yes" + export NOAPTCDROM + ;; + + noautologin) + NOAUTOLOGIN="Yes" + export NOAUTOLOGIN + ;; + + noxautologin) + NOXAUTOLOGIN="Yes" + export NOXAUTOLOGIN + ;; + + noconsolekeyboard) + NOCONSOLEKEYBOARD="Yes" + export NOCONSOLEKEYBOARD + ;; + + nofastboot) + NOFASTBOOT="Yes" + export NOFASTBOOT + ;; + + nofstab) + NOFSTAB="Yes" + export NOFSTAB + ;; + + nognomepanel) + NOGNOMEPANEL="Yes" + export NOGNOMEPANEL + ;; + + nohosts) + NOHOSTS="Yes" + export NOHOSTS + ;; + + nokpersonalizer) + NOKPERSONALIZER="Yes" + export NOKPERSONALIZER + ;; + + nolanguageselector) + NOLANGUAGESELECTOR="Yes" + export NOLANGUAGESELECTOR + ;; + + nolocales) + NOLOCALES="Yes" + export NOLOCALES + ;; + + nonetworking) + NONETWORKING="Yes" + export NONETWORKING + ;; + + nopowermanagement) + NOPOWERMANAGEMENT="Yes" + export NOPOWERMANAGEMENT + ;; + + noprogramcrashes) + NOPROGRAMCRASHES="Yes" + export NOPROGRAMCRASHES + ;; + + nojockey) + NOJOCKEY="Yes" + export NOJOCKEY + ;; + + nosudo) + NOSUDO="Yes" + export NOSUDO + ;; + + swapon) + SWAPON="Yes" + export SWAPON + ;; + + noupdatenotifier) + NOUPDATENOTIFIER="Yes" + export NOUPDATENOTIFIER + ;; + + nouser) + NOUSER="Yes" + export NOUSER + ;; + + noxautoconfig) + NOXAUTOCONFIG="Yes" + export NOXAUTOCONFIG + ;; + + noxscreensaver) + NOXSCREENSAVER="Yes" + export NOXSCREENSAVER + ;; + + persistent) + PERSISTENT="Yes" + export PERSISTENT + ;; + + persistent=*) + PERSISTENT="${ARGUMENT#persistent=}" + if [ -z "${PERSISTENT}" ] + then + PERSISTENT="Yes" + fi + export PERSISTENT + ;; + + persistent-path=*) + PERSISTENT_PATH="${ARGUMENT#persistent-path=}" + export PERSISTENT_PATH + ;; + + persistent-subtext=*) + root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}" + home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}" + root_snapshot_label="${root_snapshot_label}-${ARGUMENT#persistent-subtext=}" + home_snapshot_label="${home_snapshot_label}-${ARGUMENT#persistent-subtext=}" + ;; + + nopersistent) + NOPERSISTENT="Yes" + export NOPERSISTENT + ;; + + preseed/file=*|file=*) + LOCATION="${ARGUMENT#*=}" + export LOCATION + ;; + + nopreseed) + NOPRESEED="Yes" + export NOPRESEED + ;; + + url=*) + location="${ARGUMENT#url=}" + + mount -o bind /sys /root/sys + mount -o bind /proc /root/proc + mount -o bind /dev /root/dev + + mkdir -p /root/var/run/network + chroot /root dhclient eth0 + chroot /root wget -P /tmp "${location}" + chroot /root ifconfig eth0 down + + umount /root/sys + umount /root/proc + umount /root/dev + + LOCATION="/tmp/$(basename "${location}")" + ;; + + */*=*) + question="${ARGUMENT%%=*}" + value="${ARGUMENT#*=}" + PRESEEDS="${PRESEEDS}\"${question}=${value}\" " + export PRESEEDS + ;; + + showmounts) + SHOWMOUNTS="Yes" + export SHOWMOUNTS + ;; + + silent) + SILENT="Yes" + export SILENT + ;; + + textonly) + TEXTONLY="Yes" + export TEXTONLY + ;; + + timezone=*) + TIMEZONE="${ARGUMENT#timezone=}" + export TIMEZONE + ;; + + notimezone) + NOTIMEZONE="Yes" + export NOTIMEZONE + ;; + + todisk=*) + TODISK="${ARGUMENT#todisk=}" + export TODISK + ;; + + toram) + TORAM="Yes" + export TORAM + ;; + + toram=*) + TORAM="Yes" + MODULETORAM="${ARGUMENT#toram=}" + export TORAM MODULETORAM + ;; + + exposedroot) + EXPOSED_ROOT="Yes" + export EXPOSED_ROOT + ;; + + plainroot) + PLAIN_ROOT="Yes" + export PLAIN_ROOT + ;; + + skipunion) + SKIP_UNION_MOUNTS="Yes" + export SKIP_UNION_MOUNTS + ;; + + root=*) + ROOT="${ARGUMENT#root=}" + export ROOT + ;; + + union=*) + UNIONTYPE="${ARGUMENT#union=}" + export UNIONTYPE + ;; + + utc=*) + UTC="${ARGUMENT#utc=}" + export UTC + ;; + + xdebconf) + XDEBCONF="Yes" + export XDEBCONF + ;; + + xdriver=*) + XDRIVER="${ARGUMENT#xdriver=}" + export XDRIVER + ;; + + xvideomode=*) + XVIDEOMODE="${ARGUMENT#xvideomode=}" + export XVIDEOMODE + ;; + esac + done + + # sort of compatibility with netboot.h from linux docs + if [ -z "${NETBOOT}" ] + then + if [ "${ROOT}" = "/dev/nfs" ] + then + NETBOOT="nfs" + export NETBOOT + elif [ "${ROOT}" = "/dev/cifs" ] + then + NETBOOT="cifs" + export NETBOOT + fi + fi + + if [ -z "${MODULE}" ] + then + MODULE="filesystem" + export MODULE + fi + + if [ -z "${UNIONTYPE}" ] + then + UNIONTYPE="aufs" + export UNIONTYPE + fi } -is_live_path() { - path=$1 - if [ -d "$path/live" ]; then - if [ "$(echo $path/live/*.squashfs)" != "$path/live/*.squashfs" ] || - [ "$(echo $path/live/*.ext2)" != "$path/live/*.ext2" ] || - [ "$(echo $path/live/*.ext3)" != "$path/live/*.ext3" ] || - [ "$(echo $path/live/*.dir)" != "$path/live/*.dir" ]; then - return 0 - fi - fi - return 1 +is_live_path () +{ + DIRECTORY="${1}" + + if [ -d "${DIRECTORY}"/"${LIVE_MEDIA_PATH}" ] + then + for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs2 + do + if [ "$(echo ${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM})" != "${DIRECTORY}/${LIVE_MEDIA_PATH}/*.${FILESYSTEM}" ] + then + return 0 + fi + done + fi + + return 1 +} + +matches_uuid () +{ + if [ "${IGNORE_UUID}" ] || [ ! -e /conf/uuid.conf ] + then + return 0 + fi + + path="${1}" + uuid="$(cat /conf/uuid.conf)" + + for try_uuid_file in "${path}/.disk/live-uuid"* + do + [ -e "${try_uuid_file}" ] || continue + + try_uuid="$(cat "${try_uuid_file}")" + + if [ "${uuid}" = "${try_uuid}" ] + then + return 0 + fi + done + + return 1 } -get_backing_device() { - case "$1" in - *.squashfs|*.ext2|*.ext3) - echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}") - ;; - *.dir) - echo "directory" - ;; - *) - panic "Unrecognized live filesystem: $1" - ;; - esac +get_backing_device () +{ + case "${1}" in + *.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2) + echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${LIVE_MEDIA_ENCRYPTION}" "${2}") + ;; + + *.dir) + echo "directory" + ;; + + *) + panic "Unrecognized live filesystem: ${1}" + ;; + esac } -match_files_in_dir() { - # Does any files match pattern $1 ? +match_files_in_dir () +{ + # Does any files match pattern ${1} ? + local pattern="${1}" - local pattern="$1" - if [ "$(echo $pattern)" != "$pattern" ]; then - return 0 - fi - return 1 + if [ "$(echo ${pattern})" != "${pattern}" ] + then + return 0 + fi + + return 1 } -mount_images_in_directory() { - directory="$1" - rootmnt="$2" - if match_files_in_dir "$directory/live/*.squashfs" || - match_files_in_dir "$directory/live/*.ext2" || - match_files_in_dir "$directory/live/*.ext3" || - match_files_in_dir "$directory/live/*.dir"; then - setup_unionfs "$directory/live" "$rootmnt" - else - : - fi +mount_images_in_directory () +{ + directory="${1}" + rootmnt="${2}" + mac="${3}" + + + if match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.squashfs" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext2" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext3" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.ext4" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.jffs2" || + match_files_in_dir "${directory}/${LIVE_MEDIA_PATH}/*.dir" + then + [ -n "${mac}" ] && adddirectory="${directory}/${LIVE_MEDIA_PATH}/${mac}" + setup_unionfs "${directory}/${LIVE_MEDIA_PATH}" "${rootmnt}" "${adddirectory}" + else + panic "No supported filesystem images found at /${LIVE_MEDIA_PATH}." + fi } -is_nice_device() { - sysfs_path="${1#/sys}" - if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then - return 0 - fi - return 1 +is_nice_device () +{ + sysfs_path="${1#/sys}" + + if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb))" + then + return 0 + elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' + then + return 0 + fi + + return 1 } -is_supported_fs () { - # FIXME: do something better like the scan of supported filesystems - fstype="${1}" - case ${fstype} in - vfat|iso9660|udf|ext2|ext3|ntfs) - return 0 - ;; - esac - return 1 +copy_live_to () +{ + copyfrom="${1}" + copytodev="${2}" + copyto="${copyfrom}_swap" + + if [ -z "${MODULETORAM}" ] + then + size=$(fs_size "" ${copyfrom} "used") + else + MODULETORAMFILE="${copyfrom}/${LIVE_MEDIA_PATH}/${MODULETORAM}" + + if [ -f "${MODULETORAMFILE}" ] + then + size=$( expr $(ls -la ${MODULETORAMFILE} | awk '{print $5}') / 1024 + 5000 ) + else + log_warning_msg "Error: toram-module ${MODULETORAM} (${MODULETORAMFILE}) could not be read." + return 1 + fi + fi + + if [ "${copytodev}" = "ram" ] + then + # copying to ram: + freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\