Skip to content

Instantly share code, notes, and snippets.

@rxdu
Forked from treeherder/bbb_rootfs.md
Created January 19, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rxdu/35fb70c71cde5b44815e52bd8c338ff3 to your computer and use it in GitHub Desktop.
Save rxdu/35fb70c71cde5b44815e52bd8c338ff3 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}/*

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