Other Where am I booting from?

I have been setting up a multiboot hard disk which has numerous boot options which were launched from a Grub menu.
After creating a linux-data partition and formatting it as ext3, I copied the contents of a Ubuntu ISO file to this partition and added the appropriate Grub Menuentry, and Ubuntu loaded up without any problems. However after rebooting the Grub menu no longer appears, but instead the system up straight to Windows PE!

How do I figure out where the system is booting from?

Here is the disk layout of /dev/da0 :-
Code:
=>       40  625142368  da0  GPT  (298G)
         40       1024    1  bios-boot  (512K)
       1064    4194304    2  freebsd-ufs  (2.0G)
    4195368   10485760    3  freebsd-ufs  (5.0G)
   14681128   10485760    4  linux-data  (5.0G)
   25166888        984       - free -  (492K)
   25167872      32768    5  linux-data  (16M)
   25200640   10485760    6  linux-data  (5.0G)
   35686400   20971520    7  linux-data  (10G)
   56657920  104857600    8  ms-basic-data  (50G)
  161515520    1048576    9  freebsd-ufs  (512M)
  162564096    2097152   10  freebsd-ufs  (1.0G)
  164661248    2097152   11  freebsd-ufs  (1.0G)
  166758400  104857600   12  freebsd-ufs  (50G)
  271616000   10485760   13  ms-basic-data  (5.0G)
  282101760    2097152   14  freebsd-ufs  (1.0G)
  284198912    8388608   15  freebsd-swap  (4.0G)
  292587520    4194304   16  freebsd-ufs  (2.0G)
  296781824  146800640   17  freebsd-ufs  (70G)
  443582464    2097152   18  linux-data  (1.0G)
  445679616    4194304   19  linux-data  (2.0G)
  449873920    6291456   20  linux-data  (3.0G)
  456165376       2048       - free -  (1.0M)
  456167424  168974984   21  linux-data  (81G)


My grub.cfg is at /dev/da0p4/boot/grub and remains unchanged.

My system is a Lenovo ThinkPad X220 and I use the ThinkVantage button on startup to select the boot device from the list.

How do I check what I have in my boot sector?
 
Is there any way to tell if gpart's /boot/pmbr has been overwritten?

Something has mysteriously changed the boot behaviour, and am not sure where to look,,
 
I speak from total ignorance.
Is MBR overwritten with /boot/pmbr with each boot?, could you dump MBR with dd and diff with /boot/pmbr?
 
Is MBR overwritten with /boot/pmbr with each boot?
No. That's what you use gpart bootcode for.
could you dump MBR with dd and diff with /boot/pmbr?
Theoretically, yes. /boot/pmbr is a complete 512 byte Master Boot Record image. At the end of the MBR is a partition table with 4 entries, they are nulled in /boot/pmbr. So, you must only compare the first 446 bytes, that contain the actual first-stage bootcode, e.g. like this:
Code:
dd if=/dev/ada0 bs=512 count=1 | head -c 446 >/tmp/bootcode
head -c 446 /boot/pmbr | diff - /tmp/bootcode
 
  • Thanks
Reactions: a6h
If you want to read the GPT, sure, but you asked about comparing the bootcode. GPT is backwards-compatible, the MBR still exists. Also note half of the GPT is stored at the END of the disk, so just reading 64 blocks from the start would be wrong anyways.
 
When I boot up from a particular disk it comes up with the Windows 10 logo and brings up a Windows cmd shell. I have no idea how or from where this launched. I previously had a Grub menu with a list of bootable partitions. I can't even figure out where this Windows installation resides on the disk.
Maybe a rogue Grub has been installed... I can access the disk by booting FreeBSD from another disk, but don't see anything untoward.

Any suggestions as to where to look would be welcomed...
 
Windows 10 logo and brings up a Windows cmd shell.
That means you're in rescue/fix mode, i.e. broken Windows. We need more info. List of slices/partition, order of installation, etc. Your initial post doesn't provide enough info.
You've mentioned Grub. I suppose you have some type of multi boot system. Windows, Linux and FreeBSD. please confirm.

If you can boot from FreeBSD Live CD, what's the output of gpart show.
If you stuck in Windows command line, run bcdedit > oi.txt and post the content of text file.

Some additional info may help too. MBR/GPT, order of installation, when/what happend, did you try to fix FreeBSD boot or Linux grub from installation or Live CD, any custom change to windows boot system through command line or third party programs, , ... please be more specific. Thanks.
 
That means you're in rescue/fix mode, i.e. broken Windows. We need more info. List of slices/partition, order of installation, etc. Your initial post doesn't provide enough info.
You've mentioned Grub. I suppose you have some type of multi boot system. Windows, Linux and FreeBSD. please confirm.

If you can boot from FreeBSD Live CD, what's the output of gpart show.
If you stuck in Windows command line, run bcdedit > oi.txt and post the content of text file.

