Wednesday, July 06, 2016

Recovering AWS AMI with lost key pair

If you lost a key pair for the running AMI or an image here is the sequence of steps to recover (ubuntu 14.04 style):
1. For the image, run an instance IN THE SAME AZ where you need your new AMI. If you got a running AMI in another AZ make an image and start the new AMI from that in the AZ where you need your new instance.

2. Once you got a running old AMI in the AZ you need, stop it (do NOT Terminate).

3. Detach volume of the old AMI using AWS Console

4. Start a clean new AMI with the key pair you got.

5. Using AWS Console, attach the detached old AMI volume to the new AMI. AWS will tell you it is mounted at /dev/sdf - NOT SURE IT IS THERE

6. SSH to your new AMI where you attached the old volume


#become a root
sudo -i

#find out where the old volume is attached
sudo lsblk --output NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,LABEL

#it should give you something like
NAME    TYPE SIZE FSTYPE MOUNTPOINT LABEL
xvda    disk   8G                  
└─xvda1 part   8G ext4   /          cloudimg-rootfs
xvdf    disk  14G                  
└─xvdf1 part  14G ext4              cloudimg-rootfs



#create mount point
mkdir /mnt/recovery

#mount the volume - note it is /dev/xvdf1 (with "1" at the end)
mount /dev/xvdf1 /mnt/recovery -t ext4

#copy SSH keys to the old volume. NOTE you will need 'ec2-user' instead of 'ubuntu' in the below pathes if you do it for other OS-s
cat /home/ubuntu/.ssh/authorized_keys > /mnt/recovery/home/ubuntu/.ssh/authorized_keys

#unmount the volume
umount /mnt/recovery/

7. Attach the old volume back to stopped old AMI

8. Now you can kill the new instance and start the old one. You should be able to SSH it with your key pair

Alternatively to steps (7)-(8) you can create a snapshot from the old volume with new key pair, and then create an image from that snapshot. Next, launch a new AMI from that image.

References:
[1]

Wednesday, June 29, 2016

Ubuntu software update can not run due to insufficient disk space

This one-liner does the clean up:
dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

(source)

Tuesday, May 24, 2016

Make Mozilla Thunderbird to properly work with your Google Calendar

Thunderbird uses it's own default "Home" calendar so you need to re-configure it if you want to use your Google Calndar via Lightning plugin.
  1. Manually copy upcoming event from Home calendar to Google calendar (e.g. by creating new events at http://calendar.google.com).
  2. Remove "Home" calendar: "Events and Tasks" -> Unsubscribe selected Calendar -> Home
  3. Download & install "Provider for Google Calendar": https://addons.mozilla.org/en-US/thunderbird/addon/provider-for-google-calendar/, restart Thunderbird
  4. Add your Google calendar: File->New->Calendar->Network Calendar->Google CalendarEnter your email address and then,in the Google authorization window, provide your Google account credentials .
  5.  Last but not least: allow the calendar to accept incoming events and send notifications.Options->Advanced->Config EditorType in the search bar: calendar.google.enableEmailInvitations and click on item to make it 'true'