Is ext4 proper fs for embedded device on C4+SD card?

Post Reply
wowa
Posts: 36
Joined: Thu Nov 01, 2018 2:08 am
languages_spoken: english, russian
ODROIDs: C4, XU4
Has thanked: 16 times
Been thanked: 2 times
Contact:

Is ext4 proper fs for embedded device on C4+SD card?

Post by wowa »

Hello,

I have a GUI app which is supposed to work on an embedded (battery powered) C4 system with Ubuntu 20.04 from @tobetter's SD-image (kernel 5.13). I see that it has ext4 partitions. Is it Ok to use it on a long term basis (say 5-10 years), or should I look for some more "SD-friendly" fs like jffs or something? I'm not very experienced in embedded filesystems, is there any mainstream solution, or existing config will do well? The app itself doesn't use disk pretty much, just stores/updates (rather rarely) couple hundred bytes of settings.

Another question is about power on/off switching of such a system - what is a preferred way of organizing it? As far as I understand, there are two possibilities: 1) "hard" powerline cutoff-switch whose drawback is that system can't properly shutdown, and 2) some kind of "soft" button, but here it's unclear to me if C4 has capabilities to wake-up from power-off state using soft button - kind of properly configured GPIO pins. Is it possible?

Speaking about 1) - is write caching used on this SD-card image? How can I check this? I tried hdparm /dev/mmcblk0, hdparm -I /dev/mmcblk0, they don't show this kind of details:

Code: Select all

root@qwim:/mnt# hdparm -I /dev/mmcblk0

/dev/mmcblk0:
 HDIO_DRIVE_CMD(identify) failed: Invalid argument
root@qwim:/mnt# hdparm /dev/mmcblk0

/dev/mmcblk0:
 HDIO_DRIVE_CMD(identify) failed: Invalid argument
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Invalid argument
 geometry      = 486192/4/16, sectors = 31116288, start = 0

User avatar
mctom
Posts: 1938
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: OGA, XU4, C2, M1
Location: Gdansk, Poland
Has thanked: 222 times
Been thanked: 270 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by mctom »