Some additional info may help too. MBR/GPT, order of installation, when/what happend, did you try to fix FreeBSD boot or Linux grub from installation or Live CD, any custom change to windows boot system through command line or third party programs, , ... please be more specific. Thanks.
I don't have Windows installed. What boots up is a Windows cmd shell running 'wpeinit'. I did try running such a thing from one parttion via a Grub menuentry, but couldn't ever get it to work.

I have been adding partitions to this disk and booting various OSes via Grub menuentries. The last thing I added was Ubuntu and that booted fine, but have now deleted that partition thnking that may have been the cause of the problem.
gpart show da0:-
Code:
         40       1024    1  bios-boot  (512K)
       1064    4194304    2  freebsd-ufs  (2.0G)
    4195368   10485760    3  freebsd-ufs  (5.0G)
   14681128   10485760    4  linux-data  (5.0G)
   25166888        984       - free -  (492K)
   25167872      32768    5  linux-data  (16M)
   25200640   10485760    6  linux-data  (5.0G)
   35686400   20971520    7  linux-data  (10G)
   56657920  104857600    8  ms-basic-data  (50G)
  161515520    1048576    9  freebsd-ufs  (512M)
  162564096    2097152   10  freebsd-ufs  (1.0G)
  164661248    2097152   11  freebsd-ufs  (1.0G)
  166758400  104857600   12  freebsd-ufs  (50G)
  271616000   10485760   13  ms-basic-data  (5.0G)
  282101760    2097152   14  freebsd-ufs  (1.0G)
  284198912    8388608   15  freebsd-swap  (4.0G)
  292587520    4194304   16  freebsd-ufs  (2.0G)
  296781824  146800640   17  freebsd-ufs  (70G)
  443582464    2097152   18  linux-data  (1.0G)
  445679616    4194304   19  linux-data  (2.0G)
  449873920  175268488       - free -  (84G)
 
For FreeBSD, I only use boot0 -- more info: boot0cfg(8). I can't help you with FreeBSD sysutils/grub or sysutils/grub2. Never done that, and I'm pretty sure both are broken.
The only way I can think of: you've mentioned Ubuntu, and I suppose you have an Ubuntu Live CD/USB around. I can't get my head around your partition scheme, though.
But following method will install a Linux Grub (grub2 I suppose). IIRC, I copied it from Ubuntu docs and used it to fix Arch! I ^C/^V it from my notes. Change it to reflect your setup.
Do on your own risk, you've been warned.

Find your Linux installtion (UBUNTU?) e.g. /dev/sda20
/dev/sdXY
X: drive
Y: partition

mount /dev/sda20 /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
grub-install /dev/sda
grub-install --recheck /dev/sda
update-grub
exit
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt

and reboot.

It will fix your grub, and it should find your Windows too.
Then, go the Linux installation, change whatever need to be changed in the /etc/grub.d/40_custom to add FreeBSD, update and rest of the story.

By the way, in the old days (DOS days plus few years later) it was a fun exercise, to install multiple OSs in 24 partitions (A, B => FDD)
3 primary partition i.e. C, D and E; and IIRC 21 logical partitions on extended partition. Nowadays we have VMs, and it's much easier.
 
After much head scratching and even more trial and error, including deleting /dev/da0p1 (bios-boot) and dding zeros to /devda0 (big mistake! which gpart recover da0 fixed surprisingly) I have discovered that my system boots up from /dev/da0p7 which is type ms-basic-data and runs \windows\system32\startnet.cmd which in turn loads wpeinit.

What I can't figure out is why/how the BIOS decides to load this program. I previously had Grub2 presenting me with a choice of boot options via (I presume) the bios-boot partition, so I initially thought something had embedded itself in this partition, but after deleting it, wpeinit continues to start on boot.

I'm using a ThinkPad X220 and this particular disk (a Hitachi 320GB) will only when I enable UEFI in BIOS.

Should I add a freebsd-boot partition and running /sbin/gpart add -(b 40????) -s 472 -t freebsd-boot da0? Without the '-b' parameter I guess it would add it as the last partition (I already have 19) and would I be able to boot FreeBSD from there? Hopefully I will find a way to restore the Grub2 loader at some point.
 
After creating a linux-data partition and formatting it as ext3, I copied the contents of a Ubuntu ISO file to this partition
Have you run at some point grub-install?

Also you don't need to copy a whole Linux system in that partition to use GRUB2. Found this guide

tested on a spare hard disk:

- installed FreeBSD first
- boot up a linuxmint installer image
- created with gparted a 1G partition after FreeBSD (1G is oversized, grub files are hardly occupying 5M)
- formatted ext3
- sudo mount /dev/sdaX /mnt # replace 'a' with appropriate disk letter, 'X' with partition number
- sudo grub-install --force --root-directory=/mnt /dev/sda # grub-install is complaining it's not possible to embed grub on that partition, but forcing installs grub
- sudo nano /mnt/boot/grub/grub.cfg # added FreeBSD menu entry manually, running grub-mkconfig terminates with error
- sudo umount /mnt
- reboot

