Skip to main content

Your submission was sent successfully! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates from Canonical and upcoming events where you can meet our team.Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

  1. Blog
  2. Article

Igor Ljubuncic
on 15 April 2021


Broadly speaking, the Linux community can be divided into two camps – those who upgrade their operating systems in-vivo, whenever there is an option to do so in their distro of choice, and those who install from scratch. As it happens, the former group also tends to rarely reinstall their system when problems occur, while the latter more gladly jump at the opportunity to wipe the slate clean and start fresh. So if asked, who should you listen to?

The question of system management in Linux is a complex one, with as wide a range of answers as there are distributions. In this blog post, we discuss the concept of reinstall, and whether it’s necessary. Then, we address several other closely related ideas like system imaging, full disk encryption, and data backups.

When there’s something wrong in your Linux box…

There are various ways your system may misbehave:

  • The computer powers on, but there is no boot menu, you cannot see your operating system listed, or there is nothing on the screen.
  • The computer powers on, your distribution starts booting, but then it stops midway.
  • Your distribution reaches its graphical interface, but cannot log you into the desktop.
  • The desktop is available, but there are various issues, like say network connectivity, you cannot apply any updates, some applications crash.

In each of these scenarios, you may decide that you do not want to spend any amount of time troubleshooting the problems, and you could just opt for a quick reinstall. But it’s worth spending a few minutes trying to get the machine working.

Unbootable system

If your system cannot reach a usable work environment, you may think it’s game over, and you need to start from scratch. However, there are still quite a few things you can do, even if the system is in a bad state.

The primary reason is that most Linux distributions also ship as live systems. In other words, you can boot the system from CD/DVD or a thumb drive, run it entirely from memory, and make changes to the disk, even if the data on the disk is partially or wholly corrupt.

This is an Ubuntu 20.04 live session – allowing you to choose whether you want to test (try) the system, or install it on the disk. In the live session, you can do pretty much any task you’d on a standard, installed system. You can connect to the Internet, listen to music, and even install new applications. The only caveat is that, in most cases, there is no data persistence, so if you reboot your live session, any changes you made there will be lost.

If a Linux distribution cannot reach the desktop, usually the problem resides in two areas:

  • Bootloader – piece of code that initializes the system.
  • Kernel – essential component of any operating system that controls hardware, memory management, and task scheduling.

Bootloader

Most Linux distributions use the GRUB bootloader. The bootloader may become corrupt if you have multiple operating systems installed on your hard disk side-by-side – a scenario usually known as dual-boot or multi-boot (e.g.: Windows and Ubuntu) – and one of the other operating systems performs an action that changes the boot sequence in some way. Repairing the bootloader can get you back to a working state.

There are many ways to repair the bootloader. The “easiest” one is to boot a live image of your distribution, and then perform the repair action from there. The technical steps for how to do this are beyond the scope of this article. But this can be done, rescuing your box from a difficult situation.

Kernel

Fixing the kernel is far from trivial. Problems with the kernel can happen due to a bug, or in one of the drivers that your hardware depends on. However, most Linux distributions keep several versions of kernels on the disk. The relevant files (usually labeled vmlinuz and accompanying initrd or initramfs) are stored under the /boot directory in your filesystem tree. The bootloader scans the contents of this directory and lists all of the available entries in the boot menu. Thus, if you have a non-bootable kernel, you can just choose a different (older) kernel from the list and boot into your desktop. Then, you can update the system – which should take care of the corrupt kernel.

Partially bootable system

The second scenario is when your Linux gets past the bootloader/kernel stage, but then gives up sometime later. The chances of a successful recovery in this situation rely on several factors.

  • There should be data or error logs available for inspection.
  • You have the ability to decipher the information in those logs.

Here, the solution is often more complex than the first scenario, because there is a much greater variety of possible root causes. However, typically, the problems will resolve around the following domains:

  • Your operating system is trying to use a device that does not exist – like a swap file or a partition that has been mislabeled somehow.
  • There is a problem with one of the drivers.
  • An important file (system library) is missing.

Repairing these issues often requires expertise. In this kind of scenario, for most people, reinstalling the system may be the best option. We will talk about the steps you need to take before and after this action a bit later.

The desktop fails to load

The primary culprit for this issue is either a conflict with the graphics driver, or a corruption in the desktop environment. With graphics drivers, similar to what we’ve seen earlier, the workaround is usually to try booting an older kernel. The main reason for this is because in Linux, the drivers need to match kernel versions. If there is a problem in a newer driver edition, or how it cooperates with the kernel, using a different entry in the bootloader could help.

Corrupt desktops can be a bit harder to resolve – and they also involve moving or deleting various configuration files that store specific settings for how your desktop looks and behaves.  This is an intrusive action, and can result in data loss. We will address this shortly.

In-system errors

If your Linux distribution is working, there is usually no reason to reinstall it. Most errors can be fixed – usually by applying the latest set of system updates. Most package management tools in Linux also have some small level of self-repair functionality, so they can fix missing or broken databases of the system state information. For instance, for distributions using the apt package manager, you can repair a broken state with:

