build-rootimage 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # Create guest root image
  3. #
  4. # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
  5. # Zuercher Hochschule Winterthur
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by the
  9. # Free Software Foundation; either version 2 of the License, or (at your
  10. # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. # for more details.
  16. echo "Building root image"
  17. DIR=$(dirname `readlink -f $0`)
  18. . $DIR/../testing.conf
  19. . $DIR/function.sh
  20. [ `id -u` -eq 0 ] || die "You must be root to run $0"
  21. [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
  22. running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
  23. check_commands partprobe qemu-img qemu-nbd
  24. load_qemu_nbd
  25. mkdir -p $LOOPDIR
  26. mkdir -p $SHAREDDIR/compile
  27. mkdir -p $IMGDIR
  28. log_action "Creating root image $ROOTIMG"
  29. execute "qemu-img create -b $BASEIMG -f $IMGEXT $ROOTIMG"
  30. log_action "Connecting root image to NBD device $NBDEV"
  31. execute "qemu-nbd -c $NBDEV $ROOTIMG"
  32. do_on_exit qemu-nbd -d $NBDEV
  33. partprobe $NBDEV
  34. log_action "Mounting $NBDPARTITION to $LOOPDIR"
  35. execute "mount $NBDPARTITION $LOOPDIR"
  36. do_on_exit umount $LOOPDIR
  37. log_action "Mounting proc filesystem to $LOOPDIR/proc"
  38. execute "mount -t proc none $LOOPDIR/proc"
  39. do_on_exit umount $LOOPDIR/proc
  40. mkdir -p $LOOPDIR/root/shared
  41. log_action "Mounting $SHAREDDIR as /root/shared"
  42. execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
  43. do_on_exit umount $LOOPDIR/root/shared
  44. echo "Installing software from source"
  45. RECPDIR=$DIR/recipes
  46. if [ -d "$RECPDIR/patches" ]
  47. then
  48. execute "cp -r $RECPDIR/patches $LOOPDIR/root/shared/compile" 0
  49. fi
  50. RECIPES=`ls $RECPDIR/*.mk | xargs -n1 basename`
  51. for r in $RECIPES
  52. do
  53. cp $RECPDIR/$r ${LOOPDIR}/root/shared/compile
  54. log_action "Installing from recipe $r"
  55. execute_chroot "make SWANVERSION=$SWANVERSION -C /root/shared/compile -f $r"
  56. done
  57. log_action "Removing /etc/resolv.conf"
  58. execute "rm -f $LOOPDIR/etc/resolv.conf"