充分使用树莓派SD卡容量

参考:
http://cedar-renjun.github.io/2015/10/11/resize-raspberry-sd-volume/
按照文章说的方法果然有效啊。看了这个作者说的,才发现原来/dev/mmcblk0p2设备是挂载在/目录下,默认开始只有6.8G。通过查看/etc/fstab之后找到这一行验证了

/dev/mmcblk0p2  / ext4 errors=remount-ro 0 1

既然有p2,那么p1呢?在该文件中发现p1是挂载在/boot目录下,用于系统启动的吧?

/dev/mmcblk0p1 /boot vfat noauto 0 0

不过因为我之前不会这么做,自己新加了几个分区,导致我得先将之前的那几个分区删除或者打包转移, umount。
之前是这个鬼样子。

cqq@snort-ids  ~  df -h                                                                                                        [20:14:33]
文件系统        容量  已用  可用 已用% 挂载点
/dev/root       6.7G  6.3G   74M   99% /
devtmpfs        459M     0  459M    0% /dev
tmpfs           463M     0  463M    0% /dev/shm
tmpfs           463M   19M  445M    4% /run
tmpfs           5.0M     0  5.0M    0% /run/lock
tmpfs           463M     0  463M    0% /sys/fs/cgroup
/dev/mmcblk0p5  4.8G   39M  4.5G    1% /usr/local
/dev/mmcblk0p3   12G  406M   11G    4% /home
tmpfs            93M  4.0K   93M    1% /run/user/113
tmpfs            93M     0   93M    0% /run/user/1000

然后我就开始整理这几个多余的分区了。

cqq@snort-ids  ~  sudo fdisk  /dev/mmcblk0                                                                                     [20:14:35]
[sudo] cqq 的密码:

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.


Command (m for help): p
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x30dd529e

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1             1   125000   125000   61M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        125001 14334047 14209047  6.8G 83 Linux
/dev/mmcblk0p3      14336000 39501823 25165824   12G 83 Linux
/dev/mmcblk0p4      39501824 49987583 10485760    5G  5 Extended
/dev/mmcblk0p5      39503872 49987583 10483712    5G 83 Linux

Command (m for help): d
Partition number (1-5, default 5):

Partition 5 has been deleted.

Command (m for help): p
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x30dd529e

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1             1   125000   125000   61M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        125001 14334047 14209047  6.8G 83 Linux
/dev/mmcblk0p3      14336000 39501823 25165824   12G 83 Linux
/dev/mmcblk0p4      39501824 49987583 10485760    5G  5 Extended

Command (m for help): d
Partition number (1-4, default 4):

Partition 4 has been deleted.

Command (m for help): p
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x30dd529e

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1             1   125000   125000   61M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        125001 14334047 14209047  6.8G 83 Linux
/dev/mmcblk0p3      14336000 39501823 25165824   12G 83 Linux

Command (m for help): d
Partition number (1-3, default 3):

Partition 3 has been deleted.

Command (m for help): p
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x30dd529e

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1           1   125000   125000   61M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      125001 14334047 14209047  6.8G 83 Linux

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 设备或资源忙


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).

 ✘ cqq@snort-ids  ~  exit

然后得注释掉/etc/fstab文件中的与刚才两个设备有关的挂载命令
然后

sudo umount /dev/mmcblk0p3
sudo umount /dev/mmcblk0p2
sudo umount /dev/mmcblk0p1
# 注意:这里如果出现无法umount的话,可能是因为当前的shell是在/home/cqq目录下,或者刚才shell的进程或者其父进程是cqq用户的登录shell,于是无法删除。得先退出当前shell,然后重新ssh进入shell即可。

与此同时,在另一个终端把/home目录下的文件打包。

tar -zcvf 192.168.10.141home.tar.gz /home

然后把打包后的文件移动到我的宿主机上。

scp root@192.168.10.141:/home/192.168.10.141home.tar.gz ./

重新开机后,果然哈哈。

ssh root@192.168.10.141                                                                  [20:57:24]
root@192.168.10.141's password:
Warning: untrusted X11 forwarding setup failed: xauth key data not generated

The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Apr 29 20:50:00 2017 from 192.168.10.247
root@snort-ids:~# pwd
/root
root@snort-ids:~# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/root       6.7G  6.3G   74M   99% /
devtmpfs        459M     0  459M    0% /dev
tmpfs           463M     0  463M    0% /dev/shm
tmpfs           463M   13M  451M    3% /run
tmpfs           5.0M     0  5.0M    0% /run/lock
tmpfs           463M     0  463M    0% /sys/fs/cgroup
tmpfs            93M  4.0K   93M    1% /run/user/113
tmpfs            93M     0   93M    0% /run/user/0
root@snort-ids:~# 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.


Command (m for help): p
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 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: 0x30dd529e

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1           1   125000   125000   61M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      125001 62333951 62208951 29.7G 83 Linux

Command (m for help): q

root@snort-ids:~# resize2fs /dev/mmcblk0p2
resize2fs 1.43.4 (31-Jan-2017)
/dev/mmcblk0p2 上的文件系统已被挂载于 /;需要进行在线调整大小

old_desc_blocks = 1, new_desc_blocks = 2
/dev/mmcblk0p2 上的文件系统现在为 7776118 个块(每块 4k)。

root@snort-ids:~# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/root        30G  6.3G   22G   23% /
devtmpfs        459M     0  459M    0% /dev
tmpfs           463M     0  463M    0% /dev/shm
tmpfs           463M   13M  451M    3% /run
tmpfs           5.0M     0  5.0M    0% /run/lock
tmpfs           463M     0  463M    0% /sys/fs/cgroup
tmpfs            93M  4.0K   93M    1% /run/user/113
tmpfs            93M     0   93M    0% /run/user/0

现在再把刚才移动的文件再移动回去。

scp ./192.168.10.141home.tar.gz root@192.168.10.141:/home/

然后解压。

tar -zxvf 192.168.10.141home.tar.gz
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值