Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • Eslam ElHusseiny 3:17 am on July 19, 2014 Permalink | Reply
    Tags: AMI, AWS, EC2, HVM, Paravirtualization   

    Creating HVM AMI from existing PV AMI 


    Hi everyone, it has been long time since my first post, anyway I will try to post more frequently 🙂

    I’m currently working on migrating some AWS EC2 instances to T2 instances type.

    The issue is that T2 instances must be launched into an Amazon Virtual Private Cloud (VPC); they are not supported on the EC2-Classic platform. Amazon VPC enables you to launch AWS resources into a virtual network that you’ve defined. You cannot change the instance type of an existing EC2-Classic instance to a T2 instance type.

    So actually I created AMIs from old instances I have to be used to launch T2 instances, but the problem here was that the AMIs I created from old EC2 instances was Paravirtualization based AMIs (PV AMI) which isn’t applicable here as T2 instances required HVM based AMIs to be launched from.

    So let’s start create HVM AMIs from our previously created PV AMIs

    First we need to start an EC2 instance from PV AMI we previously created as following

    aws ec2 run-instances –image-id <previously created PV AMI iD> –key-name <ssh key pair> –security-groups default –instance-type <any instance type of your choose that works with PV AMIs>  –count 1

    Then install the following packages on EC2 instance you launched from previously created PV AMI as following “Assuming Ubuntu Instance”

    sudo apt-get install -y grub-pc grub-pc-bin grub-legacy-ec2 grub-gfxpayload-lists

    Then stop the instance and detach the root disk (/dev/sda1) from the instance

    aws ec2 stop-instances –instance-ids  <EC2 instance we launched before ID>

    // make sure instance is stopped

    aws ec2 describe-instance-status –instance-ids <EC2 instance we launched before ID>

    aws ec2 detach-volume –volume-id <root partition “/dev/sda1” volume id>

    Launch another EC2 instance, but this time let it be a HVM besed EC2 instance, and here I prefer to choose the same OS version to avoid kernel upgrade headache, for my case it will be Ubuntu 12.04, here you can find a list of different Ubuntu AMIs

    aws ec2 run-instances –image-id ami-8e7ab6e6 –key-name <ssh key pair> –security-groups default –instance-type <any instance type of your choose that works with PV AMIs>  –count 1

    Attach root partition of PV based EC2 instance to HVM based EC2 instance

    aws ec2 attach-volume –volume-id <root partition of PV based EC2 instance Volume ID> –instance-id <HVM based EC2 instance ID> –device /dev/sdf

    SSH to HVM based EC2 instance and

    mkdir -p /mnt/xvdf && mount /dev/xvdf /mnt/xvdf

    rsync -avzXA /boot/ /mnt/xvdf/boot/

    mount -o bind /dev /mnt/xvdf/dev && mount -o bind /dev/pts /mnt/xvdf/dev/pts && mount -o bind /proc /mnt/xvdf/proc && mount -o bind /sys /mnt/xvdf/sys

    chroot /mnt/xvdf

    grub-install –no-floppy –recheck –force /dev/xvdf


    // Just in case of PV instance kernel version isn’t the same as HVM instance

    sudo apt-get install -y linux-virtual linux-image-virtual

    Stop the HVM instance, detach both original root of HVM instance “/dev/sda1” and PV root partition from HVM instance “/dev/sdf”

    aws ec2 stop-instances –instance-ids  <EC2 instance we launched before ID>

    // make sure instance is stopped

    aws ec2 describe-instance-status –instance-ids <EC2 instance we launched before ID>

    aws ec2 detach-volume –volume-id <original root partiion of HVM instance “/dev/sda1”>

    aws ec2 detach-volume –volume-id <PV instance root partition “/dev/sdf”>

    Attach PV instance’s root partition to HVM instance as a root partition to the HVM instance i.e. “/dev/sda1”

    aws ec2 attach-volume –volume-id <root partition of PV instance Volume ID> –instance-id <HVM instance ID> –device /dev/sda1

    And if you have any other Disks attached to PV instance detach them from PV instance and attach them to the HVM instance with the same device mapping so as not to corrupt mount points you’ve created for those disk and not that it seems there is some device mapping in PV instances won’t be applicable in HVM ones “e.g. /dev/sdh1” that require a modification to mount points used in PV instance, i.e. edit /etc/fstab to allign with new device mapping.

    It’s time now to start the HVM instance with newly root partition “that partition was used in PV instance”  and make sure everything is working fine 🙂

    Finally bundle your newly HVM instance into a HVM AMI to be used whenever you want

    aws ec2 create-image –instance-id <HVM instance ID> –name “My HVM AMI” –description “An HVM AMI for my server from an old PV AMI”

    That’s it 🙂

    References :

    • Alexander 1:12 pm on October 16, 2014 Permalink | Reply

      Thanks! Was helpful!

    • Bruno Galindro 11:33 am on February 5, 2015 Permalink | Reply

      Just a little observation: to be possible resolve domain names inside chroot, you need to mount /run on it too.

      sudo mount -o bind /run /mnt/run

    • vishal 12:12 am on February 26, 2015 Permalink | Reply

      Dear All

      Can I do same from EC2 dashboard? My t1.micro instance is on PV and I want to migrate to t2.medium.


      • 3sl4m 12:25 pm on April 1, 2015 Permalink | Reply

        I believe, EC2 dashboard won’t help in most of requried steps.


    • zwolfinger 6:06 pm on June 25, 2015 Permalink | Reply

      When I run “grub-install –no-floppy –recheck –force /dev/xvdf” I get this message:

      /usr/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea..
      /usr/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and their use is discouraged..
      Installation finished. No error reported.

      Is this expected? If not, what do I need to do to fix it?

      • 3sl4m 2:00 am on June 26, 2015 Permalink | Reply

        actually nope, this isn’t expected,
        most probably you’ve /dev/xvdf1 instead of /dev/xvdf as a partition, you can verify using command
        fdisk -l

    • Phil Porada 2:01 pm on November 24, 2015 Permalink | Reply


  • Eslam ElHusseiny 2:39 pm on September 2, 2013 Permalink | Reply
    Tags: AP, Ubuntu, Unifi   

    Installing Unifi AP software on Ubuntu linux 


    Controlling Unifi AP should be done through Unifi software

    So if you are an Ubuntu linux user, you should follow the following steps to install Unifi software

    • edit /etc/apt/source.list.d/ubnet.list

    sudo echo deb ubuntu ubiquiti > /etc/apt/sources.list.d/ubnet.list

    sudo apt-key adv --keyserver --recv C0A52C50
    • install unifi or unifi-beta

    sudo apt-get update

    sudo apt-get install unifi-beta

    Make sure that unifi service is running and listening on port 8080

    Then open http://localhost:8080 to start controlling your Unifi AP 🙂

    • Robert 12:06 pm on April 28, 2014 Permalink | Reply

      Thanks for the article. Made it incredibly simple to set up the controller!
      Nice work!

    • Johna649 3:59 pm on May 22, 2014 Permalink | Reply

      Hi there, just became aware of your blog through Google, and found that it is really informative. Im going to watch out for brussels. Ill be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers! efaeebgcdeek

    • Johng419 3:59 pm on May 22, 2014 Permalink | Reply

      Hey, thanks for the blog article.Really looking forward to read more. Much obliged. efdbabekgkck

    • Claudio 8:47 pm on July 17, 2014 Permalink | Reply

      Hello, Thanks for the article. Do you know any command to get information about APs from the command line of the controller?

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc