Owut upgrade question for rpi4 with custom scripts and root file system size

Hello,

I am currently running 24.10.0-rc4 on rpi4.
Custom things on it is,

  • custom opkg packages.
  • custom firewall rules
  • custom static ipv4/ipv6 address.
  • one custom service (/etc/init.d/) created out of a custom script
  • and root file system expanded to full size as below
opkg install parted losetup resize2fs
wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"
. ./expand-root.sh
sed -i 's|root=PARTUUID=ba416753-02|root=/dev/mmcblk0p2|' /boot/cmdline.txt
sh /etc/uci-defaults/70-rootpt-resize

Do I simply have to run owut upgrade and it should upgrade and retain all above?

I went ahead and tried owut upgrade and it did upgrade. However few issue I ran in to,

  • It did not boot, and to fix, I had to run.
sed -i 's|root=PARTUUID=ba416753-02|root=/dev/mmcblk0p2|' /boot/cmdline.txt
  • custom service (/etc/init.d/) was gone.

See this post for an update to the extend script. I've tested it once but if you have a minute give it a go too.

It should amend the cmdline.txt with the new partuuid.

Are you suggesting I download https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0" and before executing edit expand_root.sh to include,

NEW_UUID=`blkid ${ROOT_DISK}p${ROOT_PART} | sed -n 's/.*PARTUUID="\([^"]*\)".*/\1/p'`
sed -i "s/PARTUUID=[^ ]*/PARTUUID=${NEW_UUID}/" /boot/cmdline.txt

?

expand_root.sh will create a couple of files in your file system.

/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize

These will run on first boot or manually as you have run by doing "sh /etc/uci-defaults/70-rootpt-resize".

/etc/uci-defaults/70-rootpt-resize will resize the root partition. During the resize the PARTUUID changes. If you edit 70-rootpt-resize and add the following after touch /etc/rootpt-resize (line 12)

NEW_UUID=`blkid ${ROOT_DISK}p${ROOT_PART} | sed -n 's/.*PARTUUID="\([^"]*\)".*/\1/p'`
sed -i "s/PARTUUID=[^ ]*/PARTUUID=${NEW_UUID}/" /boot/cmdline.txt

It should update the partuuid in cmdline.txt after the partition resize but before the reboot, so the system should come up again successfully without intervention. This should help with subsequent upgrades too.

My logic is that replacing the PARTUUID is a more generic way of fixing this issue rather than replacing the partuuid with /dev/mmcblk0p2 as there may be people who have their root on a different partition/device.

Hope this makes sense.

make sense.
I ran the logic outside the script and it correctly resolved NEW_UUID
I updated /etc/uci-defaults/70-rootpt-resize as you suggested.

Will monitor on next reboot/upgrade

1 Like

I was on 24.10.0, ran owut upgrade to upgrade to 24.10.1.
After reboot system did not boot.

When I checked /boot/cmdline.txt found,

console=tty1 console=serial0,115200 root=PARTUUID=a00596c2-02 rootfstype=squashfs,ext4 rootwait

So I changed root=PARTUUID=a00596c2-02 to root=/dev/mmcblk0p2 and that solved booting issue.
Is this something everything I have to perform after an upgrade?

Also files on my home directory (/root) was gone and /etc/init.d custom scripts also gone?
wont owut upgrade take care of that?

@d687r02j8g

owut doesn't do any backup/restore, it lets standard sysupgrade handle all of that. If you have configured /etc/sysupgrade.conf to contain the files and directories such that sysupgrade --list shows the correct items, that part should "just work."

Regarding your changed partition UUID, did you resize the partition after the previous upgrade? If so, then yes, this will happen every time you upgrade. If you want to avoid that and only use owut (imagebuilder, really), then configure the partition size as described at https://openwrt.org/docs/guide-user/installation/sysupgrade.owut#expanding_root_file_system

Currently,

root@OpenWrt:~# cat /etc/sysupgrade.conf
## This file contains files and directories that should
## be preserved during an upgrade.

# /etc/example.conf
# /etc/openvpn/
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize

Can adding

/etc/init.d/ddns_iface_change_status
/etc/init.d/node_exporter
/etc/init.d/power-outage-check
/usr/bin/node_exporter
/root/

to the last line of /etc/sysupgrade.conf make owut upgrade preserve those?

Yes, I had resized my partition.
Could you please once again explain what I need to do to make owut upgrade preserve my partition setup?

The files in /etc/uci-defaults/ are deleted as part of firstboot, so if you get the router to boot successfully, then they're gone and will not be backed up.

Yup, those should all work as you expect. Just run sysupgrade -l and maybe pipe through grep to see what is going to be saved.

Well, to be pedantic, nothing preserves the partition setup. What we're doing is replicating the current partitions in the new image, so when they are overwritten by sysupgrade, it appears that they have been preserved.

You do this with owut upgrade --rootfs-size 512 (512MB for example purposes, could be anything less than or equal to 1024). Since you don't want to type (or be forced to remember) --rootfs-size 512 every time you do an upgrade, you add that number to the config file and then it becomes the automatic default:

$ cat /etc/config/attendedsysupgrade
...

config owut 'owut'
       option rootfs_size 512

Subsequently, owut upgrade works as if you had supplied that value on the command line. Details and warnings here.

My router,

root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 29.3G 94.3M 29.2G 0% /
tmpfs 1.9G 36.1M 1.8G 2% /tmp
/dev/mmcblk0p1 63.9M 19.1M 44.8M 30% /boot
tmpfs 512.0K 0 512.0K 0% /dev
root@OpenWrt:~#

Does that mean, I should use 29.3G for --rootfs-size value?

No, you can't use anything bigger that 1024 MB for various reasons. Since you're only using 94.3 MB at present, and even if you try hard you'll have difficulty getting up above 500 MB or so, just set it to 1024 and carry on.

Currently my / is 30 GB roughly.
Setting --rootfs-size to 1024 mean, on next time owut upgrade it will be set as 1024 MB ?

That is correct. That is roughly 12 times the space you are currently using on that device, according to your df output.

Gotcha,
I am using a 32 GB sdcard. Just Wanted to see how can I make the remaining free space in it usable.

There's no easy way to get all of that space in a partition. Consider it like buying a big plot of land, 10 km2, then building a big house on it. You'd like to build a gigantic 10 km2 house (most of which you'd never use), but there's no easy way, the rest of the land will just have to be "wasted".

1 Like

Understood.

I made the settings changes as you suggested. I will wait for next owut upgrade and monitor.