Reputation: 839
How should I use the new AWS EC2 classes (r3, i2) with my existing AMI without recreating the whole system setup?
The new EC2 classes support only HVM based virtualization but I have only PVM AMI images.
Upvotes: 83
Views: 28189
Reputation: 1969
The answer from @divyenduz works but needs some cleanup and clarification for modern (circa 2019) AWS EC2. Importantly, modern instance classes translate the device name differently.
Here are my modified steps.
For clarity, nodes are:
BEFORE PROCEEDING: Back up Original Node PVM01
Install prerequisites on Node PVM01
install grub packages on PVM01
apt-get install grub-pc grub-pc-bin grub-legacy-ec2 grub-gfxpayload-lists
Stop node PVM01
Attach PVM01 root partition (new volume from previous step) to new HVM01 /dev/sdf
ssh PVM01 sudo fdisk -l
On HVM01:
# For xvdf, e.g. on C3.XLARGE
DEVNAME=xvdf1
# For nvme, e.g. on C5.XLARGE
DEVNAME=nvme1n1
mkdir -p /mnt/${DEVNAME} && mount /dev/${DEVNAME} /mnt/${DEVNAME}
rsync -avzXA /boot/ /mnt/${DEVNAME}/boot/
mount -o bind /dev /mnt/${DEVNAME}/dev && mount -o bind /dev/pts /mnt/${DEVNAME}/dev/pts && mount -o bind /proc /mnt/${DEVNAME}/proc && mount -o bind /sys /mnt/${DEVNAME}/sys
chroot /mnt/${DEVNAME}
grub-install --no-floppy --recheck --force /dev/${DEVNAME}
update-grub2
Exit chroot with CTRL+D
Upvotes: 3
Reputation: 2027
Start an Ubuntu HVM linux, any version, new
Start an Ubuntu / with my existing AMI / PVM linux, and install grub packages on them: apt-get install grub-pc grub-pc-bin grub-legacy-ec2 grub-gfxpayload-lists
Stop PVM linux
Detach root (/dev/sda1) partition at PVM linux
Attach PVM linux root partition to running HVM linux somewhere, e.g.: /dev/sdf
On HVM linux: 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
update-grub2
exit chroot: CTRL+D
stop HVM Linux
detach /dev/sda1 original root AND detach /dev/sdf PVM root
attach PVM root to HVM linux as /dev/sda1
Start HVM linux, voilà!
Create a new AMI image from the running HVM linux, it will be HVM virtualized.
Upvotes: 77