Difference between revisions of "Beagleboard:Expanding File System Partition On A microSD"

From eLinux.org
Jump to: navigation, search
m (typo)
(Expanding the File System Partition)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
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 [[Beagleboard:Ubuntu_On_BeagleBone_Black | Ubuntu On BeagleBoard Black]] or [[Beagleboard:Debian_On_BeagleBone_Black | 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.
 
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 [[Beagleboard:Ubuntu_On_BeagleBone_Black | Ubuntu On BeagleBoard Black]] or [[Beagleboard:Debian_On_BeagleBone_Black | 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.
 +
 +
== The automated way ==
 +
 +
On newer Debian system images coming from BeagleBoard.org / Robert Nelson, you can run the script:
 +
sudo /opt/scripts/tools/grow_partition.sh
 +
(Source at https://github.com/RobertCNelson/boot-scripts/blob/master/tools/grow_partition.sh) and then reboot to grow your partition. The below steps describe how to do so manually.
  
 
== Expanding the File System Partition ==
 
== 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 ([[Beagleboard:Terminal_Shells | described here]]) although that may be different depending on your version of Linux.<br>
+
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 ([[Beagleboard:Terminal_Shells|described here]]) or SSH 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.<br>
+
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. <br>
+
'''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).
 
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
+
  # sudo -i
 
* You don't have to become super user. If you don't want to, just put ''''sudo'''' at the beginning of all your commands.
 
* 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
 
Check available volumes on the BeagleBone Black
 
  # ls /dev/mmcblk*
 
  # ls /dev/mmcblk*
 
Depending on what version of Linux you are running it should look something like this:
 
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---- 1 root disk 179, 0 Oct 2 23:09 /dev/mmcblk0
  brw-rw---T 1 root floppy 179, 1  Jan 1 2000 /dev/mmcblk0p1
+
  brw-rw---- 1 root disk 179, 1 Oct 2 23:09 /dev/mmcblk0p1
  brw-rw---T 1 root floppy 179, 2  Jan 1 2000 /dev/mmcblk0p2
+
  brw-rw---- 1 root disk 179,  8 Oct 2 23:09 /dev/mmcblk1
  brw-rw---T 1 root floppy 179, Jan 1 2000 /dev/mmcblk1
+
  brw-rw---- 1 root disk 179, 24 Oct  2 23:09 /dev/mmcblk1boot0
  brw-rw---T 1 root floppy 179, 16 Jan 1 2000 /dev/mmcblk1boot0
+
  brw-rw---- 1 root disk 179, 32 Oct  2 23:09 /dev/mmcblk1boot1
  brw-rw---T 1 root floppy 179, 24 Jan 1 2000 /dev/mmcblk1boot1
+
  brw-rw---- 1 root disk 179, 9 Oct 2 23:09 /dev/mmcblk1p1
  brw-rw---T 1 root floppy 179, 9  Jan 1 2000 /dev/mmcblk1p1
+
This shows the μSD card (mmcblk0) and eMMC (mmcblk1), each having one partition. (You can ignore the special "boot0/1" partitions of the eMMC.) On very old systems there may be two partitions, in which case p2 should be used instead of p1 in the instructions below.
  brw-rw---T 1 root floppy 179, 10 Jan 1 2000 /dev/mmcblk1p2
+
 
Examine the partitioning on your external SD card
+
Examine the partitioning on your external SD card:
 
  # fdisk /dev/mmcblk0
 
  # fdisk /dev/mmcblk0
 
Then enter ''''p'''' and you should be shown a print out like this
 
Then enter ''''p'''' and you should be shown a print out like this
Line 29: Line 35:
 
  Command (m for help): p
 
  Command (m for help): p
 
   
 
   
  Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
+
  Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
4 heads, 16 sectors/track, 252384 cylinders, total 16152576 sectors
+
  Units: sectors of 1 * 512 = 512 bytes
  Units = sectors of 1 * 512 = 512 bytes
 
 
  Sector size (logical/physical): 512 bytes / 512 bytes
 
  Sector size (logical/physical): 512 bytes / 512 bytes
 
  I/O size (minimum/optimal): 512 bytes / 512 bytes
 
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0x80000000
+
Disklabel type: dos
 +
  Disk identifier: 0x18e8111b
 
   
 
   
        Device Boot     Start         End     Blocks  Id System
+
Device         Boot Start     End Sectors  Size Id Type
  /dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
+
  /dev/mmcblk0p1       8192 7667712 7659521 3.7G 83 Linux
  /dev/mmcblk0p2            4096    3751935    1873920  83 Linux
 
 
   
 
   
 
  Command (m for help):
 
  Command (m for help):
* Note: Depending on the size of your micro SD some values may be different. Sector size should be the same.
+
* Note: Some values may be different. '''An important value to note is the start sector of the Linux partition''', 8192 in this case.
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 the Linux partition. (If you have two partitions it will ask which partition to delete, which should be 2.)
Next, enter ''''d'''' to delete a partition and then enter ''''2'''' for partition 2 (/dev/mmcblk0p2)<br>
 
Entering ''''p'''' again will show that you have deleted '''/dev/mmcblk0p2'''
 
  
  Command (m for help): p
+
Now it should be recreated: enter ''''n'''' to create a new partition. For the first two questions (partition type and number) just press enter. '''For the start sector, be absolutely sure to use the same number it had originally.''' In our example, that would be 8192. For the last sector, you can use 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 (the max size possible).
 +
 
 +
This is what the interaction looks like in our example:
 +
  Command (m for help): d
 +
Selected partition 1
 +
Partition 1 has been deleted.
 
   
 
   
  Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
+
  Command (m for help): n
  4 heads, 16 sectors/track, 252384 cylinders, total 16152576 sectors
+
  Partition type
Units = sectors of 1 * 512 = 512 bytes
+
    p  primary (0 primary, 0 extended, 4 free)
Sector size (logical/physical): 512 bytes / 512 bytes
+
    e  extended (container for logical partitions)
  I/O size (minimum/optimal): 512 bytes / 512 bytes
+
  Select (default p):  
Disk identifier: 0x80000000
 
 
   
 
   
        Device Boot      Start        End      Blocks  Id System
+
  Using default response p.
  /dev/mmcblk0p1  *        2048       4095        1024    1 FAT12
+
  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):
 
   
 
   
  Command (m for help):
+
  Created a new partition 1 of type 'Linux' and of size 7.4 GiB.
 
 
Now create a new partition by entering ''''n'''' then ''''p'''' and then ''''2''''<br>
 
You should hit enter to have your default start sector used. <br>
 
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.
+
You can enter ''''p'''' again to view the new partition table:
  
 
  Command (m for help): p
 
  Command (m for help): p
+
  Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
  Disk /dev/mmcblk0: 8270 MB, 8270118912 bytes
+
  Units: sectors of 1 * 512 = 512 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
 
  Sector size (logical/physical): 512 bytes / 512 bytes
 
  I/O size (minimum/optimal): 512 bytes / 512 bytes
 
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0x80000000
+
Disklabel type: dos
 +
  Disk identifier: 0x18e8111b
 
   
 
   
        Device Boot      Start        End     Blocks  Id System
+
Device         Boot Start     End Sectors  Size Id Type
  /dev/mmcblk0p1   *        2048        4095        1024    1  FAT12
+
  /dev/mmcblk0p1       8192 15523839 15515648 7.4G 83 Linux
  /dev/mmcblk0p2            4096    16152576    8074240  83 Linux
 
 
   
 
   
 
  Command (m for help):
 
  Command (m for help):
 +
 +
Note that the size of the partition has increased to that of the whole card, and the start sector is still the same as it was originally.
  
 
If you are satisfied with your changes at this point you can enter ''''w'''' to commit to your changes.
 
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'''
+
(If you want to cancel without making any change to the disk, just press '''<CTRL>+C'''.)
  
 
  Command (m for help): w
 
  Command (m for help): w
Line 107: Line 101:
 
  Syncing disks.
 
  Syncing disks.
  
Reboot your system
+
The warning above will appear if you're repartitioning the disk you've booted from. In that case, reboot your system:
 
  # reboot
 
  # reboot
  
Lastly, after your BeagleBone Black reboots, you need to expand the file system. Enter the command ''''df''''<br>
+
Lastly, after your BeagleBone Black reboots, you need to expand the file system. Before expanding you need to run ''fsck'' as root, otherwise next command will fail to run:
* Remember to become root user again after reboot (enter: '''sudo su''')<br>
+
  # fsck /dev/mmcblk0p1
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
+
Finally, run the following command (again as root):
rootfs          7919880 442668  7139200  6% /
+
  # resize2fs /dev/mmcblk0p1
/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.
+
Once this command completes, you're done!
  
 
== Simplified ==
 
== Simplified ==
Line 161: Line 124:
 
# reboot
 
# reboot
 
# sudo su (after reboot is complete)
 
# sudo su (after reboot is complete)
# resize2fs /dev/mmcblk0p2
+
# resize2fs /dev/mmcblk0p1

Latest revision as of 06:58, 8 June 2021

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.

The automated way

On newer Debian system images coming from BeagleBoard.org / Robert Nelson, you can run the script:

sudo /opt/scripts/tools/grow_partition.sh

(Source at https://github.com/RobertCNelson/boot-scripts/blob/master/tools/grow_partition.sh) and then reboot to grow your partition. The below steps describe how to do so manually.

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) or SSH 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 -i
  • 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

# ls /dev/mmcblk*

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

brw-rw---- 1 root disk 179,  0 Oct  2 23:09 /dev/mmcblk0
brw-rw---- 1 root disk 179,  1 Oct  2 23:09 /dev/mmcblk0p1
brw-rw---- 1 root disk 179,  8 Oct  2 23:09 /dev/mmcblk1
brw-rw---- 1 root disk 179, 24 Oct  2 23:09 /dev/mmcblk1boot0
brw-rw---- 1 root disk 179, 32 Oct  2 23:09 /dev/mmcblk1boot1
brw-rw---- 1 root disk 179,  9 Oct  2 23:09 /dev/mmcblk1p1

This shows the μSD card (mmcblk0) and eMMC (mmcblk1), each having one partition. (You can ignore the special "boot0/1" partitions of the eMMC.) On very old systems there may be two partitions, in which case p2 should be used instead of p1 in the instructions below.

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

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk0p1       8192 7667712 7659521  3.7G 83 Linux

Command (m for help):
  • Note: Some values may be different. An important value to note is the start sector of the Linux partition, 8192 in this case.

Next, enter 'd' to delete the Linux partition. (If you have two partitions it will ask which partition to delete, which should be 2.)

Now it should be recreated: enter 'n' to create a new partition. For the first two questions (partition type and number) just press enter. For the start sector, be absolutely sure to use the same number it had originally. In our example, that would be 8192. For the last sector, you can use 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 (the max size possible).

This is what the interaction looks like in our example:

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

Using default response p.
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.

You can enter 'p' again to view the new 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: 0x18e8111b

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

Command (m for help):

Note that the size of the partition has increased to that of the whole card, and the start sector is still the same as it was originally.

If you are satisfied with your changes at this point you can enter 'w' to commit to your changes. (If you want to cancel without making any change to the disk, just press <CTRL>+C.)

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.

The warning above will appear if you're repartitioning the disk you've booted from. In that case, reboot your system:

# reboot

Lastly, after your BeagleBone Black reboots, you need to expand the file system. Before expanding you need to run fsck as root, otherwise next command will fail to run:

# fsck /dev/mmcblk0p1

Finally, run the following command (again as root):

# resize2fs /dev/mmcblk0p1

Once this command completes, you're done!

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