GRUB2 boots, executing the FreeBSD menu entry boots the system.
 
Have you run at some point grub-install?
Originally I created my 'Multiboot disk' several years ago using grub-install from Arch Linux. All worked well until last week as I was adding several different boot options, until something broke the boot loader. All I was doing was adding new partitions with various installations and editing grub.cfg on a linux-data partition mounted on FreeBSD.... My attempts to recover the disk have involved trying to recreate the installation on another disk, and whilst trying to install each of Debian, Ubuntu, Void have run grub-install, only to find the disk would not boot.... so not sure if this a 'feature' of trying to install grub on a GPT disk on a ThinkPad X220 which seems problematic for FreeBSD - hence the 'lenovofix' option of gpart.

But I will try what you suggest, maybe it will work... hope so, anyway...
 
I followed your instructions, and thanks for mentioning Linux Mint since it allows me to perform various tasks without actually installing it. Looks like I only need a small amount of space on the Linux partition, and I managed to get Grub2 to boot up. However, it boots up fine on my X1 Carbon, but refuses to boot on the X220, so it remains a mystery why wpeinit can boot up from partition 8 on my original disk...

I guess I should leave this as an unsolved mystery as it has already used up a lot of time, but thanks very much for your help.
 
After solving a boot problem I had with a different disk following advice provided to run hexdump -C -n 512 /dev/da1 I thought someone might be able to suggest what is going wrong here:-

Code:
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001c0  02 00 ee ff ff ff 01 00  00 00 af ea 42 25 00 00  |............B%..|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

This was set up as a multiboot disk and had been working fine using Grub2 on my ThinkPad X220 but it seems the boot sector became overwritten my some rogue program, and now it simply boots straight into a Windows shell program - wpeinit. I can't make any sense at all out of this.

The partition layout is intact. Here it is:-

Code:
=>       40  625142368  da1  GPT  (298G)
         40       1024    1  bios-boot  (512K)
       1064    4194304    2  freebsd-ufs  (2.0G)
    4195368   10485760    3  freebsd-ufs  (5.0G)
   14681128   10485760    4  linux-data  (5.0G)
   25166888        984       - free -  (492K)
   25167872      32768    5  linux-data  (16M)
   25200640   10485760    6  linux-data  (5.0G)
   35686400   20971520    7  linux-data  (10G)
   56657920  104857600    8  ms-basic-data  (50G)
  161515520    1048576    9  freebsd-ufs  (512M)
  162564096    2097152   10  freebsd-ufs  (1.0G)
  164661248    2097152   11  freebsd-ufs  (1.0G)
  166758400  104857600   12  freebsd-ufs  (50G)
  271616000   10485760   13  ms-basic-data  (5.0G)
  282101760    2097152   14  freebsd-ufs  (1.0G)
  284198912    8388608   15  freebsd-swap  (4.0G)
  292587520    4194304   16  freebsd-ufs  (2.0G)
  296781824  146800640   17  freebsd-ufs  (70G)
  443582464    2097152   18  linux-data  (1.0G)
  445679616    4194304   19  linux-data  (2.0G)
  449873920  175268488       - free -  (84G)

I'd be interested to know how this disk boots up from /dev/da1p8...
 
Windows is "infamous" for overwriting any boot setup / configuration you already have on your disk. Solution is simple: install Windows first, the other operating systems after.
If you accidently install Windows after some other operating system, be prepared to fix your boot configuration.
If you can't boot "automatically" into your preferred operating system, you will need to do that manually (for example via a usb stick). Since you use grub, the detailed answer isn't FreeBSD specific.
 
Windows is "infamous" for overwriting any boot setup / configuration you already have on your disk. Solution is simple: install Windows first, the other operating systems after.
If you accidently install Windows after some other operating system, be prepared to fix your boot configuration.
If you can't boot "automatically" into your preferred operating system, you will need to do that manually (for example via a usb stick). Since you use grub, the detailed answer isn't FreeBSD specific.

I have a minimal Windows installation consisting of a small number files copied to da0p8.

What I'm trying to establish is whether my boot partition got trashed by Windows by I launching it from Grub2 with the following Menuentry:-
Code:
Menuentry "Windows  <---------------New TEST ******" {
    insmod part_gpt
    insmod ntfs
    set root=(hd0,8)
    echo    'Loading Windows ...'
    chainloader (${root})/EFI/Boot/bootx64.efi
}
My current boot partition looks like (using hexdump -C -n 512 /dev/da0) :-
Code:
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001c0  02 00 ee ff ff ff 01 00  00 00 af ea 42 25 00 00  |............B%..|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
Has /EFI/Boot/bootx64.efi become embedded in my boot partition?

I guess I can clear it using gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0...

I'm just interested in clarifying, for my own peace of mind, how the disk boots straight into a Windows shell
 
(Note to self...) I guess if change BIOS to legacy only, the disk won't boot... I'll see in a moment....
 
Back
Top