Jump to content

How to customize /etc/fstab in a build?

Recommended Posts

Hi all,


  I need to customize the /etc/fstab during the build to mount a mtd partition and also to override some mountpoints with tmpfs in order to reduce wearing on mmc.

So, have added the following lines to customize-image.sh:


cat <<EOT >> /etc/fstab

# Reduce SD wearing by storing log files into ram (no need as overlayroot is used to freeze all the rootfs)

tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev 0 0

tmpfs /run tmpfs defaults,noatime,nosuid,nodev 0 0

tmpfs /var/tmp tmpfs defaults,noatime,nosuid,nodev 0 0

tmpfs /var/log tmpfs defaults,noatime,nosuid,nodev,noexec 0 0

tmpfs /var/lib/logrotate tmpfs defaults,noatime,nosuid,nodev,noexec,size=1m,mode=0755 0 0

tmpfs /var/lib/sudo tmpfs defaults,noatime,nosuid,nodev,noexec,size=1m,mode=0700 0 0

# MTD EEPROM memory

dev/mtdblock0 /mnt/mtd jffs2 ro,relatime 0 0



However changes in /etc/fstab are overridden somewhere over the build process, and this is the resulting /etc/fstab:


UUID=c8167755-b557-4288-9109-9108bc48dd94 / btrfs defaults,noatime,commit=600 0 1
UUID=27ac6cc6-eff3-4736-a7bd-5517e3b150c0 /boot ext4 defaults,commit=600,errors=remount-ro 0 2
tmpfs /tmp tmpfs defaults,nosuid 0 0


Is there a way to safely patch the /etc/fstab file?


Thanks very much!



Edited by Andrea
Link to comment
Share on other sites

Hello again! It turns out I solved this problem by utilizing the Extension Hook format_partitions (https://docs.armbian.com/Developer-Guide_Extensions-Hooks/#format_partitions)


Essentially you can follow the example outlined here https://docs.armbian.com/Developer-Guide_Extensions/#example where you can write all of your fstab setup logic in its own shell script, say it's called fstab-setup.sh.  You'll need to write a function in this fstab-setup.sh script where the function name is formatted as format_partition__func_name() where "func_name" can be any name you like. It's important to note that you will need to have the extension hook name, in this case its format_parition, first in the function name followed by 2 underscores.


Finally, in your configuration file, or on the ./compile.sh line, you will need to add ENABLE_EXTENSIONS=fstab-setup where fstab-setup is the name of the shell script. Something like

./compile.sh ENABLE_EXTENSIONS=fstab-setup BOARD=....more args....


Hope this helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines