How to Upgrade Ubuntu 18.04 LTS to Ubuntu 20.04 LTS

In this article we will demonstrate how to upgrade Ubuntu 18.04 LTS (Long Term Support) to 20.04 LTS. There are two ways to do it either via command line or GUI (Graphical Interface). To complete the upgrade smoothly, a stable internet is required on your Ubuntu system.

Upgrade Ubuntu 18.04 LTS to 20.04 LTS via Command Line
We strongly recommend please the take backup of your existing Ubuntu 18.04, may be on some external drive.

Before start upgrading, let’s take a now of existing Ubuntu Version, open the terminal and run below command,

vallabh@ubuntu18:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
vallabh@ubuntu18:~$

Step 1) Apply all updates of installed packages
Rub below apt command to install all the updates of installed packages,

Thu Jun 30 11:28:39 UTC 2022
vallabh@ubuntu18:~$ sudo apt update -y
Thu Jun 30 11:30:07 UTC 2022
vallabh@ubuntu18:~$ sudo apt upgrade -y

Once all the updates are installed including the kernel then reboot your system
vallabh@ubuntu18:~$ sudo reboot

Step 2) Remove unused Kernels and install ‘update-manager-core’
Once your Ubuntu 18.04 LTS is available after reboot, then it is recommended to remove unused kernels to free up the space from /boot partition, run beneath command:

Thu Jun 30 11:34:33 UTC 2022
vallabh@ubuntu18:~$ sudo apt --purge autoremove

Execute below command to install “update-manager-core“, as it is required for upgrade, though on most of the systems it should be installed by default. In case it is not installed run below command,

vallabh@ubuntu18:~$ sudo apt install update-manager-core -y

Step 3) Start Upgrade Process
Run following command to view whether new 20.04 LTS version is available for your system.

Thu Jun 30 11:35:45 UTC 2022
vallabh@ubuntu18:~$ sudo do-release-upgrade

do-release-upgrade-Ubuntu18-04

If, in the above command’s output, you got a message that “There is no development version of an LTS available” then we can force the above command by passing the parameter “-d” to look for the new latest LTS version.

During upgrade procedure, it will prompt you couple of times to type “y” to update package repositories and sometime “enter” to confirm to proceed with upgrade,

Enter-Y-During-Ubuntu-Upgrade

Once the upgrade process is completed successfully then we will get following message

Restart-Ubuntu-After-Upgrade

Above output confirms that upgrade is completed, upgrade tool prompted us to press ‘y’ to restart the system.

Step 4) Verify Upgrade
Once the system boots after the upgrade, open the terminal type following to verify the Ubuntu version,

vallabh@ubuntu18:~$ cat /etc/lsb-release
Upgrade-Verify-Ubuntu-Linux

Another way to verify the Ubuntu version, Go to Settings and then choose About

Settings-About-Ubuntu-Linux

This confirms that we have successfully upgrade our Ubuntu 18.04 LTS to latest Ubuntu 20.04 LTS.

Please find pre-post-check script created for ubuntu servers

root@ubuntu18:~# vi pre-post-checks.sh

#!/bin/bash
# Purpose: Pre and Post Check before performing any change on system
# Version: 1.0
# Created Date: 7 June 2022
# Modified Date:
# Author : Vallabh Darole

###############START OF SCRIPT#######################

