You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

make-base-vm 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. set -e
  3. SUITE=lucid
  4. ARCH=amd64
  5. MIRROR=http://${MIRROR_HOST:-127.0.0.1}:3142/archive.ubuntu.com/ubuntu
  6. SECURITY_MIRROR=http://${MIRROR_HOST:-127.0.0.1}:3142/security.ubuntu.com/ubuntu
  7. LXC=0
  8. usage() {
  9. echo "Usage: ${0##*/} [OPTION]..."
  10. echo "Make a base client."
  11. echo
  12. cat << EOF
  13. --help display this help and exit
  14. --suite U build suite U instead of lucid
  15. --arch A build architecture A (e.g. i386) instead of amd64
  16. --lxc use lxc instead of kvm
  17. The MIRROR_HOST environment variable can be used to change the
  18. apt-cacher host. It should be something that the target VM can
  19. resolve. It may be set to 127.0.0.1, in which case it will be
  20. changed to 10.0.2.2 on the guest. 10.0.2.2 is the host IP as visible
  21. from the guest under qemu networking.
  22. EOF
  23. }
  24. if [ $# != 0 ] ; then
  25. while true ; do
  26. case "$1" in
  27. --help|-h)
  28. usage
  29. exit 0
  30. ;;
  31. --suite|-s)
  32. SUITE="$2"
  33. shift 2
  34. ;;
  35. --arch|-a)
  36. ARCH="$2"
  37. shift 2
  38. ;;
  39. --lxc)
  40. LXC=1
  41. shift 1
  42. ;;
  43. --*)
  44. echo "unrecognized option $1"
  45. exit 1
  46. ;;
  47. *)
  48. break
  49. ;;
  50. esac
  51. done
  52. fi
  53. mkdir -p var
  54. if [ ! -e var/id_dsa ]; then
  55. ssh-keygen -t dsa -f var/id_dsa -N ""
  56. fi
  57. OUT=base-$SUITE-$ARCH
  58. FLAVOUR=virtual
  59. if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
  60. FLAVOUR=server
  61. fi
  62. addpkg=openssh-server,pciutils,build-essential,git-core,subversion
  63. if [ -e $OUT.qcow2 ]; then
  64. echo $OUT.qcow2 already exists, please remove it first
  65. exit 1
  66. fi
  67. rm -rf $OUT
  68. sudo vmbuilder kvm ubuntu --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --ssh-key=var/id_dsa.pub --ssh-user-key=var/id_dsa.pub --mirror=$MIRROR --security-mirror=$SECURITY_MIRROR --dest=$OUT --flavour=$FLAVOUR --firstboot=`pwd`/target-bin/bootstrap-fixup
  69. mv $OUT/*.qcow2 $OUT.qcow2
  70. rm -rf $OUT
  71. if [ $LXC = "1" ]; then
  72. #sudo debootstrap --include=$addpkg --arch=$ARCH $SUITE $OUT-root $MIRROR
  73. echo Extracting partition for lxc
  74. qemu-img convert $OUT.qcow2 $OUT.raw
  75. loop=`sudo kpartx -av $OUT.raw|sed -n '/loop\(.\)p1/ i\1'`
  76. sudo cp --sparse=always /dev/mapper/loop${loop}p1 $OUT
  77. sudo chown $USER $OUT
  78. sudo kpartx -d /dev/loop$loop
  79. rm -f $OUT.raw
  80. # bootstrap-fixup is done in libexec/make-clean-vm
  81. fi