ESXi Config Backup & Restore

The state.tgz file

One nice thing only a very few people know is the configuration file “state.tgz” of ESXi. If you’re using a SD-Card or USB Stick installation of ESXi, the boot image is stored on that USB / SD Card.

The boot process

During bootup, ESXi loads the configuration from /bootbank/state.tgz and extracts its contents to /etc. During the day, if the file gets updated, changes are backed up into state.tgz and placed to /bootbank again.

Advantage

Imagine the day, ESXi tells you there’s something wrong with /bootbank. At a closer look you see the SD Card suddenly died today. First – yes realize that – you’re happy ESXi and all VM’s are still up and running. You’ll be able to vMotion everything off that host and put him into maintenance mode.

Now, this is the right and latest time to create a config backup – if you didn’t before 🙂

Create a config Backup

To backup your ESXi configuration from USB / SD Card, follow this steps:

  1. Logon to your ESXi Host using SSH
  2. Run the auto-backup.sh script to confirm you have an up-to-date host configuration saved in the /bootbank/state.tgz file
  3. scp the file /bootbank/state.tgz to some safe location

Reinstall ESXi

If you’re in the same situation like me, it’s now time to shutdown the Host and reboot. You’ll see, the Host will not come up – yes because of the defective SD. 😛 Now insert a new SD Card, use ESXi boot media / installer and start from scratch.

After ESXi is installed again, just give him an IP and root passwort to be able to connect using ssh and continue with the restore process.

Restore Configuration

To restore the configuration:

  • scp the backup state.tgz to /tmp
  • Login using ssh
  • cd /tmp
  • tar -xvzf /tmp/state.tgz
  • cd /
  • mv local.tgz local.tgz.old
  • cp /tmp/local.tgz .
  • tar -xzvf local.tgz
  • Reboot the ESXi Host

The Host now starts with the restored configuration from your state.tgz file.

Source:
http://kb.vmware.com/kb/2043048

Advertisements

Boot directly from vhd File

Yes I knew about mounting vhd files as drive in Windows 8/2012, and ISO files can also be mounted directly in windows explorer. But here’s a very easy way to mount AND directly add the vhd image into BCD boot menu to boot up from:

(1) Copy the Extracted VHD file to C:\BootVHD\Server2012.vhd

(2) Mount the copied VHD file as a virtual Drive Letter

  • Right-click on the “Command Prompt” shortcut and select “Run as Administrator”
  • run “DISKPART.EXE” from the Command Prompt
  • At the “DISKPART>” prompt type the following commands, pressing Enter after each:
  • SELECT VDISK FILE=”C:\BootVHD\Server2012.vhd”
  • ATTACH VDISK
  • EXIT

(3) Wait for the VHD file to be mounted as new Drive Letter.  When completed, this new drive letter will display in “My Computer” and “Windows Explorer”

(4) Add a new OS Boot Menu Choice for Windows Server 2012

  • Right-click on the “Command Prompt” shortcut and select “Run as Administrator”
  • Run “BCDBOOT <mounted_drive_letter>:\WINDOWS” from the Command Prompt

(5) Reboot and select “Windows Server 2012” for the OS Boot Menu displayed

Done.

Source: http://blogs.technet.com/b/keithmayer/p/earlyexpertlabsetup.aspx#.UYtQlsp0bIg

Install Windows 8 on a USB Stick

Prepare a USB Stick

To start from a USB Stick, it must be made bootable and formatted with ntfs. To do so, use diskpart as described in my other blog post here but use “format fs=ntfs quick” instead of fat32 filesystem.

Install Windows using ImageX

As you may now, Windows ISO Files / DVD-Roms contain an image file with the contents of the C:\ Partition. Now to install Windows 8 it’s only needed to unpack the filesystem to the USB Stick and create a Bootloader.

To make it easier, I’ve used the GUI Version of ImageX from AutoScript.com. In this Tool there’s a Tab called “Apply” where you can direct to the install.wim Image file and select the USB Stick as destination. By applying, GImageX extracts the filesystem to the Stick.

  1. Extract “install.wim” from the Windows 8 ISO file, Folder “sources” to a temporary location on your computer
  2. Use a tools like GImageX to Apply “install.wim” to the USB Stick
  3. Open CMD with elevated rights
  4. enter “bcdboot e:\windows /s e:”, where e:\ is your USB stick’s drive letter

Done!

Source:
http://tech2.in.com/how-to/windows/how-to-install-windows-8-on-a-pen-drive/314452

Create a Win7 / Server2k8r2 Boot USB Stick

This looks like a hard “operation” on the USB Hardware, but in truth it’s just formatting a partition on the USB Stick, set the Partition as active and copy all files on it.

So here’s how to:

Create a bootable partition
Open a cmd window; admin rights are maybe required, you’ll be asked on starting diskpart. Enter the following commands to create a primary FAT32 partition marked as active:create partition primary.

diskpart (that’s a command line disk partitioning utility)

list disk (to show up all existing disks)
select disk 1 (where number 1 is the number of your USB Stick)
clean (to clear the existing config)

create partition primary
select partition 1
active
format fs=fat32 quick
assign
exit

Now just copy the content of any Windows Installation Media to the USB Stick and boot it.

(found on http://owsug.ca/blogs/…)