16

Currently I have the entire disk /dev/sda formatted as ext4, and installed Gentoo.

(There is no MBR, no partition at all. )

But finally, I can't install GRUB on it, because it seems like GRUB needs to write to MBR.

# grub-install /dev/sda
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
The file /boot/grub/stage1 not read correctly. 

neither does grub work,

# grub
grub> root (hd0)
 Filesystem type unknown, using whole disk

grub> setup (hd0)
 Error 17: Cannot mount selected partition

Any way can I install GRUB into the /dev/sda without MBR?

P.S. The /boot directory and grub.conf files:

# tree /boot 
/boot
|-- boot -> .
|-- grub
|   |-- default
|   |-- device.map
|   |-- e2fs_stage1_5
|   |-- fat_stage1_5
|   |-- ffs_stage1_5
|   |-- grub.conf
|   |-- iso9660_stage1_5
|   |-- jfs_stage1_5
|   |-- menu.lst -> grub.conf
|   |-- minix_stage1_5
|   |-- reiserfs_stage1_5
|   |-- splash.xpm.gz
|   |-- stage1
|   |-- stage2
|   |-- stage2_eltorito
|   |-- ufs2_stage1_5
|   |-- vstafs_stage1_5
|   `-- xfs_stage1_5
`-- kernel-2.6.36-gentoo-r5

# cat /boot/grub/grub.conf
default 0
timeout 30
splashimage=(hd0)/boot/grub/splash.xpm.gz

title Gentoo Linux 2.6.36-r5
root (hd0)
kernel /boot/kernel-2.6.36-gentoo-r5 root=/dev/sda

title Gentoo Linux 2.6.36-r5 Rescue
kernel /boot/kernel-2.6.36-gentoo-r5 root=/dev/sda init=/bin/bb

# cat /boot/grub/devices
(fd0)   /dev/fd0
(hd0)   /dev/sda
strugee
  • 14,723
  • 17
  • 73
  • 119
Lenik
  • 543
  • 1
  • 10
  • 20
  • It will be helpful if you can include the command that you used and the error message that you got when trying to install. For example, have you tried `grub-install /dev/sda`? – phunehehe Dec 27 '10 at 13:05
  • I have already recreated the disk layout with MBR, and copied the raw file system into the single partition of the disk. Though, I'll retry a new Gento installation and paste the error message some time later. Thanks – Lenik Dec 27 '10 at 16:51
  • **EDIT** I've added the error message. – Lenik Dec 28 '10 at 03:34

3 Answers3

7

The BIOS reads the first sector (512 bytes) of the disk and branches into it. If your disk contains PC-style partitions, the first sector also contains the partition table. If your disk contains a single filesystem, the first sector contains whatever the filesystem decides to put there. In the case of ext[234] (and many other filesystems), the first sector¹ is reserved for the bootloader (and is initially zeroed out). You can install Grub on /dev/sda.

That being said, there are occasional BIOSes that refuse to boot from a device that don't contain a partition table. (But there are also BIOSes that refuse to boot from some external devices if they do contain a partition table!) If you have one of these BIOSes, you'll have to create a partition table.

Even if a partition table is not necessary, it's recommended. You only waste a few kilobytes, and gain readability under many non-Linux OSes and less surprise for any co-sysadmin. If you accidentally plug your disk into a machine running Windows, it might suggest you to reformat the disk if it doesn't see a partition table, whereas it'll just complain it can't read the data if it sees a partition table with a partition type it doesn't recognize.

¹ In fact, the first block, I think, where a block is 1kB, 2kB or 4kB depending on the options passed to mkfs.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 5
    It's used by the guest Gentoo OS in VirtualBox. I have created a .vmdk virtual disk which back-end by a raw `image.ext4`. The reason I use the entire disk for one file system is that, I want to mount the volume directly in the host OS, without the tricky partition offset like `-o loop,offset=1048576` . – Lenik Dec 27 '10 at 13:56
  • 1
    In a related case, we have FC disks attached to a system. These are meant as JBOD for use by a database or LVM, intended to be partitionless. When re-installing Grub with `--recheck`, it's going to update its map table with with those partition-less drives, then complain when it cheks their non-existing partition table. If I remove these drive paths from the map file, the warning goes away. – Otheus Nov 24 '15 at 13:00
2

Its not mandatory that GRUB needs to be written to MBR. You can install it on partition boot sector and let the other boot loader from MBR load it, such as Windows 7 loader.

http://www.linuxselfhelp.com/gnu/grub/html_chapter/grub_3.html

Madhur Ahuja
  • 1,501
  • 3
  • 12
  • 14
0

Just about everything expects a partition table. I think you will have to re-install, and follow the suggested guidelines of having at least a /boot, swap, and /root partition. Where's your swap?

Keith
  • 7,828
  • 1
  • 27
  • 29
  • 5
    Linux doesn't care. Most BIOSes don't care (though some do). Separate swap and boot partitions are not necessary, and `/boot` is no longer recommended on modern hardware (it was a kludge to bypass BIOS limitations on disk sizes and lack of support for advanced disk modes such as LVM in Grub 1). – Gilles 'SO- stop being evil' Dec 27 '10 at 12:39
  • @Gilles You mean, I can have LVM without a separated `/boot`? If so, why is it better to leave `/boot` in the same partition as `/`? – phunehehe Dec 27 '10 at 13:01
  • 2
    @phunehehe: You can have LVM without a separate `/boot` with Lilo or Grub 2, but not with Grub 1. A separate `/boot` has an administrative cost (you need to make one more partition, and you need to be careful not to mix up `/boot` with `/`), so you would only use one if there's a reason (such as your bootloader not understanding LVM). – Gilles 'SO- stop being evil' Dec 27 '10 at 13:08
  • 1
    @Gilles now you make me feel like reinstalling... – phunehehe Dec 27 '10 at 16:57
  • 1
    You can also have things like whole disk encryption :) – XTL Mar 20 '12 at 09:13