2011年5月29日 星期日

change vdi UUID

如果你想改變vbox裡某個vdi的uuid檔,你會發現vbox會出現uuid衝突而無法直接使用,這種情形最常發生在更改了vdi檔名然後想重新安裝os。在google上找更改uuid的方法,其參數似乎已經不適用,4.0.x以上的版本應該改用sethduuid參數而不是舊的setvdiuuid。

我寫了一個shell script方便自己更改vdi的uuid:

  1. #!/bin/bash
  2. #############################################################
  3. # Filename: changeVDIuuid.sh
  4. # Date: 2011/05/29
  5. # Purpose: change uuid of vdi file
  6. # Usage:
  7. #
  8. # Description:
  9. # Author: maxsolar(Jim T. Tang@IES, Academia Sinica)
  10. #############################################################
  11.  
  12. ###########################
  13. ## pre-defined variables
  14. ###########################
  15. [ "$1" == "" ] && {
  16.     ls *vdi
  17.     read -p "please specify a vdi file: " vdi
  18.     [ -e "$vdi" ] && {
  19.         VBoxManage internalcommands sethduuid $vdi
  20.     } || {
  21.         echo "$vdi doesn't exist. program terminated."
  22.     }
  23. } || {
  24.     [ -e "$1" ] && {
  25.         VBoxManage internalcommands sethduuid $1
  26.     } || {
  27.         echo "$1 doesn't exist. program terminated."
  28.     }
  29. }