Author Topic: Possible to boot filesystem in SD card with read-only access?  (Read 68 times)

kjl

  • Active Member
  • *
  • Posts: 6
Possible to boot filesystem in SD card with read-only access?
« on: September 07, 2018, 09:28:40 PM »
Hey everyone, so I was facing the issue discussed here: https://forum.trenz-electronic.de/index.php?topic=795.0 (basically SD card not available once kernel starts) and added the following code to the Device Tree as recommended:
Code: [Select]
&sdhci1 {
    // disable-wp;
    no-1-8-v;
 
};
However, I need read-only access, which is somehow disabled. I tried adding "ro" into the earlycon for u-boot, but write is still allowed.
This line is also printed while booting:
Quote
[    3.271144] EXT4-fs (mmcblk1p2): mounted filesystem with ordered data mode. Opts: (null)
[    3.279164] VFS: Mounted root (ext4 filesystem) readonly on device 179:34.
[    3.286498] devtmpfs: mounted
[    3.289508] Freeing unused kernel memory: 512K (ffffffc000c40000 - ffffffc000cc0000)
INIT: version 2.88 booting
[    3.400822] random: fast init done
Starting udev
[    3.622014] udevd[1643]: starting version 3.2
[    3.656081] udevd[1644]: starting eudev-3.2
[    4.078810] FAT-fs (mmcblk1p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[    4.110404] EXT4-fs (mmcblk1p2): re-mounted. Opts: data=ordered
It is possible that something forced the re-mounting, and it becomes write-able after that re-mounting. But I have no idea why it would remount.
Is it possible to bypass the SD card availability issue while still retaining Write-Protected status?

Thank you.
Ken
« Last Edit: September 07, 2018, 09:53:53 PM by kjl »

Oleksandr Kiyenko

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 326
Re: Possible to boot filesystem in SD card with read-only access?
« Reply #1 on: September 09, 2018, 01:23:32 PM »
Hello,

to run Linux with a read-only root filesystem some linux subsystems should be modified. For example special files which located in root filesystem and modified during a boot process.
Unfortunately petalinux not suitable for that by default. There is a lot of information on the internet how to modify Linux for that, but I don't have an exact recipe for petalinux.
Some information
https://wiki.debian.org/ReadonlyRoot
https://forums.xilinx.com/t5/Embedded-Linux/read-only-rootfs/td-p/645209

Best regards
Oleksandr Kiyenko

kjl

  • Active Member
  • *
  • Posts: 6
Re: Possible to boot filesystem in SD card with read-only access?
« Reply #2 on: September 13, 2018, 08:34:35 PM »
Thank you for the response! So a possible solution is to do this:
1. In /etc/fstab, change
Code: [Select]
/dev/root / auto default 1 1 to
Code: [Select]
/dev/root / auto ro 1 12. In /etc/default/rcS, change
Code: [Select]
ROOTFS_READ_ONLY=no to
Code: [Select]
ROOTFS_READ_ONLY=yes3. run
Code: [Select]
sync4. restart computer

Also if you want to mount any /dev as read-only and
Code: [Select]
mount -r /dev/<devname> /mnt does not work,
try
Code: [Select]
mount /dev/<devname> /mnt then
Code: [Select]
mount -o remount,ro /dev/<devname> /mnt