qcow2 仮想HDD を 作る
- シンプロビジョニング(Thin-Provisioning)仮想ディスク(イメージファイル)を作る
Operating System
Operating System: Rocky Linux 9.6 (Blue Onyx)
Kernel: Linux 5.14.0-570.23.1.el9_6.x86_64
Bash version
$ bash --version
GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
bash script
#!/bin/bash
# ------------------------------------------------------
function _f_create_qcow2()
{
cd /var/lib/libvirt/images
(
set -x
qemu-img create -f qcow2 ${1}.qcow2 ${2}
)
chown qemu.qemu ${1}.qcow2
chmod 600 ${1}.qcow2
ls -l ${1}.qcow2
return 0
}
# ------------------------------------------------------
# MAIN
# 第一引数 : 仮想HDD容量を10進値で指定
# ------------------------------------------------------
LANG=C
( printf "%d" $1 2>/dev/nulll >&2 )
[[ $? -ne 0 ]] && printf "\n[ ERROR ] For the first argument, specify the virtual HDD capacity (Giga bytes) as a decimal value.\n\n" >&2 && exit 1
_f_create_qcow2 $( printf "HDD%03d" $1 ) ${1}G
exit 0