Expanding root partition and filesystem on OpenWRT: Difference between revisions
Created page with "Category:OpenWrt = Expanding root partition and filesystem = == Introduction == This instruction expands OpenWrt root partition and filesystem on x86 target. Follow the automated section for quick setup. == Features == * Support `ext4` and `squashfs` image types. * Automatically identify the root partition and filesystem. * Expand the root partition and filesystem using free space. * Preserve the scripts through firmware upgrade. * Automatically run after firmw..." |
No edit summary |
||
| Line 21: | Line 21: | ||
=== Configure startup scripts === | === Configure startup scripts === | ||
<syntaxhighlight lang="bash"> | |||
cat | cat << "EOF" > /etc/uci-defaults/70-rootpt-resize | ||
if [ ! -e /etc/rootpt-resize ] \ | if [ ! -e /etc/rootpt-resize ] \ | ||
&& type parted > /dev/null \ | && type parted > /dev/null \ | ||
| Line 45: | Line 45: | ||
EOF | EOF | ||
cat | cat << "EOF" > /etc/uci-defaults/80-rootfs-resize | ||
if [ ! -e /etc/rootfs-resize ] \ | if [ ! -e /etc/rootfs-resize ] \ | ||
&& [ -e /etc/rootpt-resize ] \ | && [ -e /etc/rootpt-resize ] \ | ||
| Line 69: | Line 69: | ||
EOF | EOF | ||
cat > /etc/sysupgrade.conf | cat << "EOF" >> /etc/sysupgrade.conf | ||
/etc/uci-defaults/70-rootpt-resize | /etc/uci-defaults/70-rootpt-resize | ||
/etc/uci-defaults/80-rootfs-resize | /etc/uci-defaults/80-rootfs-resize | ||
EOF | EOF | ||
</syntaxhighlight> | |||
== Examples == | == Examples == | ||
| Line 79: | Line 79: | ||
=== Install packages === | === Install packages === | ||
<syntaxhighlight lang="bash"> | |||
opkg update | opkg update | ||
opkg install parted losetup resize2fs | opkg install parted losetup resize2fs | ||
</syntaxhighlight> | |||
=== Expand root partition/filesystem === | === Expand root partition/filesystem === | ||
<syntaxhighlight lang="bash"> | |||
sh /etc/uci-defaults/70-rootpt-resize | sh /etc/uci-defaults/70-rootpt-resize | ||
</syntaxhighlight> | |||
== Automated == | == Automated == | ||
<syntaxhighlight lang="bash"> | |||
opkg update | opkg update | ||
opkg install parted losetup resize2fs | opkg install parted losetup resize2fs | ||
wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0" | wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0" | ||
. ./expand-root.sh | . ./expand-root.sh | ||
</syntaxhighlight> | |||
Revision as of 20:24, 19 April 2025
Expanding root partition and filesystem
Introduction
This instruction expands OpenWrt root partition and filesystem on x86 target.
Follow the automated section for quick setup.
Features
- Support `ext4` and `squashfs` image types.
- Automatically identify the root partition and filesystem.
- Expand the root partition and filesystem using free space.
- Preserve the scripts through firmware upgrade.
- Automatically run after firmware upgrade.
Instructions
Configure startup scripts
cat << "EOF" > /etc/uci-defaults/70-rootpt-resize
if [ ! -e /etc/rootpt-resize ] \
&& type parted > /dev/null \
&& lock -n /var/lock/root-resize
then
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]}"
parted -f -s "${ROOT_DISK}" \
resizepart "${ROOT_PART}" 100%
mount_root
done
touch /etc/rootpt-resize
if [ -e /boot/cmdline.txt ]
then
NEW_UUID=`blkid ${ROOT_DISK}p${ROOT_PART} | sed -n 's/.*PARTUUID="\([^"]*\)".*/\1/p'`
sed -i "s/PARTUUID=[^ ]*/PARTUUID=${NEW_UUID}/" /boot/cmdline.txt
fi
reboot
fi
exit 1
EOF
cat << "EOF" > /etc/uci-defaults/80-rootfs-resize
if [ ! -e /etc/rootfs-resize ] \
&& [ -e /etc/rootpt-resize ] \
&& type losetup > /dev/null \
&& type resize2fs > /dev/null \
&& lock -n /var/lock/root-resize
then
ROOT_BLK="$(readlink -f /sys/dev/block/"$(awk -e '$9=="/dev/root"{print $3}' /proc/self/mountinfo)")"
ROOT_DEV="/dev/${ROOT_BLK##*/}"
LOOP_DEV="$(awk -e '$5=="/overlay"{print $9}' /proc/self/mountinfo)"
if [ -z "${LOOP_DEV}" ]
then
LOOP_DEV="$(losetup -f)"
losetup "${LOOP_DEV}" "${ROOT_DEV}"
fi
resize2fs -f "${LOOP_DEV}"
mount_root
done
touch /etc/rootfs-resize
reboot
fi
exit 1
EOF
cat << "EOF" >> /etc/sysupgrade.conf
/etc/uci-defaults/70-rootpt-resize
/etc/uci-defaults/80-rootfs-resize
EOF
Examples
Install packages
opkg update
opkg install parted losetup resize2fs
Expand root partition/filesystem
sh /etc/uci-defaults/70-rootpt-resize
Automated
opkg update
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