Added New VMware Disk and Mount to new Directory on CentOS 6

Scenario:
Added new 10GB VMware Hard Disk,create new Volume Group(Vgs),Create new LVM,format to ext4 and mount to /data

Steps in VMware vSphere:
– Right click on VM -> Select Edit Settings… -> Click Add... -> on Device Type select Hard Disk -> Click Next
– Select Create a new virtual disk -> Click Next
– Specify disk size (this scenario is 10GB), select default Thick Provision Lazy Zeroed then specify the disk location (default is Store with virtual machine) -> Click Next
– Specify Virtual Device Node (default for 2nd Hard disk will be SCSI (0:1), on Mode box leave blank -> Click Next
– Click Finish.

Steps in Centos/RHEL 6,login as root:
1) Check the new disk new disk whether detect or not.
# fdisk -l

[root@kucing ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000e0fcc

 Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 3917 30944256 8e Linux LVM

Disk /dev/mapper/vg_kucing-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 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: 0x00000000


Disk /dev/mapper/vg_kucing-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 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: 0x00000000

[root@kucing ~]#

2) If the new Hard Disk not detected run below command:

ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done

3) Run fdisk -l again,seen new hard disk sdb.

[root@kucing ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000e0fcc

 Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 3917 30944256 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00000000


Disk /dev/mapper/vg_kucing-lv_root: 28.5 GB, 28462546944 bytes
255 heads, 63 sectors/track, 3460 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: 0x00000000


Disk /dev/mapper/vg_kucing-lv_swap: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 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: 0x00000000

[root@kucing ~]#

4) Create new Volume Group for sdb.
# vgcreate vg_data /dev/sdb

[root@kucing ~]# vgcreate vg_data /dev/sdb
 Physical volume "/dev/sdb" successfully created
 Volume group "vg_data" successfully created
[root@kucing ~]#

5) Create directory /data for our mount point as scenario above.
# cd /
# mkdir /data

6) Create Logical Volume lv_data in Volume Group data_vg using all free size:
# lvcreate -l 100%FREE -n lv_data vg_data

[root@kucing ~]# lvcreate -l 100%FREE -n lv_data vg_data
 Logical volume "lv_data" created.
[root@kucing ~]# lvdisplay
 --- Logical volume ---
 LV Path /dev/vg_data/lv_data
 LV Name lv_data
 VG Name vg_data
 LV UUID 4b6Djb-LEFh-232Z-QxUQ-mX8Q-hHiE-P3cY73
 LV Write Access read/write
 LV Creation host, time kucing, 2017-08-11 09:34:35 +0700
 LV Status available
 # open 0
 LV Size 10.00 GiB
 Current LE 2559
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:2

 --- Logical volume ---
 LV Path /dev/vg_kucing/lv_root
 LV Name lv_root
 VG Name vg_kucing
 LV UUID 3ZYnh9-evf1-MqFG-ym0W-mM9A-M8OR-SnBGnd
 LV Write Access read/write
 LV Creation host, time kucing, 2017-07-25 03:23:45 +0700
 LV Status available
 # open 1
 LV Size 26.51 GiB
 Current LE 6786
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:0

 --- Logical volume ---
 LV Path /dev/vg_kucing/lv_swap
 LV Name lv_swap
 VG Name vg_kucing
 LV UUID DhYTfY-Fezv-t31P-jRJS-LFRN-NO54-ASwKqJ
 LV Write Access read/write
 LV Creation host, time kucing, 2017-07-25 03:23:52 +0700
 LV Status available
 # open 1
 LV Size 3.00 GiB
 Current LE 768
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:1

[root@kucing ~]#

7) Format New Logical Volume lv_data to ext4
# mkfs.ext4 /dev/vg_data/lv_data

[root@kucing ~]# mkfs.ext4 /dev/vg_data/lv_data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620416 blocks
131020 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

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.
[root@kucing ~]#

8) Mount lv_data to /data
# mount /dev/vg_data/lv_data /data

9) Last step,edit /etc/fstab so our new HDD will automatcally mounted to /data if system rebooted.
First check the path of lv_data.
# lvdisplay | grep lv_data

[root@kucing data]# lvdisplay | grep lv_data
 LV Path /dev/vg_data/lv_data
 LV Name lv_data
[root@kucing data]#

Edit /etc/fstab
# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 25 03:25:14 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_kucing-lv_root / ext4 defaults 1 1
UUID=532877de-f00c-4183-8bc0-6dbb6b31e952 /boot ext4 defaults 1 2
/dev/mapper/vg_kucing-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
/dev/vg_data/lv_data /data ext4 defaults 0 0

Reference:
http://wingloon.com/2013/05/07/how-to-detect-a-new-hard-disk-without-rebooting-vmware-linux-guest/


Leave a Reply

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