Making use of is_supported_fs in find_cow_devices (like in find_files).
[live-boot-grml.git] / scripts / live
index 2afbb69..c3732fe 100755 (executable)
@@ -244,13 +244,18 @@ Arguments ()
                                export PERSISTENT
                                ;;
 
-                       persistent=*)
-                               PERSISTENT="${ARGUMENT#persistent=}"
-                               if [ -z "${PERSISTENT}" ]
-                               then
-                                       PERSISTENT="Yes"
-                               fi
-                               export PERSISTENT
+                       persistent-encryption=*)
+                               PERSISTENT_ENCRYPTION="${ARGUMENT#*=}"
+                               export PERSISTENT_ENCRYPTION
+                               ;;
+
+                       persistent-media=*)
+                               PERSISTENT_MEDIA="${ARGUMENT#*=}"
+                               export PERSISTENT_MEDIA
+                               ;;
+                       persistent-method=*)
+                               PERSISTENT_METHOD="${ARGUMENT#*=}"
+                               export PERSISTENT_METHOD
                                ;;
 
                        persistent-path=*)
@@ -258,6 +263,11 @@ Arguments ()
                                export PERSISTENT_PATH
                                ;;
 
+                       persistent-storage=*)
+                               PERSISTENT_STORAGE="${ARGUMENT#persistent-storage=}"
+                               export PERSISTENT_STORAGE
+                               ;;
+
                        persistent-subtext=*)
                                root_persistence="${root_persistence}-${ARGUMENT#persistent-subtext=}"
                                home_persistence="${home_persistence}-${ARGUMENT#persistent-subtext=}"
@@ -380,6 +390,18 @@ Arguments ()
                UNIONTYPE="aufs"
                export UNIONTYPE
        fi
+
+       if [ -n "${PERSISTENT}" ] && [ -z "${PERSISTENT_METHOD}" ]
+       then
+               PERSISTENT_METHOD="snapshot,overlay"
+               export PERSISTENT_METHOD
+       fi
+
+       if [ -n "${PERSISTENT}" ] && [ -z "${PERSISTENT_STORAGE}" ]
+       then
+               PERSISTENT_STORAGE="filesystem,file"
+               export PERSISTENT_STORAGE
+       fi
 }
 
 is_live_path ()
@@ -480,7 +502,16 @@ is_nice_device ()
 {
        sysfs_path="${1#/sys}"
 
-       if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
+       if [ -e /lib/udev/path_id ]
+       then
+               # squeeze
+               PATH_ID="/lib/udev/path_id"
+       else
+               # wheezy/sid (udev >= 174)
+               PATH_ID="/sbin/udevadm test-builtin path_id"
+       fi
+
+       if "${PATH_ID}" "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)"
        then
                return 0
        elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
@@ -730,12 +761,15 @@ do_netsetup ()
                        if [ -n "${DNSDOMAIN}" ]
                        then
                                echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
-                               echo "search ${DNSDOMAIN}" > /etc/resolv.conf
+                               echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
                        fi
 
                        for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
                        do
-                               echo "nameserver $i" >> /etc/resolv.conf
+                               if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
+                               then
+                                       echo "nameserver $i" >> /etc/resolv.conf
+                               fi
                        done
                fi
 
@@ -1030,16 +1064,17 @@ find_snap ()
        # Look for ${snap_label}.* in block devices
        snap_label="${1}"
        black_listed_devices="${2}"
+       white_listed_devices="${3}"
 
-       if [ "${PERSISTENT}" != "nofiles" ]
+       if echo ${PERSISTENT_STORAGE} | grep -qw file
        then
                # search for image files
-               snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2" "${black_listed_devices}")
+               snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2" "${black_listed_devices}" "${white_listed_devices}")
        fi
 
-       if [ -z "${snapdata}" ]
+       if echo ${PERSISTENT_STORAGE} | grep -qw filesystem && [ -z "${snapdata}" ]
        then
-               snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}")
+               snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}" "${white_listed_devices}")
        fi
        echo "${snapdata}"
 }
