Add Second Disk To Linux VM

1 minute read


Let’s say you need to attach a second disk to a linux VM with LVM setup, this is how you would do it on RHEL 7

To Resolve:

1a. Attach 70 GB Disk in vsphere by going to the VM – Hardware – Add New: Disk

2.  In the VM – we want to create the following file system:

/files1  60 G
/files2  150 G 
/files3  300 G
/files4  60 G

2a. Scan SCSI to see new DISK

echo "- - -" > /sys/class/scsi_host/host#/scan
# OR
echo "1" > /sys/class/scsi_disk/2:0:0:0/device/rescan
# After scanning  you  should  see  new  disk  under  /dev/sd*
ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb
# This means that the first disk has two partitions - sda1 and sda2, but sdb is unpartitioned.
# Likewise, you can run 'fdisk -l' to see your second disk

2b. Create physical volume:

pvcreate /dev/sdb

2c. Create Volume Group:

vgcreate FILES /dev/sdb

2d. Next create the volumes

lvcreate -L 60G -n /dev/mapper/FILES-u01 FILES
lvcreate -L 150G -n /dev/mapper/FILES-u02 FILES
lvcreate -L 300G -n /dev/mapper/FILES-u03 FILES
lvcreate -L 60G -n /dev/mapper/FILES-u04 FILES
# lvs or lvdisplay

2e. Create new file system on volumes:

mkfs.xfs /dev/mapper/FILES-u01
mkfs.xfs /dev/mapper/FILES-u02
mkfs.xfs /dev/mapper/FILES-u03
mkfs.xfs /dev/mapper/FILES-u04

2f. Create mountpoint:

mkdir /files1
mkdir /files2
mkdir /files3
mkdir /files4

2g. Mount logical volume:

mount /dev/mapper/FILES-u01 /files1
mount /dev/mapper/FILES-u02 /files2
mount /dev/mapper/FILES-u03 /files3
mount /dev/mapper/FILES-u04 /files4
# verify
df -h /files4

2h. Add to fstab for automount

cp /etc/fstab /etc/fstab.bkp
vi /etc/fstab
# add
/dev/mapper/FILES-u01 /files1         xfs             defaults        0 0
/dev/mapper/FILES-u02 /files2         xfs             defaults        0 0
/dev/mapper/FILES-u03 /files3         xfs             defaults        0 0
/dev/mapper/FILES-u04 /files4         xfs             defaults        0 0
  1. reboot

  2. After reboot, run df -h  you should see the filesystem!

Categories: ,