Azure

From DikapediaV2
Revision as of 05:42, 20 August 2024 by Ardika Sulistija (talk | contribs) (Created page with "====Migrating Ubuntu from Azure to AWS ==== ---- [+] Useful links: </br> https://ubuntu.com/aws</br> https://ubuntu.com/blog/ubuntu-on-aws-gets-serious-performance-boost-with-aws-tuned-kernel</br> https://packages.ubuntu.com/search?keywords=linux-aws</br> https://launchpad.net/ubuntu/+source/linux-aws</br> In order to run Ubuntu from Azure in AWS, the Azure kernel needs to be replaced with the 'generic' AWS turned Ubuntu kernel (<b>linux-aws</b>) either on the source o...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Migrating Ubuntu from Azure to AWS


[+] Useful links:
https://ubuntu.com/aws
https://ubuntu.com/blog/ubuntu-on-aws-gets-serious-performance-boost-with-aws-tuned-kernel
https://packages.ubuntu.com/search?keywords=linux-aws
https://launchpad.net/ubuntu/+source/linux-aws

In order to run Ubuntu from Azure in AWS, the Azure kernel needs to be replaced with the 'generic' AWS turned Ubuntu kernel (linux-aws) either on the source or target (preferably the target). This is because the azure kernel is not compatible with AWS hardware. The '-aws' kernels would have the required (xen) drivers needed to run on AWS.

Other requirements include disabling of any of the following services, if they are enabled:

/etc/systemd/system/multi-user.target.wants/
hv-fcopy-daemon.service
hv-vss-daemon.service
hv-kvp-daemon.service
ephemeral-disk-warning.service
walinuxagent.service


How to install linux-aws on the source
  • NOTE:: The 'linux-aws' kernel will cause your source machine to fail to boot if you attempt to reboot the source machine after configuring Grub to use the 'linux-aws' kernel. It is important that you are aware of this as this kernel will not be compatible with the Azure underlying hardware. Please do ensure that you create a backup of your source machine if it is a production server. Additionally, please revert any changes made from the steps below if you are looking to reboot the source machine. With that being said, if you are uncomfortable with making such changes on your source machine, then I highly recommend making these changes on the target machine in AWS (using the rescue instance method).

METHOD 1:

1) Install 'linux-aws' kernel:

$ sudo apt-get install -y linux-aws

2) Verify the AWS drivers (XEN, ENA, ixgbevf, NVME) are included:

$ sudo lsinitramfs /boot/initrd.img-$(uname -r)|grep -i xen || sudo find /lib/modules/$(uname -r)/kernel/drivers/net/ -name xen-netback.ko
$ sudo lsinitramfs /boot/initrd.img-$(uname -r)|grep -i ena
$ sudo lsinitramfs /boot/initrd.img-$(uname -r)|grep -i nvme
$ sudo lsinitramfs /boot/initrd.img-$(uname -r)|grep -i ixgbevf

3) Recreate the grub:

$ sudo update-grub -o /boot/grub/grub.cfg

4) Verify that grub has valid entries for amazon linux kernel:

$ sudo grep -i aws /boot/grub/grub.cfg 

5) Wait 10 minutes, and then relaunch the target machine from the CloudEndure console.

METHOD 2:

1) On the source machine, install 'linux-aws' kernel:

$ sudo apt-get install -y linux-aws

2) Verify the AWS drivers (XEN, ENA, NVME) are included:

$ sudo lsinitramfs /boot/initrd.img-5.4.0-1054-aws|grep -i xen
$ sudo lsinitramfs /boot/initrd.img-5.4.0-1054-aws|grep -i ena
$ sudo lsinitramfs /boot/initrd.img-5.4.0-1054-aws|grep -i nvme

3) Create backup of grub:

$ sudo cp /etc/default/grub /etc/default/grub.bak

4) Show available kernel options:

$ grep -A100 submenu  /boot/grub/grub.cfg |grep menuentry

Example output:

submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1055-azure' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1055-azure-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1055-azure (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1055-azure-recovery-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1054-aws' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1054-aws-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1054-aws (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1054-aws-recovery-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1049-azure' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1049-azure-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9' {
    menuentry 'Ubuntu, with Linux 5.4.0-1049-azure (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-1049-azure-recovery-c9ab74d2-63c9-4dba-993b-b89e598200c9' {

5) Identify the default menu entry by finding:

From the example output above, the menu entry for 'Advanced options for Ubuntu' is gnulinux-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9.

The menu entry for 'Ubuntu, with Linux 5.4.0-1054-aws' is gnulinux-5.4.0-1054-aws-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9.

Then concat the above strings with > in between "" like so:

"gnulinux-advanced-db937f23-4ed7-4c4b-8058-b23a860fae08>gnulinux-5.4.0-1054-aws-advanced-db937f23-4ed7-4c4b-8058-b23a860fae08"

6) Edit grub:

$ sudo vi /etc/default/grub

Replace GRUB_DEFAULT with value (With quotes) from step 5:

GRUB_DEFAULT="gnulinux-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c>gnulinux-5.4.0-1054-aws-advanced-c9ab74d2-63c9-4dba-993b-b89e598200c9"

7) Update grub:

$ sudo update-grub

8) Then wait 10 minutes, and then re-launch target machine.


How to install linux-aws on the target

1) Detach the root volume (/dev/sda1) from the instance "i-0ef31abeed9534962" and then re-attach it to the "rescue" temporary instance as a secondary volume (/dev/sdf).

2) Run 'lsblk' to identify block device name of the root volume. Expect it to be something like /dev/xvdf1:

$ lsblk

3) Mount the volume to /mnt directory:

$ sudo mount /dev/xvdf1 /mnt

4) Set up the environment to install 'linux-aws':

Delete the following files;

$ sudo rm -rf /mntrec/etc/netplan/51-netcfg.yaml 
$ sudo rm -rf /var/lib/cloud/*

Mount the necessary root file for the chroot to work normally:

$ sudo for i in dev proc sys run; do mount -o bind /$i /mnt/$i; done
$ sudo chroot /mnt

4) Install the 'linu-aws' kernel:

$ sudo apt install linux-aws

5) Reconfigure the grub file to boot from the 'linux-aws' kernel:

$ cd /boot/grub

# Create backup of the grub.cfg file:
$ cp grub.cfg grub.cfg_bac

Edit this file to have the entry only for linux-aws kernel and not for the azure kernel and the save and exit the file.

$ vi grub.cfg

Then exit chroot:

$ exit

6) Unmount the /mnt mountpoint:

$ sudo umount /mnt

7) Detach the volume from the temporary rescue instance and re-attach it back to "i-0ef31abeed9534962" as the root volume (/dev/sda1). The instance should boot successfully now.