OpenWrt Forum Archive

Topic: How to switch_root from initramfs based image in trunk?

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have a few access points which start from the FLASH, mount the USB flash disk and start via kexec the kernel stored on this flash disk, using one partition from the same flashdisk as the rootfs.

Previously it was achieved in quite an easy way ( https://forum.openwrt.org/viewtopic.php?id=23901 ), by modification of the /etc/preinit file with adding the 'rootfs=/dev/sda1' line.

Unfortunately this simple approach doesn't work with the newest preinit.
I've tried solutions given in https://forum.openwrt.org/viewtopic.php?id=36462 , but none of them worked (probably they were prepared for yet another, older preinit.

So does anybody know how to make the kernel started with initramfs root file system to switch to the rootfs located in the external disk?

The essential is that both: the kernel and the root filesystem are located on the removable disk and may be replaced without reflashing of the Access Point.

Update
I have tried to use the aproach described in http://wiki.openwrt.org/doc/howto/extro … aker.trunk
and added the file files/etc/config/fstab:

config 'global'
        option delay_root '10'
config 'mount'                                                                    
        option 'target'   '/'                                                       
        option 'device'   '/dev/sda1'                                               
        option 'fstype'   'ext4'                                                    
        option 'options'  'rw,sync,noatime'                                         
        option 'enabled'  '1'                                                       
        option 'enabled_fsck' '0'                                                                    

Of course I have also selected the block-mount package.
Unfortunately the rootfs doesn't get switched

(Last edited by wzab on 3 Oct 2013, 21:32)

I tried to exec switch_root directly from the preinit.
To achieve that, I have created the following script:
/lib/preinit/85_switch_root

#!/bin/sh
/bin/mkdir /tmp/new
/bin/mknod /dev/sda1 b 8 1
/bin/sleep 10
/bin/mount /dev/sda1 /tmp/new
exec /sbin/switch_root /tmp/new /tmp/new/sbin/init

Unfortunately it appears, that switch_root refuses to switch root to the USB mounted filesystem, because it is not run with PID=1.
I have investigated things more thoroughly, and I have found, that it is /sbin/init (in fact procd) run with PID=1, and
/etc/preinit is run as its child (in my case it had PID=191).

What is interesting - I was not able to change the program called as the "init" process using the "init=" kernel argument.
Neither using the command line provided by kexec, nor by hard-compiling it into the kernel.
It was always /sbin/init, which was called.
So it seems, that allowing to boot kernel from USB drive and to mount rootfs from this drive it is necessary to modify the procd sources...

(Last edited by wzab on 5 Oct 2013, 10:59)

Neither using the command line provided by kexec, nor by hard-compiling it into the kernel.

did you have a vanilla/pristine buildroot ?

However if the generic/platform specific kernel patches are modified, or some patches has been added/deleted those will not be
used without a target/linux/clean

src: openwrt-devel mailing list

that might explain why your patches to kernel commandline did have no effect

zloop wrote:

did you have a vanilla/pristine buildroot ?

Yes I have. To make sure, I have just done in an empty directory:

git clone git://git.openwrt.org/openwrt.git
cd openwrt
make menuconfig
#In the menuconfig:
#Target System (Broadcom BCM947xx/953xx)
#Target Profile (Broadcom SoC, b44 Ethernet, BCM43xx WiFi (b43, default))
#Target Images -> ramdisk [*]
#Target Images -> ramdisk -> Compression (lzma)
#Kernel modules -> Filesystems -> kmod-fs-ext4 (*)
#Kernel modules -> USB Support -> kmod-usb-ohci (*)
#Kernel modules -> USB Support -> kmod-usb-storage (*)
#Kernel modules -> USB Support -> kmod-usb2 (*)
#Utilities -> Filesystem -> e2fsprogs (*)
#Base system -> block-mount (*) ?
make kernel_menuconfig
#Kernel hacking -> Built-in kernel command line [*]
#Kernel hacking ->  Default kernel command string (init=/bin/sh noinitrd console=ttyS0,115200) 
#Kernel hacking-> Built-in command line overrides firmware arguments [*]
make -j 8 V=99 world

Afterwards I have copied the resulting kernel openwrt-brcm47xx-vmlinux-initramfs.elf to my ext4 formatted USB disk,
and also copied contents of the build_dir/target-mipsel_mips32_uClibc-0.9.33.2/root-brcm47xx directory to the same disk.

zloop wrote:

that might explain why your patches to kernel commandline did have no effect

When I put the disk to mu Asus WL500gP v2 with the "bootloader", I can see the following output:

[   43.112000] Starting new kernel
[   43.116000] Will call new kernel at 000056f0
[   43.116000] Bye ...
[    0.000000] Linux version 3.10.13 (wzab@WZlap) (gcc version 4.6.4 (OpenWrt/Linaro GCC 4.6-2013.05 r3
[    0.000000] CFE's entrypoint seal doesn't match.
[    0.000000] CPU revision is: 00029029 (Broadcom BMIPS3300)
[    0.000000] bcm47xx: using ssb bus
[    0.000000] ssb: Found chip with id 0x5354, rev 0x02 and package 0x00
[    0.000000] Couldn't find supported flash memory
[    0.000000] ssb: Sonics Silicon Backplane found at address 0x18000000
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 02000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x00000000-0x01ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x00000000-0x01ffffff]
[    0.000000] Primary instruction cache 16kB, VIPT, 4-way, linesize 16 bytes.
[    0.000000] Primary data cache 16kB, 2-way, VIPT, cache aliases, linesize 16 bytes
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 8128
[    0.000000] Kernel command line: init=/bin/sh noinitrd console=ttyS0,115200
[    0.000000] PID hash table entries: 128 (order: -3, 512 bytes)
[    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Memory: 26892k/32768k available (2394k kernel code, 5876k reserved, 562k data, 2348k in)
[    0.000000] NR_IRQS:128
[    0.000000] console [ttyS0] enabled

So it is clearly visible, that "init=/bin/sh" was passed to the kernel
However later on I can see:

[    0.084000] Calibrating delay loop... 237.82 BogoMIPS (lpj=475648)
[    0.120000] pid_max: default: 32768 minimum: 301
[    0.124000] Mount-cache hash table entries: 512
[    0.136000] NET: Registered protocol family 16
[    0.172000] bio: create slab <bio-0> at 0
[    0.188000] Switching to clocksource MIPS
[    0.216000] NET: Registered protocol family 2
[    0.224000] TCP established hash table entries: 512 (order: 0, 4096 bytes)
[    0.232000] TCP bind hash table entries: 512 (order: -1, 2048 bytes)
[    0.236000] TCP: Hash tables configured (established 512 bind 512)
[    0.244000] TCP: reno registered
[    0.248000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.256000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.260000] NET: Registered protocol family 1
[    8.452000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    8.460000] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red H.
[    8.472000] msgmni has been set to 52
[    8.476000] io scheduler noop registered
[    8.480000] io scheduler deadline registered (default)
[    8.488000] Serial: 8250/16550 driver, 2 ports, IRQ sharing enabled
[    8.516000] serial8250: ttyS0 at MMIO 0xb8000300 (irq = 3) is a U6_16550A
[    8.544000] serial8250: ttyS1 at MMIO 0xb8000400 (irq = 3) is a U6_16550A
[    8.572000] serial8250.0: ttyS0 at MMIO 0xb8000300 (irq = 3) is a U6_16550A
[    8.604000] serial8250.0: ttyS1 at MMIO 0xb8000400 (irq = 3) is a U6_16550A
[    8.620000] physmap platform flash device: 02000001 at 1c000000
[    8.624000] physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x0000c2 Chb
[    8.636000] Amd/Fujitsu Extended Query Table at 0x0040
[    8.640000]   Amd/Fujitsu Extended Query version 1.1.
[    8.648000] number of CFI chips: 1
[    8.676000] 6 bcm47xxpart partitions found on MTD device physmap-flash.0
[    8.684000] Creating 6 MTD partitions on "physmap-flash.0":
[    8.688000] 0x000000000000-0x000000020000 : "boot"
[    8.700000] 0x000000020000-0x0000007f0000 : "linux"
[    8.712000] 0x00000002001c-0x000000020960 : "loader"
[    8.724000] 0x000000020960-0x000000122c00 : "kernel"
[    8.728000] mtd: partition "kernel" must either start or end on erase block boundary or be smaller y
[    8.748000] 0x000000122c00-0x0000007f0000 : "rootfs"
[    8.752000] mtd: partition "rootfs" must either start or end on erase block boundary or be smaller y
[    8.772000] mtd: partition "rootfs" set to be root filesystem
[    8.776000] mtd: partition "rootfs_data" created automatically, ofs=0x390000, len=0x460000
[    8.784000] 0x000000390000-0x0000007f0000 : "rootfs_data"
[    8.796000] 0x0000007f0000-0x000000800000 : "nvram"
[    8.816000] bcm47xx-wdt bcm47xx-wdt.0: BCM47xx Watchdog Timer enabled (30 seconds, Software Timer)
[    8.828000] GPIO_WDT: failed to register misc device
[    8.832000] TCP: cubic registered
[    8.836000] NET: Registered protocol family 17
[    8.844000] 8021q: 802.1Q VLAN Support v1.8
[    8.896000] Freeing unused kernel memory: 2348K (802e5000 - 80530000)
Console is alive
procd: Console is alive
- watchdog -
procd: - watchdog -

So the argument "init=/bin/sh" was silently ignored (?!)and procd (probably via symlink /sbin/init) was started.  Whan I look into "init/main.c" in the kernel sources, in the kernel_init function I find:

static int __ref kernel_init(void *unused)
{
        kernel_init_freeable();
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
        free_initmem();
        mark_rodata_ro();
        system_state = SYSTEM_RUNNING;
        numa_default_policy();

        flush_delayed_fput();

        if (ramdisk_execute_command) {
                if (!run_init_process(ramdisk_execute_command))
                        return 0;
                pr_err("Failed to execute %s\n", ramdisk_execute_command);
        }

        /*
         * We try each of these until one succeeds.
         *
         * The Bourne shell can be used instead of init if we are
         * trying to recover a really broken machine.
         */
        if (execute_command) {
                if (!run_init_process(execute_command))
                        return 0;
                pr_err("Failed to execute %s.  Attempting defaults...\n",
                        execute_command);
        }
        if (!run_init_process("/etc/preinit") ||
            !run_init_process("/sbin/init") ||
            !run_init_process("/etc/init") ||
            !run_init_process("/bin/init") ||
            !run_init_process("/bin/sh"))
                return 0;

        panic("No init found.  Try passing init= option to kernel. "
              "See Linux Documentation/init.txt for guidance.");
}

So I'd expect, that I should receive at least an error message. But what I get is just silent skipping of the "init=" argument :-(

(Last edited by wzab on 5 Oct 2013, 12:12)

I have added printing of debug messages in the kernel, in init/main.c

static int __init init_setup(char *str)
{
    unsigned int i;
    pr_notice("init_setup was called: %s\n", str);

    execute_command = str;
    /*
     * In case LILO is going to boot us with default command line,
     * it prepends "auto" before the whole cmdline which makes
     * the shell think it should execute a script with such name.
     * So we ignore all arguments entered _before_ init=... [MJ]
     */
    for (i = 1; i < MAX_INIT_ARGS; i++)
        argv_init[i] = NULL;
    return 1;
}
__setup("init=", init_setup);

[...]

static int __ref kernel_init(void *unused)
{
    kernel_init_freeable();
    /* need to finish all async __init code before freeing the memory */
    async_synchronize_full();
    free_initmem();
    mark_rodata_ro();
    system_state = SYSTEM_RUNNING;
    numa_default_policy();

    flush_delayed_fput();

    if (ramdisk_execute_command) {
        if (!run_init_process(ramdisk_execute_command))
            return 0;
        pr_err("Failed to execute %s\n", ramdisk_execute_command);
    }

    /*
     * We try each of these until one succeeds.
     *
     * The Bourne shell can be used instead of init if we are
     * trying to recover a really broken machine.
     */
    pr_notice("execute_command: %s\n", execute_command);
    if (execute_command) {
        if (!run_init_process(execute_command)) {
            pr_notice("succeeded to start: %s\n", execute_command);
            return 0;
                }
        pr_err("Failed to execute %s.  Attempting defaults...\n",
            execute_command);
    }
    if (!run_init_process("/etc/preinit") ||
        !run_init_process("/sbin/init") ||
        !run_init_process("/etc/init") ||
        !run_init_process("/bin/init") ||
        !run_init_process("/bin/sh"))
        return 0;

    panic("No init found.  Try passing init= option to kernel. "
          "See Linux Documentation/init.txt for guidance.");
}

In the console output I can see:

[    0.000000] Kernel command line: init=/bin/sh noinitrd console=ttyS0,115200
[    0.000000] init_setup was called: /bin/sh
[    0.000000] PID hash table entries: 128 (order: -3, 512 bytes)

but there is no trace of calling the kernel_init.

(Last edited by wzab on 6 Oct 2013, 17:27)

OK. The problem is explained. I have added some more debug messages to kernel_init:

static int __ref kernel_init(void *unused)
{
    kernel_init_freeable();
    /* need to finish all async __init code before freeing the memory */
    async_synchronize_full();
    free_initmem();
    mark_rodata_ro();
    system_state = SYSTEM_RUNNING;
    numa_default_policy();

    flush_delayed_fput();
    pr_notice("ramdisk_ex_cmd: %s init_cmd:%s\n", ramdisk_execute_command, execute_command);

    if (ramdisk_execute_command) {
        if (!run_init_process(ramdisk_execute_command))
            pr_notice("succeeded to start: %s\n", ramdisk_execute_command);
            return 0;
        pr_err("Failed to execute %s\n", ramdisk_execute_command);
    }

    /*
     * We try each of these until one succeeds.
     *
     * The Bourne shell can be used instead of init if we are
     * trying to recover a really broken machine.
     */
    pr_notice("execute_command: %s\n", execute_command);
    if (execute_command) {
        if (!run_init_process(execute_command)) {
            pr_notice("succeeded to start: %s\n", execute_command);
            return 0;
                }
        pr_err("Failed to execute %s.  Attempting defaults...\n",
            execute_command);
    }
    if (!run_init_process("/etc/preinit") ||
        !run_init_process("/sbin/init") ||
        !run_init_process("/etc/init") ||
        !run_init_process("/bin/init") ||
        !run_init_process("/bin/sh"))
        return 0;

    panic("No init found.  Try passing init= option to kernel. "
          "See Linux Documentation/init.txt for guidance.");
}

In the boot output I have found:

[    8.900000] Freeing unused kernel memory: 2340K (802e7000 - 80530000)
[    8.908000] ramdisk_ex_cmd: /init init_cmd:/bin/sh
[    8.916000] succeeded to start: /init
Console is alive

So it means, that in case of initramfs image this is    ramdisk_execute_command which is called via:

static int __init rdinit_setup(char *str)
{
    unsigned int i;
    pr_notice("rdinit_setup was called: %s\n", str);

    ramdisk_execute_command = str;
    /* See "auto" comment in init_setup */
    for (i = 1; i < MAX_INIT_ARGS; i++)
        argv_init[i] = NULL;
    return 1;
}
__setup("rdinit=", rdinit_setup);

And the right argument to change the command run as init process is the "rdinit=".

I've tried to switch_root my system manually, after adding "rdinit=/bin/sh" as the kernel argument.
Unfortunately the results are far from good:

[    8.904000] Freeing unused kernel memory: 2340K (802e7000 - 80530000)
[    8.908000] ramdisk_ex_cmd: /bin/sh init_cmd:/bin/sh
[    8.916000] succeeded to start: /bin/sh


BusyBox v1.19.4 (2013-10-05 10:42:20 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/bin/sh: can't access tty; job control turned off
/ # mount proc /proc -t proc
/ # modprobe ssb-hcd
/ # modprobe ehci-hcd
[   34.032000] usbcore: registered new interface driver usbfs
[   34.036000] usbcore: registered new interface driver hub
[   34.044000] usbcore: registered new device driver usb
[   34.056000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
/ # modprobe ohci-hcd
[   41.016000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[   41.020000] ohci-platform ohci-platform.0: Generic Platform OHCI Controller
[   41.028000] ohci-platform ohci-platform.0: new USB bus registered, assigned bus number 1
[   41.036000] ohci-platform ohci-platform.0: irq 6, io mem 0x18003000
[   41.104000] hub 1-0:1.0: USB hub found
[   41.108000] hub 1-0:1.0: 2 ports detected
[   41.492000] usb 1-1: new full-speed USB device number 2 using ohci-platform
[   41.704000] hub 1-1:1.0: USB hub found
[   41.708000] hub 1-1:1.0: 2 ports detected
[   42.012000] usb 1-1.1: new full-speed USB device number 3 using ohci-platform
/ # modprobe usb-storage
[   46.980000] SCSI subsystem initialized
[   46.996000] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[   47.004000] scsi0 : usb-storage 1-1.1:1.0
[   47.012000] usbcore: registered new interface driver usb-storage
[   48.016000] scsi 0:0:0:0: Direct-Access     SanDisk  Cruzer Blade     8.02 PQ: 0 ANSI: 0 CCS
/ # modprobe sd_mod
[   51.932000] sd 0:0:0:0: [sda] 7856127 512-byte logical blocks: (4.02 GB/3.74 GiB)
[   51.944000] sd 0:0:0:0: [sda] Write Protect is off
[   51.956000] sd 0:0:0:0: [sda] No Caching mode page found
[   51.960000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   52.000000] sd 0:0:0:0: [sda] No Caching mode page found
[   52.004000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   52.060000]  sda: sda1 sda2
[   52.096000] sd 0:0:0:0: [sda] No Caching mode page found
[   52.100000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   52.108000] sd 0:0:0:0: [sda] Attached SCSI removable disk
/ #  mknod /dev/sda1 b 8 1
/ # mkdir /tmp/new
/ # modprobe ext4
/ # mount /dev/sda1 /tmp/new
[   94.016000] EXT4-fs (sda1): couldn't mount as ext3 due to feature incompatibilities
[   94.044000] EXT4-fs (sda1): couldn't mount as ext2 due to feature incompatibilities
[   94.440000] EXT4-fs (sda1): recovery complete
[   94.452000] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
/ # exec /sbin/switch_root /tmp/new /init
Console is alive
procd: Console is alive
- watchdog -
procd: - watchdog -
[  116.072000] diag: kernel found a "Asus WL500GP V2"
[  116.076000] diag: Detected 'ASUS WL-500g Premium V2'
[  116.100000] b44: Broadcom 44xx/47xx 10/100 PCI ethernet driver version 2.0
[  116.112000] b44 ssb0:0: failed to register MII bus
[  116.116000] b44: probe of ssb0:0 failed with error -5
[  116.176000] ehci-platform: EHCI generic platform driver
[  116.180000] ehci-platform ehci-platform.0: EHCI Host Controller
[  116.188000] ehci-platform ehci-platform.0: new USB bus registered, assigned bus number 2
[  116.196000] ehci-platform ehci-platform.0: irq 6, io mem 0x18003800
[  116.204000] usb 1-1: USB disconnect, device number 2
[  116.208000] usb 1-1.1: USB disconnect, device number 3
[  116.216000] ehci-platform ehci-platform.0: USB 2.0 started, EHCI 1.00
[  116.228000] JBD2: Error -5 detected when updating journal superblock for sda1-8.
[  116.240000] hub 2-0:1.0: USB hub found
[  116.244000] hub 2-0:1.0: 2 ports detected
[  116.248000] Aborting journal on device sda1-8.
[  116.252000] JBD2: Error -5 detected when updating journal superblock for sda1-8.
[  116.264000] EXT4-fs error (device sda1): __ext4_journal_start_sb:62: Detected aborted journal
[  116.272000] EXT4-fs (sda1): Remounting filesystem read-only
[  116.276000] EXT4-fs (sda1): previous I/O error to superblock detected
[  116.284000] journal commit I/O error
[  116.292000] EXT4-fs (sda1): previous I/O error to superblock detected
[  116.300000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #13: comm kworker/u2:2: reading directory lblock 0
[  116.312000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #61: comm kmodloader: reading directory lblock 0
[  116.336000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #61: comm kmodloader: reading directory lblock 0
kmod: failed to open /etc/modules-boot.d/50-usb-ohci
kmod: failed to open /etc/modules-boot.d/usb-storage
kmod: ran 9 iterations
- preinit -
procd: - preinit -
[  116.356000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #484: comm init: reading directory lblock 0
Failed to start preinit
procd: Failed to start preinit
[  116.376000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #543: comm init: reading directory lblock 0
[  116.580000] usb 2-1: new high-speed USB device number 2 using ehci-platform
[  116.716000] EXT4-fs error (device sda1): ext4_find_entry:1309: inode #61: comm init: reading directory lblock 0
[  116.728000] hub 2-1:1.0: USB hub found
[  116.736000] hub 2-1:1.0: 2 ports detected
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
[  117.028000] usb 2-1.1: new high-speed USB device number 3 using ehci-platform
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_objec[  117.132000] usb-storage 2-1.1:1.0: USB Mass Storage device detected
t_from_file: error reading file /etc/hotplug-preinit.json: No su[  117.148000] scsi1 : usb-storage 2-1.1:1.0
ch file or directory
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
[  118.160000] scsi 1:0:0:0: Direct-Access     SanDisk  Cruzer Blade     8.02 PQ: 0 ANSI: 0 CCS
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_objec[  118.180000] sd 1:0:0:0: [sdb] 7856127 512-byte logical blocks: (4.02 GB/3.74 GiB)
t_from_file: error reading file /etc/hotplug-preinit.json: No su[  118.188000] sd 1:0:0:0: [sdb] Write Protect is off
ch file or directory
json_object_from_file: error reading file [  118.200000] sd 1:0:0:0: [sdb] No Caching mode page found
/etc/hotplug-preinit.json: No such file or directory
json_objec[  118.208000] sd 1:0:0:0: [sdb] Assuming drive cache: write through
t_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_object_from_file: error reading file [  118.228000] sd 1:0:0:0: [sdb] No Caching mode page found
/etc/hotplug-preinit.json: No such file or directory
[  118.240000] sd 1:0:0:0: [sdb] Assuming drive cache: write through
[  118.260000]  sdb: sdb1 sdb2
json_object_from_file: error reading file /etc/hotplug-preinit.json: No such file or directory
json_object_from_file: error reading file /etc/hotplug-preinit.json: No su[  118.276000] sd 1:0:0:0: [sdb] No Caching mode page found
ch file or directory
json_object_from_file: error reading file [  118.284000] sd 1:0:0:0: [sdb] Assuming drive cache: write through
/etc/hotplug-preinit.json: No such file or directory
[  118.296000] sd 1:0:0:0: [sdb] Attached SCSI removable disk

So as it is visible, the system tried to mount my USB disk again as /dev/sdb, which of course lead to multiple errors :-(.

OK. It was my dummy error. I have forgotten to load "ehci_platform" module first.
Below are the results of the correct "manual" initialization:

[    8.908000] ramdisk_ex_cmd: /bin/sh init_cmd:/bin/sh
[    8.916000] succeeded to start: /bin/sh


BusyBox v1.19.4 (2013-10-05 10:42:20 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/bin/sh: can't access tty; job control turned off
/ # mount proc /proc -t proc
/ # modprobe diag
[   41.884000] diag: kernel found a "Asus WL500GP V2"
[   41.888000] diag: Detected 'ASUS WL-500g Premium V2'
/ # modprobe ehci-platform
[   68.752000] usbcore: registered new interface driver usbfs
[   68.760000] usbcore: registered new interface driver hub
[   68.768000] usbcore: registered new device driver usb
[   68.780000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[   68.792000] ehci-platform: EHCI generic platform driver
/ # modprobe ssb-hcd
[   93.272000] ehci-platform ehci-platform.0: EHCI Host Controller
[   93.280000] ehci-platform ehci-platform.0: new USB bus registered, assigned bus number 1
[   93.288000] ehci-platform ehci-platform.0: irq 6, io mem 0x18003800
[   93.308000] ehci-platform ehci-platform.0: USB 2.0 started, EHCI 1.00
[   93.316000] hub 1-0:1.0: USB hub found
[   93.320000] hub 1-0:1.0: 2 ports detected
[   93.636000] usb 1-1: new high-speed USB device number 2 using ehci-platform
[   93.776000] hub 1-1:1.0: USB hub found
[   93.780000] hub 1-1:1.0: 2 ports detected
[   94.056000] usb 1-1.1: new high-speed USB device number 3 using ehci-platform
/ # modprobe ohci-hcd
[  109.428000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[  109.436000] ohci-platform ohci-platform.0: Generic Platform OHCI Controller
[  109.444000] ohci-platform ohci-platform.0: new USB bus registered, assigned bus number 2
[  109.452000] ohci-platform ohci-platform.0: irq 6, io mem 0x18003000
[  109.520000] hub 2-0:1.0: USB hub found
[  109.524000] hub 2-0:1.0: 2 ports detected
/ # modprobe sd-mod
[  127.456000] SCSI subsystem initialized
/ # nmodprobe usb-storage
[  135.068000] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[  135.076000] scsi0 : usb-storage 1-1.1:1.0
[  135.084000] usbcore: registered new interface driver usb-storage
[  136.084000] scsi 0:0:0:0: Direct-Access     SanDisk  Cruzer Blade     8.02 PQ: 0 ANSI: 0 CCS
[  136.100000] sd 0:0:0:0: [sda] 7856127 512-byte logical blocks: (4.02 GB/3.74 GiB)
[  136.112000] sd 0:0:0:0: [sda] Write Protect is off
[  136.116000] sd 0:0:0:0: [sda] No Caching mode page found
[  136.124000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[  136.136000] sd 0:0:0:0: [sda] No Caching mode page found
[  136.144000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[  136.160000]  sda: sda1 sda2
[  136.172000] sd 0:0:0:0: [sda] No Caching mode page found
[  136.180000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[  136.184000] sd 0:0:0:0: [sda] Attached SCSI removable disk

/ # mknod /dev/sda1 b 8 1
/ # mkdir /tmp/new
/ # modprobe ext4
/ # mount /dev/sda1 /tmp/new
[  254.612000] EXT4-fs (sda1): couldn't mount as ext3 due to feature incompatibilities
[  254.628000] EXT4-fs (sda1): couldn't mount as ext2 due to feature incompatibilities
[  254.680000] EXT4-fs (sda1): recovery complete
[  254.720000] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
/ # exec /sbin/switch_root /tmp/new /init
Console is alive
procd: Console is alive
- watchdog -
procd: - watchdog -
[  262.588000] b44: Broadcom 44xx/47xx 10/100 PCI ethernet driver version 2.0
[  262.600000] b44 ssb0:0: failed to register MII bus
[  262.604000] b44: probe of ssb0:0 failed with error -5
kmod: ran 5 iterations
- preinit -
procd: - preinit -
ifconfig: SIOCSIFADDR: No such device
Press the [f] key and hit [enter] to enter failsafe mode
- early -
procd: - early -
- watchdog -
procd: - watchdog -
- init -
procd: - init -
Please press Enter to activate this console.
[  269.804000] NET: Registered protocol family 10
[  269.840000] nf_conntrack version 0.5.0 (456 buckets, 1824 max)
[  269.868000] ip6_tables: (C) 2000-2006 Netfilter Core Team
[  269.932000] Loading modules backported from Linux version master-2013-06-27-0-gdcfa6d5
[  269.940000] Backport generated by backports.git backports-20130617-4-ge3220f5
[  269.956000] ip_tables: (C) 2000-2006 Netfilter Core Team
[  270.068000] xt_time: kernel timezone is -0000
[  270.128000] cfg80211: Calling CRDA to update world regulatory domain
[  270.152000] cfg80211: World regulatory domain updated:
[  270.156000] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[  270.164000] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[  270.172000] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[  270.180000] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[  270.188000] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[  270.196000] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[  270.392000] PPP generic driver version 2.4.2
[  270.408000] NET: Registered protocol family 24
[  270.504000] b43-phy0: Broadcom 5354 WLAN found (core revision 13)
[  270.532000] b43-phy0: Found PHY: Analog 6, Type 5 (LP), Revision 0
[  270.560000] Broadcom 43xx driver loaded [ Features: PNL ]
[  270.592000] Broadcom 43xx-legacy driver loaded [ Features: PLD ]



BusyBox v1.19.4 (2013-10-05 10:42:20 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r38303)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------
root@OpenWrt:/# procd: - init complete -

root@OpenWrt:/# 

So it seems, that the right recipe to start the system from the initramfs and to switch it later to the external USB disk
could be to create my own "/myinit" script (should be placed as the /files/mynit file in the openwrt directory), and to add "rdinit=/myinit" as kernel parameter.
Below is the content of proposed /myinit:

#!/bin/sh
mount proc /proc -t proc
modprobe diag
modprobe ehci-platform
modprobe ssb-hcd
modprobe sd-mod
modprobe usb-storage
/bin/sleep 10
mknod /dev/sda1 b 8 1
mkdir /tmp/new
modprobe ext4
mount /dev/sda1 /tmp/new -o rw,sync,relatime
exec /sbin/switch_root /tmp/new /init

I have updated the thread https://forum.openwrt.org/viewtopic.php?id=23901 so, that it contains the updated recipe for Asus WL500Gp v2 booting from external USB disk.

(Last edited by wzab on 7 Oct 2013, 03:32)

The discussion might have continued from here.