0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

仮想ディスクイメージを作る(qcow2)

Last updated at Posted at 2025-07-03

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?