Project

General

Profile

Creating a Read-Only Filesystem

Added by Jim Twyman over 11 years ago

Hi,
We use the MityDSP-L138 in a factory automation product and need to prevent fs corruption from random shutdowns. My first attempt was to change the rootfs to read-only in a startup script, but it would be safer if the rootfs was read-only through power-up. I came across the Wiki page below and attempted to see how far I could go with this.

[[http://support.criticallink.com/redmine/projects/arm9-platforms/wiki/Configuring_a_Linux_Filesystem_for_Uncontrolled_Shutdowns]]

After implementing those changes, the root file system would still be rw after power-up. It finally came up as ro after the following changes.
1) Changed /etc/init.d/checkroot's rootmode to ro. However, I'm not sure if this is necessary.
2) Changed mtab to have rootfs as ro.

rootfs / auto ro 0 0
proc /proc proc rw 0 0
devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
usbfs /proc/bus/usb usbfs rw 0 0
tmpfs /var/volatile tmpfs rw 0 0
tmpfs /dev/shm tmpfs rw,mode=0777 0 0
tmpfs /media/ram tmpfs rw 0 0
/dev/mtdblock1 /mnt/user_nand jffs2 rw,noatime,nodiratime 0 0

My fstab file is as follows -

# stock fstab - you probably want to override this with a machine specific one

rootfs               /                    auto       defaults,ro           1  1
proc                 /proc                proc       defaults              0  0
devpts               /dev/pts             devpts     mode=0620,gid=5       0  0
usbfs                /proc/bus/usb        usbfs      defaults              0  0
tmpfs                /var/volatile        tmpfs      defaults              0  0
tmpfs                /dev/shm             tmpfs      mode=0777             0  0
tmpfs                /media/ram           tmpfs      defaults              0  0

# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

# mount TFS user nand partition
/dev/mtdblock1        /mnt/user_nand       jffs2     rw,noatime,nodiratime  0  0
#

With these changes it does power-up in readonly mode, but /mnt/user_nand is not actually mounted and thus, access to my application software that should be executed next. Rather, it falls through to the login prompt. I can manually mount /mnt/user_nand and access that partition. The goal is to have /mnt/user_nand be kept ro too and temporarily be changed to rw to update a configuration file.

Below is the power-up and you can see that there are other issues too. Is this the best approach to harden the filesystem?

U-Boot 2009.11 (Mar 31 2011 - 19:39:18)

I2C:   ready
DRAM:  128 MB
NAND:  256 MiB
MMC:   davinci: 0
In:    serial
Out:   serial
Err:   serial
ARM    Clock : 300000000 Hz
DDR    Clock : 150000000 Hz
EMIFA  CLock : 100000000 Hz
DSP    Clock : 300000000 Hz
ASYNC3 Clock : 150000000 Hz
Enet  config : 2
MMC 0 Enable : 0
Resetting ethernet phy
Net:   Ethernet PHY: GENERIC @ 0x03 [0x8]

