Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

Beagleboard:Expanding File System Partition On A microSD

From eLinux.org
Jump to: navigation, search

This is a tutorial on how to expand the space used by the file system on an external micro SD card on your BeagleBone Black. This tutorial will work with any of the Linux operating systems mentioned on Ubuntu On BeagleBoard Black or Debian On BeagleBoard Black that boot from a micro SD card. The images on those pages are set up for 1-4 GB micro SD cards. If you are using a larger micro SD card you can re-partition it to have more space available for the file system. You can expand the file system's partition to any unused space on your micro SD card. This tutorial uses fdisk and resize2fs so if the distribution you are using supports those you should be able to follow along.

Expanding the File System Partition

These steps assume you are booting from a micro SD card with some sort of extra unused space. You will need to access the command line of whatever operating system you are using. The easiest way to do this is to connect to your BeagleBone Black with a display, mouse, and keyboard. You may also try connecting over serial ( described here) although that may be different depending on your version of Linux.

Just to be completely clear, you are executing these steps from the terminal on your BeagleBone Black in the OS you are using.

Note: For the following command line instructions, do not type the '#', that is only to indicate that it is a command to enter.

From the command line of your Linux OS on your BeagleBone Black, become super user. The password will depend on your version of Linux (see the page that described how to install your version of Linux).

# sudo su
  • You don't have to become super user. If you don't want to, just put 'sudo' at the beginning of all your commands.

Check available volumes on the BeagleBone Black

# ll /dev/mmcblk*

Depending on what version of Linux you are running it should look something like this:

brw-rw---T 1 root floppy 179, 0  Jan 1 2000 /dev/mmcblk0
brw-rw---T 1 root floppy 179, 1  Jan 1 2000 /dev/mmcblk0p1
brw-rw---T 1 root floppy 179, 2  Jan 1 2000 /dev/mmcblk0p2
brw-rw---T 1 root floppy 179, 8  Jan 1 2000 /dev/mmcblk1
brw-rw---T 1 root floppy 179, 16 Jan 1 2000 /dev/mmcblk1boot0
brw-rw---T 1 root floppy 179, 24 Jan 1 2000 /dev/mmcblk1boot1
brw-rw---T 1 root floppy 179, 9  Jan 1 2000 /dev/mmcblk1p1
brw-rw---T 1 root floppy 179, 10 Jan 1 2000 /dev/mmcblk1p2

Examine the partitioning on your external SD card

# fdisk /dev/mmcblk0

Then enter 'p' and you should be shown a print out like this

Command (m for help): p

Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
4 heads, 16 sectors/track, 252384 cylinders, total 16152576 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
Disk identifier: 0x80000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
/dev/mmcblk0p2            4096     3751935     1873920   83  Linux

Command (m for help):
  • Note: Depending on the size of your micro SD some values may be different. Sector size should be the same.

You should notice that your XXXXXXXXXX bytes divided by your Sector size: 512 bytes is equal to your total XXXXXXXX sectors

  • In the example above, 8270118912 / 512 = 16152576

Next, enter 'd' to delete a partition and then enter '2' for partition 2 (/dev/mmcblk0p2)
Entering 'p' again will show that you have deleted /dev/mmcblk0p2

Command (m for help): p

Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
4 heads, 16 sectors/track, 252384 cylinders, total 16152576 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
Disk identifier: 0x80000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048        4095        1024    1  FAT12

Command (m for help):

Now create a new partition by entering 'n' then 'p' and then '2'
You should hit enter to have your default start sector used.
You can make your end sector whatever you want in case you don't want to use your whole micro SD but you can just hit enter to use the default.

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (4096-16152576, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-16152576, default 16152576): 
Using default value 16152576

You can enter 'p' again to see that the /dev/mmcblk0p2 has re-appeared.

Command (m for help): p

Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
4 heads, 16 sectors/track, 252384 cylinders, total 16152576 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
Disk identifier: 0x80000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
/dev/mmcblk0p2            4096    16152576     8074240   83  Linux

Command (m for help):

If you are satisfied with your changes at this point you can enter 'w' to commit to your changes. If you want to cancel or restart just enter <CTRL>+Z

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.

Reboot your system

# reboot

Lastly, after your BeagleBone Black reboots, you need to expand the file system. Enter the command 'df'

  • Remember to become root user again after reboot (enter: sudo su)

You should see a print out like this:

Filesystem     1K-blocks   Used Available Use% Mounted on
rootfs           1811704 441152   1276856  26% /
/dev/root        1811704 441152   1276856  26% /
devtmpfs          253716      0    253920   0% /dev
tmpfs              50772    252     50600   1% /run
tmpfs               5120      0      5120   0% /run/lock
tmpfs             101540      0    101540   0% /run/shm
/dev/mmcblk0p1      1004    472       532  48% /boot/uboot
  • Again, your numbers may vary. It may also say "/dev/mmcblkop2" instead of "rootfs"

Run the following command:

# resize2fs /dev/mmcblk0p2

This will take about a minute to complete

resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 2018560 blocks long.

Entering 'df' again will show a change in percentage of use for the file system

Filesystem     1K-blocks   Used Available Use% Mounted on
rootfs           7919880 442668   7139200   6% /
/dev/root        7919880 442668   7139200   6% /
devtmpfs          253716      0    253716   0% /dev
tmpfs              50772    252     50520   1% /run
tmpfs               5120      0      5120   0% /run/lock
tmpfs             101540      0    101540   0% /run/shm
/dev/mmcblk0p1      1004    472       532  48% /boot/uboot

The file system of your OS on your micro SD card should now be expanded to use your card to it's full potential. You should now have room to install desktops such as ubuntu-desktop, xubuntu-desktop or Gnome-desktop.

Simplified

The steps in the previous section can be simplified to these essential commands:

  1. sudo su
  2. fdisk /dev/mmcblk0
  3. d
  4. 2
  5. n
  6. p
  7. 2
  8. w
  9. reboot
  10. sudo su (after reboot is complete)
  11. resize2fs /dev/mmcblk0p2