Linux实战教学笔记54:开源虚拟化KVM(二)管理虚拟存储 (8)

删除自定义的存储池

[root@localhost ~]# virsh pool-destroy guest_images #停止存储池的活动 Pool guest_images destroyed [root@localhost ~]# virsh pool-list --all Name State Autostart ------------------------------------------- default active yes guest_images inactive yes iso active yes VM active yes [root@localhost ~]# virsh pool-delete guest_images #删除存储池目录 Pool guest_images deleted [root@localhost ~]# ll -d /gue* #存储池的存储目录已经被删除了 drws--S--- 2 root root 6 May 6 16:25 /guest_images [root@localhost ~]# virsh pool-info guest_images #存储池配置文件还在 Name: guest_images UUID: 4f37b935-1529-4623-a367-e5e3435d3b55 State: inactive Persistent: yes Autostart: yes [root@localhost ~]# ll /etc/libvirt/storage/ total 16 -rw-------. 1 root root 508 Apr 4 20:39 VM.xml drwxr-xr-x. 2 root root 78 May 11 10:58 autostart -rw-------. 1 root root 538 Mar 30 12:12 default.xml -rw------- 1 root root 539 May 11 10:41 guest_images.xml #在这里 -rw-------. 1 root root 511 Apr 4 10:16 iso.xml [root@localhost ~]# virsh pool-undefine guest_images #清除存储池配置文件 Pool guest_images has been undefined [root@localhost ~]# ll /etc/libvirt/storage/ #已经没了 total 12 -rw-------. 1 root root 508 Apr 4 20:39 VM.xml drwxr-xr-x. 2 root root 54 May 11 11:23 autostart -rw-------. 1 root root 538 Mar 30 12:12 default.xml -rw-------. 1 root root 511 Apr 4 10:16 iso.xml [root@localhost ~]# virsh pool-info guest_images #配置文件已经没了 error: failed to get pool \'guest_images\' error: 未找到存储池: 没有与名称 \'guest_images\' 匹配的存储池 5.4.4 基于分区的存储池

[x] libvirtd会自动mount分区

[x] 准备分区并创建文件系统
# fdisk /dev/sdc
# mkfs.ext4 /dev/sdc1

[x] 创建:

Source Path:块设备名

Target Path:mount到的目录名
# virsh pool-define-as guest_images_fs fs --source-dev "/dev/sdc1" --target "/guest_images2"

操作准备
给虚拟机再加入一块磁盘,分区并进行格式化来继续我们的实验

#将新磁盘sdc分两个分区,并进行格式化。 [root@localhost ~]# ll /dev/sdc brw-rw---- 1 root disk 8, 32 5月 11 20:12 /dev/sdc brw-rw---- 1 root disk 8, 33 5月 11 20:12 /dev/sdc1 brw-rw---- 1 root disk 8, 34 5月 11 20:12 /dev/sdc2 [root@localhost ~]# rm -rf /guest_images/ #清除旧存储池存放目录

(1)通过virt-manager创建一个基于分区的存储池

121.png-33.6kB

122.png-30.7kB

123.png-12.8kB

124.png-16.4kB

125.png-33.4kB

#验证创建的存储池 [root@localhost ~]# virsh pool-list --all 名称 状态 自动开始 ------------------------------------------- default 活动 是 guest_images_fs 活动 是 #有了并处于活动状态 iso 活动 是 VM 活动 是 [root@localhost ~]# virsh pool-info guest_images_fs 名称: guest_images_fs UUID: e50f34cc-89a5-47e3-80e5-324b91b0d001 状态: running 持久: 是 自动启动: 是 容量: 9.72 GiB 分配: 36.02 MiB 可用: 9.68 GiB [root@localhost ~]# ll -d /guest_images/ drwxr-xr-x 3 root root 4096 5月 11 20:14 /guest_images/ #存储池目录被自动创建了 [root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/cl-root 17G 8.9G 8.1G 53% / devtmpfs 901M 0 901M 0% /dev tmpfs 912M 4.0K 912M 1% /dev/shm tmpfs 912M 9.0M 903M 1% /run tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 1014M 144M 871M 15% /boot /dev/mapper/vmvg-lvvm1 40G 7.0G 31G 19% /vm tmpfs 183M 8.0K 183M 1% /run/user/0 /dev/sdc1 9.8G 37M 9.2G 1% /guest_images #磁盘/dev/sdc1被自动挂载了 [root@localhost ~]# cat /etc/libvirt/storage/guest_images_fs.xml #查看存储池的配置文件 <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE OVERWRITTEN AND LOST. Changes to this xml configuration should be made using: virsh pool-edit guest_images_fs or other application using the libvirt API. --> <pool type=\'fs\'> #磁盘类型为fs <name>guest_images_fs</name> <uuid>e50f34cc-89a5-47e3-80e5-324b91b0d001</uuid> <capacity unit=\'bytes\'>0</capacity> <allocation unit=\'bytes\'>0</allocation> <available unit=\'bytes\'>0</available> <source> <device path=\'/dev/sdc1\'/> #源磁盘路径 <format type=\'auto\'/> </source> <target> <path>/guest_images</path> #目标目录路径 </target> </pool> [root@localhost ~]# mount | grep sdc1 #查看mount挂载的信息 /dev/sdc1 on /guest_images type ext4 (rw,relatime,data=ordered)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjxzx.html