Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 609406 - setup_md_device in /init script within initramfs and mdadm
Summary: setup_md_device in /init script within initramfs and mdadm
Status: RESOLVED CANTFIX
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-15 11:11 UTC by Vieri
Modified: 2019-12-28 14:54 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch for linuxrc (linuxrc.patch,479 bytes, patch)
2017-02-15 11:54 UTC, Vieri
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vieri 2017-02-15 11:11:48 UTC
There is an issue with Genkernel's initramfs when using RAID devices. When I build the image, I pass genkernel an mdadm.conf with the raid sets as I want them numbered.

I cannot boot because init is unable to mount ROOT.

I'm booting with GRUB and I specify my RAIDed real_root on the kernel cmdline.

The problem is that the /init script calls the setup_md_device before calling mdadm within the startVolumes function.

In turn, setup_md_device reads the REAL_ROOT variable (/dev/md5 in my case) and creates the node since there are no md devices at startup.
It runs:

mknod /dev/md5 b 9 5 
mdstart  /dev/md5

I don't know how the last command works (mdstart), but it causes all the other raid devices to autostart. I immediately see these md devices:

/dev/md124
/dev/md126
/dev/md4
/dev/md5 

where /dev/md124 is the real ROOT, /dev/md126 is /boot, /dev/md5 is noting.
 
So I patched the /init script with:

[ "${USE_MDADM}" != 1 ] && setup_md_device

but maybe a better option would be to do something like:

if [ "${USE_MDADM}" != 1 ] || [ ! -e /etc/mdadm.conf ]; then
  setup_md_device
fi

When I boot with this custom initramfs I can finally get to the login prompt and my RAID sets are correctly numbered.

# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0] [raid1] [raid10] [linear] [multipath]
md5 : active raid1 sda5[0] sdb5[1]
      196241920 blocks [2/2] [UU]
      bitmap: 2/2 pages [8KB], 65536KB chunk

md4 : active raid1 sda4[0] sdb4[1]
      37033920 blocks [2/2] [UU]

md3 : active raid1 sda3[0] sdb3[1]
      524224 blocks [2/2] [UU]

md1 : active raid1 sda1[0] sdb1[1]
      1984 blocks [2/2] [UU]

unused devices: <none>

# cat /etc/mdadm.conf
ARRAY /dev/md1 metadata=0.90 UUID=9f998969:ad1c2cdc:c44c77eb:7ee19756
ARRAY /dev/md3 metadata=0.90 UUID=4874966d:031521b4:c44c77eb:7ee19756
ARRAY /dev/md4 metadata=0.90 UUID=c387f968:cec279b4:c44c77eb:7ee19756
ARRAY /dev/md5 metadata=0.90 UUID=1597ab49:c0c079f2:c44c77eb:7ee19756 

# genkernel --version
3.4.52.4

# genkernel --mdadm --mdadm-config=/etc/mdadm.conf initramfs
Comment 1 Vieri 2017-02-15 11:54:56 UTC
Created attachment 463814 [details, diff]
patch for linuxrc
Comment 2 Vieri 2017-02-15 12:24:51 UTC
I just realized that mdstart is a Gentoo patch for busybox.
It makes the call:

ioctl(fd, RAID_AUTORUN, part);

That seems to be causing me trouble.
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2019-12-28 14:54:55 UTC
Controlling name in /dev top level directory is not support.
Use /dev/md/<your-desired-name> instead. I.e. booting with

$ cat /etc/mdadm.conf
ARRAY /dev/md/boot metadata=1.0 name=gentoo-test-vm:boot UUID=b23a10ab:9dc12e17:cd7586dd:a42dbef8
ARRAY /dev/md/123 metadata=1.2 name=gentoo-test-vm:data UUID=0b153d25:ab%21216:4144798f:052b1b49

will create 

/dev/md/boot and /dev/md/123.