runqemu-addptable2image 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # Add a partion table to an ext2 image file
  3. #
  4. # Copyright (C) 2006-2007 OpenedHand Ltd.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. IMAGE=$1
  20. IMAGEOUT=$2
  21. echo $IMAGE
  22. echo $IMAGEOUT
  23. size=`ls -l $IMAGE | awk '{ print $5}'`
  24. size2=`expr $size / 512 / 16 / 63`
  25. echo $size
  26. echo $size2
  27. # MBR Size = 512 * 63 bytes
  28. dd if=/dev/zero of=$IMAGEOUT count=63
  29. echo "x" > /tmp/fdisk.cmds
  30. echo "c" >> /tmp/fdisk.cmds
  31. echo "1024" >> /tmp/fdisk.cmds
  32. echo "h" >> /tmp/fdisk.cmds
  33. echo "16" >> /tmp/fdisk.cmds
  34. echo "r" >> /tmp/fdisk.cmds
  35. echo "n" >> /tmp/fdisk.cmds
  36. echo "p" >> /tmp/fdisk.cmds
  37. echo "1" >> /tmp/fdisk.cmds
  38. echo "1" >> /tmp/fdisk.cmds
  39. echo "$size2" >> /tmp/fdisk.cmds
  40. echo "w" >> /tmp/fdisk.cmds
  41. /sbin/fdisk $IMAGEOUT < /tmp/fdisk.cmds
  42. cat $IMAGE >> $IMAGEOUT