# Reinstalling GPT boot loader



## SIFE (Jun 26, 2013)

My hard disk had some bad sectors, and later became not-bootable, so I repaired the sectors with this utility, it has recovered 2920 sectors and my hard disk is 500[]GB.

Now, I get this message every time I try to boot up my system:

```
Not ufs
gptboot: No /boot/loader on 0:ad(0p2)
Not ufs
gptboot: No /boot/kernel/kernel on 0:ad(0p2)

FreeBSD/x86 boot
Default: 0:ad(0p2)/boot/kernel/kernel
boot:
```

I tried to `dump` my slices in another disk in order to reformat my disk but I_'m_ stuck at this error message:

```
mount: /dev/ad4p4 : Invalid argument
```
It looks like I am unable to mount my _UFS_ partitions.
My slices are still there because typing `gpart show` output_s_ this: 

```
=> 34                976773101        ad4     GPT     (466G)
   34                      128          1     freebsd-boot      (64k)
   **                *********          1     freebsd-ufs      (2.0G)
   **                *********          1     freebsd-ufs      (40G)
   **                *********          1     freebsd-ufs      (3.0G)
   **                *********          1     freebsd-ufs      (15G)
   **                *********          1     freebsd-ufs      (100G)
   **                *********          1     freebsd-ufs      (303G)
   **                *********          1     freebsd-ufs      (2.8G)
```


----------



## SirDice (Jun 26, 2013)

The bootloader seems to be there. It looks like it cannot find some things in /boot/, including your kernel (/boot/kernel/kernel) :O

Now this is a really dirty hack but you could boot from a 9.1-RELEASE image, mount the 'old' filesystem and simply extract /usr/freebsd-dist/kernel.txz to it. That should at least give you a kernel to boot from. Depending on what else might be missing it may just be simpler to re-install over the existing filesystem.


----------



## wblock@ (Jun 26, 2013)

It's not clear what magic technology that program uses, but it most likely just forced bad block remaps.  Please install sysutils/smartmontools and run `smartctl -a` on that drive.  If it shows more than a few sectors in Reallocated_Sector_Ct, plan on replacing the drive.


----------



## SIFE (Jun 26, 2013)

SirDice said:
			
		

> The bootloader seems to be there. It looks like it cannot find some things in /boot/, including your kernel (/boot/kernel/kernel) :O
> 
> Now this is a really dirty hack but you could boot from a 9.1-RELEASE image, *mount the 'old' filesystem* and simply extract /usr/freebsd-dist/kernel.txz to it. That should at least give you a kernel to boot from. Depending on what else might be missing it may just be simpler to re-install over the existing filesystem.


Unfortunately mounting _the_ old file system give this message:

```
mount: /dev/ad4p4 : Invalid argument
```



			
				wblock@ said:
			
		

> It's not clear what magic technology that program uses, but it most likely just forced bad block remaps.  Please install sysutils/smartmontools and run smartctl -a(8) on that drive.  If it shows more than a few sectors in Reallocated_Sector_Ct, plan on replacing the drive.


I don't have access to the system yet, still stuck on how to boot it.


----------



## wblock@ (Jun 27, 2013)

It's probably not going to boot, the drive is failing.  Download mfsBSD and boot from it, but don't expect much.


----------



## SirDice (Jun 27, 2013)

I don't think it will be needed but restoring the bootcode is done like this:
`# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ad4`


----------



## SIFE (Jun 27, 2013)

I tried that before but it returns an error message:

```
gpart: /boot/pmbr: No such file or directory
```


----------



## SirDice (Jun 27, 2013)

SIFE said:
			
		

> I tried that before but it returns an error message:
> 
> ```
> gpart: /boot/pmbr: No such file or directory
> ```



Boot from a 9.1 install and use the "Shell" or "Live" option. Then the files should exist in the same location. The command assumes the needed files are in /boot/. Your system is pretty hosed so they may not be there anymore.


----------



## free-and-bsd (Jun 28, 2013)

As @wblock says, your disk must be failing and probably is no use any more. Just for the future: bad sectors mean the disk must be replaced ASAP. There is NO utility to really fix bad sectors, make no mistake.

What you've reported in this thread:
	
	



```
mount: /dev/ad4p4 : Invalid argument
```
means most likely that such partition doesn't exist any more or is corrupted and can't be recognized.

`gpart show` seems to be showing the partition information such as is stored in where it is on a GPT disk. Which doesn't guarantee the partition itself still exists on the disk.


----------



## SIFE (Jun 28, 2013)

Is there a way to recover my data even partially, I tried ufs2tool but I managed to copy user directory.

```
C:\ufs2tools>ufs2tool 2/1/0  usr
Jun 27,2013  13:55:10      <DIR> .
Jun 27,2013  13:55:09      <DIR> ..
Nov 21,2009  06:56:49      <DIR> bin
Jun 27,2013  13:55:08      <DIR> compat
Jun 27,2013  13:55:10      <DIR> games
Nov 21,2009  06:56:25      <DIR> include
Nov 21,2009  08:00:12      <DIR> lib
Nov 21,2009  06:53:58      <DIR> libdata
Nov 21,2009  06:56:52      <DIR> libexec
Nov 21,2009  06:53:58      <DIR> local
Jun 27,2013  13:55:10      <DIR> obj
Nov 21,2009  06:53:58      <DIR> ports
Nov 21,2009  06:56:57      <DIR> sbin
Jun 27,2013  13:55:10      <DIR> share
Nov 21,2009  06:53:58      <DIR> src
```


----------



## free-and-bsd (Jun 28, 2013)

That is, /usr directory , right? Which must have been on a different partition, than /home, right?

The way I read this is that you're doing the right thing (given the result you've got so far), but the HDD is really in a bad condition.

Well, just recently I had series of those HDD failures within a rather short period of time. They were Windows and Linux formatted disks, but that makes no difference. 

So, per my experience, there are no rules in such cases *but to try everything you can find* before the disk fails entirely. Then some disks would fail to get detected, then later on they may get detected again -- but this, of course, is not what you want from a HDD.

BTW: there is a good rescue CD at www.systesccd.org, which has a number of disk handling utilities like `smartmontools`. That one's useful in HDD problems diagnostics, so you can see the condition of your drive using S.M.A.R.T capabilities. There is also support for the most widely used file systems (UFS included), at least read access.


----------



## wblock@ (Jun 28, 2013)

Parts of the disk have already failed.  The first thing to do is to make a complete copy of it with dd(1), either to a large file or another disk.  Use at least a bs=64k or it will take forever.

Then _stop using the failing disk_.  The more it runs, the more damage may occur.  If the data is very valuable (hundreds or thousands of dollars), there are data recovery companies like http://www.myharddrivedied.com/.

Otherwise, you can run any data recovery software on the copy without risking further damage to the original.


----------

