ophub / amlogic-s9xxx-openwrt

Support for OpenWrt in Amlogic, Rockchip and Allwinner boxes. Support a311d, s922x, s905x3, s905x2, s912, s905d, s905x, s905w, s905, s905l, rk3588, rk3568, rk3399, rk3328, h6, etc.
GNU General Public License v2.0
1.71k stars 1.51k forks source link

Boot from usb, but initrd mount /dev/mmcblk2p2, rather than /dev/sda2 #189

Closed 0neday closed 2 years ago

0neday commented 2 years ago

I flash your latest firmware openwrt_s905d_k5.4.171_2022.01.15.1130.img , and then plug into usb port.

I found, maybe boot from usb work, but Initrd ramdisk mount /dev/mmcblk2p2

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
udev                    512.0K         0    512.0K   0% /dev
tmpfs                   181.0M    108.0K    180.9M   0% /run
/dev/mmcblk2p2          973.0M    199.5M    767.7M  21% /
tmpfs                   905.1M     84.0K    905.0M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mmcblk2p4            4.5G    161.6M      4.1G   4% /mnt

root@OpenWrt:/opt# uname  -a
Linux OpenWrt 5.4.171-flippy-69+o #366 SMP PREEMPT Tue Jan 11 23:58:30 CST 2022 aarch64 GNU/Linux

root@OpenWrt:/opt# ls /lib/modules/5.4.1
5.4.154/             5.4.170-meson64-dev/

root@OpenWrt:/opt# lsmod
gpio_keys_polled       16384  0

this show ramdisk init kernel and load drivers for hardware, and then mount rootfs is /dev/mmcblk2p2, rather than /dev/sda2 this so wierd!

I use this to extract initrd.img and check init script

maybe_break mount
log_begin_msg "Mounting root file system"
# Always load local and nfs (since these might be needed for /etc or
# /usr, irrespective of the boot script used to mount the rootfs).
. /scripts/local
. /scripts/nfs
. /scripts/${BOOT}
parse_numeric "${ROOT}"
maybe_break mountroot
mount_top
mount_premount
mountroot
log_end_msg
ophub commented 2 years ago

You are not booting from usb. The system is still booted from emmc.

Re-download the firmware, re-write the U-disk, insert the U-disk into the box, and then re-plug the power supply to boot from the U-disk.

What does extracting initrd.img do? Compile the kernel?

0neday commented 2 years ago

Re-download the firmware, re-write the U-disk, insert the U-disk into the box, and then re-plug the power supply to boot from the U-disk.

result is same.

What does extracting initrd.img do? Compile the kernel?

nop, kernel is not key, I dont care about kernel. I check why mount /dev/mmcblk2p2, rather than /dev/sda2?

cat /proc/cmdline get some bootargs,

BOOT=ROOTFS

from . /scripts/local , function local_mount_root is key function to mount rootfs

I dont know how initrd get rootfs uuid?

maybe I need a console to get into init ramdisk when system boot.

If I know how initrd get rootfs uuid, I will add a if else condition to boot rootfs from usb when detect /dev/sda devices, It is easy to realize in init script.

ophub commented 2 years ago

As long as boot from usb, sda is automatically mounted. Your current situation shows that you have not booted from usb, some n1 boxes choose a U disk, change a U disk, or change another socket, change the firmware.

ophub commented 2 years ago

But the firmware in the U disk is invalid.

Do you have a usb keyboard plugged in? Unplug it, insert the u disk into the socket near the hdmi

0neday commented 2 years ago

insert the u disk into the socket near the hdmi

yes

But the firmware in the U disk is invalid.

is valid, I confirm!

I can mount /dev/sda2 and /dev/sda1 on current system.

ophub commented 2 years ago

Your U disk is manually mounted for storage. The firmware in your USB flash drive is invalid, and the boot from the USB flash drive is not properly booted.

Change the U disk, change the firmware. Solve the function that the firmware in the U disk can boot normally.

0neday commented 2 years ago

@ophub use blkid get your firmware UUID of rootfs,

xx-pc@xx-virtual-machine:~/Desktop$ sudo blkid  /dev/loop3p2
/dev/loop3p2: LABEL="ROOTFS" UUID="b250e917-e0a6-4061-9145-b8ee0cc20fea" UUID_SUB="fdb0d788-5b35-4d1e-8619-75a37574ddba" TYPE="btrfs"

and then flush your firmware into usb, then change

sed -i "s/LABEL=ROOTFS/UUID=b250e917-e0a6-4061-9145-b8ee0cc20fea/" uEnv.txt

plug usb into N1 box, and boot successfully