Guest User

Untitled

a guest
Dec 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # source - https://gist.github.com/geoffreyanderson/1004950
  2.  
  3. imageFile=${1:-"awsImage-$(date +%m%d%y-%H%M).img"}
  4. imageMountPoint=${2:-'/mnt/image'}
  5.  
  6. echo "Creating empty 10GB image in ${imageFile}"
  7. # Create an empty 10GB image file
  8. dd if=/dev/zero of=${imageFile} bs=1M count=10240
  9.  
  10. echo "Creating filesystem in ${imageFile}"
  11. # Create a filesystem on the image file
  12. /sbin/mke2fs -F -j ${imageFile}
  13.  
  14. echo "Mounting ${imageFile} loopback at ${imageMountPoint}"
  15. # Create the directories needed for imaging
  16. mkdir -p ${imageMountPoint}
  17. mount -o loop ${imageFile} ${imageMountPoint}
  18.  
  19. echo "Beginning rsync..."
  20. rsync --stats -av --exclude=/root/.bash_history --exclude=/home/*/.bash_history --exclude=/etc/ssh/ssh_host_* --exclude=/etc/ssh/moduli --exclude=/etc/udev/rules.d/*persistent-net.rules --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/sys/* --exclude=/dev/* / ${imageMountPoint}
  21.  
  22.  
  23. echo "rsync finished. Flushing copied log data..."
  24. #clear out any remaining log data
  25. cd ${imageMountPoint}/var/log
  26. for i in `ls ./**/*`; do
  27. echo $i && echo -n> $i
  28. done
  29.  
  30. # Create base devices (console, null, zero) under the completed image
  31. for i in console null zero ; do MAKEDEV -d ${imageMountPoint}/dev -x $i ; done
  32.  
  33. # get out of the image mount point so we can successfully unmount
  34. cd /
  35.  
  36. # Sync changes and unmount the image
  37. sync
  38. umount ${imageMountPoint}
  39. rmdir ${imageMountPoint}
Add Comment
Please, Sign In to add comment