Last Updated: 01 Apr 2022

   |   

Author: dordal

This is an old revision of the document!


Adding & Formatting a New Drive Under CentOS

I always have trouble remembering the magic set of incantations required to add a new drive in CentOS… particularly without rebooting.

Here's what I usually do. Note this makes some assumptions:

  • You want to use LVM so you can expand/contract the size of the disk later.
  • You want use XFS for your filesystem

Adding the Disk

1. First, add the disk itself. You're probably using VMWare or something, so you can do this via the VMWare admin interface.

2. Either reboot so the machine sees the disk, or scan the SCSI busses:

# tail -f /var/log/messages

# echo “- - -” > /sys/class/scsi_host/host0/scan

If you don't see the disk from the first bus, you may need to scan the others:

# echo “- - -” > /sys/class/scsi_host/host1/scan

# echo “- - -” > /sys/class/scsi_host/host2/scan

Eventually the disk should show up in /var/log/messages. Let's assume it is /dev/sdb

3. Create the physical volume:

# pvcreate /dev/sdb

4. Create the volume group ('mysql' in this case):

vgcreate mysql /dev/sdb

5. Create the logical volume ('data'):

# lvcreate -l 100%VG -n data mysql

Formatting & Mounting the Disk

6. Make the XFS filesystem:

# mkfs.xfs /dev/mapper/mysql-data

7. Make the mountpoint:

# mkdir /data

8. Mount the drive:

# mount /dev/mapper/mysql-data /data

9. If you want the drive to mount at boot, add an entry in /etc/fstab

You're done. If you want to see if your new drive is online, check df -h and you should see it.

Discussion

Enter your comment. Wiki syntax is allowed: