Expanding your BeagleBone microSD Filesystem

| | 26 Comments| 7:34 AM
Categories:

There are a number of tutorials out there that show you how to expand a BeagleBone Black microSD-based filesystem. Most of them were written, however, when the delivered image from BeagleBoard.org contained two partitions: one a FAT partition, the other your standard Linux partition.

The aim of this post is to show you that indeed, you have nothing to fear expanding your BeagleBone Black partition even though there is only one (if you’re like us you get a little nervous when someone asks you to delete the partition you booted in).

Editor’s Note: I have updated this post for use with the latest BeagleBone Black IoT images which does require attention to the starting sector.

Let’s get started. We’re using the Debian 10.3 IoT 2020-04-06 4GB image from BeagleBoard.org. As you can see with df it’s a 4G (3.4G) filesystem, even though we just flashed it onto an 8GB microSD card:

debian@beaglebone:~$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1  3.4G  1.9G  1.4G  57% /

The filesystem is on the mmcblk0 device, so we’ll use fdisk to repartition:

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

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

Use the p command to print the current partition table. As expected, we see that the device itself has 8GB of space (well, 7.4), but our only partition is 3.5G.

Command (m for help): p
Disk /dev/mmcblk0: 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: dos
Disk identifier: 0x3244345d

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk0p1 *     8192 7372799 7364608  3.5G 83 Linux

Write down the starting sector as you will need it below. In our case it is 8192.

Now, the “scary” part. Enter d to delete your partition.

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

Don’t worry, we’re adding it right back, with a size larger than the existing one. Enter n for New partition, and then p for primary partition.

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

At this point hit Enter at each prompt to accept the defaults, with the exception of the First Sector which you will need the value you wrote down from above. When prompted whether or not you want to remove the ext4 signature, type N.

Partition number (1-4, default 1): 
First sector (2048-15523839, default 2048): 8192
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8192-15523839, default 15523839): 

Created a new partition 1 of type 'Linux' and of size 7.4 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Use p once more to print out the partition table:

Command (m for help): p
Disk /dev/mmcblk0: 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: dos
Disk identifier: 0x3244345d

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192 15523839 15515648  7.4G 83 Linux

Now press w (for write) and get another scary warning:

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).

You can now use resize2fs to resize your partition:

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 1940224 (4k) blocks long.

Use df -h / again and verify that you have reclaimed the unused space on your SD card.

Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1  7.3G  1.9G  5.1G  27% /

And that’s it! No reboot required, and you can enjoy the full capacity of your microSD card.

