Libvirt加密磁盘使用

创建加密磁盘

  • 进入libvirt默认存储池目录
# cd /var/lib/libvirt/images
  • 创建加密磁盘
# qemu-img convert -O qcow2 -o ? CentOS.qcow2 os.qcow2
# qemu-img convert -O qcow2 -o encryption=on -f qcow2 CentOS.qcow2 os.qcow2
Disk image 'os.qcow2' is encrypted.
password:
  • 刷新默认存储池
# virsh pool-refresh default
# virsh vol-list default

创建密钥

  • 使用xml文件创建密钥
# cat volume-secret.xml
<secret ephemeral='no' private='yes'>
         <description>Super secret name of my first puppy</description>
         <usage type='volume'>
             <volume>os.qcow2</volume>
         </usage>
</secret>
# virsh secret-define volume-secret.xml
生成 secret 175bb81b-caab-4520-a042-e678fbb73556
//这边的123就是我们创建加密磁盘时输入的密码
# MYSECRET=`printf %s "123" | base64`
# virsh secret-set-value 175bb81b-caab-4520-a042-e678fbb73556 $MYSECRET
secret 值设定

修改虚拟机配置文件

  • 为对应disk节点添加encryption节点
<source file='/var/lib/libvirt/images/os.qcow2'/>
      <target dev='hda' bus='ide'/>
      <encryption format='qcow'>
        <secret type='passphrase' uuid='175bb81b-caab-4520-a042-e678fbb73556'/>
      </encryption>

总结

  • 使用加密磁盘的虚拟机只有在关机状态下才能创建快照
  • 只有qcow2格式的磁盘才能进行加密
  • Secret的XML文件可以使用磁盘的绝对路径

相关文章:

  • 2021-06-08
  • 2021-09-19
  • 2021-09-26
  • 2022-01-20
  • 2021-11-30
  • 2021-11-23
猜你喜欢
  • 2021-07-29
  • 2021-08-07
  • 2021-12-01
  • 2021-09-23
  • 2021-06-13
  • 2021-10-29
相关资源
相似解决方案