如何扩展TF卡的剩余空间?

问题描述

我使用的是64 G的TF卡刷镜像系统,但是在昉·星光单板计算机上编译ffmpeg时提示空间不足。在启动Fedora系统并运行df -h命令后,我发现/dev/mmclbk0p4上只挂载了12 G的内存,剩余的空间去哪里了?我该如何做才能使用到剩余的空间?

产品型号

昉·惊鸿7100

硬件版本

昉·星光单板计算机

软件版本

Fedora 33

问题原因

Fedora image解压后是12.6 G,当您烧录Fedora系统时,您的TF卡只分配了12.6 G的空间,剩余的空间未分配。

解决方法

您可以在Fedora系统中扩展TF卡的剩余空间。

解决步骤

  1. 查看当前Fedora系统下的磁盘使用情况,执行以下命令后,您能看到根文件系统挂载在/dev/mmcblk0p4分区:
    [riscv@fedora-starfive ~]$ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        3.5G     0  3.5G   0% /dev
    tmpfs           3.6G     0  3.6G   0% /dev/shm
    tmpfs           1.5G  1.2M  1.5G   1% /run
    /dev/mmcblk0p4   12G  8.3G  2.9G  75% /
    tmpfs           3.6G  4.0K  3.6G   1% /tmp
    /dev/mmcblk0p3  458M  130M  314M  30% /boot
    /dev/mmcblk0p2  122M  4.5M  118M   4% /boot/efi
    tmpfs           718M   52K  718M   1% /run/user/985
    tmpfs           718M   44K  718M   1% /run/user/1000
    [riscv@fedora-starfive ~]$
  2. 执行以下命令,查看到第4分区的起始地址为“1320960”,该地址在后续创建第4分区时会用到。
    [riscv@fedora-starfive ~]$ cat /sys/block/mmcblk0/mmcblk0p4/start
    1320960
    [riscv@fedora-starfive ~]$
  3. 执行以下命令,以操作TF卡:
    [riscv@fedora-starfive ~]$ sudo fdisk /dev/mmcblk0
     
    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 riscv:          #Enter user password
     
    Welcome to fdisk (util-linux 2.36.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         #Delete partition
    Partition number (2-4, default 4): 4            #Delete partition #4
     
    Partition 4 has been deleted.
     
    Command (m for help): n         #Create a new partition
    Partition type
       p   primary (2 primary, 0 extended, 2 free)
       e   extended (container for logical partitions)
    Select (default p): p           # Create primary partition
    Partition number (1,4, default 1): 4            #Create partition #4
    First sector (2048-122138623, default 2048): 1320960            #Enter the starting address of partition #4
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (1320960-122138623, default 122138623):           #Press "enter" to select default 
    Created a new partition 4 of type 'Linux' and of size 57.6 GiB.
    Partition #4 contains a ext4 signature.
     
    Do you want to remove the signature? [Y]es/[N]o: N          #Do not remove the signature
     
    Command (m for help): w         #Write the above operations to the partition table
     
    The partition table has been altered.
    Syncing disks.
     
    [riscv@fedora-starfive ~]$
  4. 设置完成后,执行以下命令重启系统:
    sudo reboot
  5. 重启进入系统后,执行resize2fs命令来调整ext文件系统的空间大小,系统磁盘才能扩容。
    [riscv@fedora-starfive ~]$ sudo resize2fs /dev/mmcblk0p4
    [sudo] password for riscv:
    resize2fs 1.45.6 (20-Mar-2020)
    Filesystem at /dev/mmcblk0p4 is mounted on /; on-line resizing r[  313.505284] EXT4-fs (mmcblk0p4): resizing filesystem from 2999808 to 15102208 blocks
    equired
    old_desc_blocks = 2, new_desc_blocks = 8
    [  315.140090] EXT4-fs (mmcblk0p4): resized filesystem to 15102208
    The filesystem on /dev/mmcblk0p4 is now 15102208 (4k) blocks long.
     
    [riscv@fedora-starfive ~]$ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        3.5G     0  3.5G   0% /dev
    tmpfs           3.6G     0  3.6G   0% /dev/shm
    tmpfs           1.5G  1.2M  1.5G   1% /run
    /dev/mmcblk0p4   57G  8.3G   49G  15% /
    tmpfs           3.6G  4.0K  3.6G   1% /tmp
    /dev/mmcblk0p3  458M  130M  314M  30% /boot
    /dev/mmcblk0p2  122M  4.5M  118M   4% /boot/efi
    tmpfs           718M   52K  718M   1% /run/user/985
    tmpfs           718M   44K  718M   1% /run/user/1000
    [riscv@fedora-starfive ~]$

    现在您的根文件系统已经从原来的12 G扩容到57 G了。