【Linux】Linux磁盘扩容
查看当前的磁盘
1 | df -TH |
输出
1 | Filesystem Type Size Used Avail Use% Mounted on |
确认当前的磁盘
1 | sudo fdisk -l |
会输出:
1 | # 系统盘有40G |
查看磁盘系统类型
1 | sudo file -s /dev/vdb |
输出
1 | /dev/vdb: Linux rev 1.0 ext4 filesystem data, UUID=ecd8eba2-c630-43dc-b907-438b1e5be7df (needs journal recovery) (extents) (64bit) (large files) (huge files) |
可以看到 vdb 是 ext4
格式化文件系统
1 | mkfs -t ext4 /dev/vdb |
挂载
1 | # 确保目标文件夹存在 |
确认挂载成功
1 | df -TH |
输出
1 | ubuntu@VM-1-7-ubuntu:/etc$ df -TH |
可以看到多出了一个,就说明成功了
开机自动挂载
注意:在机器重启后/data下的东西会不见,并不是他不在(使用sudo fdisk -l确认),而是没有挂载上去。这就是因为你没有设置开机自动挂载,如果你真碰到这种情况也不要害怕,重新挂载一遍就好了sudo mount /dev/vdb /data。但是千万要注意,不要格式化!!!不要格式化!!!不要格式化!!!
设置自动挂载
先备份配置文件
1
cp /etc/fstab /etc/fstab.bak
再将命令行写入
1
echo "UUID=$(sudo blkid -s UUID -o value /dev/vdb) /data ext4 defaults 0 0" | sudo tee -a /etc/fstab
确认文件正常
1
2
3
4
5
6
7
8
9
10
11
12
13
14cat /etc/fstab
ubuntu@VM-1-7-ubuntu:/etc$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/7bccaefa-b039-4ff6-bd32-22dde0066c0b / ext4 defaults 0 1
/swapfile none swap sw 0 0
UUID=ecd8eba2-c630-43dc-b907-438b1e5be7df /data ext4 defaults 0 0