3
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.

vmwareの仮想マシンイメージをThin形式のままデータを引っ越しする

Last updated at Posted at 2023-01-01

1. はじめに

vmwareの仮想マシンイメージをcpでコピーするとThinイメージからThickイメージになってしまいます。
それを回避するためには、Storage vMotionを使うか、vmkfstoolsを使う必要があります。

vmware ESXiやvmware essentialではStorage vMotionは使えないのでコマンドラインでvmkfstoolsを使って移行しました。
移行するときに手作業ではミスる可能性が高いので、シェルスクリプトを組みました。

2. 結論

src_stは、移動元のストレージです。移行用のESXiからNFSでマウントされているとします。
dst_stは、移行先のストレージです。移行用のESXiからNFSでマウントされているとします。

引数で、移行する仮想マシンイメージのディレクトリ名を指定します。

#!/bin/sh

source_storage='src_st'
dest_storage='dst_st'

trans_vmdir=$1
if [ -z $trans_vmdir ]
then
  echo "Please specify the transport source directory 'transfer-vmimage.sh <vmware image dir>'"
  exit
else
  :
fi

echo "exec copy file vmware image: $trans_mvdir"

mkdir -p "/vmfs/volumes/$dest_storage/$trans_vmdir"

if [[ ! "$(find "/vmfs/volumes/$source_storage/$trans_vmdir" -name '*.vswp'| wc -l )" == "0" ]]
then
  echo "current virtual machine is running. please stop $trans_vmdir"
  exit
fi

echo "Copy files without .vmdk"
find "/vmfs/volumes/$source_storage/$trans_vmdir" -maxdepth 1 -type f | grep -v ".vmdk" | while read file; do cp -rf "$file" "/vmfs/volumes/$dest_storage/$trans_vmdir"; done

echo "Copy .vmdk file"
src_file_list=$(find "/vmfs/volumes/$source_storage/$trans_vmdir" -maxdepth 1 -type f | grep ".vmdk" | grep -v "\-flat.vmdk")

for src_file in $src_file_list
do
  dest_file=$(echo $src_file | sed -ne 's/$source_storage/$dest_storage/p')
  echo "source      .vmdk file: $src_file"
  echo "destination .vmdk file: $dest_file"
  vmkfstools -i "$src_file" -d thin "$dest_file"
done

3. 参考

Move VMware ESXi VM to new datastore - preserve thin-provisioning - Server Fault
https://serverfault.com/questions/372526/move-vmware-esxi-vm-to-new-datastore-preserve-thin-provisioning

コマンドでシンプロビジョニングの仮想マシンを別のデータストアへ移行する | MSeeeeN
https://mseeeen.msen.jp/migration-to-another-data-store-with-thin-provisioning/

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