Skip to content

Instantly share code, notes, and snippets.

@treeherder
Last active July 1, 2023 21:36
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save treeherder/34830497fa90c1b5eaea to your computer and use it in GitHub Desktop.
Save treeherder/34830497fa90c1b5eaea to your computer and use it in GitHub Desktop.
how to expand the rootfs of the beagle bone black from a flashed eMMC onto the SD card

We have used the most recent beagleboard debian eMMC flasher image to flash the beagle bone black eMMC. As of this writing: wget http://debian.beagleboard.org/images/BBB-eMMC-flasher-debian-7.5-2014-05-14-2gb.img.xz After flashing is complete, erase the sd card, then reboot. Once booted, We can use fdisk -l to list our available devices, I found mine by checking the size and the partition table. After verfifying the card's address, we can reformat it to fit our needs. Of course, this can be done before plugging the card in, as well.

debian@beaglebone:~$ fdisk -l
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes 
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192    31116287    15554048    b  W95 FAT32

After re-partitioning, it should look like this:

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048    20973567    10485760   83  Linux
/dev/mmcblk0p2        20973568    31116287     5071360   83  Linux

From here we format the partitions as ext4 for the file system:

mkfs.ext4 /dev/mmcblk0p1
mkfs.ext4 /dev/mmcblk0p2

Next, we make a place to temporarily store the files from our rootfs
mkdir /tmp/usr && mkdir /tmp/home and then we mount the new partitions we made to the appropriate points and rsync the data. If you have a new installation, this should be relatively painless, but it might take longer if you have a lot of files in these directories

mount /dev/mmcblk0p1 /tmp/usr && mount /dev/mmcblk0p2 /tmp/home
rsync -ahv --progress /usr/ /tmp/usr/
rsync -ahv --progress /home/ /tmp/home/ 

The last thing we have to do is alter fstab to reflect the changes we have made and the new location of our file system.

echo UUID=$(lsblk -no UUID /dev/mmcblk0p1) /usr ext4    defaults 0 1 >> /etc/fstab
echo UUID=$(lsblk -no UUID /dev/mmcblk0p2) /home ext4    defaults 0 1 >> /etc/fstab

After rebooting, we can check it like this:

debian@beaglebone:/$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                  1.7G  1.4G  236M  86% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   100M  564K   99M   1% /run
/dev/disk/by-uuid/e2ab0b3b-9ad4-4fdb-97a9-830a9a2cba3e  1.7G  1.4G  236M  86% /
tmpfs                                                   249M     0  249M   0% /dev/shm
tmpfs                                                   249M     0  249M   0% /sys/fs/cgroup
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   100M     0  100M   0% /run/user
/dev/mmcblk1p1                                           96M   72M   25M  75% /boot/uboot
/dev/mmcblk0p1                                          9.8G  1.1G  8.2G  12% /usr
/dev/mmcblk0p2                                          4.7G  9.7M  4.4G   1% /home

Now that we see everything is as we expected, it's time to clean up the mess: rm -r /tmp/{usr,home};mkdir /tmp/rootfs; mount --bind / /tmp/rootfs Next, we simply add a test file to check if the mounting is sound:

touch /tmp/rootfs/usr/test

root@beaglebone:/# ls /tmp/rootfs/usr/
bin  games  include  lib  local  sbin  share  src  test
root@beaglebone:/# ls /usr/
bin  games  include  lib  local  lost+found  sbin  share  src

Everything works! We can finalize our changes and move on with our lives:

rm -rf /tmp/rootfs/{usr,home}/*

@treeherder
Copy link
Author

on the intel edison, it's /dev/mmcblk1

@dsgn1graphics
Copy link

@treeherder, Thanks for this! I was able to drop my rootfs size down to 13% from 91%. This is the best write up I've seen so far on expanding the Beaglebone Black filesystem, and the only one that has actually worked for me.

@Gfast2
Copy link

Gfast2 commented Jan 15, 2017

Hi treeherder, that is cool.
But I'm *nix guru for these kind of stuff. So I find something easier:

  • In beaglebone's file system:
    cd /opt/scripts/tools
  • execute the shell script for this:
    ./grow_partition.sh
    This trick works for me. hopefully it will some else too.

cheers!

@idcrook
Copy link

idcrook commented Feb 2, 2017

@Gfast2 Thanks for this hint about /opt/scripts/tools/grow_partition.sh. I was also able to use gparted on an Ubuntu Linux host to resize the partition. Just insert with µSD card/USB reader with freshly flashed Debian image (e.g. bone-debian-8.6-lxqt-4gb-armhf-2016-11-06-4gb.img), and select the /dev where SD card gets mounted. Drag the slider to resize to full extent/whatever using its GUI, and apply partition changes. It runs the resize task.

@Chief1820
Copy link

@Gfast2 Thanks a million, I knew that script was around somewhere, but it is rare to find the location posted somewhere prominent enough to pop on a google search. You saved the day for me, I have three of these little gems, one with a nice 4 inch cape screen, I am hoping to be able to use a large card to install a gaming OS on her and use her as a portable game machine. I plan on selling my Gameboy setup, she is nice but I am no longer a boy at 67 years, and I see the price of these guys is climbing every day on Ebay. If I can replace it with a BeagleBone Black running the SNES emulator I will have a much nicer machine, I have a joystick I can hook to some of the pins and really go to town with the little gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment