LVM卷扩容分区
最近虚拟机的硬盘空间不够,所以来进行扩容,最开始安装的时候采用的是LVM管理器,所以扩容很是方便
首先使用fdisk工具查看分区
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | root@localhost /m/n/xiaofeng# fdisk -l Disk /dev/sda:40 GiB,42949672960 字节,83886080 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0xcbb43a9b 设备 启动 起点 末尾 扇区 大小 Id 类型 /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 83886079 81786880 39G 8e Linux LVM Disk /dev/mapper/fedora-root:26 GiB,26856128512 字节,52453376 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 Disk /dev/mapper/fedora-swap:2.2 GiB,2336227328 字节,4562944 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 |
可以明显的看到,sda2是LVM卷,接下来用lsblk查看lvm状态
1 2 3 4 5 6 7 8 | root@localhost /m/n/xiaofeng# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─fedora-root 253:0 0 26G 0 lvm / └─fedora-swap 253:1 0 2.2G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom |
可以看到,fedora-root和fedora-swap分区都是从sda2上面分割出来的,下面进行扩容
1 2 3 4 5 | root@localhost /m/n/xiaofeng# lvextend -L +1G /dev/mapper/fedora-root Rounding size to boundary between physical extents: 4.00 MiB. Size of logical volume fedora/root changed from 26.01 GiB (6403 extents) to <27.01 GiB (6404 extents). Logical volume fedora/root successfully resized. |
这里我只增加1G,用作演示,之后再用fdisk -l命令就可以看到新分区大小了
1 2 3 4 5 | Disk /dev/mapper/fedora-root:27 GiB,27934064640 字节,54558720 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 |
但是用df -h时,发现还是26G,空间并没有增加,下面要使用resize2fs工具重定义大小
1 2 3 4 5 6 | root@localhost /m/n/xiaofeng# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/fedora-root 26G 14G 12G 56% / tmpfs 2.0G 0 2.0G 0% /tmp /dev/sda1 976M 204M 706M 23% /boot |
1 2 3 4 | root@localhost /m/n/xiaofeng# resize2fs /dev/mapper/fedora-root resize2fs 1.44.2 (14-May-2018) resize2fs: 超级块中的幻数有错 尝试打开 /dev/mapper/fedora-root 时 找不到有效的文件系统超级块。 |
但是却报错了,原因何在?resize2fs是用于ext2/3/4格式的文件系统进行分区,而我的文件系统是xfs
1 2 3 4 5 6 | root@localhost /m/n/xiaofeng# df -T -h 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/fedora-root xfs 26G 14G 12G 56% / tmpfs tmpfs 2.0G 0 2.0G 0% /tmp /dev/sda1 ext4 976M 204M 706M 23% /boot |
对于xfs要使用xfs_growfs命令
1 2 3 | root@localhost /m/n/xiaofeng# xfs_growfs /dev/mapper/fedora-root xfs_growfs: /dev/mapper/fedora-root is not a mounted XFS filesystem |
但为何还报错了?仔细查看错误,fedora-root不是一个已挂载的XFS文件系统
那这就简单了,在最上面(df -T -h)我们可以看到fedora-root是挂载在根目录下面,所以直接使用这个命令对根目录进行操作即可
1 2 3 4 5 6 7 8 9 10 11 12 13 | root@localhost /m/n/xiaofeng# xfs_growfs / meta-data=/dev/mapper/fedora-root isize=512 agcount=7, agsize=983040 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1 spinodes=0 rmapbt=0 = reflink=0 data = bsize=4096 blocks=6556672, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 6556672 to 6819840 |
ok,已经成功,最后再用df -h查看下,可以看到空间明显已经增大了
1 2 3 4 5 | root@localhost /m/n/xiaofeng# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/fedora-root 27G 14G 13G 53% / tmpfs 2.0G 0 2.0G 0% /tmp /dev/sda1 976M 204M 706M 23% /boot |