X-Git-Url: http://git.grml.org/?p=live-boot-grml.git;a=blobdiff_plain;f=components%2F9990-main.sh;h=b9bd71b9febc6269f31a4f606d7ae35d181ec63c;hp=85b8a1de4b0394ae00d6aa778957644d2f50124a;hb=HEAD;hpb=3d474f82e4b76d73d86407c8945861fe3e3be8b5 diff --git a/components/9990-main.sh b/components/9990-main.sh index 85b8a1d..063445b 100755 --- a/components/9990-main.sh +++ b/components/9990-main.sh @@ -33,11 +33,11 @@ Live () # Needed here too because some things (*cough* udev *cough*) # changes the timeout - if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ] + if [ -n "${NETBOOT}" ] || [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] then if do_netmount then - livefs_root="${mountpoint}" + livefs_root="${mountpoint?}" else panic "Unable to find a live file system on the network" fi @@ -52,18 +52,58 @@ Live () else if [ -x /usr/bin/memdiskfind ] then - MEMDISK=$(/usr/bin/memdiskfind) - - if [ $? -eq 0 ] + if ! dd if=/dev/mem of=/dev/zero bs=1 count=1 >/dev/null 2>&1 then - # We found a memdisk, set up phram - modprobe phram phram=memdisk,${MEMDISK} - - # Load mtdblock, the memdisk will be /dev/mtdblock0 - modprobe mtdblock + log_begin_msg "access to /dev/mem is restriced, skipping memdiskfind" + log_end_msg + else + if MEMDISK=$(/usr/bin/memdiskfind) + then + # We found a memdisk, set up phram + # Sometimes "modprobe phram" can not successfully create /dev/mtd0. + # Have to try several times. + max_try=20 + while [ ! -c /dev/mtd0 ] && [ "$max_try" -gt 0 ]; do + modprobe phram "phram=memdisk,${MEMDISK}" + sleep 0.2 + if [ -c /dev/mtd0 ]; then + break + else + rmmod phram + fi + max_try=$((max_try - 1)) + done + + # Load mtdblock, the memdisk will be /dev/mtdblock0 + modprobe mtdblock + fi fi fi + # If the live media location is given via command line and access to it + # involves LVM volumes, the corresponding volumes need to be activated. + IFS=',' + for dev in $(echo "$LIVE_MEDIA") + do + case "$dev" in + /dev/mapper/*) + eval $(dmsetup splitname --nameprefixes --noheadings --rows "${dev#/dev/mapper/}") + if [ "$DM_VG_NAME" ] && [ "$DM_LV_NAME" ] + then + lvm lvchange -aay -y --sysinit --ignoreskippedcluster "$DM_VG_NAME/$DM_LV_NAME" + fi + ;; + /dev/*/*) + # Could be /dev/VG/LV; use lvs to check + if lvm lvs -- "$dev" >/dev/null 2>&1 + then + lvm lvchange -aay -y --sysinit --ignoreskippedcluster "$dev" + fi + ;; + esac + done + unset IFS + # Scan local devices for the image i=0 while [ "$i" -lt 60 ] @@ -76,7 +116,7 @@ Live () fi sleep 1 - i="$(($i + 1))" + i=$((i + 1)) done fi fi @@ -110,37 +150,23 @@ Live () then losetup -d /dev/loop0 - if is_mountpoint /live/fromiso + if is_mountpoint /run/live/fromiso then - umount /live/fromiso - rmdir --ignore-fail-on-non-empty /live/fromiso \ + umount /run/live/fromiso + rmdir --ignore-fail-on-non-empty /run/live/fromiso \ >/dev/null 2>&1 || true fi fi if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ] then - setup_unionfs "${livefs_root}" "${rootmnt}" + setup_unionfs "${livefs_root}" "${rootmnt?}" else mac="$(get_mac)" - mac="$(echo ${mac} | sed 's/-//g')" + mac="$(echo "${mac}" | sed 's/-//g')" mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}" fi - # At this point /root should contain the final root filesystem. - # Move all mountpoints below /live into /root/lib/live/mount. - # This has to be done after mounting the root filesystem to / - # otherwise these mount points won't be accessible from the running system. - for _MOUNT in $(cat /proc/mounts | cut -f 2 -d " " | grep -e "^/live/") - do - local newmount - newmount="${rootmnt}/lib/live/mount/${_MOUNT#/live/}" - mkdir -p "${newmount}" - mount -o move "${_MOUNT}" "${newmount}" > /dev/null 2>&1 || \ - mount -o bind "${_MOUNT}" "${newmount}" > /dev/null || \ - log_warning_msg "W: failed to move or bindmount ${_MOUNT} to ${newmount}" - done - if [ -n "${ROOT_PID}" ] then echo "${ROOT_PID}" > "${rootmnt}"/lib/live/root.pid @@ -148,15 +174,6 @@ Live () log_end_msg - # unionfs-fuse needs /dev to be bind-mounted for the duration of - # live-bottom; udev's init script will take care of things after that - case "${UNIONTYPE}" in - unionfs-fuse) - mount -n -o bind /dev "${rootmnt}/dev" - ;; - esac - - # aufs2 in kernel versions around 2.6.33 has a regression: # directories can't be accessed when read for the first the time, # causing a failure for example when accessing /var/lib/fai @@ -170,24 +187,38 @@ Live () then losetup -d /dev/loop0 - if is_mountpoint /root/lib/live/mount/findiso + if is_mountpoint /run/live/findiso then - umount /root/lib/live/mount/findiso - rmdir --ignore-fail-on-non-empty /root/lib/live/mount/findiso \ + umount /run/live/findiso + rmdir --ignore-fail-on-non-empty /run/live/findiso \ >/dev/null 2>&1 || true fi fi + if [ -f /etc/hostname ] && ! grep -E -q -v '^[[:space:]]*(#|$)' "${rootmnt}/etc/hostname" + then + log_begin_msg "Copying /etc/hostname to ${rootmnt}/etc/hostname" + cp -v /etc/hostname "${rootmnt}/etc/hostname" + log_end_msg + fi + + if [ -f /etc/hosts ] && ! grep -E -q -v '^[[:space:]]*(#|$|(127.0.0.1|::1|ff02::[12])[[:space:]])' "${rootmnt}/etc/hosts" + then + log_begin_msg "Copying /etc/hosts to ${rootmnt}/etc/hosts" + cp -v /etc/hosts "${rootmnt}/etc/hosts" + log_end_msg + fi + if [ -L /root/etc/resolv.conf ] ; then # assume we have resolvconf DNSFILE="${rootmnt}/etc/resolvconf/resolv.conf.d/base" else DNSFILE="${rootmnt}/etc/resolv.conf" fi - if [ -f /etc/resolv.conf ] && [ ! -s ${DNSFILE} ] + if [ -f /etc/resolv.conf ] && ! grep -E -q -v '^[[:space:]]*(#|$)' "${DNSFILE}" then log_begin_msg "Copying /etc/resolv.conf to ${DNSFILE}" - cp -v /etc/resolv.conf ${DNSFILE} + cp -v /etc/resolv.conf "${DNSFILE}" log_end_msg fi @@ -196,19 +227,27 @@ Live () panic "A wrong rootfs was mounted." fi + # avoid breaking existing user scripts that rely on the old path + # this includes code that checks what is mounted on /lib/live/mount/* + # (eg: grep /lib/live /proc/mount) + # XXX: to be removed before the bullseye release + mkdir -p "${rootmnt}/lib/live/mount" + mount --rbind /run/live "${rootmnt}/lib/live/mount" + Fstab - Netbase Swap - case "${UNIONFS}" in - unionfs-fuse) - umount "${rootmnt}/dev" - ;; - esac + if grep -q debian_networking /proc/cmdline ; then + Netbase + else + Grml_Networking + fi exec 1>&6 6>&- exec 2>&7 7>&- kill ${tailpid} - [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null + [ -w "${rootmnt}/var/log/" ] && mkdir -p "${rootmnt}/var/log/live" && ( \ + cp boot.log "${rootmnt}/var/log/live" 2>/dev/null; \ + cp fsck.log "${rootmnt}/var/log/live" 2>/dev/null ) }