#!/bin/bash
# Added files "/boot/grub/menu.lst" 
echo
echo "1. Pre-checks"
echo "2. Post-checks"
echo "3. Quit"
echo "Please select the option:"
read OPT
ROOT_DIR=/root/Patch_`date +"%B-%Y"`
PRE_DIR=$ROOT_DIR/Pre/
POST_DIR=$ROOT_DIR//Post/
BOND_FILE=/proc/net/bonding/bond0
prechecks()
{
if [ -d "$ROOT_DIR" ]; then
echo "$PRE_DIR already exists!!, Please rename it before executing the script"
exit
fi
mkdir $ROOT_DIR
mkdir $PRE_DIR
#Files to be backed up
cp -p /etc/os-release $PRE_DIR
cp -p /etc/fstab $PRE_DIR
cp -p /boot/grub/grub.cfg $PRE_DIR
# cp -p /etc/postfix/* $PRE_DIR
if [ -f "$BOND_FILE" ]; then
cp -p /proc/net/bonding/bond0 $PRE_DIR/bond0.txt
fi
#Outputs of Important commands
for i in `ifconfig -a |grep HWaddr |cut -d" " -f1`;
do
ethtool $i > $PRE_DIR/ethtool_$i.txt;
done

uname -a > $PRE_DIR/uname.txt
ifconfig -a > $PRE_DIR/ifconfig_all.txt
route -n > $PRE_DIR/routing_table.txt
mount > $PRE_DIR/mount.txt
df -h > $PRE_DIR/df.txt
sysctl -a > $PRE_DIR/sysctl
cat /proc/mounts | egrep 'nfs|cifs' > $PRE_DIR/nfs.txt
netstat -nuatp | grep LIST | awk -F "/" '{ print $2 }' > $PRE_DIR/services.txt
echo "Required files and command outputs copied to $PRE_DIR.."
}
postchecks()
{
if [ -d "$POST_DIR" ]; then
echo "$POST_DIR already exists!!, Please rename it before executing the script"
exit
fi
if [ ! -d "$PRE_DIR" ]; then
echo "Precheck Directory $PRE_DIR does not exist, please perform Prechecks first"
exit
fi
mkdir $POST_DIR
#Files to be backed up
cp -p /etc/os-release $POST_DIR
cp -p /etc/fstab $POST_DIR
cp -p /boot/grub/grub.cfg $PRE_DIR
# cp -r /etc/postfix/ $POST_DIR
if [ -f "$BOND_FILE" ]; then
cp /proc/net/bonding/bond0 $POST_DIR/bond0.txt
fi

#Outputs of Important commands
for i in `ifconfig -a |grep HWaddr |cut -d" " -f1`;
do
ethtool $i > $POST_DIR/ethtool_$i.txt;
done
uname -a > $POST_DIR/uname.txt
ifconfig -a > $POST_DIR/ifconfig_all.txt
route -n > $POST_DIR/routing_table.txt
mount > $POST_DIR/mount.txt
df -h > $POST_DIR/df.txt
sysctl -a > $POST_DIR/sysctl
cat /proc/mounts | egrep 'nfs|cifs' > $POST_DIR/nfs.txt
netstat -nuatp | grep LIST | awk -F "/" '{ print $2 }' > $POST_DIR/services.txt
for i in `ls -l $POST_DIR | grep ^- | awk '{print $9}'`
do
echo >> $POST_DIR/DIFFERENCES.TXT
echo $i >> $POST_DIR/DIFFERENCES.TXT
echo "--------" >> $POST_DIR/DIFFERENCES.TXT
diff -y --suppress-common-lines $PRE_DIR/$i $POST_DIR/$i >> $POST_DIR/DIFFERENCES.TXT
echo >> $POST_DIR/DIFFERENCES.TXT
echo >> $POST_DIR/DIFFERENCES.TXT
done
echo
echo "Post Patching Checks done, please check $POST_DIR/DIFFERENCES.TXT for important differences"
HOSTNAME=`hostname`

echo "$HOSTNAME" | mailx -s "Post-Checks of $RHOSTNAME" -a "$POST_DIR/DIFFERENCES.TXT"
}
case $OPT in
"1") prechecks
;;
"2") postchecks
;;
"3") exit
;;
*) echo "$OPT is not a valid option"
;;
esac

###############END OF SCRIPT#######################

root@ubuntu18:~# 

 

Network configuration in ubuntu
 
root@wpress01:~# cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens32:
addresses:
- 172.16.1.230/16
gateway4: 192.168.2.1
nameservers:
addresses:
- 172.16.1.200
version: 2
root@wpress01:~#

For 2 network card. 

root@wpress01:/etc/netplan# cat 50-cloud-init.yaml
network:
ethernets:
ens32:
addresses:
- 172.16.1.230/16
gateway4: 192.168.2.1
nameservers:
addresses:
- 172.16.1.200
ens35:
addresses:
- 192.168.2.230/24
gateway4: 192.168.2.1
nameservers:
addresses:
- 192.168.2.1
version: 2
root@wpress01:/etc/netplan#

To apply network setting
root@wpress01:~# netplan apply

Restart network
root@wpress01:~# systemctl restart systemd-networkd.service

 

 

 

 

No comments:

Post a Comment