樹莓派擴展分區


>> [目錄] 數據遠程采集 Step by Step


現在來解決在安裝樹莓派系統時遇到的28GB空閑空間不能被系統使用的問題。image

用PuTTY遠程登錄樹莓派,查看磁盤狀態:

pi@raspberrypi:~ $ df -h

image

系統能識別到的磁盤空間總共只有1.7G,裝完系統后已經用了1.1G,還剩470M。


網絡上可以找到兩種常用的方法來擴展分區(推薦用第1種):

方法1:使用raspi-config工具中的Expand Filesystem擴展


pi@raspberrypi:~ $ sudo raspi-config

選擇 7 Advanced Options,回車

image

選擇 A1 Expand Filesystem,

image

提示如下(下次重啟后更新),回車確認:

image

退出時會提示是否重啟,選擇是:

image


方法2:使用fdisk、resize2fs命令擴展


系統安裝完成后,SD卡中一共有兩個主分區

/dev/mmcblk0p1:Boot分區,FAT32格式

/dev/mmcblk0p2:Root分區,EXT4格式

現在要做的是擴展第2分區(Root區),輸入的命令如下:

1586938602(1)

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

image

或者用fdisk工具+p命令看一下分區信息

pi@raspberrypi:~ $ sudo fdisk /dev/mmcblk0

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM