Palemoon in Minimal chroot

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Palemoon in Minimal chroot

#1 Post by s243a »

I've been experimenting a bit with palemoon on superlupu4. There is an issue where the newer glibc library doesn't play well with the the older libraries and can result in bus errors in some sites like youtube.

What I want to do is set up a very minimal chroot environment where it is almost exactly the same as the underlying system except for some configuration differences.

Basically I want to bind across most stuff except the /etc directory so that I can use the linker with a different cache file. I looked at two palemoon wrapper files:
/usr/local/bin/palemoon-plugin-container.sh
/usr/local/bin/palemoon.sh

Which use the following commands respectively to start palemoon.

Code: Select all

exec /usr/lib/glibc219/lib/ld-linux.so.2 --library-path /usr/lib/glibc219/lib:/usr/lib/glibc219/usr/lib:/usr/lib/glibc219/libstdc++:/usr/X11R7/lib:$PMDIR $PMDIR/plugin-container_exec "$@" #exec avoids segfault after flashplayer
and

Code: Select all

/usr/lib/glibc219/lib/ld-linux.so.2 --library-path /usr/lib/glibc219/lib:/usr/lib/glibc219/usr/lib:/usr/lib/glibc219/libstdc++:/usr/X11R7/lib:$PMDIR $PMDIR/palemoon "$@"
The problem I was having was that the linker was looking for libraries in many other places other than these directories and conflicting verions of glibc libraries seem to be causing bus errors.

I noticed that with ldconfig I can specify a different cache file. So if I create a file called
/usr/lib/glibc219/etc/ld.so.conf

Code: Select all

/usr/lib/glibc219/lib
/usr/lib/glibc219/usr/lib
/usr/lib/glibc219/libstdc++
/usr/X11R7/lib
/opt/palemoon
#/lib
#/usr/lib
#/usr/local/lib
#/usr/X11R7/lib
#/root/my-applications/lib
and then type on the command line

Code: Select all

ldconfig -n -f /usr/lib/glibc219/etc/ld.so.conf -C /usr/lib/glibc219/etc/ld.so.cache
I'm able to create a new cache but I'm not able to use it with the linker at the new location without doing a chroot.

Also note that the lines commented out above in ld.so.conf are causing the bus error. So mabye we just pick what we need from these directories and either rbind it across or symbolically link it across..

Anyway, I haven't tried chroot before but I'll take a guess based on the archwiki article

Code: Select all

cd /usr/lib/glibc219
mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
mount --rbind /lib lib/
mount --rbind /usr/lib usr/lib/
mount --rbind /usr/local/lib usr/local/lib/
mount --rbind /usr/X11R7/lib usr/X11R7/lib/
mount --rbind /root/my-applications/lib root/my-applications/lib/
mount --rbind /root/my-applications/lib root/my-applications/lib
mount --rbind /usr/bin usr/bin/
mount --rbind /usr/local/bin usr/local/bin/
mount --rbind /usr/local/bin usr/local/bin/
mount --rbind /usr/X11R7/bin usr/lX11R7/bin
#mount --rbind /run run/ #The wiki mentions this. Do we need it?
mount --rbind root/my-applications/sbin root/my-applications/sbin/
chroot /usr/lib/glibc219 /usr/local/bin/palemoon


I might try this tommorow and see what happens

P.S. The wiki says that I also need to copy the following to use the internet

Code: Select all

cp /etc/resolv.conf /usr/lib/glibc219/etc/resolv.conf
P.S. does the chroot environment get it's own "bus" whatever that means.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#2 Post by s243a »

So I decided I wanted to write a script to set this stuff up so I can make changes easily.

Here is what I have so far

/etc/rc.d/pale_chroot/build-new-root

Code: Select all

