剛買的樹莓派+16g 內(nèi)存卡, 但是使用
$ df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點
/dev/root 7.2G 4.3G 2.6G 63% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 432M 0 432M 0% /dev/shm
tmpfs 432M 5.9M 426M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 432M 0 432M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 21M 43M 34% /boot
tmpfs 87M 0 87M 0% /run/user/1000
發(fā)現(xiàn)實際只使用了7.2G ,當場懷疑是不是買到了假內(nèi)存卡 ..
于是再查看實際的內(nèi)存卡大小
$ sudo fdisk -l
......
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
......
發(fā)現(xiàn)內(nèi)存卡的確是16g,只是沒有使用剩下的磁盤空間, 那么現(xiàn)在就來擴大分區(qū)
管理磁盤
$ sudo fdisk /dev/mmcblk0
輸入 p
查看當前硬盤使用情況
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0f4a54c8
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 137215 129024 63M c W95 FAT32 (LBA)
/dev/mmcblk0p2 137216 15523839 15386624 7.3G 83 Linux
刪除除了mmcblk0p1 以外的分區(qū) (注意, 請慎重刪除,如果出現(xiàn)數(shù)據(jù)丟失責任自負),在我這里就是刪除分區(qū)2
輸入d
, 再接著輸入你要刪除的分區(qū)號 ,我這里是2
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
接著重新創(chuàng)建新的分區(qū),輸入 n
(新建), 再輸入p
創(chuàng)建主分區(qū),再輸入要創(chuàng)建的主分區(qū)號 , 我這里是2
,接著輸入起始存儲塊 , 這個是根據(jù)上面/dev/mmcblk0p1
的 end
列數(shù)字+1 算出來的 ,我的上面是137215
,所以要輸入的是137216
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):
First sector (2048-31116287, default 2048): 137215
Sector 137215 is already allocated.
First sector (137216-31116287, default 137216): 137216
Last sector, +sectors or +size{K,M,G,T,P} (137216-31116287, default 31116287):
Created a new partition 2 of type 'Linux' and of size 14.8 GiB.
最后輸入 w
寫入
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
寫入后修復分區(qū)
$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3872384 (4k) blocks long.
(注意,如果這一步失敗了,可能需要重啟下 linux 再次嘗試,失敗的信息為 The filesystem is already 1923328 (4k) blocks long. Nothing to do!
)
再次輸入 df -h
,發(fā)現(xiàn)分區(qū)已經(jīng)擴大了
文件系統(tǒng) 容量 已用 可用 已用% 掛載點
/dev/root 15G 4.3G 9.6G 31% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 432M 0 432M 0% /dev/shm
tmpfs 432M 5.9M 426M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 432M 0 432M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 21M 43M 34% /boot
tmpfs 87M 0 87M 0% /run/user/1000