view sources/native/bin/qemu-setup.sh @ 425:6a8f6cecce7c

Cleanup after chroot-setup.sh, and set nameserver.
author Rob Landley <rob@landley.net>
date Wed, 29 Oct 2008 17:28:36 -0500
parents acb61c298000
children f4d6502501d7
line wrap: on
line source

#!/tools/bin/bash

# If you're doing a Linux From Scratch build, the /tools directory is
# sufficient.  (Start by installing kernel headers and building a C library.)

# Otherwise, building source packages wants things like /bin/bash and
# running the results wants /lib/ld-uClibc.so.0, so set up some directories
# and symlinks to let you easily compile source packages.

# Add /tools to $PATH if it's not there

if [ -d tools/bin ] && [ -z "$(echo :$PATH | tools/bin/grep :/tools/bin)" ]
then
  [ -z "$PATH" ] && PATH=/tools/bin || PATH="$PATH":/tools/bin
  export PATH
fi

# Create some temporary directories at the root level
mkdir -p {proc,sys,dev,etc,tmp}
[ ! -e bin ] && ln -s tools/bin bin
[ ! -e lib ] && ln -s tools/lib lib
[ ! -e usr ] && ln -s tools usr

# Populate /dev
mountpoint -q sys || mount -t sysfs sys sys
mountpoint -q dev || mount -t tmpfs dev dev
mdev -s

# Mount /proc is there
mountpoint -q proc || mount -t proc proc proc

# If we're running under qemu, do some more setup
if [ `echo $0 | sed 's@.*/@@'` == "qemu-setup.sh" ]
then

  # Note that 10.0.2.2 forwards to 127.0.0.1 on the host.

  # Setup networking for QEMU (needs /proc)
  echo "nameserver 10.0.2.3" > /etc/resolv.conf
  ifconfig eth0 10.0.2.15
  route add default gw 10.0.2.2

  # If we have no RTC, try rdate instead:
  [[ `date +%s` < 1000 ]] && rdate 10.0.2.2 # or time-b.nist.gov

  # If there's a /dev/hdb or /dev/sdb, mount it on home

  [ -b /dev/hdb ] && HOMEDEV=/dev/hdb
  [ -b /dev/sdb ] && HOMEDEV=/dev/sdb
  if [ ! -z "$HOMEDEV" ]
  then
    mkdir -p /home
    mount $HOMEDEV /home
    export HOME=/home
  fi
else
  echo "nameserver 4.2.2.1" > /etc/resolv.conf
fi

echo Type exit when done.

# Switch to a shell with command history.
if [ -z "$CONSOLE" ]
then
  /tools/bin/ash
  cd /
  umount ./dev
  umount ./home
  umount ./sys
  umount ./proc
  sync
else
  exec /tools/bin/oneit -c /dev/$CONSOLE /tools/bin/ash
fi