Add new Hard Drive to CentOS Linux

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)

fdisk /dev/sdb on dev-centos: device contains no valid partition table, new DOS disklabel created

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

fdisk m command listing the menu: n add a new partition, p print table, w write table to disk and exit

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

fdisk n command asking for partition type: e extended or p primary partition (1-4)

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

fdisk p selected for a primary partition, now asking Partition number (1-4)

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

fdisk partition number 1 entered, asking First cylinder (1-33112, default 1)

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

fdisk Last cylinder prompt answered with the default 33112, using the whole disk

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

fdisk w: The partition table has been altered, calling ioctl() to re-read partition table

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

mkfs -t ext3 /dev/sdb typed at the root prompt on dev-centos

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

mke2fs 1.41.12 warning: /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n)

you should see the format occurring

mkfs.ext3 output with a red arrow on Writing inode tables: 400/2030 progress counter

the red arrow should show your progress

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

mkfs.ext3 inode tables and journal done, now at Writing superblocks and filesystem accounting information

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

free -m during the format showing 906 MB of 996 MB memory used, mostly buffers

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

mkfs.ext3 finished: done, filesystem checked every 33 mounts or 180 days, use tune2fs -c or -i to override

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 /

cd / and ls listing the root directories on dev-centos

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 #

ls showing the new DATA directory, then mount -t ext3 /dev/sdb /DATA returning to the prompt

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

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

df -h with a red arrow on /dev/sdb 250G mounted on /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

/etc/fstab line under # Mount SDB Share At Startup: /dev/sdb /DATA ext3 defaults 0 0

** 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

mount -a at the root prompt returning with no errors

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

df -h again listing /dev/sdb 250G mounted on /DATA alongside an NFS mount

/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

df -h after reboot with red arrows on /dev/sdb and /DATA, the disk remounted from fstab

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

Related guides: Add a Disk to LVM and Expand Space | Resizing a Physical Volume CentOS 6

Leave a Reply

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