I could use a SD to boot into the device, unmount the eMMC's rootfs, extend the partition and filesystem to utilize that space. However, the SD card slot won't be available in the future custom design. So I don't find this idea useful.
Another solution I found was to use bitbake's IMAGE_ROOTFS_EXTRA_SPACE variable to build a image with necessary size. Again, the image size will be large and writing a single image into a eMMC could take much longer time, which I guess won't be efficient.
I am trying to expand the rootfs size using a script that runs during first boot up (shown below) of the system only. Although the same script (with slight modifications) works fine when trying to expand rootfs contained in an SD card, in case of eMMC, it doesn't work and complains about the mounted file system which is expected. I don't know why it worked on SD card.
To sum up, I have a root filesystem which needs to be expanded to fill the available space when the device boots up. I cannot use alternative boot media like USB or SD card. Is there any suitable solution that could work for the situation?
#!/bin/bash # Script to expand root partition and file system during first boot # Check if this is the first boot by looking for a marker file marker_file="/root/.firstboot_done" if [ -f "$marker_file" ]; then echo "First boot operations already completed. Exiting." exit 0 fi # Identify the root disk and partition root_mount=$(mount | grep ' / ' | cut -d' ' -f1) root_disk=$(echo "$root_mount" | awk '{print $1}' | sed 's/[0-9]*$//;s/p$//') root_partition=$(echo "$root_mount" | awk '{print $1}' | grep -o '[0-9]$') #echo "Root disk: $root_disk" # Expand the root partition (assuming /dev/sda and partition 2, adjust as needed) echo "Expanding partition $root_disk" parted $root_disk resizepart $root_partition 100% # Inform the kernel about the partition table changes #echo "Informing kernel about partition table changes" partprobe $root_disk # Resize the file system (assuming ext4, adjust as needed) echo "Resizing file system on $root_disk" sudo resize2fs ${root_mount} # Create a marker file to prevent repeated execution echo "Creating marker file: $marker_file" touch $marker_file echo "Root partition and file system expansion completed."
Hi
Using IMAGE_ROOTFS_EXTRA_SPACE to change rootfs size is most recommended. Also you can use script to extend it, you can try to use parted tool to resize your rootfs.
https://www.gnu.org/software/parted/manual/parted.html
Best Regards
Zhiming