Using the full capacity of your SD card

Even on small SD cards (8Gb for instance) there’s a lot of leftover space you can use. These instructions show how to create and access that space.

  1. Log into the Endpoint shell : ssh root@192.168.82.2

  2. do : fdisk -l and you should see output that ends with a table like this:

    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
    

    We’re interested in the name /dev/mmcblk1 from that first line, which is the mass-storage device’s name.

  3. Do: fdisk /dev/mmcblk1 and ignore the scary warning. What we’re going to do won’t upset the apple cart.

  4. Enter: n

  5. Enter: p

  6. Hit return three times to accept the defaults which will create a new partition encompassing all of the remaining space on your SD card. You can, of course, create multiple smaller partitions by overriding the defaults and entering specific sizes or block counts.

  7. Enter p for a list of partitions and you should see your new partition at the end of the list:

    Command (m for help): p
    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
    /dev/mmcblk1p8 6254592 15523806 9269215  4.4G Linux filesystem
    
  8. Enter w

  9. At this point, I chose to enter the command reboot and then reconnect with ssh, but that may not strictly be necessary.

  10. Now we need to create a filesystem on our partition. You should be at the ‘#’ prompt now, so enter mkfs.ext4 /dev/mmcblk1p8. This can take a bit of time to execute, from a few seconds on an 8Gb drive to much longer on larger SD cards. Be patient.

  11. Mount the new drive: (You can choose a different mount point. /mnt is just a default place to hang mounted drives)

    # mkdir /mnt/data
    # mount /dev/mmcblk1p8 /mnt/data
    
  12. Enjoy the new space: You dotnet programs can now read/write files at /mnt/data/…

    # ls -al /mnt/data
    total 21
    drwxr-xr-x    3 root     root          4096 Jan  1 00:33 .
    drwxr-xr-x    3 root     root          1024 Jan  1 00:34 ..
    drwx------    2 root     root         16384 Jan  1 00:33 lost+found
    # df /mnt/data
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/mmcblk1p8         4478204        24   4230068   0% /mnt/data
    
4 Likes

This is great, thanks. I do this using windows where I add a partition with format option. It is a couple of mouse clicks. Your way is the better way, especially if the storage is not removable.

2 Likes

We are thinking add your steps to Endpoint config…

EP tool config: Add or make P7 bigger · Issue #67 · ghi-electronics/Endpoint-Libraries (github.com)

2 Likes

Martin:

Your instructions worked great!

I believe that a file system mounted with the mount command is not persistent. You have to mount the FS again after each boot.

For completeness, this should be included with your instructions. Even better, include instructions on what has to be added to the /etc/fstab file for the filesystem to be automatically mounted at boot.

Perhaps support for mounting a filesystem from an application?
*** there is a Mount command in FileSystem class but it has a pre-defined mount directory. ***

2 Likes

Excellent point. I sailed right over that detail. To be honest, this should become part of a nuget package to make it easier to do this sort of stuff from within your app rather than having to dip into the shell all the time. I’ll think about contributing something like that, along with access to a lot of the stuff in the /proc directory, which knows everything about the current state of your board, from core temps to free disk space to global memory usage.

To make a mount permanent:

  1. Reboot, to make sure no old temporary mounts are hanging around.

  2. Log into your Endpoint with ssh root@192.168.82.2

  3. Edit /etc/fstab with: nano /etc/fstab

  4. Add the line shown below to the end of the file. You can use spaces or tabs between the columns. The existing file on your sd card has tabs between the fields.

    /dev/mmcblk1p8     /mnt/data    ext4     rw,relatime   0   0
    

    You can change /mnt/data to any location you wish, just make sure that the directory exists. Use mkdir to create the mount point if it doesn’t exist already. For example, for the entry above, I did mkdir /mnt/data.

  5. Test your changes with: mount -a which should complete with no errors. If you get any errors, don’t reboot! You typed something wrongly and your board may not boot successfully. Either correct any typos, or delete the line you added.

  6. If mount -a completed without complaining, then you can reboot and you should see your new volume mounted. If you do ls -al and see a file named “lost+found”, then that’s your new volume. If you don’t see lost+found, then nothing got mounted and you’re probably just looking at an empty directory.

2 Likes

I am wondering, is it better to make P7 larger instead of adding P8?

Interesting question…

Martin’s solution gives the user maximum flexibility, allowing for the placement and sizing of multiple additional filesystems.

But, GHI’s mantra has always been FEZ. Automatically increasing the size of the P7 partition to fill the SD on first boot is transparent. The user does not need to be concerned with evil Linux configuration files.

A compromise could be to add an API call to expand the P7 partition. Then he user can choose which is best for them and their application.

1 Like

My approach would be to create a filesystem nuget that allows the app to query the resources and then choose to either extend p7 or create one or more partitions or some combination of both.

2 Likes