現在來解決在安裝樹莓派系統時遇到的28GB空閑空間不能被系統使用的問題。
用PuTTY遠程登錄樹莓派,查看磁盤狀態:
pi@raspberrypi:~ $ df -h
系統能識別到的磁盤空間總共只有1.7G,裝完系統后已經用了1.1G,還剩470M。
方法1:使用raspi-config工具中的Expand Filesystem擴展
pi@raspberrypi:~ $ sudo raspi-config
選擇 7 Advanced Options,回車
選擇 A1 Expand Filesystem,
提示如下(下次重啟后更新),回車確認:
退出時會提示是否重啟,選擇是:
方法2:使用fdisk、resize2fs命令擴展
系統安裝完成后,SD卡中一共有兩個主分區
/dev/mmcblk0p1:Boot分區,FAT32格式
/dev/mmcblk0p2:Root分區,EXT4格式
現在要做的是擴展第2分區(Root區),輸入的命令如下:
1 查詢空閑分區(第2分區)的起始地址:
pi@raspberrypi:~ $ cat /sys/block/mmcblk0/mmcblk0p2/start
顯示的第二分區起始地址是98304,后面會用到。
2 打開Linux分區表操作工具fdisk
pi@raspberrypi:~ $ sudo fdisk /dev/mmcblk0
pi@raspberrypi:~ $ sudo 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.
fdisk 常用指令
n: 添加新的分區
p: 查看分區信息
w: 保存退出
q: 不保存退出
d: 刪除分區
t: 改變分區類型
3 刪除原來的第2分區(要修改原來的分區結束地址)
輸入d表示刪除分區,輸入2表示要刪除的分區是第2分區,提示第2分區已經被刪除:
Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted.
4 重新創建第2分區
輸入n表示添加新的分區,輸入p表示要添加的是主分區,輸入2表示要添加的分區是第2分區:
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
輸入第1步得到的第2分區起始地址:XXXX,然后輸入第2分區的結束地址,默認就是最大地址,直接回車就好了,提示已經創建了第2主分區,大小為29.7GB。提示分區2包含一個前面,是否要刪除,這個一定要選擇No,輸入n。
First sector (2048-62333951, default 2048): 98304 Last sector, +sectors or +size{K,M,G,T,P} (98304-62333951, default 62333951): Created a new partition 2 of type 'Linux' and of size 29.7 GiB. Partition #2 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: n
5 保存設置
輸入w,保存退出。提示要reboot以后生效。
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).
6 重啟
pi@raspberrypi:~ $ sudo reboot -h now
7 調整文件系統大小
重啟后還需要用resize2fs命令來調整文件系統的大小:
pi@raspberrypi:~ $ sudo resize2fs /dev/mmcblk0p2
到這里就結束了,確認一下磁盤信息
pi@raspberrypi:~ $ df –h
或者用fdisk工具+p命令看一下分區信息
pi@raspberrypi:~ $ sudo fdisk /dev/mmcblk0