Raspberry Pi - 調整你的SD卡分割區的大小


在使用Win32DiskImager為一張空白的SD卡刷入新的Rasbian系統后,卡上的可用剩余空間並不大,

本人有一張8G的SD卡,但是刷入4.1的Rasbian后,用df -h查看,根目錄下的空間使用率居然是99%,而且總空間也就3.5G左右。

原因是因為Rasbian的image是為2G SD卡(這應該指的是Wheezy版本,Jessie版本應該是3.5G或者更多)准備的,如果想用剩余空間,就得重新分配分區。

來自官方的解釋如下:

The prepared images for the Raspberry Pi are created for SD cards of the size of 2GB. The SD card can be resized or restructured to use the full size of a SD card that is greater than 2GB.

 

OK,下面就是具體方法(來自 elinux.org):

Manually resizing the SD card on Raspberry Pi

You can also resize the partitions of the SD card that your Pi is running on.

First you need to change the partition table with fdisk. You need to remove the existing partition entries and then create a single new partition than takes the whole free space of the disk. This will only change the partition table, not the partitions data on disk. The start of the new partition needs to be aligned with the old partition!

Start fdisk:

sudo fdisk /dev/mmcblk0

Then delete partitions with d and create a new with n. You can view the existing table with p.

  • p to see the current start of the main partition
  • d3 to delete the swap partition
  • d2 to delete the main partition
  • n p 2 to create a new primary partition, next you need to enter the start of the old main partition and then the size (enter for complete SD card). The main partition on the Debian image from 2012-04-19 starts at 157696, but the start of your partition might be different. Check the p output!
  • w write the new partition table

Now you need to reboot:

 sudo shutdown -r now

After the reboot you need to resize the filesystem on the partition. The resize2fs command will resize your filesystem to the new size from the changed partition table.

sudo resize2fs /dev/mmcblk0p2

This will take a few minutes, depending on the size and speed of your SD card.

When it is done, you can check the new size with:

df -h

事實上老外也早早有遇到類似問題,在stackoverflow上問過:

How can I resize my / (root) partition?

 

可能有人不喜歡慢慢看英文,下面就來段中文的,摘錄自網絡

步驟1: 重新啟動你的電腦,不要啟動X windows

步驟2: $ sudo df -h
你應該會看到/ 掛載於rootfs(已使用97%左右)。

步驟3: $ sudo fdisk /dev/mmcblk0
命令:按P(印刷)
你應該會看到三個分區,現在把分區2的信息寫下來(/dev/mmcblk0p2)。
命令:按d(刪除分區2)
命令:按p(印刷)
現在應該會看到2個分區
命令:按n(加分區)
選擇P (主要)
於分區2選擇2
第一空格輸入原來分區2的開始位置
最后的空格輸入默認值
命令:按p(印刷)
你應該會看到分區2填滿所有空間
命令:按w(保存)

步驟4: $sudo reboot
重新啟動后,使用resize2fs來修復分區2

步驟5: $ sudo resize2fs /dev/mmcblk0p2
等待約2-3分鍾

步驟6: $ sudo df -h
你應該會看到 / 掛載於rootfs(如果你使用8G SD卡,現在只會有22%的使用)

這樣你便可以善用SD卡余下的空間了。

 


當然也有人根據elinux.org的建議,在ubuntu或者其它linux系統上使用gparted來對SD卡重新分配空間,可參考下面這篇博客,本文就不細述了。

樹莓派Raspberry Pi 16G SD卡刷系統時默認空間擴容

 


免責聲明!

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



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