Microsd auto resize script

Hello!

While using openwrt on microsd device it is required that you manually resize overlay partition after flashing the device. That is annoying. Here is automated script, which can be part of openwrt.

How it works:

  1. resize partition using sfdisk (parted changes partuuid which breaks sysupgrade)

  2. run partprobe so firstboot will create propery sized (full size) overlay f2fs/ext4 partition

/lib/preinit/75_resize

do_resize() {
  ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e '$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
  ROOT_DISK="/dev/$(basename "${ROOT_BLK%/*}")"
  ROOT_PART="${ROOT_BLK##*[^0-9]}"
  echo ", +" | sfdisk --no-reread -N "$ROOT_PART" "$ROOT_DISK"
  partprobe
}

boot_hook_add preinit_essential do_resize

Does this script also require a custom/local sysupgrade image builder ?
If it does, why would the script be needed ?

It is easier to put it in a GUI linux and use fdisk with visuals.

Talk to others with your router for the specific partition. It depends on the hardware.

????
Would you like them to add a program to read your memory size and just presume how you want it partitioned???
That is annoying.

The script "doesn't work" if the amount of data in the roofs is > 1GB (4GB using 3rd party ASU server) anyway, since you won't be able to generate a rootfs large enough to accommodate everything currently stored.
That's why I asked about the local image builder.

If you have one, you won't be needing the script in the 1st place, then you simply build an image with the rootfs matching the size of your SD card.

We prefer English...

About 0:56 is what that was like.
:wink:

Now that I went over your post, word for word:

My reply was, really, ignorant.

"CLI can be challenging: you can drag the partion with 'click/hold'.

They need all the info you provided (I had not read it. I've done it that way and 'I' find it tedious) but they can look at another way, yes?

The layerd partitions OpenWrt uses are not intuitive in writing but once you see it, cli get easier.

Anyway:
Not all threads are about Scholar and one student. Someone may read it all and pick.

Still all you explaining how/why.

Problem isn't the resizing, problem is the rootfs getting written as an image.
Whatever you have currently stored, that's not Openwrt, needs to be transferred from the current rootfs to the new image during build, or it's lost.

Having a large rootfs able to store non-Openwrt stuff isn't wise. But if you don't store non-Openwrt stuff on it, you probably don't need to extend the rootfs to fill the drive/mem card, simply create an additional partition.

Btw, there's a (still open ?) PR for making the rootfs ~400MB for x86 and SBCs.

Oh:

You understood he was telling us "Can you not see this simple script will make OpenWrt up to grade school level. Here is a simple, flawed, script you beginners should use" and you were politely(?) walking them out. You were going in their direction anyway???

I really need to look at the category:
I just jump into all and would never post in here.

(walks away; tail 'tween legs)

It works (I assume, didn't test it), but that's not the issue, it's the way Openwrt handles upgrades.

Script works just fine with 2 or 3 parittions. Default image has 2 partition and it will resize second partition to the max whcih will give you all space avaiable. If you prepare microsd card manually after initial flashing and add 3-rd partition, this script does not erase it and does resize second parition to its maximum size possible. Even better, sysupgrade also keep it 3-rd parition. Should be part of openwrt.