Guest User

Untitled

a guest
Apr 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/bin/bash
  2. # Run this script on the instance to be bundled
  3.  
  4. EBS_DEVICE=${1:-'/dev/sdh'}
  5.  
  6. mkdir /mnt/ebs
  7. mkfs.ext3 ${EBS_DEVICE}
  8. mount ${EBS_DEVICE} /mnt/ebs
  9.  
  10. #make a local working copy
  11. mkdir /mnt/tmp
  12. rsync -av --exclude=/mnt/ --exclude=/proc/* / /mnt/tmp/
  13.  
  14. #remove files that should be instance specific
  15. rm /mnt/tmp/root/.bash_history
  16. rm /mnt/tmp/home/*/.bash_history
  17. rm /mnt/tmp/etc/ssh/ssh_host_*
  18. rm /mnt/tmp/etc/ssh/moduli
  19. rm /mnt/tmp/etc/udev/rules.d/*persistent-net.rules
  20.  
  21. #ensure that ami init scripts will be run
  22. chmod u+x /mnt/ebs/etc/init.d/ec2-init-user-data
  23. rm /mnt/ebs/var/lib/ec2
  24.  
  25. #clear out log files
  26. cd /mnt/tmp/var/log
  27. for i in `ls ./**/*`; do
  28. echo $i && echo -n> $i
  29. done
  30.  
  31. cd /mnt/tmp
  32. tar -cSf - -C ./ . | tar xvf - -C /mnt/ebs/
  33. #NOTE, rsync could be used, but this tar trickery saves some space in the snapshot
  34.  
  35. umount /mnt/ebs
Add Comment
Please, Sign In to add comment