#!/bin/bash
DIR=$(dirname "$(readlink -f "$0")") #https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
export ROOT_DIR='/usr/lib/glibc219/'
#chROTT_PREFIX="${chROOT_DIR:-ddot}"
export LIB_PREFIX="${LIB_PREFIX:-ddot/}"
export PATH_PREFIX="${PATH_PREFIX:-ddot/}"
sh -x $DIR/mk-chroot-dirs
#if [ ! "$(ls -A $ROOT_DIR$PATH_PREFIX/lib)" ]; then
  cd "$ROOT_DIR"
  #a_lib=('proc' '/sys' '/dev')
  #b_lib={'proc' 'sys/' 'dev/') 
  mount -t proc proc proc/
  mount -o bind /sys sys/
  mount -o bind /dev dev/	
  #Map these ones over with a specail prefix
  a_lib=('/lib' '/usr/lib' '/usr/local/lib')
  b_lib=('lib/' 'usr/lib/' 'usr/local/lib/')	
  #for i in `seq 0 ${#a_lib[@]}-1}`; do
  for (( i=0; i<${#a_lib[@]}; i++ )); do
     mkdir -p "$LIB_PREFIX${b_lib[i]}"  
     mount --rbind "${a_lib[i]}" "$LIB_PREFIX${b_lib[i]}"
  done
  #Map these ones over without a prefix
    a_lib=('/opt/palemoon' '/usr/X11R7/lib')
    b_lib=('opt/palemoon/' 'usr/X11R7/lib/')	
  #for i in `seq 0 ${#a_lib[@]}-1}`; do
  for (( i=0; i<${#a_lib[@]}; i++ )); do
     mkdir -p "${b_lib[i]}"  
     mount --rbind "${a_lib[i]}" "${b_lib[i]}"
  done
  #mount --rbind /opt/palemoon opt/palemoon/
 
 
  #Maybe some items in path we want to compile under a seperate prefix
  #In this case we are putting /usr/local/bin under a new prefix so palemoon doesn't 
  #conflict with the nonchroot environment
  a_path=('/usr/local/bin')
  b_path=('usr/local/bin/')
   for (( i=0; i<=${#a_path[@]}; i++ )); do
   mkdir -p "$LIB_PREFIX${b_path[i]}"
    mount --rbind "${a_path[i]}" "$PATH_PREFIX${b_path[i]}"
  done
  
  
 #Maybe these path items over without a seperate prefix.
  a_path=('/bin' '/usr/bin' '/usr/X11R7/bin')
  b_path=('bin/' 'usr/bin/' 'usr/X11R7/bin/')
 # for i in `seq 0 ${#a_path[@]}-1}`;  do
   for (( i=0; i<=${#a_path[@]}; i++ )); do
    mkdir -p "${b_path[i]}"
    mount --rbind "${a_path[i]}" "${b_path[i]}"
  done
  
  
#fi
#ls -sr  /usr/lib/glibc219/local/bin/palemoon
chroot /usr/lib/glibc219 /usr/local/bin/palemoon

/etc/rc.d/pale_chroot/build-new-root/mk-chroot-dirs

Code: Select all

#!/bin/bash
#https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
cd "$ROOT_DIR"
#if [ ! -d usr/local/lib ]; then
  ROOT_DIR="${chROOT_PREFIX:-/usr/lib/glibc219}"
  LIB_PREFIX="${LIB_PREFIX:-ddot/}"
  PATH_PREFIX="${PATH_PREFIX:-ddot/}"
  #chROTT_PREFIX="${chROOT_DIR:-ddot}"
  mkdir -p "$ROOT_DIR$LIB_PREFIX"
  mkdir -p "$ROOT_DIR$PATH_PREFIX"
  declare -a dirs=('etc/' 'usr/local/lib/' 'usr/local/bin' 'usr/local/X11R7/' 'proc/' 'sys/' 'dev/' 'opt/palemoon')
  for d in "${dirs[@]}"; do
    echo "d=$d"
    mkdir -p "$d"
  done
  ln -s ../../../ "$ROOT_DIR/usr/lib/glibc219" #This lets us do ldconfig outside of the chroot env. 
  echo "writing palemoon.sh"
  cat > "$ROOT_DIR/usr/local/bin/palemoon.sh" <<EOF
    #!/bin/sh
    PMDIR=/opt/palemoon
    #/usr/lib/glibc219/lib/ld-linux.so.2 --library-path /usr/lib/glibc219/lib:/usr/lib/glibc219/usr/lib:/usr/lib/glibc219/libstdc++:/usr/X11R7/lib:$PMDIR $PMDIR/palemoon "$@"
     /usr/lib/glibc219/lib/ld-linux.so.2 --library-path $PMDIR/palemoon "$@"
EOF
chmod 771 "$ROOT_DIR/usr/local/bin/palemoon.sh" 
  echo "palemoon-plugin-cointainer.sh"
   ln -s ./palemoon.sh "$ROOT_DIR/usr/local/bin/palemoon"
   cat > "$ROOT_DIR/usr/local/bin/palemoon-plugin-cointainer.sh" <<EOF
    #!/bin/sh
    PMDIR=/opt/palemoon
    #exec /usr/lib/glibc219/lib/ld-linux.so.2 --library-path /usr/lib/glibc219/lib:/usr/lib/glibc219/usr/lib:/usr/lib/glibc219/libstdc++:/usr/X11R7/lib:$PMDIR $PMDIR/plugin-container_exec "$@" #exec avoids segfault after flashplayer
    exec /usr/lib/glibc219/lib/ld-linux.so.2 --library-path  $PMDIR/plugin-container_exec "$@" #exec avoids segfault after flashplayer
EOF
   ln -s ./palemoon-plugin-cointainer.sh "$ROOT_DIR/usr/local/bin/palemoon-plugin-cointainer"
   
#fi
chmod 771 "$ROOT_DIR/usr/local/bin/palemoon-plugin-cointainer.sh"
I have to link a few more things that I need to link across for the chroot to work. I'll report back when I make more progress.

Edit: I modified some of the scripts above from my orginal post. This may be more ambitious than I originally thought.

Post Reply