找回树莓派SD卡剩余空间
前言:在安装好树莓派系统后,发现tf卡空间只有1.4G了。下面找回剩余空间。
首先来查看一下系统的磁盘情况
sudo fdisk -l
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 2048 1370111 684032 c W95 FAT32 (LBA)
/dev/mmcblk0p2 1370112 2369535 499712 83 Linux
/dev/mmcblk0p3 2369536 62930943 30280704 83 Linux
解决办法 (下列mmcblk0p2参考上面列出的磁盘情况):
pi@raspberrypi ~ $ df -h #查看当前磁盘大小,总大小只有2.9GB Filesystem Size Used Avail Use% Mounted on rootfs 2.9G 2.8G 15M 100% / /dev/root 2.9G 2.8G 15M 100% / devtmpfs 214M 0 214M 0% /dev tmpfs 44M 244K 44M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 88M 0 88M 0% /run/shm /dev/mmcblk0p1 56M 19M 37M 34% /boot tmpfs 88M 0 88M 0% /tmp pi@raspberrypi ~ $ cat /sys/block/mmcblk0/mmcblk0p2/start # 查看第二分区的起始地址,后面会用到 122880 pi@raspberrypi ~ $ sudo fdisk /dev/mmcblk0 #使用fdisk操作磁盘 Command (m for help): d #d,删除分区 Partition number (1-4): 2 # 2,删除第二分区 Command (m for help): n #创建一个新分区 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p #创建主分区 Partition number (1-4, default 2): 2 #分区2 First sector (2048-7744511, default 2048): 122880 #输入第一次得到的第二分区起始扇区 Last sector, +sectors or +size{K,M,G} (122880-7744511, default 7744511): #最后一个sector,默认即可Enter Using default value 7744511 Command (m for help): w #将上面的操作写入分区表 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: 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) Syncing disks. pi@raspberrypi ~ $ sudo reboot #设置完成需要重启,sudo reboot
重启完成之后,此时查询也还是没有变化的,还需要如下命令:
sudo resize2fs /dev/mmcblk0p2
再次
df -h
查看当前磁盘大小,会发现遗失的空间容量回来了。