WD-MyBook - OpenWRT disabling mdadm

Hello:

My WD MyBook / OpenWRT 21.02.02 installation is a one trick pony so to speak, the basic one HDD version.

Like I have mentioned before (being a hard drive install) I have added/been able to add a number of packages that make OpenWRT more useful/flexible, a work in progress.

Looking at the dmesg output, I see the following lines:

--- snip ---
[    0.853468] md: Waiting for all devices to be available before autodetect
[    0.860251] md: If you don't use raid, use raid=noautodetect
[    0.866370] md: Autodetecting RAID arrays.
[    0.870475] md: autorun ...
[    0.873264] md: ... autorun DONE.
--- /snip ---

Being a one drive setup it would seem that it has no use for md (?), which I would then like to disable.

But I cannot find where to add the "raid=noautodetect" stanza.
Looking around the forum, I found a way to query init scripts here, so I checked:

root@OpenWrt:~# for F in /etc/init.d/* ; do $F enabled && echo $F on || echo $F **disabled**; done
/etc/init.d/avahi-daemon on
/etc/init.d/boot on
/etc/init.d/cron on
/etc/init.d/dbus on
/etc/init.d/done on
/etc/init.d/dropbear on
/etc/init.d/firewall on
/etc/init.d/fstab on
/etc/init.d/gpio_switch on
/etc/init.d/led on
/etc/init.d/lm-sensors on
/etc/init.d/log on
/etc/init.d/mdadm on          # <--- here it is
/etc/init.d/network on
/etc/init.d/rpcd on
/etc/init.d/rsyncd **disabled**
/etc/init.d/sudo on
/etc/init.d/sysctl on
/etc/init.d/sysfixtime on
/etc/init.d/sysfsutils on
/etc/init.d/sysntpd on
/etc/init.d/system on
/etc/init.d/ucitrack on
/etc/init.d/uhttpd on
/etc/init.d/umount **disabled**
/etc/init.d/urandom_seed on
/etc/init.d/urngd on
/etc/init.d/vsftpd on
/etc/init.d/wpad on
root@OpenWrt:~#

Being a daemon, I can also query as to its status, start and stop it:

root@OpenWrt:~#  /etc/init.d/mdadm status 
running
root@OpenWrt:~#

So the question would be:
Being a one HDD installation, does Open WRT need mdadm to boot and work properly?
ie: can I disable mdadm without issues?

Thanks in advance.

Best,

JHM

The 'raid=noautodetect' option is a command line option. Maybe you can add it in the u-boot environment. But, as you can see in the bootlog, it will only save you 20 msec boottime.

When you didn't use raid containers, you don't need mdadm. Having just a single disk doesn't automatically imply that. It's perfectly possible to have a single disk raid1 array, or something like that.

Hello:

Yes, dmesg indicates just that.

Probably, but have not found how.
Hence my question.

But my motive for disabling mdadm has no relation to boot time.
It is related to the object of starting and running a daemon for which there is no need/use whatsoever.

That was the general idea, thanks for clearing it up.
So I can disable the mdadm daemon?

I've never come across such a thing.

As far as I know, a raid1 array is a mirrored data operation.
ie: a minimum of two disks: one a mirror (exact copy) of the other.
Cannot see how that could be done with just one disk.

Be that as it may, the WD-MyBook has very limited resources so (IMO) turning off unneeded services is the only way to make the most of them.

Thank you for your input.

Best,

JHM

fw_setenv command, or setenv via serial.

Hello:

I see.
Never bothered with a serial port mod.
Seemed too much of a hassle/complication/risk as everything was 'on disk'.
That plus disassembly/assembly of the WD-MyBook to take out the drive and hang it from my main box eventually became easy enough.

So ...

That would be:
root@OpenWrt:~# fw_setenv raid=noautodetect ?

Thanks for your input.

Best,

JHM

Try fw_printenv 1st

No. Using fw_printenv you can see the current environment. There is a variable 'cmdline' which has to be expanded with raid=noautodetect.

