If you
are reading this, probably you already created your microSD card for the
PocketBeagle which is recommended to be 4GB or bigger. But, regardless of the size
of the microSD card you used the system image that got written on it has a
fixed size that is most probably less than the total capacity of the card.
In my
case, I used a 16GB microSD card, lets see how much is used …
debian@beaglebone:~$ df -v
Filesystem 1K-blocks Used Available Use% Mounted on
udev 220048 0
220048 0% /dev
tmpfs 49624 5592
44032 12% /run
/dev/mmcblk0p1 3357264 1659656 1507352
53% /
tmpfs 248112 0
248112 0% /dev/shm
tmpfs 5120 0
5120 0% /run/lock
tmpfs 248112 0
248112 0% /sys/fs/cgroup
tmpfs 49620 0
49620 0% /run/user/1000
As you
can see the total size of the root file system is about 3.3GB and 53% is
already used !
Then, how
can you increase the size to use the total available capacity on the microSD
card ?
The
process is similar on other BeagleBoards and actually on many Linux
distributions, on the PocketBeagle is very simple since there is only one “memory
block” device /dev/mmcbkl0
debian@beaglebone:~$ ls -l
/dev/mmc*
brw-rw---- 1 root disk 179, 0
Mar 5 07:12 /dev/mmcblk0
brw-rw---- 1 root disk 179, 1
Mar 5 07:12 /dev/mmcblk0p1
For the
next few operations you will have to become the superuser (root,) instead of
having to enter each command preceded by sudo, you can just do sudo -I which
will give you the shell in root mode
debian@beaglebone:~$ sudo -i
We trust you have received the
usual lecture from the local System
Administrator. It usually boils
down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great
responsibility.
[sudo] password for debian:
root@beaglebone:~#
Notice
that after entering the password now the command prompt changed from $ to #,
you are now in superuser mode.
To increase
the size of the partition and filesystem, first we’ll have to check the
partition table and delete the current partition (don’t worry it does not
delete the contents) and create a new partition with the new size.
root@beaglebone:~# fdisk
/dev/mmcblk0
Welcome to fdisk (util-linux
2.29.2).
Changes will remain in memory
only, until you decide to write them.
Be careful before using the
write command.
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB,
15931539456 bytes, 31116288 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: 0x0736b542
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 8192 6963199 6955008 3.3G 83 Linux
Command (m for help):
Take
note on with sector the partition says it starts, in this case 8192.
Now we
will delete the existing partition and create a new one starting at the same
sector but we’ll change where it ends, you can choose a smaller number than the
total available sectors but I will chose the default which will give me all the
available space on the current microSD card
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): 8192
Last sector, +sectors or
+size{K,M,G,T,P} (8192-31116287, default 31116287):
Created a new partition 1 of
type 'Linux' and of size 14.9 GiB.
Partition #1 contains a ext4
signature.
Do you want to remove the
signature? [Y]es/[N]o: n
Command (m for help):
Notice
that it now says the size of the Linux partition is 14.9 GiB !
No need
to delete the signature, but we have not written yet the new partition table on
the microSD card, we can double check the new parameters printing the new partition
table
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB,
15931539456 bytes, 31116288 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: 0x0736b542
Device Boot Start End
Sectors Size Id Type
/dev/mmcblk0p1 8192 31116287 31108096 14.9G 83 Linux
What we
want, all the available space on the microSD card as the Linux partition, then
we are ready to write the table
Command (m for help): w
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).
As soon
as we wrote the new partition the Linux kernel detects that it has changed and
we’ll have to reboot so it can load the new table
root@beaglebone:~#
reboot
You will
obviously lose your connection to the board if you are connected via ssh, then
wait for the board to reboot then restart the connection, login and become root
with sudo -i
login as: debian
debian@192.168.7.2's password:
Linux beaglebone 4.9.82-ti-r102
#1 SMP PREEMPT Thu Feb 22 01:16:12 UTC 2018 armv7l
The programs included with the
Debian GNU/Linux system are free software;
the exact distribution terms
for each program are described in the
individual files in
/usr/share/doc/*/copyright.
Debian GNU/Linux comes with
ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Mar 5 07:31:39 2018 from 192.168.7.1
debian@beaglebone:~$ sudo -i
[sudo] password for debian:
root@beaglebone:~#
Before
you do anything else we need to finish the process by extending the size of the
filesystem with resize2fs, we’ll use the device that points to the first
partition /dev/mmcblk0p1
root@beaglebone:~# resize2fs
/dev/mmcblk0p1
resize2fs 1.43.4 (31-Jan-2017)
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 3888512 (4k) blocks long.
Let’s
check then how much space we have now
root@beaglebone:~# df -v
Filesystem 1K-blocks Used Available Use% Mounted on
udev 220048 0
220048 0% /dev
tmpfs 49624 4960
44664 10% /run
/dev/mmcblk0p1 15247576 1662340 12914392
12% /
tmpfs 248112 0
248112 0% /dev/shm
tmpfs 5120 0
5120 0% /run/lock
tmpfs 248112
0 248112 0% /sys/fs/cgroup
tmpfs 49620 0
49620 0% /run/user/1000
There you
go, now we have all the available space on the microSD card and we have only 12%
used, enough to download some updates/upgrades and packages for development.
Essentially
the same process is used to increase the size of any Linux partition but you
must be very careful if you have more than one partition on the table since
they can’t overlap and by changing the table and resizing the filesystems you
may lose the data if not done properly.
So, what’s
next ? Connecting to the Internet ? why not ?
How to coming soon !
Cheers
Jorge