@@ -1195,7 +1230,7 @@ setup_unionfs ()
 
        if [ "${UNIONTYPE}" = "aufs" ]
        then
-               roopt="rr"
+               roopt="rr+wh"
                noxino_opt="noxino,"
        elif [ "${UNIONTYPE}" = "unionfs-fuse" ]
        then
@@ -1320,6 +1355,7 @@ setup_unionfs ()
        # Looking for "${root_persistence}" device or file
        if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
        then
+
                if [ -z "${QUICKUSBMODULES}" ]
                then
                        # Load USB modules
@@ -1347,30 +1383,49 @@ setup_unionfs ()
                        done
                fi
 
-               # search for label and files (this could be hugely optimized)
-               cowprobe=$(find_cow_device "${root_persistence}")
-               if [ -b "${cowprobe}" ]
+               case "${PERSISTENT_MEDIA}" in
+                       removable)
+                               whitelistdev="$(removable_dev)"
+                               ;;
+                       removable-usb)
+                               whitelistdev="$(removable_usb_dev)"
+                               ;;
+                       *)
+                               whitelistdev=""
+                               ;;
+               esac
+
+               if echo ${PERSISTENT_METHOD} | grep -qw overlay
                then
-                       # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
-                       # makes sense to have both persistence for /cow and /home mounted, maybe also with
-                       # snapshots to be sure to really store some e.g key config files,
-                       # but not on the same media
-                       blacklistdev="${cowprobe}"
-                       PERSISTENCE_IS_ON="1"
-                       export PERSISTENCE_IS_ON
+                       # search for label and files (this could be hugely optimized)
+                       cowprobe=$(find_cow_device "${root_persistence}" "${blacklistdev}" "${whitelistdev}")
+                       if [ -b "${cowprobe}" ]
+                       then
+                               # Blacklist /cow device, to avoid inconsistent setups for overlapping snapshots
+                               # makes sense to have both persistence for /cow and /home mounted, maybe also with
+                               # snapshots to be sure to really store some e.g key config files,
+                               # but not on the same media
+                               blacklistdev="${cowprobe}"
+                               PERSISTENCE_IS_ON="1"
+                               export PERSISTENCE_IS_ON
+                       fi
+                       # homecow just mount something on /home, this should be generalized some way
+                       homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}" "${whitelistdev}")
+                       if [ -b "${homecow}" ]
+                       then
+                               PERSISTENCE_IS_ON="1"
+                               export PERSISTENCE_IS_ON
+                       fi
                fi
-               # homecow just mount something on /home, this should be generalized some way
-               homecow=$(find_cow_device "${home_persistence}" "${blacklistdev}")
-               if [ -b "${homecow}" ]
+
+               if echo ${PERSISTENT_METHOD} | grep -qw snapshot
                then
-                       PERSISTENCE_IS_ON="1"
-                       export PERSISTENCE_IS_ON
+                       root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
+                       # This second type should be removed when snapshot will get smarter,
+                       # hence when "/etc/live-snapshot*list" will be supported also by
+                       # ext2|ext3|ext4|jffs2 snapshot types.
+                       home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}" "${whitelistdev}")
                fi
-               root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
-               # This second type should be removed when snapshot will get smarter,
-               # hence when "/etc/live-snapshot*list" will be supported also by
-               # ext2|ext3|ext4|jffs2 snapshot types.
-               home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
 
                if [ -b "${cowprobe}" ]
                then
@@ -1473,8 +1528,8 @@ setup_unionfs ()
                                unionmountopts="${unionmountopts} ${unionrw}=RW:${unionro}=RO"
                                ( sysctl -w fs.file-max=391524 ; ulimit -HSn 16384
                                unionfs-fuse ${unionmountopts} "${unionmountpoint}" ) && \