26 thoughts on “Expanding your BeagleBone microSD Filesystem”

  1. Perfect. Solved my confusion.
    Much better than most of the other outdated tutorials for BeagleBoards.

    1. The best article ever, and I combed through a couple of hundred, or so it seems. It was noted from another comment that you need to put in the starting sector from the stats, not the default 2048. Having said that, it’s about a five minute setup, on BBB Debian Jessey 8.7. Also, there doesn’t seem to be the old requirement of unlplugging all devices or waiting for all lights to go solid blue. Really, after there is a steady pattern of one blue light flashing, the board is ready; easy peasy

  2. Hey I am using Beaglebone black and have installed ubuntu 14.04 on it. Now I want to expand my file system but will I loose my all data which is there in emmc ??? I am new to ubuntu so much confused!

  3. Hey Joe, I have a problem resizing my SD card. Everything goes well until I type in partprobe and it says that the partition is in use. Resize2fs says nothing to do. After I restart BBB, I cant boot into SD card, because emmc boots everytime. Do you have any idea how to fix it? Thanks.

    1. I had similar problems. Seems that the BBB is corrupting the MBR of the SD card. This happens every time if the above procedure is done on the BBB. I did the resize using another linux machine with gparted. Now the SD card boots just fine.

      Not sure if it’s something to do with the SD card make and model because I haven’t had these problems with kingston/sandisk/transcend cards. I’m using the “raspberry pi” 16GB card at the moment.

    2. Hey Firrel, I had the same problem until I found this solution on another site. When creating the new partition, make sure the starting sector is EXACTLY the same as the original starting sector. Choosing the defaults may cause it to choose another sector which with corrupt the card. After that, you can continue using the defaults and following the rest of the tutorial.

  4. At last I managed to do it. After repartition, I have restarted the device and flashed SD to EMMC. Then mmcblk0p1 is 7.4 GiB.

  5. For those of you that are having issue booting after following these steps, the issue is in the start sector. In later revisions of Debian for BBB, the start sector of the written SD cards is 8192 (at least in all of my writes). So, an amendment to the procedure:

    When you first start fdisk on /dev/mmcblk0 and type ‘p’ to list the partition table, make note of the number listed under “start”. This guide says “2048”, but mine said “8192”. Yours may differ, but you’ll need your number to do this correctly.

    Now, delete your partition according to the guide, but when creating your NEW partition, use YOUR start sector number when following the prompts, like so:

    Partition number (1-4, default 1): 1
    First sector (2048-15523839, default 2048): 8192

    Follow the rest of the guide as normal. Boots just fine! Thanks for the guide, and keep up the good work!

  6. Great tutorial! Thank you so much. I used it with a “16 GB” SanDisk Ultra Class 10 card flashed with the bone-debian-8.6-lxqt-4gb-armhf-2016-11-06-4gb.img.xz image available from https://beagleboard.org/latest-images after I had also added a few files to the card. The first print of the partition table showed a start sector of 8192 (instead of 2048), so I used 8192 instead of taking the default of 2048 in creating the new partition table that was then written back to the card.

  7. You’ll probably hate me for this 🙂

    On *nix, you can create the USB boot drive with dd, then use parted or its GUI front-end gparted to expand the partition.

    I thought I could do this in Windows using rufus and Windows Disk Manager but no go. WDM wouldn’t let me do anything to the unallocated space on the USB drive

  8. Hurray ! I got it to work after several hours of swearing and googling and as it turns out, reading dated material. Many thanks for this little tutorial. I’m a retired guy and bought a BBB to learn Linux and maybe do some LinuxCNC work with someday. I really appreciate your efforts with this and wanted to send you a note of thanks. You might want to place an “Alert” in the main text of your tutorial so that people are alerted to the 8192 thing. I usually don’t read comments and it was only after trying it a couple of times, and re-imaging the SD card, that I looked further down and read the comments – lol

    Keep up the good work.
    Lewis

  9. I did this tutorial, I get the following error when resize

    root@beaglebone:~# sudo partprobe
    root@beaglebone:~# sudo resize2fs /dev/mmcblk0p1
    resize2fs 1.43 (17-May-2016)
    resize2fs: Bad magic number in super-block while trying to open /dev/mmcblk0p1
    Couldn’t find valid filesystem superblock.
    root@beaglebone:~# sudo resize2fs /dev/mmcblk0p1
    resize2fs 1.43 (17-May-2016)
    resize2fs: Bad magic number in super-block while trying to open /dev/mmcblk0p1
    Couldn’t find valid filesystem superblock.
    root@beaglebone:~# df -h /
    Filesystem Size Used Avail Use% Mounted on
    /dev/mmcblk1p1 3.5G 3.1G 167M 95% /

  10. Thank you, first.
    but i still got this error:

    root@beaglebone:~# 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): d
    Selected partition 1
    Partition 1 has been deleted.

    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): 1
    First sector (2048-31116287, default 2048): 2048
    Last sector, +sectors or +size{K,M,G,T,P} (2048-31116287, default 31116287): 31116287

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

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

    root@beaglebone:~# partprobe
    root@beaglebone:~# resize2fs /dev/mmcblk0p1
    resize2fs 1.42.12 (29-Aug-2014)
    resize2fs: Bad magic number in super-block while trying to open /dev/mmcblk0p1
    Couldn’t find valid filesystem superblock.

  11. pac’s comment helped me too, I had to specify the correct start size but here’s what tripped me up:

    I was playing with 4GB cards and at first the default start number was correct. Then, when I moved to trying this with an 8GB card, the default number was still the same as it was for the 4GB card and I just assumed it would be correct but looking back at the fdisk’s p printout, I could see that for the 8GB card the number was different. Just gotta pay close attention to that.

  12. Thanks a ton. Really great tutorial. It turns out resizing my partition was exactly what i missed when i previously tried to increase my beaglebone’s storage

Leave a Reply to Brian Cancel reply

Your email address will not be published. Required fields are marked *