Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # source - https://gist.github.com/geoffreyanderson/1004950
- imageFile=${1:-"awsImage-$(date +%m%d%y-%H%M).img"}
- imageMountPoint=${2:-'/mnt/image'}
- echo "Creating empty 10GB image in ${imageFile}"
- # Create an empty 10GB image file
- dd if=/dev/zero of=${imageFile} bs=1M count=10240
- echo "Creating filesystem in ${imageFile}"
- # Create a filesystem on the image file
- /sbin/mke2fs -F -j ${imageFile}
- echo "Mounting ${imageFile} loopback at ${imageMountPoint}"
- # Create the directories needed for imaging
- mkdir -p ${imageMountPoint}
- mount -o loop ${imageFile} ${imageMountPoint}
- echo "Beginning rsync..."
- 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}
- echo "rsync finished. Flushing copied log data..."
- #clear out any remaining log data
- cd ${imageMountPoint}/var/log
- for i in `ls ./**/*`; do
- echo $i && echo -n> $i
- done
- # Create base devices (console, null, zero) under the completed image
- for i in console null zero ; do MAKEDEV -d ${imageMountPoint}/dev -x $i ; done
- # get out of the image mount point so we can successfully unmount
- cd /
- # Sync changes and unmount the image
- sync
- umount ${imageMountPoint}
- rmdir ${imageMountPoint}
Add Comment
Please, Sign In to add comment