Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 4201  / 1 Year ago, fri, december 16, 2022, 1:35:00

I am a new ubuntu user and after accidentally formatting the boot partition I can't get it back to work. Here is some more info:



I was trying to format an sd card from the terminal and I accidentally may have formatted the partition which boots ubuntu. Now my computer goes directly to the BIOS settings and doesn't load the operating system. Under Boot tab in the Bios there is:




  • Launch PXE OpROM [Disabled]

  • Boot Option Priorities

  • Boot Option #1 [ubuntu (Drive not ....]

  • Boot Option #2 [ubuntu (Drive not ....]

  • Boot Option #3 [Windows Boot Manag....]



(I had removed windows long time ago.)



This is how I tried to solve the problem so far:



I created an ubuntu boot usb drive and was able to start the machine from the USB (luckily all the data was still there). I then tried installing ubuntu again alongside the old ubuntu. The installation completed successfully but the machine still won't boot without a USB drive.



I then followed the instructions in the thread for CreateBootPartitionAfterInstall



I tried running Boot-Repair but kept getting an error for a missing flag "bios_grub". So in gparted I changed the flag for my /dev/sda1 to bios_grub (it was "boot" before that - not sure if this was a right thing to do but couldn't run boot-repair without it). Here is what my partitions look like:



http://eagle1.american.edu/~gp9804a/ubuntu_gparted.png



I ran boot-repair successfully but still to no avail - machine still wont' boot without the usb drive.



I then tried the advanced options in boot-repair and under the GRUB Location tab I checked "Seperate /boot partition sda1"



This also apparently went well and I received a successful boot-repair message at the end. The only problem there was that it couldn't run some updates on dev/sda6 and it instructed me to enable updates on the partition (which I have no idea how to do and thought that this was tangential to the main problem anyway). However, after restart I was back to the same problem - going straight to BIOS and still no boot.



The url from (the last) boot-repair is this:



http://paste.ubuntu.com/6939109/



I am now at a loss on what to do and how to get my machine back up. Any suggestions are greatly appreciated


More From » boot

 Answers
4

You've been digging yourself into a deeper and deeper hole. Fortunately, I think you can still recover. Both to warn off others and to help you learn, I want to point out a few of your mistakes:




  • Re-installing Ubuntu because of a boot problem is almost always overkill at best, and runs the risk of destroying your user data at worst. You say that your data still exists, so you may have just wasted some time, but I want to point this out because it could have gone very badly, with lost user data to add to your boot problems.

  • Attempting to run Boot Repair from a BIOS-mode boot on a computer that was originally set up in EFI mode was a mistake. You probably didn't even realize you were making this mistake, but you did -- the fact that Boot Repair was complaining about the need for a partition with a "bios_grub flag" was a clue about this mistake. (This complaint from Boot Repair is clearly not very informative to anybody but experts, sadly.)

  • Changing the flag on /dev/sda1 from boot to bios_grub was a mistake. In parted and GParted terminology, the "boot flag" identifies an EFI System Partition (ESP), which is a partition that holds EFI boot loaders. A "bios_grub flag," OTOH, identifies a BIOS Boot Partition, which holds second-stage GRUB boot loader code for BIOS/CSM/legacy-mode boots. When you re-installed GRUB in BIOS mode, it overwrote the first few sectors of /dev/sda1, thus damaging the data on the partition. It sounds like your problems began with accidentally trashing this partition, so you probably didn't really do any more damage (except possibly to your /etc/fstab file), but this was definitely the wrong approach to take. If your problem had had a different cause, this mistake would have made recovery even more difficult.

  • Telling Boot Repair to treat /dev/sda1 as a separate /boot partition was also a mistake. You ended up telling it to treat that partition as two mutually exclusive things: as a separate /boot partition and as a BIOS Boot Partition. This could have messed things up even further, but it looks like it didn't really have much of an effect.



As further background on EFI booting, you may want to read my Web page on the subject, the Ubuntu community wiki on EFI booting, and/or Adam Williamson's blog explaining EFI issues. All three of these pages provide background information that may help you deal with this type of problem in the future.



As to the solution: There are several approaches, but I recommend you begin by fixing some of the problems that must be dealt with for any solution:




  1. Boot a Linux emergency disc.

  2. Use GParted or parted to change the "flag" on /dev/sda1 to boot. Alternatively, use gdisk to change the type code on this partition to EF00.

  3. Create a fresh FAT32 filesystem on /dev/sda1. You can do this with GParted or by using the command-line mkdosfs or mkfs utility.

  4. Mount /dev/sda6 and edit the /etc/fstab file on it. You must add an entry to this file to mount /dev/sda1 at /boot/efi. It should look like this:



.



/dev/sda1      /boot/efi   vfat        fmask=133       0 0


Alternatively (and preferably, in some ways), you can change /dev/sda1 at the start of that line to UUID="XXXX-XXXX", where XXXX-XXXX is the "UUID" (really a serial number) value for the partition, as reported by blkid. This value will only be valid after you've created a fresh FAT filesystem on the partition, so it's unknowable as I write this answer.



Once you've made these changes, you must install a fresh EFI-mode boot loader. Several choices are available. The two that are likely to be easiest to install are:




  • rEFInd -- You can install rEFInd by booting into Linux using whatever method works, verifying that /boot/efi is mounted, and installing the Debian package, available from the rEFInd downloads page.

  • GRUB 2 via Boot Repair -- The Boot Repair tool should re-install GRUB; however, you must run the program when booted in EFI mode. Check for the presence of a directory called /sys/firmware/efi. If it's present, you've booted in EFI mode and you can run Boot Repair. If it's not present, you've probably booted in BIOS mode and Boot Repair will be useless at best. If you've booted in BIOS mode, go into your firmware setup utility and disable BIOS/CSM/legacy support; or use your firmware's built-in boot manager to select a boot option that includes the string "EFI" or "UEFI." Unfortunately, I can't be more specific because firmware setup utility and firmware boot manager details vary so much from one computer to another.



It might be necessary to wipe the BIOS-mode GRUB code from the first sector of your hard disk. If you complete the repair and still can't boot from the hard disk, try booting to Linux and typing the following command in a Terminal:



sudo dd if=/dev/zero of=/dev/sda bs=440 count=1


Be very careful when typing that command; a slip-up, especially if you omit or specify the wrong value for bs= or count=, can do serious damage to your disk. That's why I didn't include this in the main recovery procedure.



Good luck!


[#26973] Saturday, December 17, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alkeake

Total Points: 467
Total Questions: 94
Total Answers: 126

Location: Tajikistan
Member since Tue, Jun 15, 2021
3 Years ago
;