快資訊丨44-KVM虛擬化-存儲管理和磁盤擴容

2023-01-02 21:10:22 來源:51CTO博客

KVM存儲模式


(資料圖)

基于文件系統的存儲

dir: Filesystem Directory 需要有掛載點的文件系統fs: Pre-Formatted Block Device 無需掛載的文件系統,如:位于SAN存儲的文件系統,可支持多個主機同時訪問,而本地文件系統不支持netfs: Network Exported Directory 網絡文件系統,比如:NFS,SAMBA等

基于設備的存儲 - 無需文件系統,性能更好,但可管理性差,無法實現快照

Disk: Physical Disk DeviceIscsi: isCSI Targetlogical:LVM Volume Group

虛擬磁盤類型

固定Fixed
在配置時,指定磁盤大小不管在虛擬磁盤上實際存儲多少數據,都將占用相同大小宿主機的磁盤空間
動態Dynamic
初始空間占用小隨著空間的使用逐漸增長到最大容量,但是只根據需求使用更多的空間
差異Differencing
因為創建是差異磁盤,所以只保存變更的數據例如,將操作系統安裝在父盤,然后創建差異化磁盤來執行進一步配置

虛擬鏡像文件格式

KVM 上的磁盤鏡像格式包括:

raw
此為默認磁盤格式,但并是一種真正的磁盤格式,而是代表虛擬機所使用的原始鏡像,它并不存儲元數據,因此可作為保證虛擬機兼容性的候選方案。然而,也正因為它不存儲元數據,因此不支持某些高級特往,比如快照和壓縮等格式簡單,容易轉換為其他的格式。如果主機文件系統允許,raw 文件可以是預分配(pre-allocated)或 稀疏(sparse)。稀疏文件根據需求分配主機磁盤空間,因此它是一種精簡配置形式(thin provisioning)。預分配文件的所有空間需要被預先分配,但它比稀疏文件性能好。當對磁盤 I/O 性能要求非常高,而且通常不需要通過網絡傳輸鏡像文件時,可以使用 raw文件優點 : 性能好缺點 : 空間占用大,功能較少,生產不推薦使用
cow
copy-on-write格式,曇花一現
qcow
QEMU早期的copy-on-write格式,過渡性方案
qcow2
qcow2 鏡像文件提供許多高級磁盤鏡像特征,如快照、壓縮及加密。它們可以用來代表通過模板鏡像創建的虛擬機。因為只有虛擬機寫入的扇區部分才會分配在鏡像中,所以 qcow2 文件的網絡傳輸效率較高。RHEL 7.0 及更新版本支持 qcow2 v3 鏡像文件格式按需進行分配磁盤空間,不管文件系統是否支持優點 :   空間節約,功能豐富  支持快照  支持zlib的磁盤壓縮  支持AES的加密缺點 : 性能較差,生產推薦使用案例:查看不同磁盤文件格式支持選項#raw[root@ubuntu2204 ~]#qemu-img create -f raw -o ?Supported raw options:  size=            - Virtual disk sizeThe protocol level may support further options.Specify the target filename to include those options.#qcow2[root@ubuntu2204 ~]#qemu-img create -f qcow2 -o ?Supported qcow2 options:  backing_file=     - File name of a base image  backing_fmt=      - Image format of the base image  cluster_size=    - qcow2 cluster size  compat=           - Compatibility level (v2 [0.10] or v3 [1.1])  compression_type= - Compression method used for image cluster compression  data_file=        - File name of an external data file  data_file_raw= - The external data file must stay valid as a raw image  encrypt.cipher-alg= - Name of encryption cipher algorithm  encrypt.cipher-mode= - Name of encryption cipher mode  encrypt.format=   - Encrypt the image, format choices: "aes", "luks"  encrypt.hash-alg= - Name of encryption hash algorithm  encrypt.iter-time= - Time to spend in PBKDF in milliseconds  encrypt.ivgen-alg= - Name of IV generator algorithm  encrypt.ivgen-hash-alg= - Name of IV generator hash algorithm  encrypt.key-secret= - ID of secret providing qcow AES key or LUKS passphrase  encryption= - Encrypt the image with format "aes". (Deprecated in favor of encrypt.format=aes)  extended_l2= - Extended L2 tables  lazy_refcounts= - Postpone refcount updates  preallocation=    - Preallocation mode (allowed values: off, metadata, falloc, full)  refcount_bits=    - Width of a reference count entry in bits  size=            - Virtual disk sizeThe protocol level may support further options.Specify the target filename to include those options.
vmdk
VMware環境當中默認使用的磁盤格式
vhd/vhdx
微軟默認采用的文件格式
vdi
VirtualBox 采用的文件格式

