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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. VBOX=0
  9. usage() {
  10. echo "Usage: ${0##*/} [OPTION]..."
  11. echo "Make a base client."
  12. echo
  13. cat << EOF
  14. --help display this help and exit
  15. --suite U build suite U instead of lucid
  16. --arch A build architecture A (e.g. i386) instead of amd64
  17. --lxc use lxc instead of kvm
  18. --vbox use VirtualBox instead of kvm
  19. The MIRROR_HOST environment variable can be used to change the
  20. apt-cacher host. It should be something that both the host and the
  21. target VM can reach. It may be set to 127.0.0.1, in which case it will be
  22. changed to 10.0.2.2 on the guest (or GITIAN_HOST_IP if it is defined)
  23. 10.0.2.2 is the host IP as visible from the guest under qemu networking.
  24. EOF
  25. }
  26. if [ $# != 0 ] ; then
  27. while true ; do
  28. case "$1" in
  29. --help|-h)
  30. usage
  31. exit 0
  32. ;;
  33. --suite|-s)
  34. SUITE="$2"
  35. shift 2
  36. ;;
  37. --arch|-a)
  38. ARCH="$2"
  39. shift 2
  40. ;;
  41. --lxc)
  42. LXC=1
  43. shift 1
  44. ;;
  45. --vbox)
  46. VBOX=1
  47. shift 1
  48. ;;
  49. --*)
  50. echo "unrecognized option $1"
  51. exit 1
  52. ;;
  53. *)
  54. break
  55. ;;
  56. esac
  57. done
  58. fi
  59. mkdir -p var
  60. if [ ! -e var/id_dsa ]; then
  61. ssh-keygen -t dsa -f var/id_dsa -N ""
  62. fi
  63. OUT=base-$SUITE-$ARCH
  64. FLAVOUR=virtual
  65. if [ $ARCH = "amd64" -a $SUITE = "hardy" ]; then
  66. FLAVOUR=server
  67. fi
  68. addpkg=openssh-server,pciutils,build-essential,git-core,subversion,lxc
  69. # Remove cron to work around vmbuilder issue when umounting /dev on target
  70. removepkg=cron
  71. if [ $VBOX = "1" ]; then
  72. NAME="$SUITE-$ARCH"
  73. if ! vagrant status | grep "$NAME" | grep "not created" > /dev/null; then
  74. echo "Vagrant machine "$NAME" already exists, please remove it first (vagrant destroy "$NAME")"
  75. exit 1
  76. fi
  77. vagrant up "$NAME"
  78. vagrant ssh "$NAME" -c "sudo mkdir -p /root/.ssh && sudo chmod 700 /root/.ssh"
  79. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /root/.ssh/authorized_keys'" < var/id_dsa.pub
  80. vagrant ssh "$NAME" -c "sudo -u ubuntu mkdir -p /home/ubuntu/.ssh && sudo -u ubuntu chmod 700 /home/ubuntu/.ssh"
  81. vagrant ssh "$NAME" -c "sudo sh -c 'cat >> /home/ubuntu/.ssh/authorized_keys'" < var/id_dsa.pub
  82. VBoxManage snapshot "Gitian-$NAME" take "Gitian-Clean"
  83. vagrant suspend "$NAME"
  84. exit 0
  85. fi
  86. if [ -e $OUT.qcow2 ]; then
  87. echo $OUT.qcow2 already exists, please remove it first
  88. exit 1
  89. fi
  90. libexec/config-bootstrap-fixup
  91. rm -rf $OUT
  92. env -i LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 sudo vmbuilder kvm ubuntu --rootsize 10240 --arch=$ARCH --suite=$SUITE --addpkg=$addpkg --removepkg=$removepkg --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
  93. mv $OUT/*.qcow2 $OUT.qcow2
  94. rm -rf $OUT
  95. if [ $LXC = "1" ]; then
  96. #sudo debootstrap --include=$addpkg --arch=$ARCH $SUITE $OUT-root $MIRROR
  97. echo Extracting partition for lxc
  98. qemu-img convert $OUT.qcow2 $OUT.raw
  99. loop=`sudo kpartx -av $OUT.raw|sed -n '/loop.p1/{s/.*loop\(.\)p1.*/\1/;p}'`
  100. sudo cp --sparse=always /dev/mapper/loop${loop}p1 $OUT
  101. sudo chown $USER $OUT
  102. sudo kpartx -d /dev/loop$loop
  103. rm -f $OUT.raw
  104. # bootstrap-fixup is done in libexec/make-clean-vm
  105. fi