-                                       ( mkdir -p /run/initramfs
-                               pidof unionfs-fuse >> /run/initramfs/sendsigs.omit || true )
+                               ( mkdir -p /run/sendsigs.omit.d
+                               pidof unionfs-fuse >> /run/sendsigs.omit.d/unionfs-fuse || true )
                                ;;
 
                        unionmount)
@@ -1587,7 +1642,7 @@ check_dev ()
                                loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
                                devname="${loopdevname}"
                        else
-                               echo "Warning: unable to mount $ISO_DEVICE." >>/live.log
+                               echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
                        fi
                fi
        fi
@@ -1609,6 +1664,35 @@ check_dev ()
                        umount $mountpoint
                fi
        fi
+
+       IFS=","
+       for device in ${devname}
+       do
+               case "$device" in
+                       *mapper*)
+                               # Adding lvm support
+                               if [ -x /scripts/local-top/lvm2 ]
+                               then
+                                       ROOT="$device" resume="" /scripts/local-top/lvm2
+                               fi
+                               ;;
+
+                       /dev/md*)
+                               # Adding raid support
+                               if [ -x /scripts/local-top/mdadm ]
+                               then
+                                       cp /conf/conf.d/md /conf/conf.d/md.orig
+                                       echo "MD_DEVS=$device " >> /conf/conf.d/md
+                                       /scripts/local-top/mdadm
+                                       mv /conf/conf.d/md.orig /conf/conf.d/md
+                               fi
+                               ;;
+               esac
+       done
+       unset IFS
+
+       [ -n "$device" ] && devname="$device"
+
        [ -e "$devname" ] || continue
 
        if [ -n "${LIVE_MEDIA_OFFSET}" ]
@@ -1632,7 +1716,7 @@ check_dev ()
                        echo ${mountpoint}
                        return 0
                else
-                       umount ${mountpoint}
+                       umount ${mountpoint} 2>/dev/null
                fi
        fi
 
@@ -1660,38 +1744,29 @@ find_livefs ()
        # first look at the one specified in the command line
        case "${LIVE_MEDIA}" in
                removable-usb)
-                       for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+                       for sysblock in $(removable_usb_dev "sys")
                        do
-                               if [ "$(cat ${sysblock}/removable)" = "1" ]
-                               then
-                                       if readlink ${sysblock} | grep -q usb
+                               for dev in $(subdevices "${sysblock}")
+                               do
+                                       if check_dev "${dev}"
                                        then
-                                               for dev in $(subdevices "${sysblock}")
-                                               do
-                                                       if check_dev "${dev}"
-                                                       then
-                                                               return 0
-                                                       fi
-                                               done
+                                               return 0
                                        fi
-                               fi
+                               done
                        done
                        return 1
                        ;;
 
                removable)
-                       for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+                       for sysblock in $(removable_dev "sys")
                        do
-                               if [ "$(cat ${sysblock}/removable)" = "1" ]
-                               then
-                                       for dev in $(subdevices "${sysblock}")
-                                       do
-                                               if check_dev "${dev}"
-                                               then
-                                                       return 0
-                                               fi
-                                       done
-                               fi
+                               for dev in $(subdevices "${sysblock}")
+                               do
+                                       if check_dev "${dev}"
+                                       then
+                                               return 0
+                                       fi
+                               done
                        done
                        return 1
                        ;;
@@ -1709,16 +1784,7 @@ find_livefs ()
 
        # or do the scan of block devices
        # prefer removable devices over non-removable devices, so scan them first
-       for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)")
-       do
-               if [ "$(cat ${sysblock}/removable)" = "1" ]
-               then
-                       removable_devices_to_scan="$removable_devices_to_scan $sysblock"
-               else
-                       nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock"
-               fi
-       done
-       devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan"
+       devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')"
 
        for sysblock in $devices_to_scan
        do
@@ -1942,6 +2008,13 @@ mountroot ()
                log_end_msg
        fi
 
+       if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
+       then
+               log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
+               cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
+               log_end_msg
+       fi
+
        maybe_break live-bottom
        log_begin_msg "Running /scripts/live-bottom\n"