查看KVM支持的磁盤格式

[root@ubuntu2204 ~]#qemu-img --help|grep SupportSupported formats: blkdebug blklogwrites blkverify bochs cloop compress copy-before-write copy-on-read dmg file ftp ftps gluster host_cdrom host_device http https iscsi iser luks nbd null-aio null-co nvme parallels preallocate qcow qcow2 qed quorum raw rbd replication ssh throttle vdi vhdx vmdk vpc vvfat

使用qemu-img管理虛擬磁盤文件

#qemu-img 包括以下子命令check #檢查完整性create #創建鏡像commit #提交更改compare #比較convert #轉換info #獲得信息map #映射snapshot #快照管理rebase #在已有的鏡像的基礎上創建新的鏡像resize #調整大小amend #修訂鏡像格式選項#格式:qemu-img create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backing_fmt] [-u] [-o options] filename [size]
案例:創建raw格式文件
#案例1:創建raw格式非稀疏文件[root@ubuntu2204 ~]#dd if=/dev/zero of=/opt/vm2.img bs=1M count=10241024+0 records in1024+0 records out1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.2694 s, 171 MB/s[root@ubuntu2204 ~]#qemu-img info /opt/vm2.img image: /opt/vm2.imgfile format: rawvirtual size: 1 GiB (1073741824 bytes) --> 顯示1Gdisk size: 1 GiB  --> 實際占用磁盤1G#案例2:創建raw格式稀疏文件[root@ubuntu2204 ~]#dd if=/dev/zero of=/opt/vm3.img bs=1M count=0 seek=10240+0 records in0+0 records out0 bytes copied, 0.000217691 s, 0.0 kB/s[root@ubuntu2204 ~]#qemu-img info /opt/vm3.img image: /opt/vm3.imgfile format: rawvirtual size: 1 GiB (1073741824 bytes) --> 顯示1Gdisk size: 0 B --> 實際占用磁盤1字節#案例3:指定將非稀疏文件復制為稀疏格式文件[root@ubuntu2204 ~]#cp --sparse=always /opt/vm2.img /opt/vm2.img.bk [root@ubuntu2204 ~]#qemu-img info /opt/vm2.imgimage: /opt/vm2.imgfile format: rawvirtual size: 1 GiB (1073741824 bytes)disk size: 1 GiB[root@ubuntu2204 ~]#qemu-img info /opt/vm2.img.bk image: /opt/vm2.img.bkfile format: rawvirtual size: 1 GiB (1073741824 bytes)disk size: 0 B#案例4:指定將稀疏文件復制為非稀疏格式文件[root@ubuntu2204 ~]#cp --sparse=never /opt/vm3.img /opt/vm3.img.bk [root@ubuntu2204 ~]#qemu-img info /opt/vm3.imgimage: /opt/vm3.imgfile format: rawvirtual size: 1 GiB (1073741824 bytes)disk size: 0 B[root@ubuntu2204 ~]#qemu-img info /opt/vm3.img.bk image: /opt/vm3.img.bkfile format: rawvirtual size: 1 GiB (1073741824 bytes)disk size: 1 GiB
案例:創建qcow2格式文件
#qcow2 格式選項    backing_file #指定后端鏡像文件    backing_fmt #設置后端鏡像的鏡像格式    cluster_size #設置鏡像中的簇大小,取值在512到2M之間,默認值為64K    preallocation #設置鏡像文件空間的預分配模式    encryption #用于設置加密    [root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm1.img 2gFormatting "/opt/vm1.img", fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2147483648 lazy_refcounts=off refcount_bits=16[root@ubuntu2204 ~]#qemu-img info /opt/vm1.img image: /opt/vm1.imgfile format: qcow2virtual size: 2 GiB (2147483648 bytes)disk size: 196 KiBcluster_size: 65536Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: false    refcount bits: 16    corrupt: false    extended l2: false
案例:檢查虛擬磁盤
*對于關機狀態的虛擬機磁盤,可以檢查文件錯誤[root@centos8 ~]#virsh listId Name State----------------------------------------------------2 centos8 running[root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos8.qcow2qemu-img: Could not open "/var/lib/libvirt/images/centos8.qcow2": Failed to getshared "write" lockIs another process using the image [/var/lib/libvirt/images/centos8.qcow2]?[root@centos8 ~]#virsh suspend centos8Domain centos8 suspended[root@centos8 ~]#virsh listId Name State----------------------------------------------------2 centos8 paused[root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos8.qcow2qemu-img: Could not open "/var/lib/libvirt/images/centos8.qcow2": Failed to getshared "write" lockIs another process using the image [/var/lib/libvirt/images/centos8.qcow2]?[root@centos8 ~]#qemu-img check /var/lib/libvirt/images/centos7.qcow2No errors were found on the image.25572/327680 = 7.80% allocated, 1.44% fragmented, 0.00% compressed clustersImage end offset: 1676869632

