public
Last active — forked from fairchild/bundle-to-ebs.sh

bundle s3 AMI to EBS

  • Download Gist
bundle-to-ebs.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/bin/bash
 
mkdir /mnt/ebs
mkfs.ext3 ${EBS_DEVICE}
mount ${EBS_DEVICE} /mnt/ebs
 
mkdir /mnt/tmp
rsync -av --exclude=/mnt/ --exclude=/proc/ / /mnt/tmp/
 
rm /mnt/tmp/root/.bash_history
rm /mnt/tmp/home/*/.bash_history
rm /mnt/tmp/etc/ssh/ssh_host_*
rm /mnt/tmp/etc/ssh/moduli
rm /mnt/tmp/etc/udev/rules.d/*persistent-net.rules
 
#ensure that ami init scripts will be run
chmod u+x /mnt/ebs/etc/init.d/ec2-init-user-data
rm /mnt/ebs/var/lib/ec2
 
#clear out log files
cd /mnt/tmp/var/log
for i in `ls ./**/*`; do
echo $i && echo -n> $i
done
 
# rsync --stats -avx --exclude-from=excludes.txt / /mnt/ebs/
cd /mnt/tmp
# tar cpS ./ | cpipe -vt -b 1024 | gzip -c | tar zxpS -C /mnt/ebs/
tar -cSf - -C ./ . | tar xvf - -C /mnt/ebs/
mv /mnt/ebs/mnt/tmp/* /mnt/ebs/ #FIX THIS UGLYNESS
 
umount /mnt/ebs
instance-to-ebs-ami.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
echo ''
echo "
sudo -s
mkdir /mnt/ebs
mkfs.ext3 ${EBS_DEVICE}
mount ${EBS_DEVICE} /mnt/ebs
 
mkdir /mnt/tmp
rsync -av --exclude=/mnt/ --exclude=/proc/ / /mnt/tmp/
 
rm /mnt/tmp/root/.bash_history
rm /mnt/tmp/home/*/.bash_history
rm /mnt/tmp/etc/ssh/ssh_host_*
rm /mnt/tmp/etc/ssh/moduli
rm /mnt/tmp/etc/udev/rules.d/*persistent-net.rules
 
#ensure that ami init scripts will be run
chmod u+x /mnt/ebs/etc/init.d/ec2-init-user-data
rm /mnt/ebs/var/lib/ec2
 
#clear out log files
cd /mnt/tmp/var/log
for i in `ls ./**/*`; do
echo $i && echo -n> $i
done
 
# rsync --stats -avx --exclude-from=excludes.txt / /mnt/ebs/
cd /mnt/tmp
# tar cpS ./ | cpipe -vt -b 1024 | gzip -c | tar zxpS -C /mnt/ebs/
tar -cSf - -C ./ . | tar xvf - -C /mnt/ebs/
mv /mnt/ebs/mnt/tmp/* /mnt/ebs/ #FIX THIS UGLYNESS
 
umount /mnt/ebs
"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.