Add new Hard Drive to CentOS Linux

Add new Hard Drive to CentOS Linux

BEFORE PROCEEDING, MAKE A BACKUP OF YOUR ENTIRE LINUX SYSTEM, DO NOT PERFORM THIS ON A PRODUCTION SYSTEM, and i take ZERO RESPONSIBILITY FOR ANY ACTIONS TAKEN, and you are proceeding at your own will, keep in mind technology changes and this could be out of date by the time this is read.

 

Configure NEW Disk:

  1. mkdir /mount/point

  2. pvcreate /dev/xvdb

  3. vgcreate VolGroup00 /dev/xvdb

  4. lvcreate VolGroup00 -n lvname -l100%FREE

  5. mkfs -t ext4 /dev/VolGroup00/lvname

  6. add to fstab /dev/VolGroup00/lvname /mount/point ext4 defaults 0 0

 

Linux Extend LVM to New Disk

 

  • pvcreate /dev/xvdf

  • vgextend VolGroup00 /dev/xvdf (newdisk)

  • lvextend -L100%FREE /dev/Volgroup00/rpmbuild

  • resize2fs /dev/VolGroup00/rpmbuild

 

 

 

The Below listed is another, but less efficient way to do this. DO NOT PROCEED, USE THE ABOVE PROCEDURE!!

 

adding a new hard disk to Linux can be somewhat scary because of the naming convention, but we will get through it like champs. The first thing you have to do is Physically install the new hard drive on the CentOS Linux system and Reboot.

BEFORE PROCEEDING, MAKE A BACKUP OF YOUR ENTIRE LINUX SYSTEM, DO NOT PERFORM THIS ON A PRODUCTION SYSTEM, and i take ZERO RESPONSIBILITY FOR ANY ACTIONS TAKEN, and you are proceeding at your own will, keep in mind technology changes and this could be out of date by the time this is read.

the first thing we want to do is see what we all have connected to the system, in terms of hard drives, issue the following command:

fdisk -l

as you can see there are two physical disks attatched, SDA and SDB,

it's important to understand that the first disk created when you install a Linux system is more often than not SDA, and usually the second disk is SDB, and after that the third is SDC, get the pattern?

ALSO, make sure before you proceed any further that you are doing this in off-business hours, it takes pretty much all of the RAM for the system, so it's very resource intensive.

also i know that there is a 270GB hard drive that i just installed, this shows that SDB is our canidate

if you do fdisk /dev/sdb you should get the following output (suggesting that there is nothing on the drive)

press the M for the menu as to what to do:

press the n key to create a new partition

it will ask if we want to do an extended or primary partition go with primary

it will ask what partition number we would want to use, let's use 1

it will then ask first cylinder, go with 1 the defaults

it will ask for the last cylinder, go ahead an add the default

now we just have to write the changes to the disk, issue the w command

the start/finish has been written to the disk

now from here we have to write the filesystem to the disk, much like in windows we have to select NTFS or FAT, in Linux we have to write the ext3 or ext4 filesystem (or whatever is the most current) to the disk

so here we are formatting the disk with the ext3 filesystem and the device is again /dev/sdb

you will get a notice that you are formatting the entire device, it will ask if you want to proceed

you should see the format occurring

the red arrow should show your progress

it should sit for a minue or two at the "writing superblocks" area

this will take a while, the example was for a 250GB drive and took about 15 minutes, it could be longer depending on the drive you are using, and other variables

this also takes alot of system resources, take a look at memory of this system

as you can see, this process has finished on the system

it notifies you that every 33 mounts or 180 days the filesystem will be checked automatically with FSCK.

From here, let's create a target to mount the hard drive on, so do a cd /

Let's create a folder to mount it to (you don't have to, but it helps with troubleshooting down the road) Let's call the new hard drive "DATA" for kicks

mkdir /DATA

now from here we have to do a test mount to make sure it works, use the following command:

mount -t ext3 /dev/sdb /DATA

if it succesfully mounts, you should be returned to #

do a df -h to see if the file system is mounted

as you can see /dev/sdb is mounted to the /DATA

WERE NOT DONE YET, this only mounts the drive one time, we need it to mount every time, like when we reboot for example

do vi /etc/fstab

add this to the bottom of the FSTAB

** Before you issue the following command, be aware that this re-mounts ALL Filesystems, and will more than likely disconnect most other users *****

to make sure this mounts automatically, issue the following command:

mount -a

if you are returned to # your mount worked, try df -h once more

/dev/sdb is present on the device.

if you can get away with it, do a reboot, and see if it remounts

as you can see the filesystem remounted after a reboot

 

you have successfully configured adding a hard drive to CentOS Linux 6.3!

 

That's It! If you found this article helpful, please consider donating to keep the blog running