sudo apt update --fix-missing
sudo apt install -f

And with dpkg, you can do the following:

sudo dpkg --configure -a

But sometimes, you may just want to reinstall, because things are “too broken”. This is where the fresh install vs. upgrade concept comes into play. Often, people will notice more errors after performing an in-vivo upgrade of the systems rather than after a clean installation.

What to do when reinstalling?

There are several critical actions you should do before any major system change.

Data backup 

This is critical. If your data is safe (and up to date) in a separate, backup location, you can afford to take much higher risks. The worst that can happen is losing time reinstalling a system, but you will not lose any personal, valuable information. However, even if you have not made any backups, or you feel your second copy is not up to date, you can always make an ad-hoc copy before reinstalling. You can do it from a live session, if necessary.

  • Backup your snaps by creating snapshots. You can then restore them after reinstalling the system (and even if you have wiped your disk clean).
  • Backup your application settings with mackup. This tool supports more than 400 common applications.
  • Use a tool like rsync (on the command line), Grsync (rsync with GUI), or just plain copy & paste in a file manager, to create a backup of your data. Ideally, you will have a robust backup system in place, with a frequent schedule and verifiable, tested data restores.

System imaging

Another useful method of preserving data is system imaging. This is a process of taking a snapshot image of your hard disk structure (in its entirety or specific partitions), including system areas and/or any personal data, as well. Then, if something goes wrong, you can restore the system image snapshot, and this will be similar to “going back in time”. You will restore a state of your Linux distribution before the problematic change.

CloneZilla is a popular, useful system imaging tool. It runs from a live image, and it can be used to create snapshots of any type of partition on your disk, including Windows and Linux installations.

Reinstall with or without formatting

Linux distributions can be installed without formatting the target partition. Normally, you would want to reformat, but if you’re trying to repair your system, you can then just start an installation without wiping the data. The installation wizard will then delete the contents of system directories like /etc, /usr, and others, but it will not touch your /home directory.

This scenario also emphasises the importance of having a flexible disk layout. Specifically, you should keep a separate partition or disk for your personal data. Thus, you can safely reinstall the system partition (and even format it), and then just mount the /home partition without any problems.

Disk encryption

If you have a laptop, you likely want to encrypt the hard disk contents. This is because laptops tend to get (more easily) stolen, and if that happens, you don’t want anyone but yourself to have access to your personal data. There are two encryption modes:

  • Full Disk Encryption (FDE) – the entire disk is encrypted.
  • Home directory encryption – only your /home partition is encrypted.

When you set up FDE, you will be presented with a screen asking you to provide your password to unlock your hard disk. Without it, the contents of the disk remains scrambled and inaccessible, and you won’t be able to boot your system.

There are obvious security benefits to using encryption, but there are also potential downsides:

  • If a hard disk or a partition containing encrypted data gets corrupted, you may completely lose access to your entire set of data. With non-encrypted disks, some access or recovery may be possible. But with encrypted disks, it’s usually all or nothing.
  • You may be able to access the contents of an encrypted system from a live session, provided you have the necessary tools to decrypt the storage, but this may not be guaranteed.
  • You most likely cannot reinstall without formatting.
  • If you use encryption, you must have a proven and safe backup procedure in place.

Summary

System problems are an unfortunate side effect of software usage. With some luck and operational discipline, you can avoid most of them. When they do happen, you want to know what to do. Reinstalling your Linux system is always an option, but it’s usually not necessary, even for various difficult, complex problems.

Even if you do decide to reinstall, you should consider using a live session to inspect the system or perform any last-minute backups, have a solid backup procedure in place regardless, and weigh the benefits of encryption against your day-to-day needs and risks. System images can also help you reduce the hassle of getting back to speed when you do decide to “reset” your distro. That’s all we have on Linux reinstallations. If you have any comments or suggestions, please join our forum, and let us know your thoughts.

Related posts


Holly Hall
15 January 2024

Managing software in complex network environments: the Snap Store Proxy

Internet of Things Article

As enterprises grapple with the evolving landscape of security threats, the need to safeguard internal networks from the broader internet is increasingly important. In environments with restricted internet access, it can be difficult to manage software updates in an easy, reliable way. When managing devices in the field, change management ...


Heather Ellsworth
27 June 2023

Improving snap maintenance with automation

Desktop Article

Co-written with Sergio Costas Rodríguez. As the number of snaps increases, the need for automation grows. Any automation to help us maintain a group of snaps is welcome and necessary for us to be able to scale. The solution detailed in this article has two main benefits: Any users of snaps that have adopted this ...


Igor Ljubuncic
16 June 2023

Snapcraft 8.0 and the respectable end of core18

Ubuntu Article

‘E’s not pinin’! ‘E’s passed on! This base is no more! He has ceased to be! ‘E’s expired and gone to meet ‘is maker! ‘E’s a stiff! Bereft of life, ‘e rests in peace! If you hadn’t nailed ‘im to the perch ‘e’d be pushing up the daisies! ‘Is software processes are now ‘istory! ‘E’s ...