[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: wmlive and empty fstab



On Sat, Jun 09, 2012 at 08:28:07PM +0200, Daniel Baumann wrote:
> On 06/09/2012 08:10 PM, Paul Seelig wrote
and much more as:
> > i'd rather prefer to see all the shortcomings of the
> > live-installer be fixed, in order to be able to get rid of my own hacks.
> 
> we do so too, and patches are welcome.
> 

The .tar.gz that Paul Seelig refered to has a
 ./build-config/includes.chroot/usr/local/sbin/wmlive-fix-install

Find it attached.  Please review it for usefullness.
This posting is to avoid downloads of a 25M .tar.gz for only 9K shell script.

And to get a constructive discussion.


Cheers
Geert Stappers

#!/bin/sh

if [ "$1" = "-d" ]
then
    set -x
fi

# Copyright (C) 2011 by Paul Seelig <wmlive@rumbero.org>

# 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, either version 3 of the License, or
# (at your option) any later version.

# 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 General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Make sure to exclude running under any locale other than C:
export LC_ALL=C

if [ ! "$(/usr/bin/whoami)" = "root" ]; then
    echo "Sorry, only root can do this"
    exit 0
fi

DEBTARGET="/live/installer/target"

copy_missing_vardirs ()
{
# working around a debian-installer copying omission:
[ -d "$DEBTARGET" ] && for VARDIR in /var/*
do
    if [ ! -d "$DEBTARGET$VARDIR" ]
    then
        # Copying the missing "$VARDIR" directories:
        cp -a "$VARDIR" "$DEBTARGET"/var
    fi
done

# Cleaning up the copied system dirs from old unrelated content:
rm -rf "$DEBTARGET"/var/mail/* "$DEBTARGET"/tmp/*
rm -f "$DEBTARGET"/var/log/*/* "$DEBTARGET"/var/log/* > /dev/null 2>&1
}

if [ -d "$DEBTARGET" ] && [ "$(mount | grep -c "on $DEBTARGET type")" = "1" ]
then
    copy_missing_vardirs
    echo "$0" > "$DEBTARGET"/root/.wmliverc
    chroot "$DEBTARGET" /bin/bash --rcfile /root/.wmliverc -i
elif [ "$(mount | grep -c "aufs on / type aufs")" = "1" ]
then
    cat << EOF

    You are executing this command on the Live CD environment,
    with no "$DEBTARGET" target directory being present.

    Therefore we simply quit without any further action.

EOF
    exit 1
fi

wmlive_installer_removal ()
{
if [ -f /usr/share/applications/debian-installer-launcher.desktop ]
then
    cat << EOF

    Removing unnecessary packages and updating the initramfs image...
    (depending on your system's CPU speed, this will take some time)

EOF
    apt-get --yes --purge remove live-config live-config-sysvinit live-boot live-boot-initramfs-tools debian-installer-launcher
fi
}

wmlive_luks_initramfs ()
{
cat << EOF

    Correcting the missing LUKS configuration

    Updating the initramfs image with the LUKS boot information...
    (depending on your system's CPU speed, this will take some time)
EOF
update-initramfs -k all -u > /dev/null 2>&1
}
grub_success_msg ()
{
cat << EOF

    Congratulations, grub-installation has successfully completed!

EOF
}

grub_failure_msg ()
{
cat << EOF

    Something unpredicted has happened, and this script has failed!

    Please copy the script output from the terminal window into a file,
    and send it to wmlive@users.sf.net for troubleshooting assistance.

EOF
exit 1
}

fix_complete_exit ()
{
if [ ! "$(mount | grep -c "on $DEBTARGET type")" = "1" ] && [ ! "$(mount | grep -c "aufs on / type aufs")" = "1" ]
then
    kill -9 $PPID > /dev/null 2>&1
fi
}

wmlive_mkfstab ()
{
cat > /etc/fstab << MKFSTABFIRST
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
$(mount | grep "on / type" | awk '{print $1, $3, $5}') defaults,noacl,noatime,nodiratime       0       1
tmpfs   /tmp    tmpfs   size=512m       0       0
proc    /proc   proc    defaults        0       0
MKFSTABFIRST

for mntdev in $(mount | grep ^/dev | grep -v ^/dev/sr0 | grep -v "on / type" | awk '{print $1}')
do
    echo "$(mount | grep $mntdev | awk '{print $1, $3, $5}') defaults,noacl,noatime,nodiratime       0       2" >> /etc/fstab
done

cat >> /etc/fstab << MKFSTABSECOND
/dev/sr0       /media/cdrom  auto    ro,user,noauto  0       0
MKFSTABSECOND

chmod 644 /etc/fstab
}

if [ ! "$(mount | grep -c "aufs on / type aufs")" = "1" ]
then

    if [ ! -d /var/tmp ]
    then
        echo ""
        echo "Creating the missing /var/tmp directory"
        mkdir -m 1777 /var/tmp
    else
        chmod 1777 /var/tmp
    fi

    # Cleaning /etc/apt/sources.list from live-build approx entries:
    if [ ! "$(grep "deb http://192.168"; /etc/apt/sources.list | grep -c ":9999")" = "0" ]
        then
        TMPFILE=$(mktemp --tmpdir=/tmp)
        grep -v "deb http://192.168"; /etc/apt/sources.list > $TMPFILE &&\
             cat $TMPFILE > /etc/apt/sources.list
    fi

    if [ ! "$(grep "deb http://192.168"; /etc/apt/sources.list.d/wmlive.list | grep -c ":9999")" = "0" ]
        then
        TMPFILE=$(mktemp --tmpdir=/tmp)
        grep -v "deb http://192.168"; /etc/apt/sources.list.d/wmlive.list > $TMPFILE &&\
             cat $TMPFILE > /etc/apt/sources.list.d/wmlive.list
    fi

    # For a LUKS based LVM setup, create a proper initramfs configuration entry:
    if [ ! "$(blkid | grep -c TYPE=\"crypto_LUKS\")" = "0" ]
    then
        echo ""
        export LUKSCONFIG=/etc/initramfs-tools/conf.d/cryptroot
        if [ ! -s $LUKSCONFIG ]
        then
            # The 'target=' specifier can be any name, using alphanumeric characters only.
            # 'source=' specifies the disk partition UUID used as physical volume for LVM.
            # 'lvm=' specifies the name of the logical volume used as the root file system.
            # Adding comments to the file breaks it's function, so better don't add any.
            export LUKSROOTDEV=$(basename $(mount | grep "on / type" | awk '{print $1}'))
            export LUKSUUID=$(blkid | grep -m1 TYPE=\"crypto_LUKS\" | awk '{print $2}' | tr -d \")
            cat > $LUKSCONFIG << EOF
target=luks,source=$LUKSUUID,key=none,lvm=$LUKSROOTDEV
EOF
        fi

        # The presence of /etc/crypttab only produces useless error messages,
        # and it also doesn't belong to any valid package, so just remove it:
        [ -f /etc/crypttab ] && rm -f /etc/crypttab

        # Removing the live-boot-initramfs-tools also includes updating initramfs
        # so we take advantage of this to prevent initramfs from being built twice,
        # but will better leave an alternative option in case of failure as fallback:
        wmlive_installer_removal || wmlive_luks_initramfs
    fi

    if [ ! -s /boot/grub/grub.cfg ]
    then
        echo ""
        echo "Continuing to fix the broken grub installation now:"
        echo ""
        # checking whether /boot resides on its own partition:
        if [ "$(mount | grep /boot | grep -c ^/dev/sd)" = "1" ] && [ ! "$(/bin/ls -1A /boot/ | wc -l)" = "0" ]
        then
            echo "OK, /boot resides on its own partition..."
            echo ""
            echo "Writing grub to the master boot record of the hard disk:"
            echo ""
            BOOTDEV="$(mount | grep "on /boot type" | awk '{print $1}'| tr -d [0-9])"
            grub-install --no-floppy --recheck --force "$BOOTDEV" && update-grub
            grub_success_msg
        # check if /boot resides on the root partition:
        elif [ ! "$(mount | grep -v "type aufs" | grep /boot | grep -c ^/dev/sd)" = "1" ] && [ ! "$(/bin/ls -1A /boot | wc -l)" = "0" ]
        then
            echo "OK, /boot has no partition of its own..."
            echo ""
            echo "Will write grub to the master boot record of the hard disk now:"
            echo ""
            BOOTDEV="$(mount | grep "on / type" | awk '{print $1}'| tr -d [0-9])"
            grub-install --no-floppy --recheck --force "$BOOTDEV" && update-grub
            grub_success_msg
        else
            grub_failure_msg
        fi
    fi

    # silently try again, in case this has not yet been completed:
    wmlive_installer_removal

    # create /etc/fstab file if still missing
    if [ ! -s /etc/fstab ]
    then
        wmlive_mkfstab
    fi
fi

# Killing the PPID of this very script, in order to fully leave the chroot:
fix_complete_exit

# After having left the chroot:
if [ "$(mount | grep -c "on $DEBTARGET type")" = "1" ]
then
    rm -f "$DEBTARGET"/root/.wmliverc
    if [ ! "$(/bin/ls -1A "$DEBTARGET"/boot/ | wc -l)" = "0" ]
    then
        cat << EOF

    All known installation issues have been fixed, and we
    have successfully "Killed" and left the chroot session.

    Now please return to the debian-installer window, and
    confirm to finish the installation. The installer will
    properly finish and the system boot will work as expected.

    If the boot menu should still be missing some entries
    for dualbooting of parallel installed operating systems,
    just continue booting into Linux, and the configuration
    will be automagically updated with any missing entries.

EOF
    else
        grub_failure_msg
    fi
    echo $(date -R) > /var/tmp/wmlive-install-fixed
    df $DEBTARGET >> /var/tmp/wmlive-install-fixed
fi

Attachment: signature.asc
Description: Digital signature


Reply to: