How many of you have had that sinking feeling as your PC boots up? You know, a slight niggle in the back of your mind that says "this is taking longer than usual" before Windows drops dead in front of you, and refuses to play ball.

When it comes to fixing your broken Windows install, Ubuntu has its uses there too. If you happen to break your filesystem or master boot record on Windows, then fear not, all is not lost. You can use Ubuntu to fix issues related to the Windows operating system. This technique should work on any Ubuntu-based Linux distribution.

Download, Install, and Boot Ubuntu

Those of you who already have a dual-boot Ubuntu and Windows machine can skip this step.

If you haven't got a live USB stick then you're going to need to get hold of one. But first, you'll have to download the official Ubuntu installation ISO.

Download: Ubuntu ISO

Once done, it's now time to create a new bootable Ubuntu USB. There are several tools to create a bootable USB from an ISO file, but you can use balenaEtcher as it comes with an easy-to-use, intuitive interface. All you need to do is select the ISO file and the media device, and hit Flash.

flashing ubuntu on usb with etcher

If you're dual-booting, then this is a simple step of choosing Ubuntu over Windows at boot. For live USB sticks and CDs, you're going to need to enter the BIOS setup as your PC boots (usually by pressing F2 or Del) and arrange your boot devices to prioritize your USB device or CD drive to boot before your main hard drive.

If you've done everything correctly, you'll see the Ubuntu bootloader appear. From here you'll want to boot directly into the live operating system by selecting Try Ubuntu. After a minute or two, you'll see the desktop appear, and we're ready to begin.

Fixing a Corrupt Windows NTFS Partition

Luckily, you can schedule an NTFS consistency check to attempt to repair your tattered Windows NTFS partition from Ubuntu, but you're going to need to install some packages first. It is worth mentioning that this should work with any NTFS drive that refuses to mount in Ubuntu too.

Open a terminal and install NTFS-3G by typing this command:

        sudo apt install ntfs-3g
    

You can now set about fixing your Windows installation. First, locate your Windows partition. In the terminal, type:

        sudo fdisk -l
    

Output:

identifying windows ntfs filesystem

You're looking for an entry that looks like this:

        /dev/sda9 * 638 12312 93773824 8.9G Microsoft basic data
    

The important bit is the /dev/sda9 which tells us where the Windows partition is mounted and "Microsoft basic data" lets us know that the partition is a Microsoft Windows formatted device. You can also identify the Windows drive by looking at the size of the partition (8.9G).

So in this case, /dev/nvme0n1p9 means that Windows is on an NVMe SSD and that its partition number is nine. Usually, if your Windows partition is located on a hard drive, the device name will be /dev/sdax, where x is a number.

Armed with this information, you have to use the ntfsfix command to attempt to fix the partition. Type the following in the terminal:

        sudo ntfsfix /dev/<device name>
    

Replace <device name> with your Windows partition (e.g. /dev/nvme0n1p9) and enter your password. NTFS-3G will now mount your drive and check it for consistency, and any errors found should be automatically fixed.

fixing ntfs partition on Ubuntu

Restart your PC to assess the situation, and if all goes well you'll see Windows boot without any issues.

Fixing a Corrupt Master Boot Record

If you've got a problem with Windows' boot record then you can also fix that from within Ubuntu. Assuming you've already booted into Ubuntu, open up the terminal and run:

        sudo os-prober
    

Then, regenerate the GRUB configuration file by entering the following in the command line:

        sudo update-grub
    
running os-prober and update-grub commands

GRUB will now identify the Windows EFI partition on your storage device and attempt to add it to its entry. You'll probably want to restart your machine now, just make sure you take any live CD/USB devices out as you do.

Alternatively, you can use the LILO bootloader. Install it on your system first by typing:

        sudo apt install lilo
    

Enter your password to proceed with the installation; you might get a few warnings along the way.

By now, you should know the device name for the Windows installation partition. If you missed it, type:

        sudo fdisk -l
    

Find the "Microsoft basic data" partition that relates to your Windows installation and type:

        sudo lilo -M /dev/<device name> mbr
    

Replace <device name> with your Windows partition (e.g. /dev/sda2) and hit Enter. LILO will attempt to restore your master boot record. Again, restart your system to check if the issue still persists.

Recover Data From Windows Partitions on Ubuntu

If you're having problems with a Windows install, and you've tried everything and it still doesn't work, there's still hope. Don't forget that you can mount the partition and rescue as much data as you think you'll need. Using the terminal, enter the following commands one by one:

        sudo mkdir /media/windows
sudo ntfs-3g -o force,rw /dev/<device name> /media/windows

Replace <device name> with your Windows partition location and the drive should pop up on your desktop. The mkdir command created a directory where the Windows filesystem will be mounted and then, using the ntfs-3g command, you mounted the filesystem to the newly-created folder.

Copy any important data from the Windows filesystem to your Linux partition. You can then transfer this to a removable media and restore it after fixing the issue with the Windows installation.

Troubleshooting Windows Issues Using Ubuntu

Has Ubuntu saved your bacon recently? You can use almost any other Linux system-repair distro to troubleshoot such issues with Windows. Some distributions like SystemRescue and Ultimate Boot CD are focused entirely on fixing and repairing problems related to operating system boot, filesystem, and more.

If the Ubuntu desktop appeals to you, then maybe you should consider installing Ubuntu on your Windows desktop. Or even better, you can dual-boot Ubuntu with Windows, but make sure you're well aware of the risks associated with dual-booting first.