如何在KVM虚拟机中扩展LVM磁盘

本文介绍了如何在KVM环境中为虚拟机增加磁盘,并通过LVM进行分区、创建VG、LV,以及扩展LV和实际文件系统。详细步骤包括使用qemu-img创建磁盘、热挂载磁盘、fdisk创建分区、vgcreate、lvcreate等操作,最后通过xfs_growfs扩展文件系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

KVM中增加磁盘作为扩展

创建空磁盘

通过qemu-img 命令创建qcow2的磁盘,也可以创建其他类型的磁盘,但扩展磁盘的时候,在kvm里面的命令有所区别

[root@server10 ~]# qemu-img create -f qcow2 /opt/extern.qcow2 100G
Formatting '/opt/extern.qcow2', fmt=qcow2 size=107374182400 encryption=off 

[root@server10 opt]# qemu-img info extern.qcow2
image: extern.qcow2
file format: qcow2
virtual size: 100G (107374182400 bytes)
disk size: 294M
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false

热挂载磁盘 ,注意,增加磁盘必须使用-subdriver,否则不认识kvm内部不认识磁盘

直接挂载磁盘到虚拟机.虚拟机需要在运行状态可直接看到有其他硬盘被挂载

[root@server10 opt]# virsh attach-disk centos7V1-bigdata /opt/extern.qcow2 vdb  --subdriver=qcow2 --persistent

virsh help  attach-disk
  NAME
    attach-disk - attach disk device

  SYNOPSIS
    attach-disk <domain> <source> <target> [--targetbus <string>] [--driver <string>] [--subdriver <string>] [--iothread <string>] [--cache <string>] [--io <string>] [--type <string>] [--mode <string>] [--sourcetype <string>] [--serial <string>] [--wwn <string>] [--rawio] [--address <string>] [--multifunction] [--print-xml] [--persistent] [--config] [--live] [--current]

  DESCRIPTION
    Attach new disk device.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--source] <string>  source of disk device
    [--target] <string>  target of disk device
    --targetbus <string>  target bus of disk device
    --driver <string>  driver of disk device
    --subdriver <string>  subdriver of disk device
    --iothread <string>  IOThread to be used by supported device
    --cache <string>  cache mode of disk device
    --io <string>    io policy of disk device
    --type <string>  target device type
    --mode <string>  mode of device reading and writing
    --sourcetype <string>  type of source (block|file)
    --serial <string>  serial of disk device
    --wwn <string>   wwn of disk device
    --rawio          needs rawio capability
    --address <string>  address of disk device
    --multifunction  use multifunction pci under specified address
    --print-xml      print XML document rather than attach the disk
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain
 

创建分区 

选择卷标必须使用8e,这个表示是LVM磁盘格式


[root@localhost ~]# fdisk /dev/vdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x14401f11.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老骥又出发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值