virt-installがPermission deniedによりインストールできない問題

以下のインストールするためのシェルスクリプトを作成する。

vim create-vpn2.sh
#!/bin/bash
VMNAME=vpn2
IMAGE_FILE=/var/lib/libvirt/images/${VMNAME}.qcow2
CIDATA_FILE=$PWD/cidata-${VMNAME}.iso

if [ ! -r $CIDATA_FILE ]; then
        echo "error: $CIDATA_FILE not found"
        exit 1
fi
if [ ! -r $IMAGE_FILE ]; then
        echo "error: $IMAGE_FILE not found"
        exit 2
fi
sudo virt-install \
        --name $VMNAME \
        --ram 49152 \
        --vcpus 16 \
        --arch x86_64 \
        --os-type linux \
        --os-variant ubuntu22.04 \
        --hvm \
        --virt-type kvm \
        --file $IMAGE_FILE \
        --cdrom $CIDATA_FILE \
        --boot hd \
        --network bridge:br0 \
        --network network:default \
        --graphics none \
        --serial pty \
        --console pty \
        --autostart --noreboot

シェルスクリプトを用いて、virt-installしようとするとPermission deniedのエラーを出力する。

$ ./create-vpn2.sh
VMNAME ........ vpn2
VCPUS ......... 2
RAMSIZE ....... 8 G
DISKSIZE ...... 30 G
CIDATA_PATH ... /home/ubuntu/cloud-init/cidata-vpn2.iso
IMAGE_PATH .... /var/lib/libvirt/images/vpn2.qcow2
BASE_PATH ..... /var/lib/libvirt/images/jammy-server-cloudimg-amd64.img

Is this OK? ('y' to proceed) y
/var/lib/libvirt/images ~/cloud-init
image: vpn2.qcow2
file format: qcow2
virtual size: 30 GiB (32212254720 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: jammy-server-cloudimg-amd64.img
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
~/cloud-init
WARNING  --os-type is deprecated and does nothing. Please stop using it.
WARNING  /home/ubuntu/cloud-init/cidata-vpn2.iso may not be accessible by the hypervisor. You will need to grant the 'libvirt-qemu' user search permissions for the following directories: ['/home/ubuntu']
WARNING  /home/ubuntu/cloud-init/cidata-vpn2.iso may not be accessible by the hypervisor. You will need to grant the 'libvirt-qemu' user search permissions for the following directories: ['/home/ubuntu']
WARNING  CDROM media does not print to the text console by default, so you likely will not see text install output. You might want to use --location. See the man page for examples of using --location with CDROM media

Starting install...
ERROR    internal error: process exited while connecting to monitor: 2023-12-22T01:31:30.396162Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"/home/ubuntu/cloud-init/cidata-vpn2.iso","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}: Could not open '/home/ubuntu/cloud-init/cidata-vpn2.iso': Permission denied
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
  virsh --connect qemu:///system start vpn2
otherwise, please restart your installation.

ユーザのフォルダのパーミッションを変更するとうまくインストールをすることができた。

# 変更前
$ ll
drwxr--r--  5 ubuntu ubuntu 4096 Dec 22 01:31 ubuntu/

# パーミッション変更
$ chmod 755 ubuntu/
# 確認
$ ll
drwxr-xr-x  5 ubuntu ubuntu 4096 Dec 22 01:31 ubuntu/

# install
$ cd ubuntu
$ ./create-vpn2.sh
(さきほどのエラーが出力されず、うまくインストールできる)