It's not a daemon which keeps running. It's a procedure in the kernel which runs once, for autodetect, and when it says 'autorun DONE' it's really done.

At some level a raid array is no more than a header on a partition. mdadm reads that header and tells the kernel to find the filesystem at an offset (header size) of the partition. (Mdadm isn't there to stay, it just reads the headers and assambles the raid arrays. Exit mdadm. Unless you run it in daemon mode, in which case it sends you an email if something goes wrong).
The purpose of a single disk raid1 array is either to be able to add a second disk in future, or to keep the firmware simple and simply put all data partitions in a raid array, no matter what.

Hello:

Right ...

root@OpenWrt:~# fw_printenv
Cannot parse config file '/etc/fw_env.config': No such file or directory
root@OpenWrt:~#

Seems uboot-envtools has not been configured.(?)

Thanks for your input.
Best,

JHM

Hello:

See above.

Is there a manfile for that?

I see.
But it was 'on' and now it is 'disabled'.
Just like wpad, which I did not need.
(see OP)

root@OpenWrt:~# for F in /etc/init.d/* ; do $F enabled && echo $F on || echo $F **disabled**; done
/etc/init.d/avahi-daemon on
/etc/init.d/boot on
/etc/init.d/cron on
/etc/init.d/dbus on
/etc/init.d/done on
/etc/init.d/dropbear on
/etc/init.d/firewall on
/etc/init.d/fstab on
/etc/init.d/gpio_switch on
/etc/init.d/led on
/etc/init.d/lm-sensors on
/etc/init.d/log on
/etc/init.d/mdadm **disabled**         # <--- here it is
/etc/init.d/network on
/etc/init.d/rpcd on
/etc/init.d/rsyncd **disabled**
/etc/init.d/sudo on
/etc/init.d/sysctl on
/etc/init.d/sysfixtime on
/etc/init.d/sysfsutils on
/etc/init.d/sysntpd on
/etc/init.d/system on
/etc/init.d/ucitrack on
/etc/init.d/uhttpd on
/etc/init.d/umount **disabled**
/etc/init.d/urandom_seed on
/etc/init.d/urngd on
/etc/init.d/vsftpd on
/etc/init.d/wpad **disabled**
root@OpenWrt:~#

I see.
Learned something new today.
Thanks for that. 8^)

Best,

JHM

That are two different things. The 'raid autodetect' runs in the kernel, even before the rootfs is mounted. (The rootfs might be on the 'to be detected' array). mdadm is a tool which runs in userspace, to assemble&maintain raid arrays which are not autodetected.
That is also the reason that you have to switch it off in the kernel command line. It cannot be a config file, because there are no files, yet.

Probably. Strange that uboot-envtools are included in the image, then. Unfortunately the wiki doesn't tell how the flash is organized. Normally there is a (ro) flash partition of 128~256kB containing u-boot, followed by a (rw) partition of 8~64kB containing the environment. uboot-tools need to know which flash device to use, at which offset, and which size. And that is defined in /etc/fw_env.config.

cat /proc/mtd should tell you how to set up the conf file, or just search the forum for fw_env.config.

Hello:

I'm afraid not:

root@OpenWrt:~# cat /proc/mtd
dev:    size   erasesize  name
root@OpenWrt:~#

Looking ...

I found this.

The entries I see in the example are:
NOR example
MTD SPI-dataflash example
MTD device name
NAND example
Block device example
VFAT example
UBI volume
UBI volume by name

From what I can see (and understand) the only possiblilities are either in /dev or /boot but none of the examples are present in /dev:

root@OpenWrt:~# ls /dev | grep mtd* | grep mmc* | grep ubi*
root@OpenWrt:~#

What I do see in /dev are sda, /sda1, /sda2 and /sda3.
ie: my HDD partitions

With respect to /boot:

root@OpenWrt:/boot# ls
boot        lost+found
root@OpenWrt:
root@OpenWrt:/boot/boot# ls
apollo3g.dtb  boot.scr      uImage
root@OpenWrt:

