<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator> <link href="https://blog.jaysinh.dev/tags/GRUB/feed.xml" rel="self" type="application/atom+xml"/> <link href="https://blog.jaysinh.dev/" rel="alternate" type="text/html"/> <updated>2026-08-01T12:49:14+00:00</updated> <id>https://blog.jaysinh.dev/</id> <title type="html">Jaysinh’s own heed</title> <subtitle>I am a Full-stack developer by profession, Computer scientist by heart and an Actor by gene. I write mostly on programming topics. Browse through my blog posts to identify my taste of writing. </subtitle> <entry> <title type="html">How to repair a broken GRUB in Ubuntu?</title> <link href="https://blog.jaysinh.dev/2017/08/28/how_to_repair_a_broken_grub_in_ubuntu.html" rel="alternate" type="text/html" title="How to repair a broken GRUB in Ubuntu?"/> <published>2017-08-28T08:05:42+00:00</published> <updated>2017-08-28T08:05:42+00:00</updated> <id>https://blog.jaysinh.dev/2017/08/28/how_to_repair_a_broken_grub_in_ubuntu</id> <content type="html" xml:base="https://blog.jaysinh.dev/2017/08/28/how_to_repair_a_broken_grub_in_ubuntu.html">&lt;p&gt;&lt;img src=&quot;https://blog.jaysinh.dev/assets/images/how_to_fix_broken_grub/grub_title.png&quot; alt=&quot;How to repair a broken GRUB&quot; /&gt;&lt;/p&gt; &lt;h2 id=&quot;background-story&quot;&gt;Background story&lt;/h2&gt; &lt;p&gt;Yesterday, I was having some free time after lunch. I decided to complete a long term plan of checking the compatibility of few &lt;a href=&quot;https://www.gnu.org/philosophy/free-sw.en.html&quot;&gt;Freedom Operating Systems&lt;/a&gt; with my workstation. From &lt;a href=&quot;https://www.gnu.org/distros/free-distros.en.html&quot;&gt;this list&lt;/a&gt;, I decided to check &lt;a href=&quot;https://trisquel.info/&quot;&gt;Trisquel&lt;/a&gt; OS first. &lt;a href=&quot;https://trisquel.info/&quot;&gt;Trisquel&lt;/a&gt; is freedom clone of world-famous OS Ubuntu. The simplest option was to prepare a live USB drive and boot the &lt;a href=&quot;https://trisquel.info/&quot;&gt;Trisquel&lt;/a&gt; from it. I inserted the USB drive and instructed the &lt;a href=&quot;http://gparted.org/&quot;&gt;Gparted&lt;/a&gt; to format it. Bang! That simple step ruined my entire Sunday evening. Instead of formatting my USB drive, I mistakenly formatted the boot partition! Without putting any extra measures, I formatted my root partition which is also a type &lt;a href=&quot;https://en.wikipedia.org/wiki/File_Allocation_Table&quot;&gt;FAT&lt;/a&gt;. I was lucky enough to identify that I have formatted the partition from my SSD and not the USB drive. After taking advice from the people of &lt;a href=&quot;https://freenode.linux.community/&quot;&gt;##linux&lt;/a&gt; I found, I will not be able to re-boot because the &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt; is lost. In this post, I will describe the steps I followed to restore the &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt;.&lt;/p&gt; &lt;h2 id=&quot;procedure-of-restoring-the-grub&quot;&gt;Procedure of restoring the GRUB&lt;/h2&gt; &lt;p&gt;You can restore your &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt; using three methods:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;Using GUI utility &lt;a href=&quot;https://help.ubuntu.com/community/Boot-Repair&quot;&gt;“Boot-repair”&lt;/a&gt;. This is the simplest step to follow first. Unfortunately, I was not able to fix my &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt; using this method.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Boot from a live operating system, mount the infected boot partition and perform the steps of restoring the &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt;. Since I identified the problem at an early stage, I didn’t restart my system until I was sure that nothing is broken.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Last is to run the steps of restoring the &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt; from the command line if you haven’t reboot your system after formatting the boot partition. I will describe the steps of restoring your &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt; using this method in this post.&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;p&gt;If you had rebooted and are unable to start the system then I will request to follow the steps described at &lt;a href=&quot;https://www.howtogeek.com/114884/how-to-repair-grub2-when-ubuntu-wont-boot/&quot;&gt;How to geek&lt;/a&gt; post rather than continuing here. If you are using Legacy BIOS rather than UEFI type then this post might not work for you. To identify which type your system has booted with, &lt;a href=&quot;https://askubuntu.com/a/162896&quot;&gt;follow this steps&lt;/a&gt;.&lt;/p&gt; &lt;h2 id=&quot;so-lets-start&quot;&gt;So let’s start!&lt;/h2&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Identify the type of your boot partition:&lt;/strong&gt; You can use GUI utilities like &lt;a href=&quot;http://gparted.org/&quot;&gt;GParted&lt;/a&gt; or any other of your choice. The boot partition is the very first partition of the drive you are using for booting your operating system.&lt;/p&gt; &lt;p&gt;&lt;img src=&quot;https://blog.jaysinh.dev/assets/images/how_to_fix_broken_grub/gparted_identification_parition.png&quot; alt=&quot;Identify boot partition using gparted&quot; /&gt;&lt;/p&gt; &lt;p&gt;In my case, it is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/dev/sda1&lt;/code&gt;. This partition should be either &lt;a href=&quot;https://en.wikipedia.org/wiki/File_Allocation_Table#FAT32&quot;&gt;FAT32&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/File_Allocation_Table#FAT16&quot;&gt;FAT16&lt;/a&gt;. If it is anything other than that you should format it to &lt;a href=&quot;https://en.wikipedia.org/wiki/File_Allocation_Table&quot;&gt;FAT&lt;/a&gt; version of your choice.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Assert &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/boot/efi&lt;/code&gt; is mounted:&lt;/strong&gt; Run below command at your terminal.&lt;/p&gt; &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo mount /boot/efi&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Sample output&lt;/p&gt; &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$sudo mount /boot/efi/ mount: /dev/sda1 is already mounted or /boot/efi busy /dev/sda1 is already mounted on /boot/efi &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;If it is mounted, it will throw a warning indicating that the partition is already mounted. If it isn’t mounted, then the prompt will come back without any warning message.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Next, restore and update the &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt;:&lt;/strong&gt; Run below command at your terminal.&lt;/p&gt; &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo grub-install &amp;amp;&amp;amp; update-grub&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Sample output&lt;/p&gt; &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo grub-install &amp;amp;&amp;amp; update-grub Installing for x86_64-efi platform. Installation finished. No error reported. &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;If there is any error, I will advise to not move further and try other options I mentioned above for restoring your &lt;a href=&quot;https://www.gnu.org/software/grub/&quot;&gt;GRUB&lt;/a&gt;.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;&lt;strong&gt;Finally, replace the UUID of the formatted partition:&lt;/strong&gt; Find the &lt;strong&gt;UUID&lt;/strong&gt; of your boot partition. Once you format the partition, the &lt;strong&gt;UUID&lt;/strong&gt; of the partition is changed. You have to update the new &lt;strong&gt;UUID&lt;/strong&gt; value at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/fstab&lt;/code&gt; file. Use below command to get the latest &lt;strong&gt;UUID&lt;/strong&gt; of your boot partition.&lt;/p&gt; &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo blkid /dev/sda1&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;img src=&quot;https://blog.jaysinh.dev/assets/images/how_to_fix_broken_grub/uuid_blkid_shell.png&quot; alt=&quot;Identifying UUID of boot efi&quot; /&gt;&lt;/p&gt; &lt;p&gt;Copy the value of &lt;strong&gt;UUID&lt;/strong&gt; which is between the double quotes.&lt;/p&gt; &lt;p&gt;Open the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/fstab&lt;/code&gt; file with your desired editor and update the value with the existing &lt;strong&gt;UUID&lt;/strong&gt; of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/dev/sda1&lt;/code&gt;. I am doing this procedure using the &lt;a href=&quot;http://www.vim.org&quot;&gt;vim&lt;/a&gt; editor. You can choose any editor of your choice.&lt;/p&gt; &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo vim /etc/fstab&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;img src=&quot;https://blog.jaysinh.dev/assets/images/how_to_fix_broken_grub/vim_etc_fstab.png&quot; alt=&quot;Updating the UUID to the etc fstab file&quot; /&gt;&lt;/p&gt; &lt;p&gt;You will require the root privileges for writing to this file.&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;p&gt;We are done! Now when you will run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo ls -l /boot/efi&lt;/code&gt;, you should able to identify the files beneath that directory. It is time to confirm by rebooting your system.&lt;/p&gt; &lt;h2 id=&quot;vote-of-thanks&quot;&gt;Vote of Thanks!&lt;/h2&gt; &lt;p&gt;I would like to thank &lt;a href=&quot;https://launchpad.net/~di-iorio&quot;&gt;ioria&lt;/a&gt; and &lt;a href=&quot;https://launchpad.net/~ducasse&quot;&gt;ducasse&lt;/a&gt;, member of &lt;a href=&quot;irc://irc.freenode.net/ubuntu&quot;&gt;#ubuntu&lt;/a&gt; at Freenode, who invested a great amount of time to guide me in fixing this problem. &lt;a href=&quot;irc://irc.freenode.net/ubuntu&quot;&gt;#ubutu&lt;/a&gt; has great members who are always willing to help you.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Note: While mentioning the GRUB in this post, I actually mean the GRUB2.&lt;/em&gt;&lt;/p&gt; &lt;h6 id=&quot;proofreaders-dhavan-vaidya-pentodelinuxfreenode-parsnipemacs-freenode&quot;&gt;Proofreaders: &lt;a href=&quot;http://codingquark.com/&quot;&gt;Dhavan Vaidya&lt;/a&gt;, Pentode@##linux(Freenode), parsnip@#emacs (Freenode)&lt;/h6&gt;</content> <author> <name>Jaysinh Shukla</name> </author> <category term="Ubuntu"/> <category term="GRUB"/> <category term="How-to"/> <summary type="html">Steps to restore your GRUB if you have formatted boot partition mistakenly</summary> </entry> </feed>