How to rename a VM through SSH on ESXi ? |VMware Communities
Posted by jpluimers on 2021/06/28
From [WayBack] How to rename a VM through SSH on ESXi ? |VMware Communities (numbering and code highlighting mine):
Kindly find the below:
- Backup the virtual machine
- Power down the virtual machine
- Remove the virtual machine from the vSphere host inventory
- Open an SSH console session to the vSphere host
- Navigate to the storage directory containing the virtual machine: For example:
cd /vmfs/volumes/<datastore_name>/<original_vmname>- Rename the primary
.vmdkconfiguration files:vmkfstools -E "<original_vmname>.vmdk" "<new_vmname>.vmdk"- Rename the
.vmxconfiguration file:mv "original_vmname.vmx" "new_vmname.vmx"- Edit the virtual machine .vmx configuration file (Be sure to properly update the directory and file name of the
.vswpswap file reference):vi "new_vmname.vmx"- Rename any remaining files in the virtual machine’s folder as needed:
- Rename the
.vmxfconfiguration file:mv "original_vmname.vmxf" "new_vmname.vmxf"- Rename the
.nvramconfiguration file:mv "original_vmname.nvram" "new_vmname.nvram"- Rename the
.vsdconfiguration file:mv "original_vmname.vsd" "new_vmname.vmsd"- Rename the virtual machine folder: Move up one directory level to the parent folder (
cd ..) then rename the virtual machine directory:mv "original_directory" "new_directory"- Add the newly-named virtual machine to the host’s inventory (the newly renamed
.vmxconfiguration file)- Power on the newly renamed virtual machine
- Answer “I moved it” to the virtual machine question prompt (not “I copied it”)
- Review the virtual machine and all files/folders to make sure it is named as desired and functioning properly
Note: There are other methods to allow for renaming, but this method is fairly quick and easy. It should work on all editions of vSphere from free to Enterprise Plus.
The “Answer question” prompt where you should selected “I moved it”:
->
Prompt with symlink names in the path
On a site note, I need to figure uit how to set the ESXi shell prompt to show the current path like pwd does (with symlink names in it instead of the followed symlink targets):
[root@ESXi-X9SRI-3F:~] cd /vmfs/volumes/EVO860_250GB/ [root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] pwd /vmfs/volumes/EVO860_250GB
The ESXi shell is based on busybox, in fact it uses the ash variety:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] `readlink -f \`which readlink\`` | grep ^BusyBox BusyBox v1.29.3 (2018-11-02 15:37:50 PDT) multi-call binary. BusyBox is copyrighted by many authors between 1998-2015. [root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] type chdir chdir is a shell builtin
This seemed to work fine:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] PS1="[\u@\h:`pwd`] " [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
But in faxt fails, as it only takes a pwd value once, and not every time the prompt is evaluated:
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] cd .. [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] pwd /vmfs/volumes [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
So I need to re-visit these links:
- Identifying disks when working with VMware ESXi/ESX (1014953)
- Downloading files with wget on ESXi · random writes (explaining the BusyBox version trick)
- busybox prompt – Google Search
- [WayBack] shell – What are special prompt symbols for busybox’s sh support? – Unix & Linux Stack Exchange
BusyBox has two shells, ash and hush. To see which one you have, run
type chdir: ash has it as a builtin (synonymous withcd), hush doesn’t. Both have an optional prompt expansion feature. Ash’s is enabled by activating theASH_EXPAND_PRMTfeature at compile time, while hush requiresFEATURE_EDITING_FANCY_PROMPT.When that feature is present, in ash the value of
PS1is expanded like a double-quoted string:$foo,$(command)and`command`constructs are expanded.Some backslash escapes are processed (in ash, after substitutions). They are a subset of bash’s.
\!: line history count\a: bell\b: backspace\e,\E: escape\f: form feed\h: host name\n: newline\r: carriage return\t: tab\u: user name (only withFEATURE_GETUSERNAME_AND_HOMEDIR)\v: vertical tab\w: current directory, with~for the home directory (only withFEATURE_GETUSERNAME_AND_HOMEDIR)\W: current directory (unabbreviated)\xHHor\XHHwhere HH are two hexadecimal digits: a character given by its hex code\[…\]: the enclosed text doesn’t count for width calculation purposes
(If you’re looking at the source code, this happens in
parse_and_put_promptinlibbb/lineedit.c.) - [WayBack] shell – busybox ash PS1 not expanding – Unix & Linux Stack Exchange
- [WayBack] Quick Tip – How to Change ESXi SSH Prompt
- [WayBack] shell – How to display current path in command prompt in linux’s sh (not bash)? – Super User
- [WayBack] shell – What are special prompt symbols for busybox’s sh support? – Unix & Linux Stack Exchange
–jeroen





-> 

Leave a comment