But nowhere can I find how to add raid=noautodetect to the kernel cmd line.

It's not important but now I am getting curious what fw_env.config has to do with it.

Thanks for your input.
Best,

JHM

Hello:

I think I found the where ...

root@OpenWrt:/boot/boot# ls
apollo3g.dtb  boot.scr      uImage
root@OpenWrt:/boot/boot#
root@OpenWrt:/boot/boot# cat boot.scr
^�.�T�� Boot Script&setenv boot_args 'setenv bootargs root=/dev/sda2 rw rootfstype=squashfs,ext4'
setenv load_part1 'ext2load sata 0:1 ${kernel_addr_r} /boot/uImage; ext2load sata 0:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_part2 'ext2load sata 1:1 ${kernel_addr_r} /boot/uImage; ext2load sata 1:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_sata 'sata init; if run load_part1; then echo Loaded part 1; elif run load_part2; then echo Loaded part 2; fi'
setenv boot_sata 'run load_sata; run boot_args addtty; bootm ${kernel_addr_r} - ${fdt_addr_r}'
run boot_sata
root@OpenWrt:/boot/boot#

... but not the how.

The first line in boot.scr, preceded by some code, is the kernel command line:

'setenv bootargs root=/dev/sda2 rw rootfstype=squashfs,ext4'

I'm quite sure that this is not a *.txt file that can be edited via nano or jed.
But that's where the stanza raid=noautodetect has to be added.

Is there an editor or utility to do this?
Thanks in advance.

Best,

JHM

boot.src is a script file handled by u-boot. As most files handled by u-boot it is preceded by a 64 byte header, containing the purpose, a name ('Boot Script' in your case) and a checksum.
You can create your own boot.scr using mkimage:
mkimage -A powerpc -O linux -T script -C none -a 0 -e 0 -n 'Boot Script' -d plain.txt boot.scr
I think your plain text starts with the setenv after the '&'.
mkimage is part of uboot-tools. 'Boot Script' can be anything, the name is not used by u-boot, only printed to console.
You can strip the plain text with the command
tail -c +64 boot.scr

Hello:

I see.

Something new I learned today.
Thanks.

Right ...

Q1: all the content ie: purpose, name and checksum result from the mkimage above?

So it would be done in three steps:

  1. strip the text as indicated.
  2. edit the line/text containing the relevant kernel commands and save.
  3. generate a new version of boot.scr with the mkimage stanza above.

Q2: does the *.scr file have room for any sort of # comments?

I'll know for sure when I strip the text.

So I could change the name to boot2.scr without any effect?

Right.

Thank you very much for taking the time to explain how to do this.
Much obliged.

I'll do it this week and report the results, hopefully usefull to the dozen or so owners of a WD-MyBook out there who have not given up and finally thrown it into a skip. 8^D

Best,

JHM

Hello:

root@OpenWrt:~# opkg install uboot-tools
Unknown package 'uboot-tools'.
Collected errors:
 * opkg_install_cmd: Cannot install package uboot-tools.
root@OpenWrt:~#

The only available uboot-<whatever> package I have found is uboot-envtools, so I installed it.
But ...

root@OpenWrt:/home/groucho/boot# mkimage -A powerpc -O linux -T script -C none -a 0 -e 0 -n 'Boot Script'-T script -C none -a 0 -e 0 -n 'Boot Script' -
d plain.txt boot.scr
-ash: mkimage: not found
root@OpenWrt:/home/groucho/boot#

Seems that uboot-envtools is not the same thing as 'uboot-tools'?
What should I do now?

Thanks in advance,
Best,

JHM

Right. I took a look, and it seems uboot-tools is not available as package on OpenWrt, and uboot-envtools is a subset of that. The envtools contain fw_printenv and fw_setenv, tools which have to be run on the router itself. The other tools can be run on another platform. I suppose for that reason nobody cared to package it for the size-constrained OpenWrt.
Further, the name of the package on Debian is u-boot-tools.

The most obvious work-around is to install u-boot-tools on your favorite non-OpenWrt Linux box and create the boot.scr there.

