# UFS disk cannot be booted



## Haines (Sep 29, 2020)

I have a SATA disk attached to an somewhat old machine. Because of other disks/operating systems, BIOS is set up as 
legacy BIOS rather than UEFI. 

I installed FreeBSD onto that disk using the entire disk. Did the automatic partitioning with MS_DOS format and get: 
      ada2         466 Gb MBR
          ada2s1     466 Gb BSD
            ada2s1a  462 Gb freebsd-ufs  /
            ada2s1b  3.8 Gb freebsd-swap none

The boot did not see the disk and it dawned on me that perhaps I neglected to make the primary partition bootable. So I did: 
# parted set 1 flag boot. Now parted print shows that the Flat is "boot". I thought I has solved the problem, but when tried to boot
to that disk I get a blinking cursor UL on blank screen. This might mean BIOS does not see the drive, but in fact BIOS does see 
it. 

I get mixed message from an online search. If the MS-DOS partition scheme is used, is there a 500 Kb freebsd-boot partition 
with a boot flag. My installation did not create such a partition.


----------



## Alexander88207 (Sep 30, 2020)

Haines said:


> I get mixed message from an online search. If the MS-DOS partition scheme is used, is there a 500 Kb freebsd-boot partition
> with a boot flag. My installation did not create such a partition.



Hello* Haines*,

is this not the case with GPT?


----------



## Emrion (Sep 30, 2020)

I don't understand what you say about MS_DOS format... Unless you boot in UEFI mode, there is no need of a MS DOS file system.

Strange that you don't get any message. I don't know whether the installation puts boot0 or mbr in the first sector. Should be boot0 (if I read correctly the handbook) and maybe it crashes because of the presence of others disk with different schemes and OSes?

Have you tried to boot with all the other disks unplugged?


----------



## olli@ (Sep 30, 2020)

Haines said:


> I have a SATA disk attached to an somewhat old machine. Because of other disks/operating systems, BIOS is set up as
> legacy BIOS rather than UEFI.



Actually UEFI supports multiple operating systems (provided that all of those system support UEFI, of course).



> I installed FreeBSD onto that disk using the entire disk. Did the automatic partitioning with MS_DOS format and get:



When you say “MS_DOS format”, I guess you mean the MBR partitioning scheme, right?



