ESXi 5 vSphere Ubuntu VM, adding a second hard drive

Posted on Thursday, April 5, 2012



I have an Ubuntu 10.04 Desktop running as a VM image in an ESXi 5 server.  I want to add a second hard drive to it format it and mount it.  Here is a simple how to.

First open up vSphere Client and login to your ESXi 5 server.



Now select the virtual server you want to add an extra hard drive to and click on Edit Virtual Machine Settings.


Click on the Add button.




Select Hard Disk and click Next.



Select Create a new virtual Disk and click Next.



Set the Disk size and click Next.  (I set mine to 50GiB)



Here you can select which drive you want this to be.  I used the default which just selects the next available slot and click next.


Click Finish.



Now you can see the extra hard drive.  Click OK.



Right click on the server and select “Open Console”




Reboot the server.

Open up a terminal and from the command line run the following command


      > ls /dev/sd*


Here you can see the /sdb drive which is the second drive I just added.



First let’s format the hard drive.  First switch over to root


      >  sudo su root
      >  fdisk /dev/sdb



From fdisk run the following commands



      >  n
      >  p
      >  1
      >  1    (just hit enter for default)
      >  6527  (just hit enter for default
      >  w




Now format the drive


      >  mkfs.ext3 –b 4096 /dev/sdb1




Now mount the drive.  I made a folder called /disk2 mounted it and did a quick check



      >  mkdir /disk2
      >  mount /dev/sdb1 /disk2
      >  df -hT








Set fstab to automount drives


There is one more problem to go over, this set up does not survive a reboot.

To automatically attach a hard drive on a reboot you need to edit the /etc/fstab  and make a little script.   In truth there are ways to edit the /etc/fstab so you do not need a script,  but I use one. 

Here is my quick reasoning on using a script.  I set up the /etc/fstab to be aware of the new drive and then the script auto executes on a new reboot to automount the drive(s).   I have had bad experiences in the past that if I do it all in /etc/fstab then I remove the extra hard drive that the OS will lock up on a reboot as it expects the drive to be there or else it won't start.  The way I do it allows it to start even if the extra drive is not there.  Maybe there is a better way to do this but it’s the way I like to use currently.  (Have a better idea then share it)

So with that all in mind let's first edit the /etc/fstab


Edit /etc/fstab


> sudo vi /etc/fstab


Add the following


/dev/sdb1 /disk2 ext2  rw,suid,dev,exec,noauto,nouser,async  0  0





Set up start up script (to mount the hard drives


> sudo vi /etc/init.d/mountHD


Then place the following in it.


mount /disk2





Make it executable


> sudo chmod 755 /etc/init.d/mountHD



Add it to autostart


> sudo update-rc.d mountHD defaults


Reboot to test auto mount of hard drives


> sudo reboot now


After a reboot if you run this command…


> df -h



And you should see your mounted hard drives



There you have it J


References

4 comments:

  1. this works great, but doesn't persist thru a restart...

    http://www.psychocats.net/ubuntu/mountlinux
    from the part where the UUID is discovered will fill in the gaps.

    Thanks... new to esxi and was missing the little pieces!!

    ReplyDelete
    Replies
    1. Thanks for the catch, I really should have added a section on automounting through a restart. The article is now updated with the way I automount extra drives with /etc/fstab and a small script.

      If anyone has any other good methods to automount extra drives please share them /etc/fstab can be intimidating.

      Delete
  2. Hi Pat! Long time no see! hope you are doing great.

    Running into this error after the command update-rc.d mountHD defaults.

    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
    perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
    insserv: warning: script 'mountHD' missing LSB tags and overrides

    Then rebooted and drive was not mounted.

    ReplyDelete
    Replies
    1. Ahh I have a guess at the problem.
      This was an old script on Ubuntu 10.04 Since then things have changed.
      If you are using " update-rc.d mountHD defaults" which adds it to be auto run on reboot and a few other things
      You probably need to give it a bit more instructions on what to do in the script itself.

      see https://help.directadmin.com/item.php?id=379
      Look at the
      ### BEGIN INIT INFO
      # Provides: dovecot
      # Required-Start: $local_fs $network
      # Required-Stop: $local_fs
      # Default-Start: 2 3 4 5
      # Default-Stop: 0 1 6
      # Short-Description: dovecot
      # Description: dovecot pop & imap daemon
      ### END INIT INFO

      Part something similar to this needs to be added to the top of your script
      It is used to determine run states

      Delete