Posted On November 29, 2020

How to Fix a Broken Ubuntu Upgrade

kimconnect 0 comments
blog.KimConnect.com >> Linux >> How to Fix a Broken Ubuntu Upgrade

Sometimes, a power failure or manual interruption during a Linux OS upgrade can render the machine as un-bootable. Here are some methods to recover from such events:

Method 1:

1. Ensure that the network cable is attached to the target machine and Internet access is available
2. Boot up the system using a live CD or a Ubuntu Installation USB Thumb drive
3. Initate the Terminal emulation program and run these lines:

rootPartition=$(df | grep /$ | awk '{print $1;}')
sudo mkdir -p /recovery/ubuntu
sudo mount $rootPartition /recovery/ubuntu
sudo mount --bind /dev /recovery/ubuntu/dev
sudo mount --bind /proc /recovery/ubuntu/proc
sudo mount --bind /sys /recovery/ubuntu/sys
sudo cp /etc/resolv.conf /recovery/ubuntu/etc/resolv.conf
sudo chroot /recovery/ubuntu
sudo apt-get update -y
sudo dpkg --configure -a
sudo apt-get upgrade -y
Method 2:

Although ‘Method 1’ is recommended, this alternative is about reinstalling grub2 in cases where dual boot corruption has been suspected. Here are the commands:

# Alternative A:

# Source: https://help.ubuntu.com/community/Grub2/Installing

# Discover root
ls
# Set environment prefixes
set prefix=(hd0,1)/grub # these values may vary on each system
set root=(hd0,1)
# Get into shell
insmod normal
normal
# eh...
linux /boot/vmlinuz-3.2.0-14-generic root=/dev/sda1 ro
initrd /initrd.img # select the correct image
boot
sudo update-grub
bootDisk=/dev/sdb # Define boot disk (not partition)
sudo grub-install $bootDisk
sudo update-grub
# Alternative B:

bootDisk=/dev/sda
bootPartition=/dev/sda1
sudo mount $bootPartition /mnt
sudo mount $bootPartition /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
grub-install $bootDisk
update-grub

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

A Few Todos while Securing Apache Server

- Install mod_security - Set expose_php = Off in php.ini - Set SecResponseBodyAccess Off in…

Linux: Copy File Contents Into Clipboard

Install XCLIP (if not already installed) sudo apt install xclip -y Reading package lists... Done…

Disable and Enable Sleep Mode on a Linux Workstation

The following commands would work on any Linux machine with SystemD (Ubuntu, Linux Mint, Redhat,…