磁盤預分配策略

raw 文件的預分配策略和文件系統是否支持有關,而qcow2則無關

off
此為缺省策略,即不使用預分配策略,預分配后的虛擬磁盤占用空間很小,不屬于稀疏映像類型,生成的磁盤文件占用空間很小
metadata
只預分配元數據(metadata),預分配后的磁盤文件屬于稀疏映像類型,相當于vmware中的磁盤置備選項: Thin Provision(精簡配置)生成的磁盤文件為稀疏格式,實際占用的空間比off策略稍大一些
falloc
分配文件的塊并標識它們的狀態為未初始化,即只分配空間,但不置零(不格式化). 預分配后的虛擬磁盤屬于非稀疏映像類型,相對full模式來說,創建虛擬磁盤的速度要快很多,相當于vmware中的磁盤置備選項:厚置備延遲置零生成的磁盤文件實際占用的空間和分配的空間相同大小
full
分配所有磁盤空間并置零,預分配后的虛擬磁盤屬于非稀疏映像類型,創建最慢,相當于vmware中的磁盤置備選項: 厚置備置零生成的磁盤文件實際占用的空間和分配的空間相同大小

案例:創建預分配置策略

#案例1:默認開啟默認預分配策略 - 稀疏格式,根據實際需要自動分配磁盤空間[root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm1.img 2gFormatting "/opt/vm1.img", fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2147483648 lazy_refcounts=off refcount_bits=16[root@ubuntu2204 ~]#qemu-img info /opt/vm1.img image: /opt/vm1.imgfile format: qcow2virtual size: 2 GiB (2147483648 bytes)disk size: 196 KiBcluster_size: 65536Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: false    refcount bits: 16    corrupt: false    extended l2: false    #案例2:指定off關閉預分配[root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm2.img 1g -o preallocatinotallow=offFormatting "/opt/vm2.img", fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=off compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16[root@ubuntu2204 ~]#qemu-img info /opt/vm2.img image: /opt/vm2.imgfile format: qcow2virtual size: 1 GiB (1073741824 bytes)disk size: 196 KiBcluster_size: 65536Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: false    refcount bits: 16    corrupt: false    extended l2: false#案例3:指定預分配metadata[root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm3.img 1g -o preallocatinotallow=metadataFormatting "/opt/vm3.img", fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=metadata compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16[root@ubuntu2204 ~]#qemu-img info /opt/vm3.img image: /opt/vm3.imgfile format: qcow2virtual size: 1 GiB (1073741824 bytes)disk size: 324 KiBcluster_size: 65536Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: false    refcount bits: 16    corrupt: false    extended l2: false#案例4:指定預分配falloc[root@ubuntu2204 ~]#qemu-img create -f qcow2 /opt/vm4.img 1g -o preallocatinotallow=fallocFormatting "/opt/vm4.img", fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=falloc compression_type=zlib size=1073741824 lazy_refcounts=off refcount_bits=16[root@ubuntu2204 ~]#qemu-img info /opt/vm4.img image: /opt/vm4.imgfile format: qcow2virtual size: 1 GiB (1073741824 bytes)disk size: 1 GiBcluster_size: 65536Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: false    refcount bits: 16    corrupt: false    extended l2: false#文件系統顯示大小[root@ubuntu2204 ~]#ll -h /opt/vm*-rw-r--r-- 1 root root 193K Jan  1 17:40 /opt/vm1.img-rw-r--r-- 1 root root 193K Jan  1 18:04 /opt/vm2.img-rw-r--r-- 1 root root 1.1G Jan  1 18:08 /opt/vm3.img-rw-r--r-- 1 root root 1.1G Jan  1 18:08 /opt/vm4.img#查看真實大小[root@ubuntu2204 ~]#du -h /opt/vm*196K    /opt/vm1.img196K    /opt/vm2.img324K    /opt/vm3.img1.1G    /opt/vm4.img

