Expand Endpoint partition to use the whole SD card

In another post, I showed how to create and mount a new partition or partitions on an Endpoint device. This post will show how to expand the Endpoint application partition to the full size of your SD card. Which approach, or blend of approaches you choose will depend on the needs of your application. For simplicity, you might want a single large partition. Or, you might choose to use a separate ext4 partition, or even a raw partition, for storing logs or data streams at maximum efficiency.

Whatever design you choose, you should always resize partition 7 before creating or modifying partitions 8 or above.

  1. Your dotnet app must not be running. Make sure it isn’t by using the Endpoint tool to disable run-at-startup, and then reboot your Endpoint board. It’s best if you start with a newly created SD card, or at least one that doesn’t have anything irreplaceable on it as typos or errors here might require that you re-image your SD card. It’s also best that you not reboot in between these steps.
  2. Connect to your Endpoint with ssh : ssh 192.168.82.2
  3. List the current partitions with : fdisk -l
    Disk /dev/mmcblk1: 7.4 GiB, 7948206080 bytes, 15523840 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: B27368D9-649F-47CD-80E2-C6B0A4C16DC0
    
    Device           Start     End Sectors  Size Type
    /dev/mmcblk1p1      34    1057    1024  512K Linux filesystem
    /dev/mmcblk1p2    1058    2081    1024  512K Linux filesystem
    /dev/mmcblk1p3    2082   10273    8192    4M Linux filesystem
    /dev/mmcblk1p4   10274 1058849 1048576  512M Linux filesystem
    /dev/mmcblk1p5 1058850 2107425 1048576  512M Linux filesystem
    /dev/mmcblk1p6 2107426 4204577 2097152    1G Linux filesystem
    /dev/mmcblk1p7 4204578 6252577 2048000 1000M Linux filesystem
    
  4. Take note of the “Start” block number for p7. In my case, it is 4204578.
  5. Unmount p7 with umount /root/.epdata
  6. Run fsdisk with : fsdisk /dev/mmcblk1
  7. Delete partition 7:
    Command (m for help): d
    
    Partition number (1-7, default 7): 7
    
    Partition 7 has been deleted.
    
  8. Write the new partition table:
    Command (m for help): w
    
    The partition table has been altered.
    Syncing disks.
    
  9. Run fsdisk again : fsdisk /dev/mmcblk1
  10. Create a new partition 7 and write that out. It is essential that you manually enter the First Sector value using the same number noted above in step 4:
    Command (m for help): n
    
    Partition number (7-128, default 7): 7
    First sector (4204578-15523806, default 4206592): 4204578
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (4204578-15523806, default 15523806):
    
    Created a new partition 7 of type 'Linux filesystem' and of size 5.4 GiB.
    Partition #7 contains a ext4 signature.
    
    Do you want to remove the signature? [Y]es/[N]o: N
    
    Command (m for help): w
    
    The partition table has been altered.
    Syncing disks.
    
  11. Now we have a partition that is the right size, but the filesystem (directory) structure within that partition still thinks it is the old size, so let’s run resize2fs to update the filesystem. Be sure to type the full partition name with p7 on the end in the resize2fs command: /dev/mmcblk1p7:
    # resize2fs /dev/mmcblk1p7
    resize2fs 1.46.5 (30-Dec-2021)
    Resizing the filesystem on /dev/mmcblk1p7 to 1414903 (4k) blocks.
    The filesystem on /dev/mmcblk1p7 is now 1414903 (4k) blocks long.
    
  12. Now, let’s remount our filesystem : mount /dev/mmcblk1p7 /root/.epdata
  13. A df command will show the new wide open spaces we have for our application and data:
    # df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/root               419444    198323    194088  51% /
    devtmpfs                154820         0    154820   0% /dev
    tmpfs                   220868         0    220868   0% /dev/shm
    tmpfs                   220868       228    220640   0% /tmp
    tmpfs                   220868        32    220836   0% /run
    /dev/mmcblk1p6          757680    736500         0 100% /root/.epnet
    /dev/mmcblk1p7         5554812     20352   5235096   0% /root/.epdata
    
  14. You should now be able to reboot and .epdata should be automatically remounted for you because it is listed in /etc/fstab. My SD card is an 8Gb card, and this shows around 5.5Gb of space that will be available for my application and any data that it saves in or below the app directory. Compare the mmcblk1p7 output from fdisk -l below to the output from step 3:
    Disk /dev/mmcblk1: 7.4 GiB, 7948206080 bytes, 15523840 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: B27368D9-649F-47CD-80E2-C6B0A4C16DC0
    
    Device           Start      End  Sectors  Size Type
    /dev/mmcblk1p1      34     1057     1024  512K Linux filesystem
    /dev/mmcblk1p2    1058     2081     1024  512K Linux filesystem
    /dev/mmcblk1p3    2082    10273     8192    4M Linux filesystem
    /dev/mmcblk1p4   10274  1058849  1048576  512M Linux filesystem
    /dev/mmcblk1p5 1058850  2107425  1048576  512M Linux filesystem
    /dev/mmcblk1p6 2107426  4204577  2097152    1G Linux filesystem
    /dev/mmcblk1p7 4204578 15523806 11319229  5.4G Linux filesystem
    
4 Likes

This step makes us headache if making a nuget. We can’t unmount if an application is running on that partition.

Unfortunately, it’s unavoidable. There are workarounds though. One workaround would be to have the dotnet code write a shell script to /tmp (or any other location not under /root/.eproot) and let that script do the umount, fsdisk, and resizefs, and then restart the app or reboot the board. That does mean that expanding the partition forces an app restart, but this is a one-time, first-run kind of an activity so that doesn’t sound too awful.

2 Likes

yep. Thanks