Can’t Mount A USB Device On ESX/ESXi Server

You may want to mount a USB device (Key or media) on an ESX server to export or import files (e.g. vmdk). The problem is the USB devices shows up with “lsusb” but is not mounted properly.

The reason for this behaviour is that the ESX/ESXi 4.1 is designed for passthrough to any virtual machine on the system. As such, the usbarbitrator service will always claim external devices plug into the host using the passthrough technology to make it available for the virtual machines. To resolve this issue, the usbarbitrator must be stopped first before the external device can successfully be mounted. In the following steps, I will explain how it’s been done:

Requirement:

  • SSH server must be running on the host (ESX/ESXi)
  • PuTTY or the console of another UNIX/Linux system 

1.) Stop the usbarbitrator service by running this command

/etc/init.d/usbarbitrator stop

2.) Disconnect and reconnect the usb device. The device might be automatically mounted under

/vmfs/volumes/NO NAME/ (just navigate here to export or import your files)

**) If not automatically mounted, use the following commands to find out where the device is connected to (e.g. /dev/sda1)

fdisk -l
tail /var/log/messages

To mount the device, first create a folder

mkdir /ExtUSB

mount the device with

mount -t ext3 /dev/sda1 /ExtUSB/

3.) After using the device, run the following command to start the usbarbitrator service

/etc/init.d/usbarbitrator start

We are done!


Posted in ESX, ESXi, Linux, VMware and tagged , , by with comments disabled.

How to Export/Import Virtual Machine On ESX Server

We recently updated our hardware (old ESX server) and had to export and import the virtual machines to the new server

In achieving this goal, we had to use an external USB drive to backup and transfer VMDK files from an old ESX server to the new one.

Requirements:

  • External USB drive with enough capacity
  • The drive has to be formated (preferably ext3 or ext4)
  • Coffee, cigarett or anything but no alcohol 😉

Format and Mount the Drive:

 Steps:

  • Connect the external drive to the ESX server
  • Login to the server console using ssh connection (e.g putty)
  • To find out where the device is connected, enter “fdisk -l” (without the quotes ” “)
  1. fdisk -l

 

 

 

 

Note: As seen above, a partition has been created and only need to be formated

  • Format the new drive by typing these commands

  mkfs.ext3 -m 1 /dev/sdb1

 e2label /dev/sdb1 /ExtUSB (optional)

  where sdb1 is the partition shown above and 1 for 1% of the partition for administrative purposes

  for more information, type man mkfs.ext3   

  • Create a folder (mount point) where you want to mount the new drive (Example: mkdir /ExtUSB)
  • mount -t ext3 /dev/sdb1 /ExtUSB

  To make this permanet, type vi /etc/fstab and enter:

  LABEL=/ExtUSB1  /ExtUSB   ext3   defaults        0 0

  Save the file (type  :wq and press ENTER)

  • mount the partition

  mount -a

  • Check the to see that the new partition is mounted as expected by typing

  mount

Export the VM files and Logs to the external USB drive:

Vmktools is the VMware ESX Server file system management tool we used for this task. It is a program for creating and manipulating virtual disks, files systems, logical volumes and physical storage devices on the VMware ESX Server. To export or import VMDK (virtual disk) files, the command to use is ‘vmkstools’.

Export:

  • Enter the following comands as it is to export the VMDK files

  vmkfstools -i /vmfs/volumes/[datastore_name]/[vm_name]/[vm_name].vmdk /mnt/usb/[vm_name].vmdk -d 2gbsparse

  • To also export the configuration files for the virtual machine, just copy all those files with the following extentions: *.vmx, /.log, *.nvram, *.vmxf and *.vmsd. The best way to do this, is to first zip the files in tar.gz format and then copy to the external USB drive as follows:

  cd /vmfs/volumes/[datastore_name]/[vm_name]/

  tar -czvf [vm_name].tar.gz *.vmx *.log *.nvram *.vmxf *.vmsd

  cp [vm_name].tar.gz /mnt/usb/

Import:

Prior to importing the exported files, make sure you have created a new virtual machine (name it whatever you want). The VMDK and other files in the newly created virtual machine must be deleted to avoid conflicts with the ones to be imported. Take a look at these images to get an idea where to find these files:

Browse Data Storage

Browse the Data Storage