虛擬磁盤格式轉換

#qemu-img 可以將不同格式的虛擬磁盤文件進行格式轉化#案例:將vmdk轉化為raw 和qcow2格式[root@centos8 ~]#qemu-img info CentOS8.2.vmdkimage: CentOS8.2.vmdkfile format: vmdkvirtual size: 200G (214748364800 bytes)disk size: 1.6Gcluster_size: 65536Format specific information:cid: 2898578192parent cid: 4294967295create type: monolithicSparseextents:[0]:virtual size: 214748364800filename: CentOS8.2.vmdkcluster size: 65536format:#默認轉化為raw格式[root@centos8 ~]#qemu-img convert CentOS8.2.vmdk CentOS8.2.img#比較大小[root@centos8 ~]#ll -h CentOS8.2.vmdk CentOS8.2.img-rw-r--r-- 1 root root 1.6G Sep 20 16:00 CentOS8.2.vmdk-rw-r--r-- 1 root root 200G Sep 20 16:10 CentOS8.2.img[root@centos8 ~]#du -h CentOS8.2.vmdk CentOS8.2.img1.6G CentOS8.2.vmdk1.5G CentOS8.2.img[root@centos8 ~]#qemu-img info CentOS8.2.imgimage: CentOS8.2.imgfile format: rawvirtual size: 200G (214748364800 bytes)disk size: 1.4G[root@centos8 ~]#mv CentOS8.2.img /var/lib/libvirt/images/[root@centos8 ~]#virt-install --import --name=centos8-test2 --vcpus=1 --ram=2048--disk bus=scsi,path=/var/lib/libvirt/images/CentOS8.2.img --networknetwork=default --graphics vnc,listen=0.0.0.0 --os-type=Linux --osvariant=centos8 --noautoconsole --boot hd#轉化為qcow2格式[root@centos8 ~]#qemu-img convert -f vmdk -O qcow2 CentOS8.2.vmdkCentOS8.2.qcow2#比較大小[root@centos8 ~]#ll -h CentOS8.2.vmdk CentOS8.2.qcow2-rw-r--r-- 1 root root 1.6G Sep 20 16:00 CentOS8.2.vmdk-rw-r--r-- 1 root root 1.6G Sep 20 16:12 CentOS8.2.qcow2[root@centos8 ~]#du -h CentOS8.2.vmdk CentOS8.2.qcow21.6G CentOS8.2.vmdk1.6G CentOS8.2.qcow2[root@centos8 ~]#qemu-img info CentOS8.2.qcow2image: CentOS8.2.qcow2file format: qcow2virtual size: 200G (214748364800 bytes)disk size: 1.5Gcluster_size: 65536Format specific information:compat: 1.1lazy refcounts: falserefcount bits: 16corrupt: false[root@centos8 ~]#mv CentOS8.2.qcow2 /var/lib/libvirt/images/[root@centos8 ~]#virt-install --import --name=centos8-test3 --vcpus=1 --ram=2048--disk bus=scsi,path=/var/lib/libvirt/images/CentOS8.2.qcow2 --networknetwork=default --graphics vnc,listen=0.0.0.0 --os-type=Linux --osvariant=centos8 --noautoconsole --boot hd

