Skip to contentSkip to conversation

kernel cmdline: root=/dev/sdb1,/dev/sda1 "fallback"?

DISCUSSION Tomasz Chmielewski 4 participants 12 messages Jan 17, 2007 – Jan 18, 2007

lore
Share & tools
lore
#0 lore raw

I have a Linux (ARM) device that normally starts from /dev/sda1.

It is configured to do so via a cmdline in a RedBoot bootloader:

root=/dev/sda1

The device is pretty small and has no keyboard, video card etc., so if it ever happens to break (can be a disk failure, but also operator who messed with startup scripts), it has to be opened (warranty!).

These all unpleasant tasks could be avoided if it was possible to have a "fallback" device. For example, consider this hypothetical command line:

root=/dev/sdb1,/dev/sda1

/dev/sdb1 - USB-stick which can boot the device
/dev/sda1 - HDD which normally starts the device

It would mean, that kernel tries to boot the OS from /dev/sdb1, and if there isn't such a device, it tries to boot the OS from /dev/sda1.

In our case, /dev/sdb1 would be an external USB-stick capable to boot the device (in that case, we'd have to add rootdelay= option, too). One would connect it only if he/she wants to service the device.

If /dev/sdb1 is not found by the kernel, the boot would start ("fallback") from /dev/sda1.

Does this make sense?

As I understand correctly, the needed change would have to be done in init/do_mounts.c, around "static int __init do_mount_root" and "void __init mount_block_root"? Any clues on that?

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#1 lore raw
Quoted 1 line · Tomasz Chmielewski

Does this make sense?

Why not add this logic into your initramfs?

Best Regards,
Alon Bar-Lev.

#2 lore raw
Quoted 4 lines · Alon Bar-Lev
Quoted 1 line · Tomasz Chmielewski

Does this make sense?

Why not add this logic into your initramfs?

Because the kernel itself is on a small flash partition (RedBoot executes the kernel from /dev/mtd1), which is only 1572864 bytes big.

So it leaves me only about 300 kB left (kernel is about 1.2 MB) for all tools needed to script such a logic, and it includes all the tools I would need. Another obstacle would be to place the initramfs image on the same partition as the kernel (normally, I dd kernel to /dev/mtd1).

Or perhaps, I don't understand initramfs correctly.

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#3 lore raw
Quoted 2 lines · Tomasz Chmielewski

Another obstacle would be to place the initramfs image on the same partition as the kernel (normally, I dd kernel to /dev/mtd1).

As far as I know you can embed the initramfs into the kernel image using CONFIG_INITRAMFS_SOURCE.

http://www.timesys.com/timesource/initramfs.htm

Best Regards,
Alon Bar-Lev.

#4 lore raw
Quoted 8 lines · Alon Bar-Lev
Quoted 2 lines · Tomasz Chmielewski

Another obstacle would be to place the initramfs image on the same partition as the kernel (normally, I dd kernel to /dev/mtd1).

As far as I know you can embed the initramfs into the kernel image using CONFIG_INITRAMFS_SOURCE.

http://www.timesys.com/timesource/initramfs.htm

The question was rather if
(a) kernel code is cheaper than
(b) userspace

And I say: neither. If things get really tight, write your own init.c, compile with -static and link against uclibc/klibc, and let it hopefully be small enough to fit.

	-`J'
#5 lore raw
In reply to Tomasz Chmielewski
Quoted 9 lines

The device is pretty small and has no keyboard, video card etc., so if it ever happens to break (can be a disk failure, but also operator who messed with startup scripts), it has to be opened (warranty!).

These all unpleasant tasks could be avoided if it was possible to have a "fallback" device. For example, consider this hypothetical command line:

root=/dev/sdb1,/dev/sda1

You should use initramfs to achieve that.

(Note that SD naming is anyway dynamic - if only one of USB or HDD is plugged in, it will most likely become sda.)

	-`J'
#6 lore raw
Quoted 10 lines · Jan Engelhardt
Quoted 8 lines

The device is pretty small and has no keyboard, video card etc., so if it ever happens to break (can be a disk failure, but also operator who messed with startup scripts), it has to be opened (warranty!).

These all unpleasant tasks could be avoided if it was possible to have a "fallback" device. For example, consider this hypothetical command line:

root=/dev/sdb1,/dev/sda1

You should use initramfs to achieve that.

All right.
I see that initramfs is attached to the kernel itself.

So it leaves me only a question: will I fit all tools into 300 kB (considering I'll use uClibc and busybox)?

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#7 lore raw
Quoted 6 lines · Tomasz Chmielewski

All right.
I see that initramfs is attached to the kernel itself.

So it leaves me only a question: will I fit all tools into 300 kB (considering I'll use uClibc and busybox)?

You don't need to use busybox and have a bunch of tools.

The klibc distribution comes with "kinit", which does the equivalent to the kernel root-mounting code; it's in the tens of kilobytes, at least on x86. If you're using ARM, you can compile it as Thumb.

-hpa

#8 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 6 lines · Tomasz Chmielewski

All right.
I see that initramfs is attached to the kernel itself.

So it leaves me only a question: will I fit all tools into 300 kB (considering I'll use uClibc and busybox)?

You don't need to use busybox and have a bunch of tools.

The klibc distribution comes with "kinit", which does the equivalent to the kernel root-mounting code; it's in the tens of kilobytes, at least on x86. If you're using ARM, you can compile it as Thumb.

Hmm, I'm having problems compiling klibc-1.4 on ARM (using gcc-4.1.1):

# make
  GEN     klcc/klibc.config
  GEN     klcc/klcc
  HOSTCC  scripts/basic/fixdep
  GEN     usr/klibc/syscalls/SYSCALLS.i
  GEN     usr/klibc/syscalls/syscalls.nrs
  GEN     usr/klibc/syscalls/typesize.c
  KLIBCCC usr/klibc/syscalls/typesize.o
In file included from usr/klibc/../include/sys/poll.h:9,
                 from usr/klibc/../include/poll.h:1,
                 from usr/klibc/syscalls/syscommon.h:13,
                 from usr/klibc/syscalls/typesize.c:1:
usr/klibc/../include/sys/time.h:12: warning: 'struct timezone' declared inside parameter list
usr/klibc/../include/sys/time.h:12: warning: 'struct timeval' declared inside parameter list
usr/klibc/../include/sys/time.h:13: warning: 'struct timezone' declared inside parameter list
usr/klibc/../include/sys/time.h:13: warning: 'struct timeval' declared inside parameter list
usr/klibc/../include/sys/time.h:14: warning: 'struct itimerval' declared inside parameter list
usr/klibc/../include/sys/time.h:15: warning: 'struct itimerval' declared inside parameter list
usr/klibc/../include/sys/time.h:16: warning: 'struct timeval' declared inside parameter list
In file included from usr/klibc/../include/poll.h:1,
                 from usr/klibc/syscalls/syscommon.h:13,
                 from usr/klibc/syscalls/typesize.c:1:
usr/klibc/../include/sys/poll.h:18: warning: 'struct timespec' declared inside parameter list
In file included from usr/klibc/../include/sys/resource.h:10,
                 from usr/klibc/syscalls/syscommon.h:18,
                 from usr/klibc/syscalls/typesize.c:1:
/usr/include/linux/resource.h:24: error: field 'ru_utime' has incomplete type
/usr/include/linux/resource.h:25: error: field 'ru_stime' has incomplete type
In file included from usr/klibc/syscalls/syscommon.h:19,
                 from usr/klibc/syscalls/typesize.c:1:
usr/klibc/../include/sys/select.h:15: warning: 'struct timespec' declared inside parameter list
In file included from usr/klibc/syscalls/syscommon.h:20,
                 from usr/klibc/syscalls/typesize.c:1:
usr/klibc/../include/sys/socket.h:47: warning: 'struct msghdr' declared inside parameter list
usr/klibc/../include/sys/socket.h:48: warning: 'struct msghdr' declared inside parameter list
In file included from usr/klibc/../include/sys/stat.h:11,
                 from usr/klibc/syscalls/syscommon.h:21,
                 from usr/klibc/syscalls/typesize.c:1:
usr/include/arch/arm/klibc/archstat.h:33: error: field 'st_atim' has incomplete type
usr/include/arch/arm/klibc/archstat.h:34: error: field 'st_mtim' has incomplete type
usr/include/arch/arm/klibc/archstat.h:35: error: field 'st_ctim' has incomplete type
In file included from usr/klibc/syscalls/syscommon.h:21,
                 from usr/klibc/syscalls/typesize.c:1:
usr/klibc/../include/sys/stat.h: In function 'mkfifo':
usr/klibc/../include/sys/stat.h:30: error: 'S_IFMT' undeclared (first use in this function)
usr/klibc/../include/sys/stat.h:30: error: (Each undeclared identifier is reported only once
usr/klibc/../include/sys/stat.h:30: error: for each function it appears in.)
usr/klibc/../include/sys/stat.h:30: error: 'S_IFIFO' undeclared (first use in this function)
  LIST    usr/klibc/syscalls/syscalls.list
  GEN     usr/klibc/socketcalls/SOCKETCALLS.i
  GEN     usr/klibc/socketcalls/socketcalls.mk
  KLIBCCC usr/klibc/socketcalls/socket.o
In file included from usr/klibc/../include/sys/stat.h:10,
                 from usr/klibc/socketcalls/socketcommon.h:12,
                 from usr/klibc/socketcalls/socket.c:1:
usr/klibc/../include/sys/time.h:12: warning: 'struct timezone' declared inside parameter list
usr/klibc/../include/sys/time.h:12: warning: 'struct timeval' declared inside parameter list
usr/klibc/../include/sys/time.h:13: warning: 'struct timezone' declared inside parameter list
usr/klibc/../include/sys/time.h:13: warning: 'struct timeval' declared inside parameter list
usr/klibc/../include/sys/time.h:14: warning: 'struct itimerval' declared inside parameter list
usr/klibc/../include/sys/time.h:15: warning: 'struct itimerval' declared inside parameter list
usr/klibc/../include/sys/time.h:16: warning: 'struct timeval' declared inside parameter list
In file included from usr/klibc/../include/sys/stat.h:11,
                 from usr/klibc/socketcalls/socketcommon.h:12,
                 from usr/klibc/socketcalls/socket.c:1:
usr/include/arch/arm/klibc/archstat.h:33: error: field 'st_atim' has incomplete type
usr/include/arch/arm/klibc/archstat.h:34: error: field 'st_mtim' has incomplete type
usr/include/arch/arm/klibc/archstat.h:35: error: field 'st_ctim' has incomplete type
In file included from usr/klibc/socketcalls/socketcommon.h:12,
                 from usr/klibc/socketcalls/socket.c:1:
usr/klibc/../include/sys/stat.h: In function 'mkfifo':
usr/klibc/../include/sys/stat.h:30: error: 'S_IFMT' undeclared (first use in this function)
usr/klibc/../include/sys/stat.h:30: error: (Each undeclared identifier is reported only once
usr/klibc/../include/sys/stat.h:30: error: for each function it appears in.)
usr/klibc/../include/sys/stat.h:30: error: 'S_IFIFO' undeclared (first use in this function)
In file included from usr/klibc/socketcalls/socketcommon.h:14,
                 from usr/klibc/socketcalls/socket.c:1:
usr/klibc/../include/sys/socket.h: At top level:
usr/klibc/../include/sys/socket.h:47: warning: 'struct msghdr' declared inside parameter list
usr/klibc/../include/sys/socket.h:48: warning: 'struct msghdr' declared inside parameter list
make[3]: *** [usr/klibc/socketcalls/socket.o] Error 1
make[2]: *** [usr/klibc/socketcalls] Error 2
make[1]: *** [all] Error 2
make: *** [klibc] Error 2
Signature · 1 line
Tomasz Chmielewski
#9 lore raw
Quoted 6 lines · Tomasz Chmielewski
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Tomasz Chmielewski

All right.
I see that initramfs is attached to the kernel itself.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

So it leaves me only a question: will I fit all tools into 300 kB (considering I'll use uClibc and busybox)?

You don't need to use busybox and have a bunch of tools.

The klibc distribution comes with "kinit", which does the equivalent to the kernel root-mounting code; it's in the tens of kilobytes, at least on x86. If you're using ARM, you can compile it as Thumb.

Hmm, I'm having problems compiling klibc-1.4 on ARM (using gcc-4.1.1):

Could you send me your kernel .config, as well as what version of the kernel you're building against?

-hpa

#10 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Tomasz Chmielewski
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Tomasz Chmielewski

All right.
I see that initramfs is attached to the kernel itself.

So it leaves me only a question: will I fit all tools into 300 kB (considering I'll use uClibc and busybox)?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

You don't need to use busybox and have a bunch of tools.

The klibc distribution comes with "kinit", which does the equivalent to the kernel root-mounting code; it's in the tens of kilobytes, at least on x86. If you're using ARM, you can compile it as Thumb.

Hmm, I'm having problems compiling klibc-1.4 on ARM (using gcc-4.1.1):

Could you send me your kernel .config, as well as what version of the kernel you're building against?

I managed to compile a "Testing" 1.4.31 version (in fact, version 1.4 didn't compile because I didn't have a "linux" link pointing to kernel sources; version 1.4.31 tells that it's missing - so both versions compile fine).

The problem is... I'm not sure how to start with it. The package doesn't have much documentation (other than "read the source"), does it?

On the other hand, I see it comes with a couple of useful tools, like sh (dash)... They are also pretty small, so everything should fit into 300 kB (dash=70kB, kinit=70kB, mount=12kB).

As I understand, this is what I have to do:

1. compile a kernel with initramfs, which will include a cpio image with some tools

2. tools/scripts in cpio image should do the following:

mount /proc
DISKS=$(cat /proc/diskstats)
for WORD in $DISKS
do
[ $WORD = sdb1 ] && echo "partition found, what next?..." done

# do a similar logic for sda1

Am I correct? Of course I'd appreciate how to achieve point 2 (where now "partition found, what next?..." is).

Signature · 2 lines
Tomasz Chmielewski
http://wpkg.org
#11 lore raw
Quoted 3 lines · Tomasz Chmielewski

I managed to compile a "Testing" 1.4.31 version (in fact, version 1.4 didn't compile because I didn't have a "linux" link pointing to kernel sources; version 1.4.31 tells that it's missing - so both versions compile fine).

At this point, 1.4.31 is probably what you should be using.

Quoted 3 lines

The problem is... I'm not sure how to start with it. The package doesn't have much documentation (other than "read the source"), does it?

On the other hand, I see it comes with a couple of useful tools, like sh (dash)... They are also pretty small, so everything should fit into 300 kB (dash=70kB, kinit=70kB, mount=12kB).

With kinit you don't even need dash/mount... kinit is a monolithic binary for everything.

In other words, you'd typically use *either* dash+mount, *or* kinit...

-hpa