Shrink root partition, cant answer Yes

I can not asnwer Yes to parted.

How to modify script to send Yes to parted ?

root@OpenWrt:/etc/uci-defaults# sh ./70-rootpt-resize
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?

already done:

parted -f -s "${ROOT_DISK}"
resizepart "${ROOT_PART}" 1GiB Yes

doesnt works

You have to shrink the filesystem first (which I think is resize2fs), then change the partition table. Otherwise some of the data will be abandoned outside the partition. As a general rule filesystems don't fill up the disk in order from the start of the partition. The resize filesystem process will gather up all the data that are part of existing files (thus needs to be saved) and place it into the new smaller space.

It is probably necessary to boot another OS (such as OpenWrt from a USB drive) so that the filesystem you are shrinking is not mounted.

nothing will be shrinked in real data

because i did expand and want to shrink back.

You must unmount the ext4 filesystem to shrink, cannot happen with ext4 root.

Am I lost, or didn't the OP just ask a question based on an impossible premise?

What official OpenWrt image are you trying to shrink [that's capable of expansion] are you using that's [originally] larger than 1 GiB?

i use 70,80 scripts from openwrt wiki.

it can resize partition, unmound and resize fs.

i did mistake and did run script with 100% value, now my root uses 100% of hard drive.

i need to shrink it.

It can not unmount rootfs containing resize2fs.

What is in ubus call system board ?

why it can not?

while in initramfs 70,80 scripts do work.

{
"kernel": "6.6.93",
"hostname": "OpenWrt",
"system": "Intel(R) Atom(TM) CPU D525 @ 1.80GHz",
"model": "Intel Corporation D525MWV",
"board_name": "intel-corporation-d525mwv",
"rootfs_type": "ext4",
"release": {
"distribution": "OpenWrt",
"version": "24.10.2",
"revision": "r28739-d9340319c6",
"target": "x86/64",
"description": "OpenWrt 24.10.2 r28739-d9340319c6",
"builddate": "1750711236"
}
}

Boot ubuntu from usb and resize what you need.

i know.

but dont want do it.

On initramfs stage i can resize, isnt it?

this is how 80-rootfs-resize works, isnt it?

You have to have all tools outside partition you are sizing down…

If you dont want we dont push you, enjoy your terabyte partition for longer.

i suppose i have it

80-rootfs-resize works there, isnt it?

fs is not rootfs and you have 2 identical guid-s likely…. Ubuntu to have nothing colliding together.

dont understand what are you talking about…

one thing i see, i have to resize2fs before part table resize.

An ext4 filesystem can be enlarged while it is mounted and active, but it must be unmounted to reduce the size.

I doubt that the script was ever designed or tested for the case of reducing the size. You should do that manually. Or even back up your configuration, reinstall OpenWrt from scratch, and use the script to resize (upward) to the size you want.

I'm still missing something that that user already erased 100% of all remaining partitions?

100% == 100% + ? of the [lost] data?

Is this an academic exercise to resize the partitions and copy the correct binary data [from the official OpenWrt img]?

no , it is not academic exercise.

on windows i can expand or shrink very well.

on linux i have a bunch of troubles . dont know how i can resize root partition.

i thought this script can shrink as well as expand.

but now i understand that sequence must be reverted for shrink operation.

Install squashfs installation, then you will have router-like stable backup image and resize whatever you want. Like “normal” linux has init ramdisk that has basic tools to …. check disks and edit fstabs….

Ahh yes, ext4 x84 can not fsck root and will go rotten sooner or later.

hi,

usually you can simulate interactive question-answer based linux tool by feeding the answers like this:

echo “yn” | tool

which will feed y to first question, then n to 2nd question if questions expecting one character answer.

but in your case, shrinking will not work on a mounted file system as others already told. better boot a live linux and do it from there, or re-write the owrt factory image again to your disk.

Well, you can chroot to tmpfs with installation copied, umount rootfs and fsck it, but you have to be command line copperfield to achieve it.