香蕉派系统是直接烧录再SD卡内,所以我的32GB SD卡有二十多个G空间浪费掉了,所以就开始了扩容

首先查看系统分区情况

pi@bpi-iot-ros-ai:~$ sudo df -h
[sudo] password for pi: 
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.0G  5.4G  1.3G  82% /
devtmpfs        431M     0  431M   0% /dev
tmpfs           431M     0  431M   0% /dev/shm
tmpfs           431M   23M  409M   6% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           431M     0  431M   0% /sys/fs/cgroup
tmpfs            87M     0   87M   0% /run/user/1000

下面开始分区前检查,查看需要操作的分区的柱面信息,这里记住mmcblk0p2开始柱面号码:729088,下面会用到

pi@bpi-iot-ros-ai:~$ sudo fdisk -l
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x5f5cd814

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1      204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 15267839 14538752    7G 83 Linux

操作目的是删除掉mmcblk0p2,然后重新给它分区

pi@bpi-iot-ros-ai:~$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-62333951, default 2048): 729088   
Last sector, +sectors or +size{K,M,G,T,P} (729088-62333951, default 62333951): 

Created a new partition 2 of type 'Linux' and of size 29.4 GiB.

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

以上步骤做完,其他的就不要操作,直接重启,使用resize2fs命令更新文件系统

pi@bpi-iot-ros-ai:~$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
resize2fs: Permission denied to resize filesystem

如果成功的话,这里就完成了,但是我遇到了问题,resize2fs不成功
出现错误:resize2fs: Permission denied to resize filesystem

我处理这个问题,是将SD卡从香蕉派上取下来,接入我virtualbox中的ubuntu系统内进行resize2fs操作的

以上仅是我的成功操作过程的记录