Adding Storage to Linux

by Christopher

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!

{ 7 comments… read them below or add one }

Robin Dong February 5, 2012 at 11:12 pm

this is very good website, you provided a very useful info for me to contrinue work on Linux.
God bless a nice guy like you.

Reply

Christopher February 6, 2012 at 10:15 am

Thanks Robin! :) Always glad to help.

Reply

Robin Dong February 14, 2012 at 8:03 pm

I am very glad to find your tip for adding a storage to a Linux server.
I have a brand new storage device, 2 disks and each 500gb. I connect this device to my Linux server by switch. the problem is I never able to see this device from my Linux server at all.
I tried ‘fdisk -l | grep Disk’, the output is ‘/dev/sda’ on my local server, not able to see any thing like: ‘Disk /dev/sdb’
dont know why and wanted to know so bad. Please help.

thank you very much.

Robin

Reply

Christopher February 15, 2012 at 2:59 pm

Can you elaborate a little more on what you are trying to do? Is this a new array or an extra hard drive?

Reply

Robin Dong February 18, 2012 at 10:03 pm

thank you very much for the reply.
this is a brand new NETGEAR product, called stora and come with a CD (I guess it is the driver for this storage device). I connect it with another 2 Linux server by a switch. try to see this device from the Linux server. but never see any thing.
I guess my switch may be not a good one, not managed switch?
or I need sign a IP to this storage before my Linux to check on it?
thank you for your help.
Robin

Reply

Christopher February 18, 2012 at 10:13 pm

AH! That product is a USB box, I believe. My instructions mainly revolved around a iSCSI environment with a virtual machine having the drives attached already. Obviously, my article could apply to your situation but since my instructions don’t seem to be working, you could always try an article over at Novell, that explains how to mount a flash drive (similar to your situation). Good luck though and sorry I couldn’t help!!!

Reply

Robin Dong February 20, 2012 at 1:32 am

Thank you very much. I will work on it.

Reply

Leave a Comment