1
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?

More than 1 year has passed since last update.

実際に使う際にはご自身でご確認の上ご利用ください。
何があっても責任は負えません。

#!/bin/bash

new_storage="hdd" #ここに移動先のストレージ名を入れる

for vmid in $(qm list | awk '{if(NR>1) print $1}')
do
    echo "Processing VM $vmid"

    qm config $vmid | grep "virtio[0-9]:\|scsi[0-9]:\|ide[0-9]:\|sata[0-9]:\|tpmstate[0-9]:\|efidisk[0-9]:" | cut -d ':' -f1 | while read -r disk
    do
        current_storage=$(qm config $vmid | grep "$disk:" | cut -d ':' -f2 | sed 's/ //g')
        if [[ ${current_storage} != ${new_storage} && ! ${current_storage} =~ cdrom ]];then
            echo "Moving disk $disk of VM $vmid from $current_storage to $new_storage"
            #qm move-disk $vmid $disk $new_storage --delete
            #実際に実行する際は↑の行のコメントを外してね
        fi
    done
done
  • VirtIO Block
  • SCSI
  • IDE
  • SATA
    上記4種に加え
  • TPMの状態
  • EFIディスク
    の一括移動に対応しています。

移動させたくないディスクは一時的にディスクをデタッチしてunusedにすることで、移行対象から外す事ができます。

1
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
1
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?