Delete VMDK Files

Delete all files from the VM folder as shown above

  • Enter the following comands to import the VMDK files

 vmkfstools -i /[path_to_USB_mount]/[vm_name].vmdk /vmfs/volumes/[datastore_name]/[vm_name]/[vm_name].vmdk

  • To also import the configuration files for the virtual machine, first extract [vm_name].tar.gz file to a folder (should be created first) and just copy all those files with the following extentions: *.vmx, /.log, *.nvram, *.vmxf and *.vmsd to /vmfs/volumes/[datastore_name]/[vm_name]/. The following comands should take care of this task:

  cd ~ (change to home directory)

  mkdir VMDK-Files

  cp /ExtUSB/[vm_name].tar.gz VMK-Files/

  cd VMDK-Files/

 tar -xzvf [vm_name].tar.gz

  rm -rf [vm_name].tar.gz

    cp * /vmfs/volumes/[datastore_name]/[vm_name]/

You can check to see if all files are imported as shown below:

Imported VMDK Files

Now, go ahead and start your VM machine. If carefully done, it should work as expected.

Related Site:

http://www.vladan.fr/


Posted in ESX, ESXi, Linux, VMware and tagged , , , by with comments disabled.

HowTo Disable the “ZEROCONF” in Linux

Most linux distribution uses the zero configuration network ( ZEROCONF) suite to automatically configure themselves and communicate on a network without the need of DHCP or DNS servers. ZEROCONF is an IETF organ that planned and coordinated a series of dynamic protocols to allow many operating systems to automatically configure themselves.

 

ZEROCONF commonly referred to as IPv4 Link-Local (IPv4LL) and Automatic Private IP Addressing (APIPA) utilises the 169.254.0.0/16 network address to auto-configure a network interface. It uses a series of unanswered “ARP” queries and then assumes an address if the queries yield an empty result. As a result, a route to the ZEROCONF network is added to the routing table by the network initscripts. Example:

The ZEROCONF route

ZEROCONF can be disabled by adding the following entry to the “/etc/sysconfig/network” configuration file.

 

[bash] # vi /etc/sysconfig/network
NOZEROCONF=yes or no (either answer will disable the “ZEROCONF route”)

It is important to note that the value of the “NOZEROCONF” parameter can actually be set to any value. The initscripts can only check to determine whether the parameter has a zero length or not. In other words, setting “NOZEROCONF=no” will have the same effect as setting it to “yes”. In order to reactivate ZEROCONF, the above entry “NOZEROCONF=yes/no” will have to either be commented out or removed entirely.

The network service must be restarted for the changes above to take effect.

[bash] # vi /etc/init.d/network restart

To see if the ZEROCONF route has been disabled, we have to check the routing table again.

The IP routing table

If you ever wonder and want to know more about the the makeup and history of the ZEROCONF, check this very informative zeroconf article written by John C. Welch and this zeroconf article on wikipadia.


Posted in CentOS, ESX, ESXi, Linux and tagged , by with comments disabled.

How to Create a Swap File

A swap file is an ordinary file that is in noway special to the kernel. The purpose of the swap file is to reserve the disk space so that the kernel can quickly swap out a page without having to go through all the things that are necessary when allocating a disk sector to a file.Because a hole in a file means that there are no disk sectors allocated (for that place in the file), it is not good for the kernel to try to use them.

In order to create the swap file without holes, use the following command:

1.) Assuming we want to create a swap file with 2GB size (1024 x 1024 x 2 = 2097152).

[bash]# dd if=/dev/zero of=/swapfile bs=1024 count=2097152

     where if is source, of is output file for dd to write to which is /swapfile in this case, bs is read/write byte size at a time and count is number of blocks.

2.) The next step is to make it a swap file

[bash]# mkswap /swapfile

3.) Activate the swap file

[bash]# swapon /swapfile

4.) Check the newly created swap space usinf free or top

[bash]# free -m

     or 

[bash]# top

5.) Write it to fstab to make it available for the system even after a reboot

[bash]# echo swapfile swap swap defaults 0 0 >> /etc/fstab

 

**) Using cat give you the following output:

[bash]# cat /etc/fstab
/swapfile1 swap swap defaults 0 0

Posted in CentOS, ESX, ESXi, Linux and tagged , by with comments disabled.

