Sysupgrade on X86 with combined ext4 root

What is the proper process of sysupgrading an generic X86 image with combined ext4fs root fs?

Every time I do sysupgrade, it wipes all the settings.
Embedded Wifi-routers don't seem to do that. They are able to keep settings.

So what would be the correct process to keep /etc when I have only one RW partition?

/dev/root on / type ext4 (rw,noatime)
/dev/nvme0n1p1 on /boot type vfat

It is annoying to update an headless X86 device that always resets to default.

Tried the squashfs image instead?

and what exactly is /dev/root, post fdisk -l ?

I have a combined ext4 image and I upgrade via the GUI with keeping settings.

root@X86:~# df -T
Filesystem           Type       1K-blocks      Used Available Use% Mounted on
/dev/root            ext4          253800     90212    158348  36% /
tmpfs                tmpfs        1019324       352   1018972   0% /tmp
/dev/sda1            vfat           16334      6610      9724  40% /boot
/dev/sda1            vfat           16334      6610      9724  40% /boot
tmpfs                tmpfs            512         0       512   0% /dev
root@X86:~#

I make my own builds but otherwise use OWUT to upgrade.
Make sure you have set the proper root fs_size beforehand if you changed that see:

Sorry for the long delay...
I finally got a time to get back to this.

I have now fixed the issue, like @egc pointed out:

So, I have my settings now:

root@reititin:~# uci show attendedsysupgrade.owut
attendedsysupgrade.owut=owut
attendedsysupgrade.owut.verbosity='1'
attendedsysupgrade.owut.pre_install='/etc/owut.d/pre-install.sh'
attendedsysupgrade.owut.rootfs_size='256'

And I created an extra partition to keep my backups:

root@reititin:~# parted -l -s
Model: ShiJi 128GB M.2-NVMe (nvme)
Disk /dev/nvme0n1: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name    Flags
128     17.4kB  262kB   245kB                        bios_grub
 1      262kB   17.0MB  16.8MB  fat16        boot    legacy_boot
 2      17.0MB  285MB   268MB   ext4         root
 3      2147MB  4295MB  2147MB  ext4         backup

This works now, BUT, there is one issue:
First time you set the owut.rootfs_size, it seems to completely wipe your partition table. I was trying to create root partition with exactly 256 MiB and expanded the ext4 to that size. However, it was completetly wiped.

But now, when restored from backup, and doing owut upgrade --force, everything works. Even the extra partitions are kept.

So the attendedsysupgrade.owut.rootfs_size is the answer. But only after it wipes the partition table once.

Yeah, it appears that sysupgrade is doing a simple size check and if the rootfs has changed size, then it writes a new partition table from scratch.

This actually sounds like a bug.

When I was not defining the root_fs size, it uses some kind of default.
It is documented to be 104MiB.

But even when the partition is created as exactly same size, it still seem to be re-created every time, unless I manually specify the rootfs_size = <something> for owut.

So either there is something wrong on sysupgrade when it calculates the default (or current) size, or this has to be documented.
If I would have known this, I could have created the initial install image using the rootfs_size already set. But I cannot find any way to control this for OpenWrt Firmware Selctor. The value used for default build is not shown there.

So for X86 with ext4 rootfs, best way to install is to install once with default image, then define the rootfs_size that you want, then re-install with owut and finnish the setup with probably extra partitions if you prefer.

Worth mentioning here, in case someone stumbles on the same issue:

If you have a larger disk, and you plan to create extra partitions:
Leave a large gap between rootfs and your extra partition.

And try to remember where your partition started.

For example, when I created the partition, I used something like:

parted /dev/nvme0n1 mkpart backup 1024MiB 2048Mib
mkfs.ext4 /dev/nvme0n1p3

# Add this to /etc/fstab, and add /etc/fstab to a list of files to backup
/dev/nvme0n1p3 /mnt/backup ext4 defaults 0 0

# Then add this to /etc/rc.local
mkdir -p /mnt/backup
mount -a 

NOTE: My /etc/owut.d/pre-install.sh does local backups into /mnt/backup.

Now, when I lost the partition table on the first install, I can recover it because I rembember it was 1024MiB from the beginning of the disk.
So booting OpenWRT in rescue mode

mount_root
parted /dev/nvme0n1 rescue 1024MiB 2048MiB

mkdir -p /mnt/backup
mount -t ext4 /dev/nvme0n1p3 /mnt/backup

# Now I can restore the local backup
sysupgrade -r /mnt/backup/backup-<timestamp>.tgz

This thread seems to be a valuable one to read… I picked up a atom-based x86_64 box - now running Openwrt with AdGuardHome and Tailscale, but I was unsure of how attendedsysupgrade interacts with the partitions, grub.

I’ll be sure to backup my settings and Tailscale statefile before tinkering.