<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Linux on Tech Philosopher</title><link>https://blog.bktus.com/en/tags/linux/</link><description>Recent content in Linux on Tech Philosopher</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 26 Nov 2021 11:51:13 +0800</lastBuildDate><atom:link href="https://blog.bktus.com/en/tags/linux/index.xml" rel="self" type="application/rss+xml"/><item><title>Fix grub2 boot UEFI after Ubuntu dual system reinstallation of Windows</title><link>https://blog.bktus.com/en/archives/0vspvh/</link><pubDate>Fri, 26 Nov 2021 11:51:13 +0800</pubDate><guid>https://blog.bktus.com/en/archives/0vspvh/</guid><description>&lt;p>Say you have Ubuntu and Windows installed as a dual-boot system, and then you reinstall Windows. The Grub boot entry will very likely be overwritten by Windows Boot Manager, and at that point you can&amp;rsquo;t get into Ubuntu anymore. But don&amp;rsquo;t panic. You can fix the grub2 boot entry with the steps below, and you don&amp;rsquo;t need to install any extra software.&lt;/p>
&lt;h2 id="making-an-ubuntu-usb-boot-drive">Making an Ubuntu USB Boot Drive&lt;/h2>
&lt;p>To repair the boot entry, we need the software tools that come with Ubuntu. We can&amp;rsquo;t get into the original Ubuntu system for now, but we can use the image written to an Ubuntu USB drive to get a basic, working Ubuntu environment. Download the image file from the &lt;a href="https://ubuntu.com/download/desktop">Ubuntu website&lt;/a>.&lt;/p></description><content:encoded><![CDATA[<p>Say you have Ubuntu and Windows installed as a dual-boot system, and then you reinstall Windows. The Grub boot entry will very likely be overwritten by Windows Boot Manager, and at that point you can&rsquo;t get into Ubuntu anymore. But don&rsquo;t panic. You can fix the grub2 boot entry with the steps below, and you don&rsquo;t need to install any extra software.</p>
<h2 id="making-an-ubuntu-usb-boot-drive">Making an Ubuntu USB Boot Drive</h2>
<p>To repair the boot entry, we need the software tools that come with Ubuntu. We can&rsquo;t get into the original Ubuntu system for now, but we can use the image written to an Ubuntu USB drive to get a basic, working Ubuntu environment. Download the image file from the <a href="https://ubuntu.com/download/desktop">Ubuntu website</a>.</p>
<p><img alt="Ubuntu download page" loading="lazy" src="https://img.bktus.com/yxvShcvU.webp"></p>
<p>To make the USB boot drive, you can use <a href="https://rufus.ie/zh/">rufus</a>, which is small, easy to use and doesn&rsquo;t need to be installed. With rufus you can quickly create a USB boot drive. Just make sure you choose GPT mode.</p>
<p><img alt="Creating a USB boot drive with rufus" loading="lazy" src="https://img.bktus.com/2Epyqvjl.webp"></p>
<h2 id="booting-from-the-usb-boot-drive">Booting from the USB Boot Drive</h2>
<p>Restart the computer and choose the USB drive in the BIOS boot settings. When the Ubuntu installer comes up, select Try Ubuntu on the installation screen to enter Ubuntu Live.</p>
<h2 id="rebuilding-grub2">Rebuilding Grub2</h2>
<p>Use fdisk to find the EFI partition and the partition that holds the /boot mount point (if you didn&rsquo;t set up a separate /boot mount point, use the / mount point instead). Mount the partition that holds the /boot mount point to /mnt (my partitions are on an NVMe SSD).</p>
<pre tabindex="0"><code>% sudo mount /dev/nvme0n1p6 /mnt/
</code></pre><p>Mount the EFI partition. Here you need to know which partition on your disk is the EFI system partition (for me it&rsquo;s the fifth one).</p>
<pre tabindex="0"><code>% sudo mount /dev/nvme0n1p5 /mnt/boot/efi
</code></pre><p>Bind the other directories we need</p>
<pre tabindex="0"><code>% sudo mount --bind /dev /mnt/dev
% sudo mount --bind /dev/pts /mnt/dev/pts
% sudo mount --bind /proc /mnt/proc
% sudo mount --bind /sys /mnt/sys
</code></pre><p>Change the root directory to /mnt</p>
<pre tabindex="0"><code>% sudo chroot /mnt
</code></pre><h2 id="repairing-the-grub2-boot-entry">Repairing the Grub2 Boot Entry</h2>
<p>The command you need to run here is different for 32-bit and 64-bit systems. Both are given below. 32-bit systems:</p>
<pre tabindex="0"><code>% sudo grub-install --target=i386-efi /dev/nvme0n1
</code></pre><p>64-bit systems:</p>
<pre tabindex="0"><code>% sudo grub-install --target=x86_64-efi /dev/nvme0n1
</code></pre><p>After running one of the commands above, run a recheck as well</p>
<pre tabindex="0"><code>% grub-install --recheck /dev/nvme0n1
</code></pre><p>Cleanup afterwards (optional)</p>
<pre tabindex="0"><code>% exit
% sudo umount /mnt/sys
% sudo umount /mnt/proc
% sudo umount /mnt/dev/pts
% sudo umount /mnt/dev
% sudo umount /mnt
</code></pre><p>Then reboot. You&rsquo;ll see that you can get into the grub2 menu again, and grub2 has found both Ubuntu and Windows Boot Manager.</p>
<h2 id="rebuilding-the-windows-boot-manager-entry-in-grub2">Rebuilding the Windows Boot Manager Entry in Grub2</h2>
<p>Restart the computer, boot into Ubuntu through Grub, and run the following command to regenerate the configuration file</p>
<pre tabindex="0"><code>% sudo update-grub
</code></pre>]]></content:encoded></item></channel></rss>