Expanding the filesystem on a bootable SD card kb-2

Octavo / Beaglebone Black  

If you flash a bootable image onto a large SD card, you won't be able to make use of the space beyond the initial install size of 3.6 Gb until you expand the root partition.  There are other guides on the internet for doing this expansion, but they often refer to a 'p2' partition, which is no longer present in recent distributions for the BeagleBone and Octavo/GHI OSD3358.


  1. Create a bootable SD card by flashing a debian image onto it
  2. Boot your device using this new SD card
  3. Use Tera Term or a similar program to log onto your device.
  4. Execute df -h / and notice that it appears that we've got a full drive (99%)

    debian@beaglebone:~$ df -h /
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/mmcblk0p1  3.3G  3.0G   36M  99% /

  5. Also, note that your filesystem is on the /dev/mmcblk0 device, and the /dev/mmcblk0p1 partition
  6. The first step is to re-partition the sd card with fdisk.  We'll start by listing out the partition table:

    debian@beaglebone:~$ sudo fdisk /dev/mmcblk0

    Welcome to fdisk (util-linux 2.25.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Command (m for help): p
    Disk /dev/mmcblk0: 14.9 GiB, 16021192704 bytes, 31291392 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: dos
    Disk identifier: 0x6c6218b4
    Click and drag to move
    Device         Boot Start     End Sectors  Size Id Type
    /dev/mmcblk0p1 *     2048 6963199 6961152  3.3G 83 Linux


  7. Delete partition 1. Yes, that's the partition your OS is on - the OS that is currently running!  However, nothing that we're doing will disrupt the running system.

    Command (m for help): d
    Selected partition 1
    Partition 1 has been deleted.

  8. We will immediately re-create that partition, but at the maximum size of the SD card. It looks like a lot going on here, but we just type n, p and then press ENTER three times for the default values:

    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1):
    First sector (2048-31291391, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-31291391, default 31291391):

    Created a new partition 1 of type 'Linux' and of size 14.9 GiB.

  9. Write the table to the SD card.  You can ignore the warning - it is expected

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Re-reading the partition table failed.: Device or resource busy

    The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).


  10. Force the OS to 'notice' the new partition table:

    debian@beaglebone:~$ sudo partprobe

  11. And now, resize the filesystem living within that partition so that it takes up all of the available space we just created:

    debian@beaglebone:~$ sudo resize2fs /dev/mmcblk0p1
    resize2fs 1.42.12 (29-Aug-2014)
    Filesystem at /dev/mmcblk0p1 is mounted on /; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/mmcblk0p1 is now 3911168 (4k) blocks long.


  12. Now we can verify that we actually have more space:

    debian@beaglebone:~$ df -h /
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/mmcblk0p1   15G  3.0G   11G  22% /

  13. And you can see that we now have a full 15Gb of space to use.


comments powered by Disqus