chroot 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. DIR=$(dirname `readlink -f $0`)
  3. . $DIR/../testing.conf
  4. . $DIR/function.sh
  5. [ `id -u` -eq 0 ] || die "You must be root to run $0"
  6. running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
  7. [ -n "$1" ] || die "$0 <image to mount: base|root|<guest>>"
  8. check_commands partprobe qemu-nbd
  9. load_qemu_nbd
  10. mkdir -p $LOOPDIR
  11. mkdir -p $IMGDIR
  12. mkdir -p $SHAREDDIR
  13. echo "Mounting image"
  14. case "$1" in
  15. base)
  16. [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
  17. log_action "Connecting base image to NBD device $NBDEV"
  18. execute "qemu-nbd -c $NBDEV $BASEIMG"
  19. affected="root and guest"
  20. ;;
  21. root)
  22. [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found"
  23. log_action "Connecting root image to NBD device $NBDEV"
  24. execute "qemu-nbd -c $NBDEV $ROOTIMG"
  25. affected="guest"
  26. ;;
  27. *)
  28. echo $STRONGSWANHOSTS | grep -q "\b$1\b" || die "Guest $1 not found"
  29. GUESTIMG="$IMGDIR/$1.$IMGEXT"
  30. [ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found"
  31. log_action "Connecting guest image to NBD device $NBDEV"
  32. execute "qemu-nbd -c $NBDEV $GUESTIMG"
  33. ;;
  34. esac
  35. do_on_exit qemu-nbd -d $NBDEV
  36. partprobe $NBDEV
  37. log_action "Mounting $NBDPARTITION to $LOOPDIR"
  38. execute "mount $NBDPARTITION $LOOPDIR"
  39. do_on_exit umount $LOOPDIR
  40. log_action "Mounting proc filesystem to $LOOPDIR/proc"
  41. execute "mount -t proc none $LOOPDIR/proc"
  42. do_on_exit umount $LOOPDIR/proc
  43. mkdir -p $LOOPDIR/root/shared
  44. log_action "Mounting $SHAREDDIR as /root/shared"
  45. execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
  46. do_on_exit umount $LOOPDIR/root/shared
  47. if [ -n "$affected" ]; then
  48. echo
  49. echo "Rebuild the $affected images after making changes to this image!"
  50. echo
  51. fi
  52. export debian_chroot="$1"
  53. chroot $LOOPDIR /bin/bash -i