Re. How2 use aps in other 'installations' with chroot ? - Slackware

This is a discussion on Re. How2 use aps in other 'installations' with chroot ? - Slackware ; > > OTOH, when we 'upgrade' we often loose good-old aps. Tom N wrote:- > Don't every 'upgrade'. Just install new apps and new libs, > one at a time, if they are worth it. Yes. But from where I ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Re. How2 use aps in other 'installations' with chroot ?

  1. Re. How2 use aps in other 'installations' with chroot ?

    > > OTOH, when we 'upgrade' we often loose good-old aps.

    Tom N wrote:-
    > Don't every 'upgrade'. Just install new apps and new libs,
    > one at a time, if they are worth it.


    Yes. But from where I am now, I have different apps on different
    instalations/partitions, which I want to run -- ALL.

    > > I've had partial success with using scripts:
    > > chroot
    > >


    From: Shadow_7:-
    > I got this from the gentoo site/forums. And adapted it for my needs.
    >
    > #----- START -----
    > #! /bin/sh
    >
    > mount /dev/hd?# /mnt/chroot
    > mount -t proc none /mnt/chroot/proc
    > mount -o bind /lib/modules /mnt/chroot/lib/modules
    > mount -o bind /sys /mnt/chroot/sys
    > mount -o bind /tmp /mnt/chroot/tmp
    > mount -o bind /dev /mnt/chroot/dev
    > mount -o bind /dev/pts /mnt/chroot/dev/pts
    >
    > cp /home/user1/.Xauthority /mnt/chroot/.Xauthority
    > echo "cp /etc/resolv.conf /mnt/chroot/etc/resolv.conf"
    >
    > echo "chroot /mnt/chroot"
    > echo "su - "
    > echo "export DISPLAY=\":0.0\""
    > #----- END -----


    I tried to investigate this.
    I like to understand what I'm doing ?
    ..Xauthority & resolv.conf seem only concerned with inet-connection.

    Initially I don't even want to do X-apps -- I switch to VT-mode for
    most tasks.

    AFAIK many apps need libraries and perhaps config files, which are
    located from 'pointers' in the executable.
    Apparently the libs can be located by: ldd
    But his is not needed, since when the 'chroot ...' is called the executable
    DOES take all 'file pointers' relative to "it's new" root-dir ?

    One problem which I had, since I wanted to repeatedly call elinks,
    so I wanted to use a script, which I do when calling it from its own
    partition.
    When I used 2 lines in the bash-script:-
    chroot
    elinks
    then when the script returned, the VT was still in the 'new' root,
    as seen by 'rdev'.

    But if I used one line thus:
    chroot ; elinks
    it was OK.

    Why would I need any of the script lines:
    mount -t proc none /mnt/chroot/proc
    mount -o bind /lib/modules /mnt/chroot/lib/modules
    mount -o bind /sys /mnt/chroot/sys
    mount -o bind /tmp /mnt/chroot/tmp
    mount -o bind /dev /mnt/chroot/dev
    mount -o bind /dev/pts /mnt/chroot/dev/pts
    ??

    When it's running with I guess it
    uses ?
    But these haven't been created by the boot process ?

    It's interesting, but beyond my knowledge !

    Thanks for any input.

    == Chris Glur.



  2. Re: Re. How2 use aps in other 'installations' with chroot ?

    problems@gmail wrote:
    >>> OTOH, when we 'upgrade' we often loose good-old aps.

    >
    > Tom N wrote:-
    >> Don't every 'upgrade'. Just install new apps and new libs,
    >> one at a time, if they are worth it.

    >
    > Yes. But from where I am now, I have different apps on different
    > instalations/partitions, which I want to run -- ALL.
    >
    >> > I've had partial success with using scripts:
    >> > chroot
    >> >

    >
    > From: Shadow_7:-
    >> I got this from the gentoo site/forums. And adapted it for my needs.
    >>
    >> #----- START -----
    >> #! /bin/sh
    >>
    >> mount /dev/hd?# /mnt/chroot
    >> mount -t proc none /mnt/chroot/proc
    >> mount -o bind /lib/modules /mnt/chroot/lib/modules
    >> mount -o bind /sys /mnt/chroot/sys
    >> mount -o bind /tmp /mnt/chroot/tmp
    >> mount -o bind /dev /mnt/chroot/dev
    >> mount -o bind /dev/pts /mnt/chroot/dev/pts
    >>
    >> cp /home/user1/.Xauthority /mnt/chroot/.Xauthority
    >> echo "cp /etc/resolv.conf /mnt/chroot/etc/resolv.conf"
    >>
    >> echo "chroot /mnt/chroot"
    >> echo "su - "
    >> echo "export DISPLAY=\":0.0\""
    >> #----- END -----

    >
    > I tried to investigate this.
    > I like to understand what I'm doing ?
    > .Xauthority & resolv.conf seem only concerned with inet-connection.
    >
    > Initially I don't even want to do X-apps -- I switch to VT-mode for
    > most tasks.
    >
    > AFAIK many apps need libraries and perhaps config files, which are
    > located from 'pointers' in the executable.
    > Apparently the libs can be located by: ldd
    > But his is not needed, since when the 'chroot ...' is called the executable
    > DOES take all 'file pointers' relative to "it's new" root-dir ?
    >
    > One problem which I had, since I wanted to repeatedly call elinks,
    > so I wanted to use a script, which I do when calling it from its own
    > partition.
    > When I used 2 lines in the bash-script:-
    > chroot
    > elinks
    > then when the script returned, the VT was still in the 'new' root,
    > as seen by 'rdev'.


    rdev do not see you the root environment. chroot
    execute a command in the chroot environment. If you do not specify a
    command it executes $SHELL. If interactively you do:

    chroot /mnt/chroot # line 1
    ls # line 2
    exit # line 3

    then the first line executes a shell in the new root; the second line
    executes ls within the new shell (thus in the chrooted environment); the
    third line exit the chrooted shell and return to the original shell.

    If you do the same in a script; the first line execute bash in a
    chrooted environment that immediately exit since this new bash have no
    command to execute. the second line do ls in the original shell and exit
    exit the script. If you want to execute several commands from a script
    in a chroot environment you have to make a script, say script.sh with
    these commands and from the main script you do chroot /mnt/chroot
    script.sh (you can also use redirection of stdin to specify commands to
    the chrooted shell).

    You can even launch X aps from the chrooted environment. To do so; you
    have to ensure that X is not launched with the -nolisten tcp option (if
    you use kdm, edit /etc/kde/kdm/kdmrc ) and to copy the ~/.Xauthority in
    the new home of the user who will execute program. I have make a script
    that put me in a Mandriva chrooted environement (with sudo mdvswitch);
    assuming the correct directories are present in fstab. As I have done
    this script for myself; I have not documented it; but I attach it here
    in case it might be useful (I license it under MIT).

    Olive


    #! /bin/sh
    set -e
    KEEP_HOME=0
    NO_HOME=0
    UMOUNT=0
    OPTIONC=0

    cleanexit() {
    if [ $UMOUNT == 1 ] ; then
    mdvumount || exit 2
    echo "/mnt/mdv fully unmounted" 1>&2
    fi
    }

    trap 'cleanexit ; exit 1' ERR

    while getopts ":kHuc" name ; do
    if [ $OPTIONC = 1 ] ; then
    echo "Error -c must be the last option" 1>&2
    false
    fi

    case "$name" in
    'k') # keep home
    KEEP_HOME=1
    ;;
    'H') # Do not mount home in ~/homeslack
    NO_HOME=1
    ;;
    'u') # Automatically umount on exit
    UMOUNT=1
    ;;
    'c' ) # Run a custom command
    OPTIONC=1
    ;;
    ':')
    echo "Option -$OPTARG requires an argument" 1>&2
    false
    ;;
    '?')
    echo "Illegal option: $OPTARG" 1>&2
    false
    esac
    done

    shift $((OPTIND-1))

    grep -q '/mnt/mdv ' /proc/mounts || mount LABEL=USB_MDV-2008.0 /mnt/mdv
    grep -q '/mnt/mdv/boot ' /proc/mounts || mount LABEL=USB_BOOT /mnt/mdv/boot
    grep -q '/mnt/mdv/dev ' /proc/mounts || mount --rbind /dev /mnt/mdv/dev
    grep -q '/mnt/mdv/sys ' /proc/mounts || mount --rbind /sys /mnt/mdv/sys
    grep -q '/mnt/mdv/proc ' /proc/mounts || mount --rbind /proc /mnt/mdv/proc

    if ! [ -e /mnt/mdv/lib/modules/$(uname -r) ] ; then
    mkdir -p /mnt/mdv/lib/modules/$(uname -r)
    fi

    grep -q "/mnt/mdv/lib/modules/$(uname -r) " /proc/mounts || mount --bind "/lib/modules/$(uname -r)" "/mnt/mdv/lib/modules/$(uname -r)"
    if [ $KEEP_HOME == 1 ] ; then
    grep -q '/mnt/mdv/home/oesser/homeslack ' /proc/mounts && umount /mnt/mdv/home/oesser/homeslack
    grep -q '/mnt/mdv/home/oesser ' /proc/mounts || mount --bind /home/oesser /mnt/mdv/home/oesser
    else
    if [ $NO_HOME == 0 ] ; then
    if grep -q '/mnt/mdv/home/oesser ' /proc/mounts ; then umount /mnt/mdv/home/oesser ; fi
    grep -q '/mnt/mdv/home/oesser/homeslack ' /proc/mounts || mount --bind /home/oesser /mnt/mdv/home/oesser/homeslack
    else
    grep -q '/mnt/mdv/home/oesser/homeslack ' /proc/mounts && umount /mnt/mdv/home/oesser/homeslack
    grep -q '/mnt/mdv/home/oesser ' /proc/mounts && umount /mnt/mdv/home/oesser
    fi

    [ $OPTIONC == 0 ] && [ -e "$XAUTHORITY" ] && cp -a $XAUTHORITY /mnt/mdv/home/oesser/.Xauthority
    fi

    cp /etc/resolv.conf /mnt/mdv/etc/resolv.conf

    [[ "$DISPLAY" = :* ]] && DISPLAY="127.0.0.1$DISPLAY"
    if [ $OPTIONC = 1 ]
    then
    env -i "TERM=$TERM" "DISPLAY=$DISPLAY" /usr/bin/chroot /mnt/mdv "$@"
    else
    env -i "TERM=$TERM" "DISPLAY=$DISPLAY" /usr/bin/chroot /mnt/mdv /bin/su - oesser
    fi

    sleep 1
    cleanexit





+ Reply to Thread