[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] grub-1.98: support for partitionable array v1.2

From: Gaëtan Schmidt
Subject: [PATCH] grub-1.98: support for partitionable array v1.2
Date: Tue, 20 Jul 2010 17:56:46 +0200

I modify grub2 to understand mdadm 1.2 partition array without the need to map 
either the metadevice or the partitions in the file. Just the 
physical devices are required.  As the meta devices are added, they will be 
recognized automatically. Only raid 1 is supported for the moment but it can be 
extended to other layouts.

The patches allow an embedded GPT partition table because the metadata 
superblock is at the beginning of the disk and not at the end like mdadm 1.0.  
GPT has its second header at the end. The partition tools will not complain. 
The first header begins at the first sector of the metadevice. There isn't any 

mdadm 1.1 is not fit to be bootable, its superblock overlaps the boot sector 0. 
Instead, mdadm 1.2 is 4k behind, so you have enough room for the boot image. 
Also fdisk will see a unique EFI GPT ee partition. So, the user is warned that 
the disk isn't empty and has a valid fake dos ee partition.

Parted can be used on the md_dX device to create the embedded GPT partitions 
table. The first partition nests grub core image.

I don't use mdX and md/X syntaxes. md_dX is more relevant because of the mdadm 
default 1.x kernel device scheme /dev/md_dX. So there is no possible confusion 
with mdadm 0.9 devices. (0.9 doesn't support partitions array).

Partitions are named in the grub way: md_dX,Y.

Moreover, partitions can be greater than 2T. Let’s forget dos/bsd partitions 
table for now and switch to gpt :).

I successully booted from a 80, 250, 500 and 640Go disks with that layout. It 
will probably work with a 4k block sector ready disk as well. The portion of 
code that reads/writes block of 4k comes from the mdadm project.

grub-setup.c and grub-probe.c have been heavily altered to understand mdadm 1.2 
partitionable array. That means, grub-setup.c does not support embedded core 
image in the MBR first sectors gap (<64k) anymore.

To avoid any confusion, grub-setup should be renamed grub-mdraid-setup or 
something like that.

Minor changes have been added. For instance, trailing spaces are removed from 
the cmdline parser. A lot of superfluous grub_dprintf have been added to 
understand what is going on.

You can install a gpt bootable partition on a 256Mo and more usb stick with the 
patched grub2 version I propose.

The patches are based on the grub-1.98 release
(source tarball from

For the try and fix version of the patches, please forget it. It is really 
messy. I am using git for the development and i was not able to convert the bzr 
repository to git, so i don't have a valid tree. Anyway, if you are interested 
in it, please let me know.

Please note that the bootloader was built from a bootable rescue stick with a 
working grub2 environment and mdadm binaries, directly on the targeted disks. 
It was not built from a working linux desktop. So you will stay on the right 


as a prerequisite, assembled md raid1 device w/ at least 4 partitions and a 
valid gpt label for md_d0. Physical devices are labeled msdos.
for an hd, p1 (grub_bios) 128kiB; p2 (boot), 128MiB; p3 (root) 1024MiB; p4, ...

for a stick w/o md, a grub_bios of 48kiB is enough

The offset of the gpt 1 partition 17kiB (17,4k reported), alignment is the 
cylinder. Unit is the byte.


cmd() { echo "$@"; }

fun() {
»···local gpath=${ROOT}/boot/grub

»···[ -d ${gpath} ] || cmd mkdir -p ${gpath}

»···local map="${gpath}/"

»···cmd grub-mkdevicemap --no-floppy --verbose --device-map=${map}

»···sed -i 's/grep -qw/grep -q/' /sbin/grub-install # busybox???

»···modules="biosdisk ext2 part_gpt part_msdos raid mdraid configfile search cat
»···cmd grub-install --root-directory=/ --modules="${modules}" \
»···»···»···»···»··· --grub-setup='/bin/true' --debug '(md_d0)'

»···cmd grub-setup -v -r '(md_d0,2)' -d ${gpath} \
»···»···»···»···»···»···»···»···»··· -b boot.img -c core.img '(md_d0)'

»···cmd mkdir -p ${gpath}/fonts ${gpath}/images &&
»···cmd cp /usr/share/grub/* ${gpath}/fonts

»···$GLOBAL GRUB_DEVICE_BOOT="${mdraid}p2"
»···$GLOBAL GRUB_DEVICE="${mdraid}p3"
»···# need a patch
»···cmd grub-mkconfig --output=${gpath}/grub.cfg

grub command,

set root=(md_d0,2)
/boot/vmlinuz root=/dev/md/d0p3 ...

supposing boot is installed in the second partition and rootfs in the third 


Gaëtan Schmidt (1):
  mdadm 1.2 partitions array ready

 disk/i386/pc/biosdisk.c   |    2 +-
 disk/mdraid_linux.c       |  177 +++++++++++++---
 disk/raid.c               |   52 ++++-
 include/grub/disk.h       |    3 +
 include/grub/raid.h       |    2 +
 kern/device.c             |    4 +
 kern/disk.c               |   17 ++-
 kern/fs.c                 |    6 +
 kern/parser.c             |    8 +-
 normal/main.c             |    6 +
 partmap/apple.c           |    4 +-
 partmap/gpt.c             |    9 +-
 util/deviceiter.c         |   19 ++
 util/getroot.c            |   23 +--
 util/      |    2 +-
 util/     |   18 ++-
 util/grub-probe.c         |   13 +-
 util/hostdisk.c           |   15 ++-
 util/i386/pc/grub-setup.c |  502 ++++++++++++++++++++++----------------------
 19 files changed, 563 insertions(+), 319 deletions(-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]