Skip to content

Instantly share code, notes, and snippets.

@hgl
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save hgl/f45c4f40e5beec74fe06 to your computer and use it in GitHub Desktop.

Select an option

Save hgl/f45c4f40e5beec74fe06 to your computer and use it in GitHub Desktop.

Thoughts on OpenWrt's sysupgrade script

I want to improve the sysupgrade script, making it support extroot better.

I have the following improvements in mind:

  • After upgrading but before restarting, new usb storage related packages are installed to the jffs2 partition, along with the fs package to support the current usb overlay's filesystem.
  • Before upgrading, /etc/config/fstab in jffs2 partition is saved to /tmp, and after upgrading, restored to the jffs2 partition
  • The upper directory in the usb overlay is removed after upgrading, making sure no mismatched kernel and kernel modules.
  • All other saved configs (if any) are restored to the usb overlay after upper is removed.

This as the following benefits comparing to the current version:

  • After upgrading and restarting, extroot is still loaded.
  • Saved config are restored to usb overlay, not jffs2.

What needs to be done

  • Each new release should contain a script that installs usb storage and fs packages required to make a functioning extroot. We don't want an old release to install these packages for a new release.
  • The upper directory in usb overlay should be automatically removed after upgrading, since the usb overlay will be loaded after restarting.

Problems

KanjiMonster raise that concern that automatically wiping out the usb overlay might cause some damage, since it's currently persist across upgrading. I think it can be fixed by put the extroot support behind a flag in the sysupgrade script, only when enabled, the usb overlay is wiped out, otherwise the script does exactally what it does now.

Technical issues

I intend to implement the extroot support, and have given the sysupgrade souce a read. There are a few things I don't quite understand, and would like to get some help:

  • The script calls ubus call system upgrade, what does it do? Is it simply a event notification that by default no other processes listen to?

  • Who calls the script with nand command, in which case it executes nand_upgrade_stage2?

  • What does mount -o bind /tmp/root /tmp/root do? Binding a directory to itself doesn't make sense to me.

    Google doesn't help much on this topic. Although the man page of mount does mention the case of bind a directory to itself, but I failed to understand the explanation: "it's also possible to use the bind mount to create a mountpoint from a regular directory". Isn't mountpoint just a mounted directory? What does creating a mounted directory from the same directory mean?

  • I search the whole OpenWrt repo, no script is using the jffs2_copy_config function in the common.sh script. No packages seem to be using this function either. Is it safe to remove it?

  • How is the jffs2 partition wiped out? The mtd command that writes the image to flash has this firmware arguments passed, which mean it should only overwrite that mtd block. I don't see other commands that overwrites the jffs2 partition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment