Adding a new disk drive to Centos 6
Installing a new HDD
The disk drives in Centos is named hd* or sd*. In system with only one HDD you should receive following output:
# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2Now connect new HDD to the system. If it is visible to BIOS it will be automatically detected by OS.
After new HDD is installed output of the same system will be like this:# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdbThe new HDD is assigned sdb with no partitions. A new partitions can be created on the new HDD and then mounted or the disk can be added to an existing volume group as a physical volume.
Creating partitions
Creating partitions using fdisk utility (root rights required).
# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xd1082b01. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help):Switch off DOS compatible mode and change the units to sectors by entering the c and u commands:
Command (m for help): c DOS Compatibility flag is not set Command (m for help): u Changing display/entry units to sectorsIn order to view the current partitions on the disk enter the p command:
Command (m for help): p Disk /dev/sdb: 34.4 GB, 34359738368 bytes 255 heads, 63 sectors/track, 4177 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd1082b01 Device Boot Start End Blocks Id Systemfdisk output shows that the disk has no partitions yet because it has not been used before. New partition can be created by entering n (for new partition) and p (for primary partition):
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4):Currently we plan to create only one partition - partition 1, so the first available sector will be beginning and the last one will be end. If you wish to create multiple partitions you can specify the size of each partition by sectors, bytes, kilobytes or megabytes.
Partition number (1-4): 1 First sector (2048-67108863, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-67108863, default 67108863): Using default value 67108863Now when partition is specified write it to disk by entering w:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.The new partition is now visible as /dev/sdb1:
# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1The next step is to create file system on the new partition with mkfs.ext4 utility.
# /sbin/mkfs.ext4 -L /backup /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label=/backup OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 2097152 inodes, 8388352 blocks 419417 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 256 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.Now when a file system on the new partition is created we need to mount it so that it is accessible. For example, let's create a directory /media which will be our mountpoint.
# mkdir /mediaMount file system:
# mount /dev/sdb1 /mediaRunning the mount command with no arguments shows us all currently mounted file systems (including our new file system):
# mount /dev/mapper/vg_CentOS6-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/sr0 on /media/CentOS_6.0 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500, iocharset=utf8,mode=0400,dmode=0500) /dev/sdb1 on /media type ext4 (rw)In order to Centos automatically mount new file system at boot add it to /etc/fstab file. Below is shown fstab configured to automount /media at boot:
/dev/mapper/vg_centos6-lv_root / ext4 defaults 1 1 UUID=0d06ebad-ea73-48ad-a50a-1b3b8ef24491 /boot ext4 defaults 1 2 /dev/mapper/vg_centos6-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 LABEL=/backup /media ext4 defaults 1 2