前言
最近手头一台运行在 Hyper-V 下面抓数据的服务器 (Ubuntu 16.04) 磁盘空间不够了,之前也没有把数据单独放到一个分区,所以只能想办法把根目录给搞大一点。之前没有处理过这样的问题,网上搜了很多资料,现在把拓展方法记录,分享出来。
建议在操作之前做好备份工作
步骤概览
调大物理磁盘
确定要操作的磁盘
扩展 LVM 逻辑分区所在的物理拓展分区
新增 LVM 逻辑分区
新分区合并到相应 Volumn Group
更新文件系统
调大物理磁盘
虚拟机关机,然后直接在虚拟机管理里面操作。
现在把磁盘从 100G 调整到了 300G
确定要操作的磁盘
先看下磁盘使用情况,运行命令
root@vm003:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 8.6M 789M 2% /run
/dev/mapper/Ubuntu-root 94G 88G 1.9G 98% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 382M 66M 86% /boot
tmpfs 100K 0 100K 0% /run/lxcfs/controllers
tmpfs 798M 0 798M 0% /run/user/0
虽然我们已经把物理磁盘调整到了 300G,但是根目录还是100G的样子,已用 98%
运行命令
root@vm003:~# fdisk -l
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xa88f1366
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 209713151 208711682 99.5G 5 Extended
/dev/sda5 1001472 209713151 208711680 99.5G 8e Linux LVM
Partition 2 does not start on physical sector boundary.
Disk /dev/mapper/Ubuntu-root: 95.5 GiB, 102563315712 bytes, 200318976 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum