Rate This Document
Findability
Accuracy
Completeness
Readability

Creating a Data Drive

Create a data drive to store MySQL data files.

Method 1: Using mkfs to Create a Data Drive

  1. View the drive.
    1
    ls /dev/nvme*
    
  2. Format the drive.
    1
    2
    mkfs.xfs -f /dev/nvme0n1
    du -sh /dev/nvme0n1
    
  3. Create a data directory.
    1
    mkdir /data
    
  4. Mount the drive to the data directory.
    1
    2
    mount /dev/nvme0n1 /data/
    df -h
    

Method 2: Using fdisk to Create a Data Drive

  1. Create a partition, for example, /dev/nvme0n1.
    1
    fdisk /dev/nvme0n1
    
  2. Type p (print the partition table) and press Enter to display the current partition.
  3. Type n (add a new partition) and press Enter.
  4. Type p (create a primary partition) and press Enter.
  5. Type 1 (set the partition number to 1) and press Enter.
  6. Press Enter to retain the default setting for the first partition.
  7. Press Enter to retain the default setting for the last partition.
  8. Type p and press Enter, and check that the partition information is correct.

  9. Type w to save the settings and press Enter.
  10. Create a file system, for example, xfs.
    1
    2
    ls /dev/nvme*
    mkfs.xfs -f /dev/nvme0n1p1
    
  11. Mount the partition to /data of the OS.
    1
    2
    mkdir /data
    mount /dev/nvme0n1p1 /data
    
  12. Edit /etc/fstab to enable the data drive to be automatically mounted after the OS is restarted.
    1. Open /etc/fstab.
      vim /etc/fstab
    2. Press i to enter the insert mode and add the line to the end of the file.

      /dev/sdb1 is used as an example. Replace it with the actual one.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.

Method 3: Using LVM to Create a Data Drive

Install the LVM2 package (contained in the image) and create a data drive as follows:

  1. Install lvm2.
    1
    yum -y install lvm2
    
  2. Create a physical volume, for example, sdb.
    1
    pvcreate /dev/sdb
    
  3. Create a physical volume group, for example, datavg.
    1
    vgcreate datavg /dev/sdb
    
  4. Create a logical volume, for example, datalv of 600 GB.
    1
    lvcreate -L 600G -n datalv datavg
    
  5. Create a file system.
    1
    mkfs.xfs /dev/datavg/datalv
    
  6. Create a data directory and mount it.
    1
    2
    mkdir /data
    mount /dev/datavg/datalv /data
    
  7. Edit /etc/fstab to enable the data drive to be automatically mounted after the OS is restarted.
    1. Open /etc/fstab.
      vim /etc/fstab
    2. Press i to enter the insert mode and add the line to the end of the file.

      In the last line, /dev/datavg/datalv is only an example.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.