> ```
> ada2     466 Gb MBR
> ada2s1   466 Gb BSD
> ada2s1a  462 Gb freebsd-ufs  /
> ...



Basically it should work like that, although it’s not optimal.
– First, the swap partition should be placed near the beginning of the disk, not at the end, because of performance reasons (unless this is an SSD). The FreeBSD installer should take care of that automatically.
– Second, nowadays it is better to use the GPT partition scheme along with a compatibility MBR (also called “protective MBR”). This gets you the best of both worlds: It is recognized by legacy systems that only support MBR (e.g. old BIOS), but you get all the advantages of GPT. Again, the FreeBSD installer does this by default, AFAIK.
– Third, it’s better to not dump everything into the root file system, but use several separate partitions. At the very least, I would create a root partition, a /var partition, and a /usr partition for everything else. Depending on purpose, further partitions might make sense.



> The boot did not see the disk and it dawned on me that perhaps I neglected to make the primary partition bootable. So I did:
> # parted set 1 flag boot.



Wait a second, what “parted”? FreeBSD does not have a tool called parted. Are you using a different operating system to install this FreeBSD disk? That won’t work because the boot blocks will not be installed, and other details of the various boot stages are probably not initialized correctly. I’m not surprised that you can’t boot from this disk. You’ll have to install it with the FreeBSD installer, or with FreeBSD’s gpart(8) tool.


----------



## chrbr (Sep 30, 2020)

Haines said:


> The boot did not see the disk and it dawned on me that perhaps I neglected to make the primary partition bootable. So I did:
> # parted set 1 flag boot. Now parted print shows that the Flat is "boot". I thought I has solved the problem, but when tried to boot
> to that disk I get a blinking cursor UL on blank screen. This might mean BIOS does not see the drive, but in fact BIOS does see
> it.


Dear Haines,
may be the boot code has not been installed. With your setup as ada2 it should be done by `gpart bootcode -b /boot/mbr ada2`. I refer to http://www.wonkity.com/~wblock/docs/html/disksetup.html. The MBR setup is documented in the last section. In my opinion all the other docs are perfect, too.


----------



## Haines (Sep 30, 2020)

Well, yes. Is is true that FreeBSD installation using the MS-DOS partitioning automatically creates a MBR file. I finally figured 
out how to mount a UFS partition on a Linux mount point and see that an MBR file was created in the /boot partition. Is this
location the reason why the OS won't boot? If so, what is the workaround?


----------



## Haines (Sep 30, 2020)

olli@ said:


> Actually UEFI supports multiple operating systems (provided that all of those system support UEFI, of course).
> 
> 
> 
> ...



---------

By MS-DOS format, I did mean the MBR partitioning scheme. I know it is not optimal, but I have other disks with another operating system already 
in this old sandbox. So set it up with legacy BIOS.

I'm not using a different operating system to install FreeBSD. I simply put the FreeBSD ISO on a USB key and ran the FreeBSD installer.  

I normally have a dozen partitions (don't ask why), but for FreeBSD I wanted a simple default installation with guided partitioning. I assumed that 
using the defaults I would end up with a bootable operating system.

I booted the FreeBSD /foot on a Linux mount point (unfortunately read only). In Linux the FreeBSD drive is seen as /dev/sdb. It has a primary partition 
and  a swap partition. The root partition did not seem to be bootable when viewed in Linux parted, and so I made it bootable with parted from Linux. 
Parted is a Linux utility that "can detect UFS". Not sure that this means but used it to set the bootable flag for the root partition of FreeBSD. Or at least 
parted print command now shows the partition to be bootable. 

The boot process was changed by doing this. Before flagging /root as bootable BIOS did not even see the FreeBSD disk and simply skipped over it 
to the next disk with a bootable operating system. After flagging the FreeBSD partition as bootable, now the boot of FreeBSD hangs with blinking 
cursor at UP of black screen. At least the HD is seen, but perhaps MBR not found.  I see it /root/boot/. Is that its proper location?


----------



## T-Daemon (Sep 30, 2020)

The easiest action at this point is to install fresh. Choose this time GPT instead of MBR as partition scheme.


----------



## Haines (Sep 30, 2020)

olli@ said:


> Actually UEFI supports multiple operating systems (provided that all of those system support UEFI, of course).
> 
> 
> 
> ...



I understand that the MS-DOS partitioning format is not ideal, but I'm working with an older machine (2014) that is a sandbox that holds other 
drives. 

I installed FreeBSD by copying its ISO to a usbkey. I installed on a separate disk (a 2.5" disk adapted to a 3.5" bay. Earlier attempts to install
FreeBSD failed because the adapter was faulty. When I used a different one, things went much better). If worse comes to worse I'll sacrifice 
what's on one the other 3.5" drives and install FreeBSD on it.

I did a default installation rather than customize partttions (I normally run a dozen). This created a /root primary slice and a swap  slice. I was 
able to mount (ro) the /root slice on a Linux mount point and found that /root/boot/ contained a MBR file. This location struck me as odd, but I
 suppose it is accessible to BIOS. 

Parsed is a Linux utility that can see UTF  whatever that means. In any case, I used it to display the FreeBSD /root partition and saw that
its the Flag field was empty. So I used parted to toggle the Flag to boot. The slice now shows up as bootable. Why wouldn't a default installation
have made it bootable in the first place?

After I set the bootable flag, the result of trying to boot FreeBSD changed. Before BIOS did not see the disk as bootable and simply skipped it 
and went on to the next bootable disk. After setting the boot flag on FreeBSD's /root slice the disk is now seen, but the boot process hangs with 
a  blinking cursor at UL of black screen.  Unsure what this means. Is it that the disk is seen to have a bootable partition, but there is nothing
there to boot?


----------



## Emrion (Sep 30, 2020)

The bootable flag you speak of is the second stage of the MBR booting process. Before, the BIOS must load the MBR sector if it has the "magic number" 0xaa55 at its end. And, if it is the case (and it should be), the control is given to the MBR program. This is why I think it's the MBR program who fails (if it's boot0 which has been installed).

If you make a new install with a GPT scheme as *T-Daemon* say, the pmbr program should work (no multiboot inside). You can also try to put /boot/mbr (also no multiboot) as *chrbr* advised.

Well, at least, you have to try.


----------



## T-Daemon (Sep 30, 2020)

Haines said:


> I understand that the MS-DOS partitioning format is not ideal, but I'm working with an older machine (2014)


I'm running multiple OS's on different disks, exclusively on GPT schemes on a 2011 machine. There is no reason not to choose GPT on a 2014 machine.


----------



## a6h (Sep 30, 2020)

Haines said:


> his created a /root primary slice and a swap slice.


By `/root` do you mean `/` ?


Haines said:


> Parsed is a Linux utility that can see UTF whatever that means


OT: Time to time I have to mount a FreeBSD UFS on Debian. Then I always fsck such UFS on FreeBSD. Sometimes you'll be surprised by the result!


Haines said:


> but the boot process hangs with a blinking cursor at UL of black screen.


Than means you destroyed boot loader.
My suggestion: start again. I know you're using BIOS. That's OK. In the installation choose GPT, select custom and create three partitions: /boot, / and swap and don't manipulate UFS slice/partitions with Linux tools. Try a clean BIOS/GPT install and report back.


----------



## Haines (Sep 30, 2020)

chrbr said:


> Dear Haines,
> may be the boot code has not been installed. With your setup as ada2 it should be done by `gpart bootcode -b /boot/mbr ada2`. I refer to http://www.wonkity.com/~wblock/docs/html/disksetup.html. The MBR setup is documented in the last section. In my opinion all the other docs are perfect, too.



When you say "boot code" are you referring to the MBR code? I found it difficult to infer the command from the document you referenced. In any case I tried  
# gpart boot-code - b /boot/mbr ada2.  This was not a valid command, perhaps because I ran it from Linux. In linux gpart man, there is no mention of boot-code 
option.  The command sounds like it would copy /boot/mbr to ada2 (or /dev/sdb; I tried both).

Why wouldn't a default installation of FreeBSD take care of MBR if I specifed the filesystem to be MS-DOS?


----------



## olli@ (Sep 30, 2020)

Haines said:


> Why wouldn't a default installation of FreeBSD take care of MBR if I specifed the filesystem to be MS-DOS?


Because that is the wrong thing to do.  MS-DOS is an operating system of the previous century and has nothing to do with FreeBSD.
FreeBSD will *not* work when installed in an MS-DOS filesystem (a.k.a. FAT).


----------



## chrbr (Oct 1, 2020)

Haines said:


> # gpart boot-code - b /boot/mbr ada2. This was not a valid command, perhaps because I ran it from Linux. In linux gpart man, there is no mention of boot-code
> option. The command sounds like it would copy /boot/mbr to ada2 (or /dev/sdb; I tried both).


Basically the command does what you expect. But /boot/mbr must be available. Usually you boot a FreeBSD medium as a installer or thumb drive. There you will find the file. Since you mention Linux - may be it can be compared to the former times where the first stage of the Linux boot loader LILO could be installed in the MBR. Regarding the file system FAT can be read or write by FreeBSD. If you run the intstaller you see the available options UFS and ZFS. UFS is rock solid while ZFS requires more resources depending which options are activated. If you do not have ancient hardware (Pentium4 or so) and your applications to not require all the RAM please try ZFS and use the GPT partitioning scheme. If you decide to stick to MBR than check the difference in the naming of partitions. In FreeBSD are slices and partitions which is confusing when you come from the Linux world.

Basically it is a very good approach to use one disk for FreeBSD. Then testing various options reduces the risk to mess up the booting of other operating systems. I am confident that you will find a good setup for your needs.


----------



## Haines (Oct 1, 2020)

vigole said:


> By `/root` do you mean `/` ?
> 
> My suggestion: start again. I know you're using BIOS. That's OK. In the installation choose GPT, select custom and create three partitions: /boot, / and swap and don't manipulate UFS slice/partitions with Linux tools. Try a clean BIOS/GPT install and report back.



Thanks, that worked. I had no idea that if a MB is set up for legacy BIOS it could support GPT drives. In any case, I managed to install and boot the system successfully


----------



## olli@ (Oct 2, 2020)

Haines said:


> Thanks, that worked. I had no idea that if a MB is set up for legacy BIOS it could support GPT drives.


As was mentioned earlier in this thread, FreeBSD installs a so-called “protective MBR” when a GPT is used, so the disk can be booted by an old BIOS that doesn’t support GPT. Therefore there is really no reason to avoid GPT.

Also, I’d like to stress what vigole said above: Do not manipulate the disk with Linux tools. It will likely cause breakage, because Linux knows practically nothing about FreeBSD’s boot stages. A notable exception is UEFI: There should be no problem editing the UEFI boot variables or the ESP partition with Linux (e.g. for changing the UEFI boot options or adding Linux to the UEFI boot selection) because this is an OS-independent standard.


----------

