Search code examples
yocto

How to set /dev/root filesystem size to the partition size


# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       4.3G  1.9G  2.2G  47% /
devtmpfs        980M     0  980M   0% /dev
tmpfs           981M     0  981M   0% /dev/shm
tmpfs           981M   33M  948M   4% /run
tmpfs           981M     0  981M   0% /sys/fs/cgroup
tmpfs           981M     0  981M   0% /tmp
tmpfs           981M   16K  981M   1% /var/volatile
# fdisk -l
Disk /dev/mmcblk1: 7.3 GiB, 7818182656 bytes, 15269888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier:

Device         Start      End  Sectors  Size Type
/dev/mmcblk1p1 16384    24575     8192    4M unknown
/dev/mmcblk1p2 24576    32767     8192    4M unknown
/dev/mmcblk1p3 32768    69859    37092 18.1M unknown
/dev/mmcblk1p4 81920 15269854 15187935  7.2G unknown

As far as I know, the /dev/root filesystem size is the size of the content that is being copied to the /dev/root.

My goal is to have /dev/root size the same as /dev/mmcblk1p4 which is 7.2G.
How can I instruct Yocto give the /dev/root filesystem the size of the partition it is mounted to?


Solution

  • I can see two possible solutions to your issue.

    The first one is by telling Yocto to generate an image with a sepcific IMAGE_ROOTFS_SIZE value. As stated in the Yocto Mega-Manual. The size is specified in KBytes. Modify your machine.conf or local.conf to add this parameter.

    In your case, the value seems to be:

    15269854 - 81920 = 15187934 sectors
    sectors are 512 Bytes on your system (see verification below)
    15187935 * 512 = 7776222208 Bytes
    7776222208 / 1024 = 7593967 KBytes
    
    To verify the sector size of 512B: 
    7593967 / (1024 * 1024) = 7.242 GB
    With 512 Bytes blocksize, the partition size is 7.2GB, as stated by fdisk
    

    I think it is a good idea to reduce it a little bit, a value like 7230000 Kilobytes (~7.23 GB) can be a good candidate.

    The other method is to use resize2fs program if your partition type is ext2/3/4. This program can be executed on mounted or unmounted devices. If you are using a SDcard, the simplest method will be to insert it into your computer, to unmount it, and run resize2fs /dev/<mysdcarddevice>. You can also execute it directly from your embedded board. In this case you will need to add the package e2fsprogs-resize2fs on the board with IMAGE_INSTALL += "e2fsprogs-resize2fs", then run resize2fs /dev/mmcblk1p4.