ARM嵌入式Linux设备根文件系统只读问题永久解决求助
Alright, let's work through this read-only root filesystem problem on your ARM embedded Linux device. You already have the temporary fix down with mount -o remount,rw /, so let's lock in a permanent solution—since your first pass at tweaking U-Boot kernel parameters (around initramfs) didn't stick, let's cover the common missteps and correct approaches step by step.
First, let's make sure you're modifying the right U-Boot environment variables correctly—this is where most folks slip up:
- Boot into U-Boot's command line (usually by pressing a specific key like Ctrl+C or Space during power-on; check your device's boot prompt for hints)
- Print your current boot arguments to confirm the issue:
You’ll probably see something like this, with aprintenv bootargsroflag attached to the root filesystem:console=ttyAMA0,115200 root=/dev/root rootfstype=ext4 ro initramfs initrd.img-5.10.0-arm64 - Edit the bootargs to replace
rowithrw:
Note: If your bootargs use a separatesetenv bootargs 'console=ttyAMA0,115200 root=/dev/root rootfstype=ext4 rw initramfs initrd.img-5.10.0-arm64'rootflags=roparameter, change that torootflags=rwinstead. - Don’t forget to save the environment—this is the step most people miss:
saveenv - Reboot your device and check
/proc/mountsagain to confirm the root filesystem is mounted rw by default.
Since you mentioned initramfs was part of your earlier attempt, it’s possible the root filesystem is being forced to read-only in the initramfs initialization script:
- Extract the initramfs image (adjust the path to match your device's initramfs file):
mkdir initramfs_temp && cd initramfs_temp gzip -dc /boot/initramfs.cpio.gz | cpio -idmv - Look for the main initialization script—this is usually named
init(it’s a shell script in most cases) - Search for lines where the root filesystem is mounted. You might find something like:
Change# Mount root filesystem read-only first mount -o ro /dev/root /rootrotorw, or if the script is supposed to remount later, ensure this line exists and isn’t commented out:# Switch to read-write mount -o remount,rw /root - Repack the initramfs image:
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../new_initramfs.cpio.gz - Replace the old initramfs on your device (this might involve flashing it via U-Boot or copying it to the boot partition, depending on your setup)
Sometimes the kernel automatically mounts the root filesystem as read-only if it detects filesystem corruption. Let’s rule this out:
- Use your temporary remount command to make the root filesystem writable:
mount -o remount,rw / - Run a filesystem check (adjust the command for your filesystem type—e.g.,
fsck.jffs2for JFFS2,fsck.ext4for ext4):e2fsck -f /dev/root - Follow the prompts to fix any detected errors, then reboot and check if the root filesystem mounts rw by default.
Some ARM devices store boot arguments in the device tree instead of U-Boot environment variables. If the above steps didn’t work:
- Extract your device tree blob (
.dtb) and convert it to a human-readable.dtsfile:dtc -I dtb -O dts /boot/your-board.dtb > your-board.dts - Look for the
chosennode—you might see bootargs hardcoded here with theroflag:chosen { bootargs = "console=ttyAMA0,115200 root=/dev/root ro"; }; - Change
rotorw, recompile the device tree:dtc -I dts -O dtb your-board.dts > new-your-board.dtb - Update the device tree on your device and reboot.
内容的提问来源于stack exchange,提问作者Jonas Eschmann