Perhaps to make SD card live longer you could make a partition living in RAM, and save the settings on SD less often (or only on shutdown if that's okay).
When system shuts down it sends SIGTERM to all processes. This may be caught by your software to save data and exit gracefully. If some process doesn't want to end, it will get SIGKILL after some tens of seconds. (Everyone please feel free to correct me here).

SD cards in general fail due to lots of data rewrites, as well as fail randomly in time. With the latter, there's not much that can be done about it.

Another random option to consider is no SD card at all and network boot instead? I have no experience with it, just a random thought.

Another idea: To make your life easier, you could configure your OS so it mounts a filesystem root in read only mode. That rules out SD card wear due to writes. About that small amounts of data you wish to store, perhaps you could use a SPI EEPROM chip with endurance of 1 million cycles (pretty much standard these days).
Or an additional partition with "SD friendly" filesystem, so you'll save yourself troubles of migrating the whole OS onto an exotic filesystem.
These users thanked the author mctom for the post:
wowa (Thu Sep 22, 2022 12:56 am)
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
mad_ady
Posts: 10815
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4 (HC1, HC2), C1+, C2, C4 (HC4), N1, N2, H2, Go, Go Advance, M1
Location: Bucharest, Romania
Has thanked: 647 times
Been thanked: 950 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by mad_ady »

If your application is the kind that never updates (or updates mean reflashing) you'd better look into a squashfs (readonly) root filesystem + a jffs2 partition for rw data. Logs will need to go to a ramdisk (or be disabled) - /tmp mounted as a ramdisk + log2ram for /var/log. Note that a traditional "ubuntu" distro might not like this layout, because it will expect to be allowed to write at least to /var.

A simpler option would be to use overlayfs on top of ext4. Rootfs gets mounted readonly, a rw overlay is created on top and all changes get written to ramdisk, giving the illusion of a readwrite filesystem. Changes to the filesystem are lost on reboot. It should also resist corruption due to power outages. You have the advantage that you can write the overlay changes into the base filesystem if needed. There's an article about it in Odroid magazine, but can't find it at the moment, but here is a quick example: https://wiki.odroid.com/odroid-c2/appli ... s_odroidc2

I too was worried about sd longevity, but I've used an industrial 16G sd in my HC2 for about 4 years now and had no issues with it. In my HC4 I sometimes had boot failure until I added forcefsck option to kernel boot args. But in both cases the rootfs is ext4 and I took no special measures to prevent log writes.
These users thanked the author mad_ady for the post:
wowa (Thu Sep 22, 2022 10:17 pm)

User avatar
mctom
Posts: 1938
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polish
ODROIDs: OGA, XU4, C2, M1
Location: Gdansk, Poland
Has thanked: 222 times
Been thanked: 270 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by mctom »

mad_ady wrote:
Thu Sep 22, 2022 3:40 am
I too was worried about sd longevity, but I've used an industrial 16G sd in my HC2 for about 4 years now and had no issues with it.
Man I hosted a website on the original Raspberry Pi with a generic Class 4 SD card. It also worked for some 4 years until I moved on to Odroids.
Punk ain't no religious cult, punk means thinking for yourself!

Maintainer of PiStackMon

User avatar
tobetter
Posts: 10564
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 690 times
Been thanked: 1802 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by tobetter »

mad_ady wrote:
Thu Sep 22, 2022 3:40 am
If your application is the kind that never updates (or updates mean reflashing) you'd better look into a squashfs (readonly) root filesystem + a jffs2 partition for rw data. Logs will need to go to a ramdisk (or be disabled) - /tmp mounted as a ramdisk + log2ram for /var/log. Note that a traditional "ubuntu" distro might not like this layout, because it will expect to be allowed to write at least to /var.

A simpler option would be to use overlayfs on top of ext4. Rootfs gets mounted readonly, a rw overlay is created on top and all changes get written to ramdisk, giving the illusion of a readwrite filesystem. Changes to the filesystem are lost on reboot. It should also resist corruption due to power outages. You have the advantage that you can write the overlay changes into the base filesystem if needed. There's an article about it in Odroid magazine, but can't find it at the moment, but here is a quick example: https://wiki.odroid.com/odroid-c2/appli ... s_odroidc2
In case when OS that runs on the RAM is required, ODROID-STAMPER can help since it has an option to build it using --live. This option will build an OS image and put a squashfs image for a root file system. Still the tool is not mature yet, but can help to build a custom OS image.

wowa
Posts: 36
Joined: Thu Nov 01, 2018 2:08 am
languages_spoken: english, russian
ODROIDs: C4, XU4
Has thanked: 16 times
Been thanked: 2 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by wowa »

mad_ady wrote:
Thu Sep 22, 2022 3:40 am
If your application is the kind that never updates (or updates mean reflashing) you'd better look into a squashfs (readonly) root filesystem + a jffs2 partition for rw data. Logs will need to go to a ramdisk (or be disabled) - /tmp mounted as a ramdisk + log2ram for /var/log. Note that a traditional "ubuntu" distro might not like this layout, because it will expect to be allowed to write at least to /var.
Thanks for the hints, they are very informative, will look into it, or may be even leave it as is for now, as in your latter point). The "update model" is exactly as you described - no need for frequent updates.

To all: still, is C4 capable to be woken up from GPIO or some other option? And how to find out if write caching is enabled on the fs?

User avatar
mad_ady
Posts: 10815
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4 (HC1, HC2), C1+, C2, C4 (HC4), N1, N2, H2, Go, Go Advance, M1
Location: Bucharest, Romania
Has thanked: 647 times
Been thanked: 950 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by mad_ady »

I think you can add a power button to the gpio and have it wake up from suspend with a button push. It should be documented on the wiki.

Write caching is done by all linux kernels. You can flush the cache with
sync; echo 1 > /proc/sys/vm/drop_caches

User avatar
rooted
Posts: 9634
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 761 times
Been thanked: 505 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by rooted »

I like to use 3 instead of 1 so it drops the dentries and inodes along with page cache but that's certainly not necessary.

User avatar
rooted
Posts: 9634
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 761 times
Been thanked: 505 times
Contact:

Re: Is ext4 proper fs for embedded device on C4+SD card?

Post by rooted »

If this is a terminal based application I would likely just go with coreelec and disable Kodi from startup, it's already a RO system but with a user partition which is persistent.

One is also able to use docker containers.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 2 guests