Ubuntu
How to upgrade Ubuntu linux kernel
Update/upgrade kernel:
$ sudo apt-get update && sudo apt-get upgrade $ sudo apt-get dist-upgrade $ sudo reboot
If the reboot doesn't work and it is still booting to the old kernel, then follow steps 3+ in section "How to Change the Default Ubuntu Kernel on AWS" on this page.
How to perform a major release upgrade
Ubuntu 14.04 LTS ------> Ubuntu 16.04 LTS ------> Ubuntu 18.04 LTS
I tried replicating the above scenario in my test environment. For this, I launched an instance using the public AMI ami-47a23a30 and then performed the below steps for upgrading the instance from Ubuntu 14.04 to 16.04:
1. Update all current packages to their latest version.
$ sudo apt-get update && sudo apt-get upgrade
2. Now You will need to run the distribution upgrade.
$ sudo apt-get dist-upgrade
3. Create a Firewall Rule. As upgrade process started on port 1022. You will need to allow connections to this port on your instance security group[4].
4. Now to perform the upgrade to the ubuntu 16 version, you can run:
$ sudo do-release-upgrade
5. If the above command is giving you issues or cannot be found, then run the below command, once done, run Step 4 again:
$ sudo apt-get install update-manager-core
6. Once the instillation is completed and you SSH back into your instance, the following command can confirm what Ubuntu version you currently have installed.
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.7 LTS Release: 16.04 Codename: xenial
To upgrade the instance OS from Ubuntu 16 to 18 you can follow the above steps again.
I've also attached links to help you upgrade from:
Ubuntu 14 ---> 16[5]. Ubuntu 16 ---> 18[6]. Ubuntu 18 ---> 20[7].
[5] https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-ubuntu-16-04-lts
[6] https://www.cloudbooklet.com/how-to-upgrade-to-ubuntu-18-04-bionic-beaver/
[7] https://www.cloudbooklet.com/how-to-upgrade-to-ubuntu-20-04-lts/
How to use apt-get on old Ubuntu (EOL)versions such as 12.04
Because Ubuntu 12.04 has reached EOL, the aws repos no longer work.
In order for repos to work, you must edit the /etc/apt/sources.list file and replace all repos to 'old-releases' like so:
ubuntu@ip-172-31-85-14:~$ cat /etc/apt/sources.list ## Note, this file is written by cloud-init on first boot of an instance ## modifications made here will not survive a re-bundle. ## if you wish to make changes you can: ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg ## or do the same in user-data ## b.) add sources in /etc/apt/sources.list.d ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl # # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://old-releases.ubuntu.com/ubuntu/ precise main restricted deb-src http://old-releases.ubuntu.com/ubuntu/ precise main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://old-releases.ubuntu.com/ubuntu/ precise-updates main restricted deb-src http://old-releases.ubuntu.com/ubuntu/ precise-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://old-releases.ubuntu.com/ubuntu/ precise universe deb-src http://old-releases.ubuntu.com/ubuntu/ precise universe deb http://old-releases.ubuntu.com/ubuntu/ precise-updates universe deb-src http://old-releases.ubuntu.com/ubuntu/ precise-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://old-releases.ubuntu.com/ubuntu/ precise multiverse deb-src http://old-releases.ubuntu.com/ubuntu/ precise multiverse deb http://old-releases.ubuntu.com/ubuntu/ precise-updates multiverse deb-src http://old-releases.ubuntu.com/ubuntu/ precise-updates multiverse ## Uncomment the following two lines to add software from the 'backports' ## repository. ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://old-releases.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://old-releases.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu precise partner # deb-src http://archive.canonical.com/ubuntu precise partner deb http://old-releases.ubuntu.com/ubuntu precise-security main deb-src http://old-releases.ubuntu.com/ubuntu precise-security main deb http://old-releases.ubuntu.com/ubuntu precise-security universe deb-src http://old-releases.ubuntu.com/ubuntu precise-security universe # deb http://old-releases.ubuntu.com/ubuntu precise-security multiverse # deb-src http://old-releases.ubuntu.com/ubuntu precise-security multiverse
How to Change the Default Ubuntu Kernel on AWS
https://meetrix.io/blog/aws/changing-default-ubuntu-kernel.html
Another similar method, which also works: https://discourse.ubuntu.com/t/how-to-downgrade-the-kernel-on-ubuntu-20-04-to-the-5-4-lts-version/26459
1)Launch instance in us-east-1 using AMI ami-000b3a073fc20e415 (Ubuntu 14.04)
2) Updated and installed old kernel (3.13.0-55-generic) and gcc:
$ sudo apt-get update $ sudo apt-get install gcc $ sudo apt-get install linux-headers-3.13.0-55-generic* $ sudo apt-get install linux-image-3.13.0-55-generic* $ sudo apt install -y module-init-tools
3) Then moved all the files I just downloaded to a new directory:
$ sudo mkdir /tmpdir $ cd /var/cache/apt/archives $ sudo mv linux-image-3.13.0-55-generic_3.13.0-55.94_amd64.deb /tmpdir/ $ sudo mv linux-headers-3.13.0-55-generic_3.13.0-55.94_amd64.deb /tmpdir/ $ sudo mv linux-headers-3.13.0-55_3.13.0-55.94_all.deb /tmpdir/ $ cd /tmpdir/ $ sudo dpkg -i *.deb
4) Update grub to boot to the old kernel:
$ sudo cp /etc/default/grub /etc/default/grub.bak $ grep -A100 submenu /boot/grub/grub.cfg |grep menuentry submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-93875578-5ca8-431a-af18-c049eac03817' { menuentry 'Ubuntu, with Linux 3.13.0-170-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-170-generic-advanced-93875578-5ca8-431a-af18-c049eac03817' { menuentry 'Ubuntu, with Linux 3.13.0-170-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-170-generic-recovery-93875578-5ca8-431a-af18-c049eac03817' { menuentry 'Ubuntu, with Linux 3.13.0-55-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-55-generic-advanced-93875578-5ca8-431a-af18-c049eac03817' { menuentry 'Ubuntu, with Linux 3.13.0-55-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-55-generic-recovery-93875578-5ca8-431a-af18-c049eac03817' {
5) Edit Grub and replace GRUB_DEFAULT to boot to 3.13.0-55-generic:
$ sudo vi /etc/default/grub GRUB_DEFAULT="gnulinux-advanced-93875578-5ca8-431a-af18-c049eac03817>gnulinux-3.13.0-55-generic-advanced-93875578-5ca8-431a-af18-c049eac03817" $ sudo update-grub
6) Boot into kernel: 3.13.0-55-generic
$ sudo reboot $ uname -r 3.13.0-55-generic
EQUIVALENT TO LSINITRD IN UBUNTU
- lsinitramfs
$ lsinitramfs /boot/initrd.img-3.13.0-55-generic | egrep -i 'xen|ena|nvme' lib/modules/3.13.0-55-generic/kernel/drivers/net/xen-netback lib/modules/3.13.0-55-generic/kernel/drivers/net/xen-netback/xen-netback.ko
How can I make my secondary network interface work in my Ubuntu instance?
How can I make my secondary network interface work in my Ubuntu instance?
How can you make TWO network interfaces ON THE SAME SUBNET work in my Ubuntu 18.04/20.04 instance
To avoid asymmetric routing issues, use a single elastic network interface, or place duplicate elastic network interfaces into non-overlapping subnets.
As you know, having two interfaces on the same subnet will cause asymmetric routing issues. Adding a secondary network interface to a non-Amazon Linux EC2 instance causes traffic flow issues. These issues occur because the primary and secondary network interfaces are in the same subnet, and there is one routing table with one gateway. Traffic that comes into the secondary network interface leaves the instance using the primary network interface. But this isn't allowed, because the secondary IP address doesn't belong to the MAC address of the primary network interface.
So what if you NEED to have two interfaces of the same subnet attached to an Ubuntu instance? Here is how you can make it work. You will need to create two network config files for both interfaces, use different routing tables for each, but direct the traffic to the same default gateway (since they are in the same subnet). In this example, I am using Ubuntu 20.04 and have the following interfaces attached:
- Primary interface IP: 172.31.24.153
- Secondary interface IP: 172.31.28.195
- Default Gateway: 172.31.16.1
1) Rename the original network interface configuration file (/etc/netplan/50-cloud-init.yaml) to back it up, as it won't be used:
$ sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.backup
2) Create a new network interface configuration file for the primary interface and add the following lines:
- Be sure to change eth0 to ens5 if on nitro.
$ sudo vi /etc/netplan/51-eth0.yaml network: version: 2 renderer: networkd ethernets: eth0: addresses: - 172.31.24.153/20 dhcp4: no routes: - to: 0.0.0.0/0 via: 172.31.16.1 # Default gateway table: 1000 - to: 172.31.24.153 via: 0.0.0.0 scope: link table: 1000 routing-policy: - from: 172.31.24.153 table: 1000
3) Then create another network interface configuration file for the secondary interface with the following lines:
- Be sure to change eth1 to ens6 if on nitro.
$ sudo vi /etc/netplan/51-eth1.yaml network: version: 2 renderer: networkd ethernets: eth1: addresses: - 172.31.28.195/20 dhcp4: no routes: - to: 0.0.0.0/0 via: 172.31.16.1 # Default gateway table: 1001 - to: 172.31.28.195 via: 0.0.0.0 scope: link table: 1001 routing-policy: - from: 172.31.28.195 table: 1001
4) Lastly, apply the new network configurations:
$ netplan --debug apply
Migrating Ubuntu from Azure to AWS (using CE/MGN/DRS)
[+] 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, 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 nvme1n1p1
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:
- The steps in this section can be found in the third-party document: https://meetrix.io/blog/aws/changing-default-ubuntu-kernel.html
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 or just: $ sudo lsinitramfs /boot/initrd.img-5.4.0-1099-aws | grep -iE 'xen|ena|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.
Aws Replication Agent fails to install on Ubuntu18 in Azure
If installation fails with:
Cannot insert aws-replication-driver Installation returned with code 2 Installation failed due to unspecified error: Traceback (most recent call last): File "shared/installer_linux/install_agent.py", line 1273, in main SystemExit: 2 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "cirrus/installer_shared/installer_main.py", line 1033, in _main File "cirrus/installer_shared/installer_main.py", line 905, in main File "cirrus/installer_shared/installer_main.py", line 781, in install File "cirrus/installer_shared/installer_main.py", line 365, in run_agent_installer shared.installer_utils.cloud_utils.Error: Failed Installing the AWS Replication Agent [agent_version: 4.7.0, installation_id: , mac_addresses:, _origin_client_type: installer]
Most likely secure boot is enabled, which is a setting on the Azure console under "Security Type".
Setting Homepage for Firefox via Command line
1. Create the directory /etc/firefox/policies:
$ sudo mkdir /etc/firefox/policies $ sudo chmod 755 /etc/firefox/polcies
2. Create the policies.json file:
$ sudo vi /etc/firefox/policies/policies.json
3. Enter the following configuration:
{ "policies": { "Homepage": { "URL": "https://dikapedia.com/", "Locked": true, "StartPage": "homepage-locked" }, "Preferences": { "browser.policies.loglevel": { "Value": "debug", "Status": "locked" }, "browser.tabs.warnOnClose": { "Value": false, "Status": "default" } } } }
4. Modify the permissions of the policies.json file:
$ sudo chmod 644 /etc/firefox/policies/policies.json
5. Should be good to go.
How to Remove Old Kernels on Ubuntu
Sometimes, when you have a lot of kernel images under /boot, it can take up a lot of space. There are ways to clean up the /boot directory by removing old kernels. See this third-party document: https://linuxconfig.org/how-to-remove-old-kernels-on-ubuntu
NetPlan YAML Configuration Parameters
https://netplan.readthedocs.io/en/latest/netplan-yaml/