在使用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
- d, 3 to delete the swap partition
- d, 2 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卡刷系统时默认空间扩容