Hit any key to stop autoboot:  0
8192 KiB M25P64 at 0:0 is now current device
## Booting kernel from Legacy Image at c0700000 ...
   Image Name:   Linux-2.6.34-rc1-14815-g0e16b7d
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1981448 Bytes =  1.9 MB
   Load Address: c0008000
   Entry Point:  c0008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

 Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Linux version 2.6.34-rc1-14815-g0e16b7d (mitydspl138@mitydspl138-desktop) (gcc version 4.3.3 (GCC) ) #4 PREEMPT Thu Nov 17 15:31:10 EST 2011
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
CPU: VIVT data cache, VIVT instruction cache
Machine: MityDSP-L138
Peripheral Config Block Found
Enet_Config = 2
PHYMask = 0x8
No LCD Configured
UART[0] = 0, 0, 0, 115200
UART[1] = 1, 1, 0, 115200
UART[2] = 0, 0, 0, 115200
SPI[0] = 0, 0, 00, 0, 0
SPI[1] = 1, 1, 01, 0, 30000000
Memory policy: ECC disabled, Data cache writethrough
DaVinci da850/omap-l138 variant 0x0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 24384
Kernel command line: mem=96M console=ttyS1,115200n8 mtdparts=nand:128M(rootfs),-(userfs) ro root=/dev/mtdblock0 ro rootfstype=jffs2 ip=off
PID hash table entries: 512 (order: -1, 2048 bytes)
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 96MB = 96MB total
Memory: 93320k/93320k available, 4984k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xff000000 - 0xffe00000   (  14 MB)
    vmalloc : 0xc6800000 - 0xfea00000   ( 898 MB)
    lowmem  : 0xc0000000 - 0xc6000000   (  96 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .init : 0xc0008000 - 0xc002a000   ( 136 kB)
      .text : 0xc002a000 - 0xc039a000   (3520 kB)
      .data : 0xc03b4000 - 0xc03d69e0   ( 139 kB)
Experimental preemptable hierarchical RCU implementation.
NR_IRQS:245
Console: colour dummy device 80x30
Calibrating delay loop... 149.50 BogoMIPS (lpj=747520)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
DaVinci: 144 gpio irqs
regulator: core version 0.5
NET: Registered protocol family 16
mityomapl138_init...
mityomapl138_setup_nand: using 16 bit data
EMAC: MII PHY configured, RMII PHY will not be functional
mityomapl138_init: setting phy_mask to 8
mityomapl138_init: no LCD device enabled
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
regulator: VDCDC1: 1150 <--> 1350 mV at 1200 mV
regulator: VDCDC2: 1710 <--> 1910 mV at 3300 mV
regulator: VDCDC3: 1120 <--> 1320 mV at 1800 mV
regulator: LDO1: 1800 mV
regulator: LDO2: 3300 mV
Switching to clocksource timer0_1
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
msgmni has been set to 182
io scheduler noop registered (default)
Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x1c42000 (irq = 25) is a 16550A
serial8250.0: ttyS1 at MMIO 0x1d0c000 (irq = 53) is a 16550A
console [ttyS1] enabled
serial8250.0: ttyS2 at MMIO 0x1d0d000 (irq = 61) is a 16550A
brd: module loaded
at24 1-0050: 256 byte 24c02 EEPROM (read-only)
MityOMAPL138: Found MAC = 00:50:c2:bf:89:7f
MityOMAPL138: Part Number = L138-CG-225-Rc
MityOMAPL138: setting max frequency to 300 MHz
ahci ahci: forcing PORTS_IMPL to 0x1
ahci ahci: AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
ahci ahci: flags: ncq sntf pm led clo only pmp pio slum part ccc
scsi0 : ahci
ata1: SATA max UDMA/133 irq 67
NAND device: Manufacturer ID: 0x2c, Chip ID: 0xca (Micron NAND 256MiB 3,3V 16-bit)
Creating 2 MTD partitions on "davinci_nand.1":
0x000000000000-0x000008000000 : "rootfs" 
0x000008000000-0x000010000000 : "homefs" 
davinci_nand davinci_nand.1: controller rev. 2.5
spi_davinci spi_davinci.1: Controller at 0xfef0e000
console [netcon0] enabled
netconsole: network logging started
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci ohci.0: DA8xx OHCI
ohci ohci.0: new USB bus registered, assigned bus number 1
Waiting for USB PHY clock good...
ohci ohci.0: irq 59, io mem 0x01e25000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
omap_rtc omap_rtc: rtc core: registered omap_rtc as rtc0
omap_rtc: RTC power up reset detected
omap_rtc: already running
i2c /dev entries driver
watchdog watchdog: heartbeat 60 sec
cpuidle: using governor ladder
cpuidle: using governor menu
davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
TCP cubic registered
NET: Registered protocol family 17
Clocks: disable unused i2c1
Clocks: disable unused emac
Clocks: disable unused mcasp
Clocks: disable unused lcdc
Clocks: disable unused spi0
Clocks: disable unused mcbsp0
Clocks: disable unused mcbsp1
Clocks: disable unused vpif
regulator_init_complete: incomplete constraints, leaving LDO2 on
regulator_init_complete: incomplete constraints, leaving LDO1 on
regulator_init_complete: incomplete constraints, leaving VDCDC3 on
regulator_init_complete: incomplete constraints, leaving VDCDC2 on
regulator_init_complete: incomplete constraints, leaving VDCDC1 on
emac-mii: probed
omap_rtc omap_rtc: setting system clock to 2012-07-20 17:56:18 UTC (1342806978)
ata1: SATA link down (SStatus 0 SControl 300)
Empty flash at 0x012306a0 ends at 0x01230800
Empty flash at 0x03d2d190 ends at 0x03d2d800
Empty flash at 0x03d350d0 ends at 0x03d35800
jffs2_scan_inode_node(): CRC failed on node at 0x0401efc4: Read 0xffffffff, calculated 0x6f615b7a
Empty flash at 0x0401f0e8 ends at 0x0401f800
VFS: Mounted root (jffs2 filesystem) readonly on device 31:0.
Freeing init memory: 136K
INIT: version 2.86 booting
Please wait: booting...
Starting udev
Remounting root file system...
Caching udev devnodes
rm: cannot remove '/etc/volatile.cache': Read-only file system
chown: /var/volatile/cache: Read-only file system
chmod: /var/volatile/cache: Read-only file system
chown: /var/volatile/lock: Read-only file system
chmod: /var/volatile/lock: Read-only file system
chown: /var/volatile/log: Read-only file system
chmod: /var/volatile/log: Read-only file system
chown: /var/volatile/run: Read-only file system
chmod: /var/volatile/run: Read-only file system
chown: /var/volatile/tmp: Read-only file system
chmod: /var/volatile/tmp: Read-only file system
touch: /var/log/wtmp: Read-only file system
chown: /var/lock/subsys: Read-only file system
chmod: /var/lock/subsys: Read-only file system
touch: /var/log/lastlog: Read-only file system
chown: /var/log/wtmp: No such file or directory
chown: /var/log/lastlog: No such file or directory
chmod: /var/log/wtmp: No such file or directory
chmod: /var/log/lastlog: No such file or directory
touch: /var/run/utmp: Read-only file system
chown: /var/run/utmp: Read-only file system
chmod: /var/run/utmp: Read-only file system
touch: /var/run/resolv.conf: Read-only file system
touch: /var/run/resolv.conf: Read-only file system
chown: /var/run/resolv.conf: No such file or directory
chmod: /var/run/resolv.conf: No such file or directory
chown: /var/run/resolv.conf: No such file or directory
chmod: /var/run/resolv.conf: No such file or directory
Configuring network interfaces... ifup: can't open '/var/run/ifstate': Read-only file system
done.
Starting portmap daemon: portmap.
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
INIT: Entering runlevel: 5
mkdir: cannot create directory '/var/run/dbus': Read-only file system
mkdir: cannot create directory '/var/volatile/dropbear': Read-only file system
creating NFS state directory: /etc/rc5.d/S20nfsserver: line 149: can't create sm/state: Read-only file system
done
starting 8 nfsd kernel threads: done
starting mountd: done
starting statd: done
Starting syslogd/klogd: done
 * Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon
Timeout reached while wating for return value
Could not receive return value from daemon process.
   ...fail!

Starting my configuration
/etc/rc5.d/S95_my_startup: line 20: ./init_network: not found
/etc/rc5.d/S95_my_startup: line 22: ./start: not found
Now Starting my application
/etc/rc5.d/S95_my_startup: line 26: ./sensor: not found

Sensor startup has completed!

.-------.
|       |                  .-.
|   |   |-----.-----.-----.| |   .----..-----.-----.
|       |     | __  |  ---'| '--.|  .-'|     |     |
|   |   |  |  |     |---  ||  --'|  |  |  '  | | | |
'---'---'--'--'--.  |-----''----''--'  '-----'-'-'-'
                -'  |
                '---'

The Angstrom Distribution mityomapl138 ttyS1

Angstrom 2010.7-test-20101202 mityomapl138 ttyS1

mityomapl138 login:

Replies (7)

RE: Creating a Read-Only Filesystem - Added by Jonathan Cormier over 11 years ago

"I can manually mount /mnt/user_nand and access that partition"
Whats the full command you use to manually mount your partition? Does mount /mnt/user_nand work?

RE: Creating a Read-Only Filesystem - Added by Jim Twyman over 11 years ago

I had used -
mount -t jffs2 /dev/mtdblock1 /mnt/user_nand
and just -
mount /mnt/user_nand
also works.

RE: Creating a Read-Only Filesystem - Added by Jonathan Cormier over 11 years ago

Your fstab entry doesn't have auto in the options list so it isn't auto mounted on startup. You should probably use the defaults and then override the options you want changed.

defaults Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

RE: Creating a Read-Only Filesystem - Added by Jonathan Cormier over 11 years ago

rm: cannot remove '/etc/volatile.cache': Read-only file system
chown: /var/volatile/cache: Read-only file system
chmod: /var/volatile/cache: Read-only file system
chown: /var/volatile/lock: Read-only file system
chmod: /var/volatile/lock: Read-only file system
chown: /var/volatile/log: Read-only file system
chmod: /var/volatile/log: Read-only file system
chown: /var/volatile/run: Read-only file system
chmod: /var/volatile/run: Read-only file system
chown: /var/volatile/tmp: Read-only file system
chmod: /var/volatile/tmp: Read-only file system
touch: /var/log/wtmp: Read-only file system
chown: /var/lock/subsys: Read-only file system
chmod: /var/lock/subsys: Read-only file system
touch: /var/log/lastlog: Read-only file system
chown: /var/log/wtmp: No such file or directory
chown: /var/log/lastlog: No such file or directory
chmod: /var/log/wtmp: No such file or directory
chmod: /var/log/lastlog: No such file or directory
touch: /var/run/utmp: Read-only file system
chown: /var/run/utmp: Read-only file system
chmod: /var/run/utmp: Read-only file system
touch: /var/run/resolv.conf: Read-only file system
touch: /var/run/resolv.conf: Read-only file system
chown: /var/run/resolv.conf: No such file or directory
chmod: /var/run/resolv.conf: No such file or directory
chown: /var/run/resolv.conf: No such file or directory
chmod: /var/run/resolv.conf: No such file or directory
Configuring network interfaces... ifup: can't open '/var/run/ifstate': Read-only file system

Udev happens before the tmpfs entries get mounted from the fstab file.

RE: Creating a Read-Only Filesystem - Added by Jim Twyman over 11 years ago

I changed fstab for the /mnt/user_nand to as follows -
/dev/mtdblock1 /mnt/user_nand jffs2 defaults,rw,noatime,nodiratime 0 0

However, the power-up was the same and the partition was not mounted.

RE: Creating a Read-Only Filesystem - Added by Jonathan Cormier over 11 years ago

Jim,
Any luck? As far as I can tell that mount entry should work.

RE: Creating a Read-Only Filesystem - Added by Jim Twyman over 11 years ago

I worked on it some more and ended up with a script with seven patch files that change it to a read-only filesystem. My plan is to setup a time delay relay that toggles the power to a board for a weekend test.

    (1-7/7)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)