Accessing the console and enabling SSH in ESXi 4.0

SSH in ESXi 4.0 is by default disabled. The following steps illustrate how to enable the SSH service in ESXi 4.0 server. Steps 1-3 are needed ONLY if you just want to access the ESXi console and whereas, steps 4-6 additionally show you how to enable SSH in ESXi server.

 

1.) On the ESXi server keyboard, press ALT-F1 to access the console window.

2.) Enter unsupported and press Enter. Note that you will not see the text typed in.

3.) If the unsupported text was typed in correctly, you should see the Tech Support Mode warning and a password prompt. Enter the root password and press Enter

4.) You should now be able to see the prompt ~#. Type vi /etc/inetd.conf in the console to edit the file.

5.) Search in the file for line that begin with #ssh and remove the #. Save the file afterwards. Just in case you’re new to the vi editor, move the cursor down to the lines that begin with #ssh and press “i” key for insert. Move the cursor over one space and then hit the backspace to delete the #. Press the ESC key to escape the insert mode. Type :wq and Enter to save the file and exit vi editor.

6.) You can either restart the host or restart the inetd process after closing the vi editor. To restart inetd process, type ps | grep inetd on the console to determine the inetd process ID. The output should look like this:

1234 1234 ZeusBox      inetd (This clearly shows that the process ID is 1234).

Then, run kill -HUP
i.e. kill -HUP 1234 as in our example. Thereafter, you should be able to access the host via SSH.

Note: With some applications like WinSCP, the default encryption cipher used is AES. You will see significantly faster transfers if you change that to Blowfish.

Changing the port for SSH

To change the port for SSH, edit the file /etc/services and change the SSH port listed in the file. Save the file and repeat the step 6 above.

Enable Telnet

While it is NOT generally recommended to enable Telnet, there may be circumstances whereby it is necessary. If this is the case, the steps are the same with SSH by removing the # from the two telnet entries in /etc/inetd.conf. 

 You can also download an oem.tgz file which will enable SSH (and FTP). Copy the file to a datastore with the VI client and then to bootbank with the command cp /vmfs/volumes//oem.tgz /bootbank/oem.tgz and then reboot. 

Enable SSH access for a non-root account

Use the following process to enable SSH access for a non-root account

1.) Login to the ESXi server using SSH or directly the console with the root account

2.) Create a new account with the following command: useradd -M -d/. This will set the home directory to / instead of /home.

3.) Set the new user password using passwd .

4.) Edit the passwd file with vi /etc/passwd. On the line for the new user, change the /bin/sh at the end of the line to /bin/ash. Save the file and exit. The example below illustrates how the file should look like after editing:

root:x:0:0:Administrator:/:/bin/ash
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/:/sbin/nologin
dcui:x:100:100:DCUI User:/:/sbin/nologin
daemon:x:2:2:daemon:/:/sbin/nologin
vimuser:x:12:20:vimuser:/sbin:/sbin/nologin
test1:x:500:500:Linux User,,,:/:/bin/ash

Now, you should be able to connect with SSH using the new account.

Disable SSH access for the root account

If you have created non-root accounts for SSH access you can disable root access via SSH. Edit the /etc/inetd.conf file using the initial procedure described earlier on this page and add the option -w after the -i option. The line in inetd.conf will appear similar to the one below.

ssh stream tcp nowait root /sbin/dropbearmulti dropbear ++min=0,swap,group=shell -i -w -K60

Once you have made the change, save the file and run the kill -HUP command as described above to restart the inetd process. You will now be able to login with a non-root account, but will get access denied if you use a root account. Once you have established a SSH session with your non-root account you can issue the command su – to switch to the root account.


Posted in ESX, ESXi, Linux, VMware and tagged , , , , by with comments disabled.

How To Reset The Root Password In A Linux OS

You are hired to take charge of a Linux or Unix production system and no password has been provided for whatever reason (maybe the administrator has just been fired). There are two basic methods to reset the root password:
Method 1:
—————

1. Place the first installation CD/DVD in the CD/DVD-Rom

2. Reboot the system

3. enter “linux rescue” as boot option + ENTER

4. click continue to mount the system

5. cd /mnt/sysimage/ (or chroot /mnt/sysimage/ and skip to step 9)

6. type “ls” (to show the none root environment) – optional

