Kernel only image

Hi.

When performing sysupgrade, the new image takes a full image, and overrides both kernel and rootfs partitions.
What if, I only want to update the kernel partition? I can't find the kernel-only image (zImage, uImage, whatever).
Where can I find that?

Thanks in advance.

I think a kernel-only upgrade is not possible, because it will leave incompatible kernel-modules in rootfs partition.

3 Likes

That is what I think as well, but if I wan'na take the risk and do it, is it possible? I want to change some sources in the kernel, without replacing the rootfs...

Not possible as kernel modules are in the root file system. There’s the further complication that the MTD partitions are dynamic, based on the size of the kernel.

1 Like

Thanks for your reply.
So where can I locate user files that I wish to be unchanged when I upgrade firmware?

sysupgrade -h will provide help text, which includes

	-l | --list-backup
	             list the files that would be backed up when calling
	             sysupgrade -b. Does not create a backup file.

The list comes from metadata about the installed packages' config files to start. It can be modified to include additional files/directories by editing /etc/sysupgrade.conf

For example, on one of my boxes, to handle things that I configured (not part of packages):

## This file contains files and directories that should
## be preserved during an upgrade.

# /etc/example.conf
# /etc/openvpn/

/etc/.git
/etc/.gitignore
/etc/ethers
/etc/logrotate.d/
/etc/mac80211-post-add.sh

/root
/home

Thanks again for your reply.
What if I want to upgrade my system using mtd write instead of sysupgrade?
is there any possibility to save information and then restore?

Not in any reasonable way without effectively replicating what sysupgrade does and then some.

I hope it's okay I am reviving this old thread.
I am still trying to cope with this issue. I want to manually save some config files, update firmware using mtd write and restore the config files.
I noticed that sysupgrade saves the configurations in a file named sysupgrade.tfx, but while it looks it is saved /tmp partition, the mount_boot searches for sysupgrade.tgz in "/" partition when booting, to restore.
So where is it being saved? It must be a free partition which is not deleted while updating firmare partition (which includes kernel, rootfs and rootfs_data) and not erased when rebooting.

Thanks for your help

While sysupgrade is running, root is on a RAM-backed file system. The tar file gets copied to the new overlay after the image is flashed.

How is it copied to the new overlay after flashing?
Just to make sure it works, i'm trying to create a new file by using:

echo "some text" > /filename.txt

running that line right after I flash the image, and before the reboot.
but after reboot, the new file is not available....
What am I missing? Should I access the new overlay in a different way?

Thanks

Possibly that you’re not pivoting off the boot-time root.

Secondly that the just-flashed image for most NOR-based devices isn’t mounted, and effectively can’t be

The file, for “default” NOR-based devices, is written raw by mtd -j

I am indeed using a NOR based device (SPI-NOR, to be specific), but I never use the -j option.
How do I pivot the boot-time root?

Thanks a lot for your help.

You probably do if you’re using sysupgrade

You can’t “cut off the branch you’re standing on”. All processes other than procd need to be killed and it needs to exec something that uses the new root. See pivot_root if you want to pursue further.

Writing a custom upgrade function within the existing sysupgrade process is likely an easier approach.

Edit:

default_do_upgrade() {
        local err
        sync
        if [ "$SAVE_CONFIG" -eq 1 ]; then
                get_image "$1" "$2" | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
        else
                get_image "$1" "$2" | mtd $MTD_ARGS write - "${PART_NAME:-image}"
        fi
        err=$?
        if [ $err -ne 0 ] ; then
                >&2 echo "ERROR: default_do_upgrade mtd write error: $err"
                exit 1
        fi
}

This must be done at a low level for NOR flash as you can't mount the file system before rebooting in any reasonable way.

I am sure it is easier, but it won't answer my needs.
I need a simple updater, to store my own couple of files (previously known and hard coded - no need to make all the tests and checkups), use mtd write to flash the image and the restore my previously saved files.

Where can I find information about the pivot_root? I managed to find some info in openwrt site, but it says it's obsolete.

Thanks

You would be surprised. You can do just about anything you need, letting the existing sysupgrade framework take care of the process of changing the root filesystem. See the contents of package/base-files/files/lib/upgrade/ as well as how the stage2 upgrader is selected. See, for an example of "something completely different" target/linux/ipq40xx/base-files/lib/upgrade/linksys.sh

On a full Linux distro

man 8 pivot_root
man 2 pivot_root

That will not work because / is not a directory configured to be saved.

sysupgrade ability to save setting is based on a tar-gz of the whole tree of files to be save. This tar is kept in the ram disk while writing the flash. Then it is extracted and written to the new filesystem before rebooting. So you can make the backup, add any extra files you want using regular archive tools, then run sysupgrade with that new backup and all the files will be in the new install.

If that is all you’re doing, either burning them into your image or /etc/sysupgrade.conf should do it.

1 Like

Again, I'm trying to avoid the use ot sysupgrade. I want to use mtd write.
I looking in all the upgrade scripts, and I'm kinda losing myself...

You should consider that if you don't understand how those work, your likelihood of being successful in writing a replacement, which is effectively what you will have to do, will continue to be vanishingly small.