Hello:

Thanks a lot.
Really appreciate your doing so.

Makes sense.
And Openwrt on a WD-MyBook is a rather strange animal.
But then, one that has proven to be up to the task.

I was wondering if it would be available as a Debian package.

Indeed.

I'll do that and report the result.
Once again, thank you very much for your help with this.

Best,
JHM

Hello:

Done.
Almost, but no cigar ... 8^/
It did not (complete) the boot sequence.

Here's what I did:

Took the original boot.scr and stripped the plain.txt:

Original plain.txt from original boot.scr:

&setenv boot_args 'setenv bootargs root=/dev/sda2 rw rootfstype=squashfs,ext4'
setenv load_part1 'ext2load sata 0:1 ${kernel_addr_r} /boot/uImage; ext2load sata 0:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_part2 'ext2load sata 1:1 ${kernel_addr_r} /boot/uImage; ext2load sata 1:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_sata 'sata init; if run load_part1; then echo Loaded part 1; elif run load_part2; then echo Loaded part 2; fi'
setenv boot_sata 'run load_sata; run boot_args addtty; bootm ${kernel_addr_r} - ${fdt_addr_r}'
run boot_sata

Edited to add raid=noautodetect:

&setenv boot_args 'setenv bootargs root=/dev/sda2 rw rootfstype=squashfs,ext4 raid=noautodetect'
setenv load_part1 'ext2load sata 0:1 ${kernel_addr_r} /boot/uImage; ext2load sata 0:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_part2 'ext2load sata 1:1 ${kernel_addr_r} /boot/uImage; ext2load sata 1:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_sata 'sata init; if run load_part1; then echo Loaded part 1; elif run load_part2; then echo Loaded part 2; fi'
setenv boot_sata 'run load_sata; run boot_args addtty; bootm ${kernel_addr_r} - ${fdt_addr_r}'
run boot_sata

I then made a new image in my Devuan box:

groucho@devuan:~/Desktop/WD-MRB$ 
groucho@devuan:~/Desktop/WD-MRB$ mkimage -A powerpc -O linux -T script -C none -a 0 -e 0 -n 'Boot Script' -d plain.txt boot.scr
Image Name:   Boot Script
Created:      Tue Aug 29 12:59:53 2023
Image Type:   PowerPC Linux Script (uncompressed)
Data Size:    577 Bytes = 0.56 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 569 Bytes = 0.56 KiB = 0.00 MiB

Verified it was created:

groucho@devuan:~/Desktop/WD-MRB$ ls
 boot.scr   plain.txt  'tail -c +64.txt'
groucho@devuan:~/Desktop/WD-MRB$

Had a look at it:

groucho@devuan:~/Desktop/WD-MRB$ cat boot.scr
'V]��d��ArU܇Boot Script9&setenv boot_args 'setenv bootargs root=/dev/sda2 rw rootfstype=squashfs,ext4 raid=noautodetect'
setenv load_part1 'ext2load sata 0:1 ${kernel_addr_r} /boot/uImage; ext2load sata 0:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_part2 'ext2load sata 1:1 ${kernel_addr_r} /boot/uImage; ext2load sata 1:1 ${fdt_addr_r} /boot/apollo3g.dtb'
setenv load_sata 'sata init; if run load_part1; then echo Loaded part 1; elif run load_part2; then echo Loaded part 2; fi'
setenv boot_sata 'run load_sata; run boot_args addtty; bootm ${kernel_addr_r} - ${fdt_addr_r}'
run boot_sata
groucho@devuan:~/Desktop/WD-MRB$

I then ftp'd as root to the WD-MBL, renamed the original boot.scr to boot.bak and copied the new boot.scr to /boot/boot.

But the boot sequence did not complete.

Cannot figure out what I did wrong.
Could it be that my box is 64bit?.
Any ideas?

Thanks in advance.

Best,

JHM

That first & does not belong to the plaintext.
And no, the platform on which mkimage runs doesn't matter. It's a simple tool to create a header, nothing fancy.