Expanding root partition and filesystem

  • This instruction expands OpenWrt root partition and filesystem on x86 target.
  • Follow the automated section for quick setup.
  • 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.
# Configure startup scripts
cat << "EOF" > /etc/uci-defaults/70-rootpt-resize
if [ ! -e /etc/rootpt-resize ] \
&& type parted > /dev/null \
&& lock -n /var/lock/rootpt-resize
then
BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)"
BOOT_PART="${BOOT_DEV##*[^0-9]}"
DISK_DEV="${BOOT_DEV%${BOOT_PART}}"
parted -l ---pretend-input-tty << EOI
ok
fix
EOI
parted -s "${DISK_DEV%p}" resizepart "$((BOOT_PART+1))" 100%
touch /etc/rootpt-resize
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/rootpt-resize
then
BOOT_DEV="$(sed -n -e "\|\s/boot\s.*$|{s///p;q}" /etc/mtab)"
BOOT_PART="${BOOT_DEV##*[^0-9]}"
DISK_DEV="${BOOT_DEV%${BOOT_PART}}"
ROOT_DEV="${DISK_DEV}$((BOOT_PART+1))"
ROOT_TYPE="$(ubus call system board \
| jsonfilter -e "$['rootfs_type']")"
case "${ROOT_TYPE}" in
(ext4) LOOP_DEV="$(losetup -f)"
losetup "${LOOP_DEV}" "${ROOT_DEV}" ;;
(squashfs) LOOP_DEV="$(losetup -n -l \
| sed -n -e "\|\s.*\s${ROOT_DEV#/dev}\s.*$|{s///p;q}")" ;;
esac
resize2fs -f "${LOOP_DEV}"
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
# Install packages
opkg update
opkg install parted losetup resize2fs
 
# Expand root partition/filesystem
sh /etc/uci-defaults/70-rootpt-resize
uclient-fetch -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"
. ./expand-root.sh
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/04/28 01:11
  • by vgaetera