Adding Storage to Linux

There are plenty of articles out there on how to add new storage to Linux.  This is something I don’t do that often, so I’m going to document it here for future reference – maybe it’ll help someone as well.

My Linux VM is a CentOS 5.5 64-bit machine running on ESX 4.1.  I’ve directly attached iSCSI storage to it within vSphere and now I need to have the VM actually see the storage.  To the command line!

The first thing to do is make sure Linux sees the new drives:

  • fdisk -l | grep Disk

You should see something like this:

  • Disk /dev/sdb:  1099.5 GB, 1099511558144 bytes

Obviously, your GB size will vary depending on the size of the drive/storage you are trying to attach.  The above example is what I see because I’ve added a 1TB data store to my VM as a directly attached drive.  That being said, the next thing we need to do is create a partition:

  • fdisk /dev/sdb
  • n  – create new partition
  • p – primary
  • 1 – tell the drive what partition number it is (in my case it was the 1st partition)
  • defaults (just press “enter”) – the rest of the options, I just use the defaults because I wanted to use the whole drive for storage.  You can adjust these to your liking.
  • w – write the new partition table and exit.

Now we need to format the new drive using whatever type of file system we want.  In my case, I chose ext3 so I entered the following:

  • mkfs.ext3 /dev/sdb1 – prepare to wait a while depending on the drive size.  Note here, that with the new partition, you now see /sdb1…not just /sdb.  We will be working with /sdb1 moving forward.

Once this is complete we need to create a mount point for the new drive and then actually mount the new storage.  You can create a directory anywhere you wish, but I recommend creating a folder in the /mnt/ directory for best practices:

  • mkdir /mnt/something – this creates the directory where Linux will access the storage
  • mount /dev/sdb1 /mnt/something – note that “something” means for you to pick what you want it to say.

Once this is done, you can verify your new drives are working by using:

  • df -H – this will show your mount points and drives.

The last thing to do is, we need to edit the fstab so that these drives are mounted when the system is booted:

  • vi /etc/fstab – this opens, in vi (you can use any editor here – nano, etc.), the fstab for editing.  Enter the following for each drive you want mounted on boot:
    • /dev/sdb1     /mnt/something     ext3     defaults     1 2
  • Save your changes and exit the editor.

That’s it!  You now have usable storage for Linux.  This is just the tip of the iceberg; you can set partitions to boot, create multiple partitions, change the file system to any number of other choices, etc.  As always, let me know if you have questions or see something wrong!  Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *