ThisCalculator

Everyday

Recover Files Before Reinstalling Linux?

Updated · Standard formula, shown below

Yes, you should recover and back up your important files before reinstalling Linux. A reinstall wipes the system partition, and without a backup, personal documents, photos, and configuration files are permanently lost. This article explains what to save, how to back it up, and what to do if you forgot to back up first.

Why Reinstalling Erases Your Data

Most Linux distributions offer an option to “erase disk and reinstall” during the installation process. This option formats the root partition (usually /) and often the home partition (/home) as well. Formatting overwrites the file system structure, making existing files unreachable. Even if you choose “reinstall alongside” or “keep files,” the installer may still modify boot loaders and system files, which can cause data loss if the operation fails or if you select the wrong partition.

The only safe assumption is that any file not backed up externally will be gone after a reinstall. This includes files in /home/yourusername, system configuration files in /etc, and any data stored on the root partition outside of mounted drives.

What Files Should You Back Up?

Focus on files that are unique to you and cannot be recreated by reinstalling software. A good checklist includes:

  • Personal documents, spreadsheets, PDFs, and text files
  • Photos, videos, music, and other media files
  • Browser bookmarks, passwords (exported from the browser), and saved sessions
  • Email archives (if using a local client like Thunderbird, back up the profile folder)
  • SSH keys (~/.ssh), GPG keys (~/.gnupg), and any other encryption keys
  • Configuration files for applications you use heavily (e.g., ~/.bashrc, ~/.config/ for many apps)
  • Project source code, especially if it is not in a remote repository
  • Database dumps (if you run local MySQL or PostgreSQL)

You do not need to back up system packages or the operating system itself—those can be reinstalled from the distribution’s repositories.

How to Back Up Before Reinstalling

If your system still boots, the easiest method is to copy files to an external drive or a network location. Use a file manager or the command line:

  1. Connect an external USB drive or mount a network share.
  2. Copy your /home directory to the external drive. For example, cp -a /home/yourusername /media/external/backup preserves permissions and timestamps.
  3. Export browser bookmarks and passwords (usually via the browser’s settings menu).
  4. Make a list of installed packages if you want to restore them later: dpkg --get-selections > packages.txt (Debian/Ubuntu) or pacman -Q > packages.txt (Arch).
  5. Verify the backup by checking that files open correctly on another machine or by running diff on a few directories.

If you cannot boot into the graphical interface, boot from a live USB stick and mount your internal drive. Then copy files to the external drive using the same commands. The live environment gives you full access to the disk as long as it is not encrypted.

If You Already Forgot to Back Up

If you have already reinstalled and lost files, recovery is possible but not guaranteed. The key is to stop using the drive immediately—any new writes can overwrite the deleted data. Boot from a live USB and use recovery tools:

  • testdisk can recover deleted files and repair partition tables.
  • photorec (from the same package) scans raw disk blocks for file signatures and recovers files even if the file system is damaged.
  • extundelete works specifically for ext3/ext4 file systems and can restore files that were deleted but not yet overwritten.

These tools are more likely to succeed if the reinstall happened recently and the drive was not heavily used afterward. Recovery to the same drive is risky—always write recovered files to a different disk.

Common Mistakes and How to Avoid Them

Many users make errors that lead to data loss. Here are the most frequent ones:

  • Assuming the installer will preserve files. Even “keep files” options can fail if the partition layout changes.
  • Backing up only the home folder. System configuration files in /etc may be needed for server setups or custom network settings.
  • Not verifying the backup. A backup that cannot be read is useless. Test it before reinstalling.
  • Using the same external drive for the backup and the reinstall. If the installer targets the wrong disk, you lose both.
  • Ignoring encrypted drives. If you used LUKS encryption, you must unlock the drive before you can copy files. Without the passphrase, data is unrecoverable.

Alternatives to a Full Reinstall

Before wiping the system, consider whether a reinstall is truly necessary. Many issues can be fixed without losing data:

  • Reset a forgotten password by booting into recovery mode or using a live USB to edit the /etc/shadow file.
  • Repair broken packages with apt --fix-broken install or dnf check.
  • Reinstall the desktop environment without touching your home directory.
  • Restore system files from the distribution’s installation media using the “try without installing” option.
  • Use a system snapshot if you have Timeshift or similar tool configured.

If you do decide to reinstall, choose the “manual partitioning” option and keep /home on a separate partition. This allows future reinstalls to preserve your personal data.

Frequently Asked Questions

Can I recover files from the old system after reinstalling?
Possibly, if the reinstall did not overwrite the entire disk. Use a live USB and tools like testdisk or photorec immediately. The longer you use the new system, the lower the chance of recovery.

Does reinstalling Linux delete my files on other partitions?
No, if you select the correct partition during installation. Files on separate partitions (e.g., a /data partition or a Windows NTFS drive) are untouched. Always double-check the installer’s target disk.

What is the fastest way to back up my home directory?
Use rsync to an external drive: rsync -av --progress /home/yourusername /media/external/backup. It copies only changed files on subsequent runs and preserves permissions.

Should I back up installed packages?
It is helpful for restoring your environment, but not essential. You can reinstall packages from the repositories. To get a list, use dpkg --get-selections (Debian) or pacman -Q (Arch).

Can I recover files from a LUKS-encrypted drive after reinstalling?
Only if you have the passphrase and the LUKS header is intact. The reinstall may overwrite the header, making decryption impossible. Back up the header separately if you plan to reinstall.

Is it safe to reinstall without backing up if I use cloud storage?
Only if you are certain every important file is synced. Cloud storage often misses local configuration files, browser data, and files outside the sync folder. Check your cloud account before proceeding.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.