AnsweredAssumed Answered

After initramfs starts, the init process is not 1,and switch_root cannot be used

Question asked by zh_y on Feb 13, 2020
Latest reply on Feb 13, 2020 by Victor Linnik

Board: i.MX6Q
Uboot:2019-04
kernel:4.1.15

My file system was built with buildroot-2019.02.9 and works fine on the board.I added the init script file under /, which is as follows:
[CODE]#!/bin/sh
echo "sleep 10s"
sleep 10
echo "finished sleep"
echo "current pid is $$"
[/CODE]
Use the following command for cpio packaging.
[CODE]find . | cpio --create --format='newc' | gzip > ../ramdisk.img
mkimage -A arm -O linux -T ramdisk -C none -a 0x12c00000 -n "Label you want" -d ./ramdisk.img ./uramdisk.img
[/CODE]
On the uboot command line, type the following command, copy the initramfs of the usb disk into the DDR, and start the kernel
[CODE]Hit any key to stop autoboot: 0
=> usb start;fatload usb 0 0x12c00000 uramdisk.img;fatload mmc 3:1 0x12000000 zImage;fatload mmc 3:1 0x18000000 topeet_9.7inch.dtb;run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
starting USB...
USB0: Port not available.
USB1: USB EHCI 1.00
scanning bus 1 for devices... 4 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
2036176 bytes read in 174 ms (11.2 MiB/s)
8306792 bytes read in 235 ms (33.7 MiB/s)
46349 bytes read in 15 ms (2.9 MiB/s)
Kernel image @ 0x12000000 [ 0x000000 - 0x7ec068 ]
## Loading init Ramdisk from Legacy Image at 12c00000 ...
Image Name: Label you want
Image Type: ARM Linux RAMDisk Image (uncompressed)
Data Size: 2036112 Bytes = 1.9 MiB
Load Address: 12c00000
Entry Point: 12c00000
Verifying Checksum ... OK
## Flattened Device Tree blob at 18000000
Booting using the fdt blob at 0x18000000
Using Device Tree in place at 18000000, end 1800e50c

Starting kernel ...
[/CODE]
After starting initramfs, I found that my /init file was not executed and the process in pid = 1 was {linuxrc} init.According to the busybox documentation, when the kernel goes into initramfs, it calls the /init file first with PID = 1,and can then use switch_root for system switching. But that's not what my board looks like. What's the problem?
[QUOTE]Starting syslogd: OK
Starting klogd: OK
Starting mdev...
modprobe: can't change directory to '/lib/modules': No such file or directory
Initializing random number generator... random: dd urandom read with 16 bits of entropy available
done.
Starting network: OK
# top
Mem: 79348K used, 1982272K free, 4168K shrd, 0K buff, 4168K cached
CPU: 0% usr 2% sys 0% nic 97% idle 0% io 0% irq 0% sirq
Load average: 0.07 0.02 0.01 1/86 240
PID PPID USER STAT VSZ %VSZ %CPU COMMAND
240 233 root R 2164 0% 2% top
233 1 root S 2268 0% 0% -/bin/sh
1 0 root S 2164 0% 0% {linuxrc} init
205 1 root S 2164 0% 0% /sbin/syslogd -n
209 1 root S 2164 0% 0% /sbin/klogd -n
87 2 root SW 0 0% 0% [kworker/1:1]
6 2 root SW 0 0% 0% [kworker/u8:0]
90 2 root SW 0 0% 0% [kworker/u8:1]
24 2 root SW 0 0% 0% [kdevtmpfs]
88 2 root SW 0 0% 0% [scsi_eh_0]
2 0 root SW 0 0% 0% [kthreadd]
3 2 root SW 0 0% 0% [ksoftirqd/0]
4 2 root SW 0 0% 0% [kworker/0:0]
5 2 root SW< 0 0% 0% [kworker/0:0H]
7 2 root SW 0 0% 0% [rcu_preempt]
8 2 root SW 0 0% 0% [rcu_sched]
9 2 root SW 0 0% 0% [rcu_bh]
10 2 root SW 0 0% 0% [migration/0]
11 2 root SW 0 0% 0% [migration/1]
12 2 root SW 0 0% 0% [ksoftirqd/1]
# pwd
/
# cat init
#!/bin/sh
echo "sleep 10s"
sleep 10
echo "finished sleep"
echo "current pid is $$"

# ls
bin init linuxrc opt run tmp
dev lib media proc sbin usr
etc lib32 mnt root sys var
# echo $$
233
#
[/QUOTE]

Attachments

Outcomes