調整虛擬磁盤大小

*做虛擬磁盤調整之前需要注意以下幾點:

操作之前,一定要做好數據備份增加文件大小后,需要在客戶機中使用fdisk、parted等分區工具進行相應的操作才能真正讓客戶機使用到增加后的鏡像空間。縮小鏡像之前,要在客戶機中保證里面的文件系統有空余空間,否則會數據丟失。另外xfs文件系統不支持縮減qcow2不支持縮小鏡像的操作

案例:擴展虛擬磁盤

#思路:擴展分區-擴容物理卷-擴容邏輯卷組-擴容指定邏輯卷[root@ubuntu2204 ~]#qemu-img info   /var/lib/libvirt/images/centos7-mooreyxia.qcow2 image: /var/lib/libvirt/images/centos7-mooreyxia.qcow2file format: qcow2virtual size: 10 GiB (10737418240 bytes)disk size: 1.6 GiBcluster_size: 65536Snapshot list:ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT1         centos7-s1            0 B 2023-01-01 19:01:27 00:00:00.000          0Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: true    refcount bits: 16    corrupt: false    extended l2: false[root@ubuntu2204 ~]#du -sh /var/lib/libvirt/images/centos7-mooreyxia.qcow2 1.6G  /var/lib/libvirt/images/centos7-mooreyxia.qcow2#擴容 - 增加10G空間[root@ubuntu2204 ~]#qemu-img info   /var/lib/libvirt/images/centos7-mooreyxia.qcow2 image: /var/lib/libvirt/images/centos7-mooreyxia.qcow2file format: qcow2virtual size: 20 GiB (21474836480 bytes)disk size: 1.6 GiBcluster_size: 65536Snapshot list:ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT1         centos7-s1            0 B 2023-01-01 19:01:27 00:00:00.000          0Format specific information:    compat: 1.1    compression type: zlib    lazy refcounts: true    refcount bits: 16    corrupt: false    extended l2: false    #qemu-img resize 擴展空間后,在虛擬機內還需執行如下操作才能最終擴容[root@localhost ~]# lsblkNAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsr0              11:0    1 1024M  0 rom  vda             252:0    0   20G  0 disk ├─vda1          252:1    0    1G  0 part /boot└─vda2          252:2    0    9G  0 part   ├─centos-root 253:0    0    8G  0 lvm  /  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]  [root@localhost ~]# df -hFilesystem               Size  Used Avail Use% Mounted ondevtmpfs                 908M     0  908M   0% /devtmpfs                    919M     0  919M   0% /dev/shmtmpfs                    919M  8.6M  911M   1% /runtmpfs                    919M     0  919M   0% /sys/fs/cgroup/dev/mapper/centos-root  8.0G  1.3G  6.8G  16% //dev/vda1               1014M  153M  862M  15% /boottmpfs                    184M     0  184M   0% /run/user/0#重新創建/dev/vda2,容量使用所有空間,/dev/vda2擴容到20G[root@localhost ~]# fdisk /dev/vdaWelcome 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.Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   g   create a new empty GPT partition table   G   create an IRIX (SGI) partition table   l   list known partition types   m   print this menu   n   add a new partition   o   create a new empty DOS partition table   p   print the partition table   q   quit without saving changes   s   create a new empty Sun disklabel   t   change a partition"s system id   u   change display/entry units   v   verify the partition table   w   write table to disk and exit   x   extra functionality (experts only)Command (m for help): pDisk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000df5df   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048     2099199     1048576   83  Linux/dev/vda2         2099200    20971519     9436160   8e  Linux LVMCommand (m for help): dPartition number (1,2, default 2): Partition 2 is deletedCommand (m for help): pDisk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000df5df   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048     2099199     1048576   83  LinuxCommand (m for help): pDisk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000df5df   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048     2099199     1048576   83  LinuxCommand (m for help): nPartition type:   p   primary (1 primary, 0 extended, 3 free)   e   extendedSelect (default p): Using default response pPartition number (2-4, default 2): First sector (2099200-41943039, default 2099200): Using default value 2099200Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): Using default value 41943039Partition 2 of type Linux and of size 19 GiB is setCommand (m for help): pDisk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000df5df   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048     2099199     1048576   83  Linux/dev/vda2         2099200    41943039    19921920   83  LinuxCommand (m for help): tPartition number (1,2, default 2): Hex code (type L to list all codes): 8eChanged type of partition "Linux" to "Linux LVM"Command (m for help): pDisk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000df5df   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048     2099199     1048576   83  Linux/dev/vda2         2099200    41943039    19921920   8e  Linux LVMCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.#同步文件系統,擴展邏輯卷[root@localhost ~]# lsblkNAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsr0              11:0    1 1024M  0 rom  vda             252:0    0   20G  0 disk ├─vda1          252:1    0    1G  0 part /boot└─vda2          252:2    0   19G  0 part   ├─centos-root 253:0    0    8G  0 lvm  /  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]  [root@localhost ~]# lsblk -fNAME            FSTYPE      LABEL UUID                                   MOUNTPOINTsr0                                                                      vda                                                                      ├─vda1          xfs               1a55b4e7-3e79-4319-8fd0-7ceb3d1ab505   /boot└─vda2          LVM2_member       0Sybbx-w3aS-ZdSN-1zQO-eXpw-0zqz-YcYT4V   ├─centos-root xfs               f1205cb4-8a06-44a8-bece-89e8610e5a77   /  └─centos-swap swap              7ccb94cc-3909-4af8-9abf-e1b63d627f52   [SWAP]#當前物理卷空間并沒有擴容,需要執行下面操作擴容PV[root@localhost ~]# pvs  PV         VG     Fmt  Attr PSize  PFree  /dev/vda2  centos lvm2 a--  <9.00g    0   [root@localhost ~]# pvresize --setphysicalvolumesize 19G /dev/vda2  WARNING: /dev/vda2: Overriding real size <19.00 GiB. You could lose data./dev/vda2: Requested size 19.00 GiB exceeds real size <19.00 GiB. Proceed?  [y/n]: y  WARNING: /dev/vda2: Pretending size is 39845888 not 39843840 sectors.  Physical volume "/dev/vda2" changed  1 physical volume(s) resized or updated / 0 physical volume(s) not resized  [root@localhost ~]# pvs  PV         VG     Fmt  Attr PSize   PFree   /dev/vda2  centos lvm2 a--  <19.00g 10.00g#邏輯卷組被自動擴容[root@localhost ~]# vgs -a  VG     #PV #LV #SN Attr   VSize   VFree  centos   1   2   0 wz--n- <19.00g    0   #擴容指定邏輯卷[root@localhost ~]# lvextend -r -l +100%free /dev/centos/root  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to <18.00 GiB (4607 extents).  Logical volume centos/root successfully resized.meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=1        finobt=0 spinodes=0data     =                       bsize=4096   blocks=2096128, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=1log      =internal               bsize=4096   blocks=2560, versinotallow=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 2096128 to 4717568[root@localhost ~]# lvs  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  root centos -wi-ao---- <18.00g                                                      swap centos -wi-ao----   1.00g                                                    [root@localhost ~]# lsblk NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsr0              11:0    1 1024M  0 rom  vda             252:0    0   20G  0 disk ├─vda1          252:1    0    1G  0 part /boot└─vda2          252:2    0   19G  0 part   ├─centos-root 253:0    0   18G  0 lvm  /  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]--------------------------------------------------------------------------------#如果是分區不是邏輯卷,則執行如下操作#如果是xfs文件系統xfs_growfs /#如果是extresize2fs /dev/vda2----------------------------------------------------------------------------------

我是moore,大家一起加油!新年快樂!

標簽: 虛擬磁盤 文件系統 磁盤文件

上一篇:Python__20-- 常見Bug
下一篇:世界簡訊:SDK更新不了問題解決