How to Safely Upgrade Your Ubuntu VM on Google Cloud Platform
Ensuring a Smooth Transition: Upgrading Ubuntu on Google Cloud Platform
Upgrading your Ubuntu Virtual Machine (VM) on Google Cloud Platform (GCP) can be a straightforward process, but it requires a few key steps to ensure a smooth transition. Whether you’re upgrading from Ubuntu 18.04 LTS to 20.04 LTS or 22.04 LTS, this guide will walk you through the process and address common concerns, especially when performing the upgrade over SSH.
1. Preparing for the Upgrade
Before initiating the upgrade, it’s crucial to ensure your current system is fully updated and to back up any important data. Here’s how:
Update All Current Packages
Connect to Your VM:
Open the Google Cloud Console.
Navigate to your VM instance.
Click on “SSH” to open a terminal session.
Update Package List and Installed Packages:
Run the following commands to update the package list and upgrade all installed packages:
Explainsudo apt update sudo apt upgrade -y sudo apt dist-upgrade -y sudo apt autoremove -y
Install the Update Manager Core:
Ensure that the update manager core package is installed:
sudo apt install update-manager-core
2. Initiating the Distribution Upgrade
Once your system is prepared, you can start the upgrade process:
Start the Upgrade:
Run the command to begin the upgrade:
sudo do-release-upgrade
Handling SSH Connection Warning:
During the upgrade, you may encounter a warning about performing the upgrade over SSH:
ExplainThis session appears to be running under ssh. It is not recommended to perform a upgrade over ssh currently because in case of failure it is harder to recover. If you continue, an additional ssh daemon will be started at port '1022'.Option 1: Continue with SSH:
If you proceed, type
Yand pressEnter. An additional SSH daemon will start on port1022for fallback purposes.In case of disconnection, reconnect using:
ssh -p 1022 <username>@<ip_address>
Option 2: Use a Terminal Multiplexer:
Install and use a terminal multiplexer like
tmuxorscreenbefore starting the upgrade. This allows you to reattach to your session if the connection drops.Example with
tmux:
sudo apt install tmux
tmux
Run the upgrade command inside the
tmuxsession. If disconnected, reconnect and typetmux attachto resume.
Option 3: Upgrade Locally:
If possible, use the “Serial Console” from the Google Cloud Console, which might be more stable than network SSH connections.
3. Completing the Upgrade
Follow On-Screen Prompts:
During the upgrade process, you will be asked to confirm certain actions (e.g., overwriting configuration files). Follow the prompts to complete the upgrade.
Reboot the VM:
After the upgrade finishes, reboot your VM to apply all changes:
sudo reboot
Verify the Upgrade:
Once your VM reboots, verify that it’s running the new version:
lsb_release -a
uname -r
You should see the updated Ubuntu version in the output.
Important Tips
Backup: Always ensure you have a backup of your VM before performing major upgrades.
Downtime: The upgrade process may cause temporary downtime, so plan accordingly.
By following these steps, you can safely upgrade your Ubuntu VM on GCP and enjoy the benefits of the latest features and security improvements. If you encounter any issues or have questions, feel free to reach out!