7. type “pwd” (to show the “present working directory” in a none root environment) – optional

8. chroot . bash -i (in order to get the root environment with “bash shell”)

9. type “pwd” (to show the “present working directory” in root environment) – optional

10. type “ls” (to show root environment) – optional

11. type “passwd”    –> to reset the root password

*) other forms of system repairs (instead of just changing root password) can be perfomed here.

12. type “exit”  —> until the system reboots

Method 2:
—————

1. Reboot

2. at the menu of the boot manager (e.g. grub), type ‘e’ for editing

3. navigate to the kernel you want to boot

4. at the right of the line, enter “init 1” or “single” and press enter

5. type ‘b’ to boot the system into the single user mode

6. type “passwd” to reset the root password

7. type “reboot” to restart the system

Check out this link below for how to recover VMware ESXi root password:

Posted in CentOS, ESX, ESXi, Linux and tagged , , , by with comments disabled.

Low-Level formating vs Zero-Filling an IDE Hard Drive

Very often, Zero-Filling an IDE hard drive is easy confused with Low-Level format. Let me start by saying that you don’t “low-level-format” IDE or ATA hard drives. This term is misnomer from old MFM hard drives days when drives could have the tracks and sectors defined using low-level-format.

All IDE or ATA drives we use today have their tracks and sectors preset at the factory and a real low level format would destroy the drive or at least slow it down drastically… in order words, you cannot redefine the tracks and sectors on these drives with low level format. At least it is fair to say that it is absolutely impossible to change the physical geometry of current IDE/ATA drives without destroying it. In conclusion, low-level-format is an old term that really doesn’t apply to today’s IDE/ATA hard drives.

Now, in today’s situation, there is a different approach in redefining the logical geometry of an IDE/ATA hard drive by building partition(s) on the drive. Keep in mind that there are also the differences between physical and logical geometry of a drive.

When people today use the term low-level-format, there is every indication that this is a real problem. Usually, one of the following issues may have occured:

  • The drive has a boot sector virus and can no long be accessed to clean it off the drive
  •  

  • The drive has begun to develope numerous bad sectors and they are increasing (usually seen when running Scan Disk)
  •  

  • The drive has Linux, WindowsNT or other operating system installed which makes creating a Fat System on the drive incompatible with the new operating sytem to be installed.
  •  

What next… when people have these problems? They are usually wrongly told to low-level-format their hard drives. What really need to be done is reinitializing or mid-level format the drive.

ReInitializing an IDE/ATA Drive:

Now that we have the terminology straightened out, the next question would be… why does this matter? It is extremly important for you to know what exactly you’re doing to your drive.

When you reinitialize a hard drive, you basically use the appropriate tools to zero-fill the drive and as a result, cleaning every area of the hard drive. Most hard drive manufacturers provide on their web sites such utilities for downloading. One of such tools can be found on linux or UNIX operating systems and is simply called “dd”.

dd is the abbreviation for “dataset definition”. It is also jokingly said to stand for “disk destroyer” or “data destroyer”. since being used for low-level operations on hard disks, a small reversing the if and of parameters, can possibly result in the loss of all or some data on a hard disk.

    Example:

                 Using dd to wipe an entire disk with random data.
                 We are going to use a flash drive for thepurpose of this example.

                 first, we need to switch to root account

                 [stan@lnx]$su –

                 Enter the root password and type:

                 [root@lnx]#dd if=/dev/zero of=/dev/hdd

                 or

                 [root@lnx]#dd if=/dev/urandom of=/dev/hdd

                 or

                 for n in {1..7}; do dd if=/dev/urandom of=/dev/sdd bs=8b conv=notrunc; done

Once this process is complete, the drive will be void of any partitions. You will need to use FDISK for microsoft products to partition the drive and then format the new drive.

On a linux system, do the following:

[root@lnx]#fdisk /dev/sdd

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdd: 1010 MB, 1010827264 bytes
32 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 1952 * 512 = 999424 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended

p primary partition (1-4): p
Partition number (1-4): 1
First cylinder (1-1011, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1011, default 1011): 1011

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

Now, format the new partition:

[root@lnx]#mkfs.vfat -F 32 /dev/sdd1

 


Posted in CentOS, ESX, Linux and tagged , , by with comments disabled.