iAchieved.it

Software Development Tips and Tricks

By

Expanding your BeagleBone microSD Filesystem

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

Let’s get started. We’re using the Debian 8.3 LXQT 2016-01-24 4GB image from BeagleBoard.org. As you can see with df it’s a 4G (3.3G) 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.3G  2.8G  282M  91% /

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.25.2).
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.3G.

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: 0xa2911fde

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk0p1 *     2048 6963199 6961152  3.3G 83 Linux

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.

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

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

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: 0xa2911fde

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       2048 15523839 15521792  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).

Some tutorials would have you reboot here, but we’re going to run partprobe instead and then use resize2fs to resize our partition:

debian@beaglebone:~$ sudo partprobe
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.

Editor’s Update: If you get to sudo partprobe only to find out that it isn’t installed, don’t panic! Just run sudo apt-get install parted and you’ll be on your way. Yes, this is after you’ve written you’re partition table and before you’ve resized your filesystem!

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

debian@beaglebone:~$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1  7.3G  2.8G  4.2G  40% /

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

26 Responses to Expanding your BeagleBone microSD Filesystem

  1. Jim Lind says:

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

  2. Julio says:

    Excellent, thanks!

    • Joe says:

      You’re welcome!

    • 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

  3. Jef says:

    Thanks for this NEW tutorial.
    Avoid me from get “scared” while doing this 😉

    cheers

  4. dangraz says:

    Thank you. Very nice and useful tutorial.

  5. Jan says:

    Thanks a lot!

  6. Udai says:

    Good to-the-point post, Thanks !

  7. JoeZhou says:

    This is very nice! Thank you!

  8. PJR says:

    Excellent post. Well explained and complete. Thank you.

  9. swati shirke says:

    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!

  10. Firrel says:

    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.

    • Pete says:

      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.

    • Derek says:

      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.

  11. Firrel says:

    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.

  12. Arda Tekin says:

    Debian was not able to boot up after resizing 32GB microsd for the installed debian 8.6 image (https://debian.beagleboard.org/images/bone-debian-8.6-lxqt-4gb-armhf-2016-11-06-4gb.img.xz), seems that this is the current working method,

    http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Expanding_File_System_Partition_On_A_microSD

  13. pac says:

    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!

  14. Dick Morris says:

    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.

  15. Daniel Escasa says:

    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

  16. Lewis says:

    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

  17. Charlie says:

    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% /

  18. bbb says:

    don’t forget to make partition bootable:
    Command (m for help): a
    Partition number (1-4): 1

  19. bing says:

    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.

  20. Andrew says:

    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.

  21. Dan says:

    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

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