LATEST TOPICS

Vmware : Add a new Virtual Disk without System Reboot

Introduction:

While working on Linix in VMware, you often need to add new disks. However, the standard process requires a system reboot for Linux to identify the newly added disks.

Today, in my post; I would be demonstrating the step by step procedure to add new virtual disk to a VMware Linux machine without rebooting the operating system.

 

Demonstration:

Steps to be performed from VMware:

  1. Add a new virtual disk to VM by selecting (VM –> Settings) as show below

vm_disk_add_1

 

 

  1. Click on ADD to add a new Disk

vm_disk_add_2

 

  1. Select Hard Disk and Click on Next
    vm_disk_add_3

 

  1. Choose “Create a new virtual disk” option from the pop-up menu to add a virtual disk. Click on Next to continue
    vm_disk_add_4

 

  1.  Select the disk type (Note: You can only add a device of type SCSI while the Linux machine is running). Click on Next to continue.

 

vm_disk_add_5

 

  1. Provide the details of the new disk like Size, Space Allocation option and  Split options. Once the details are filled, click on Next to continue.
    vm_disk_add_6

 

  1. Select the name and location of the new virtual disk. Click on Finish to complete the  virtual disk addition to VM.

 

vm_disk_add_7

 

  1. Wait while the new virtual disk gets created (if you have opted for “allocate disk space now“, this step would take a bit longer time depending on the size of the new virtual disk)

 

vm_disk_add_8

 

  1. Review the properties of the new virtual disk and click on Ok to complete the task.

 

vm_disk_add_9

 

Now, we have a new virtual disk attached to the VM Linux machine. Our next task is to discover the disk from Linux and create a file system to access the new disk.

 

Steps to be performed from Linux:

  1. Login to the Linux machine as root.
-bash-3.2# hostname
labserver.home.com
-bash-3.2# who am i
root     pts/1        2014-09-22 14:47 (192.168.230.1)

 

  1. Re-scan the SCSI Bus to Add a SCSI Device Without rebooting the VM using the following command
echo "- - -" > /sys/class/scsi_host/host#/scan

Replace host# with the the value from your Linux machine. You can list the value of host# as follows

-bash-3.2# ls /sys/class/scsi_host
host0  host1  host2

Now for each of the host# run the scan command

-bash-3.2# hostname
labserver.home.com
-bash-3.2# who am i
root     pts/1        2014-09-22 14:47 (192.168.230.1)
-bash-3.2# echo "- - -" > /sys/class/scsi_host/host0/scan
-bash-3.2# echo "- - -" > /sys/class/scsi_host/host1/scan
-bash-3.2# echo "- - -" > /sys/class/scsi_host/host2/scan

 

  1. Query fdisk to check if you can view the new disk.
-bash-3.2# fdisk -l | tail
Disk /dev/sdk doesn't contain a valid partition table
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdj1               1        2610    20964793+  83  Linux

Disk /dev/sdk: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Now, we can format the disk and create partitions to access it through a filesystem

  1. Run fdisk to create a disk partition for the new disk.
-bash-3.2# fdisk /dev/sdk
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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)

Command (m for help): p

Disk /dev/sdk: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):
Using default value 652

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 

  1. Allocate a file system to the created disk partition
-bash-3.2# mkfs.ext3 /dev/sdk1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 1309289 blocks
65464 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

  1. Create a directory to mount the file system,
-bash-3.2# mkdir /workspace

 

  1. Add an entry in /etc/fstab for the new disk partition
-bash-3.2# echo "/dev/sdk1 /workspace ext3 defaults 1 2" >> /etc/fstab

 

  1. Mount the new disk partition
-bash-3.2# mount /dev/sdk1
  1. Crosscheck, if the new disk partition is mounted or not.
-bash-3.2# df -h /workspace
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdk1             5.0G  139M  4.6G   3% /workspace

 

All done!! We have added a new disk without rebooting the Linux machine !!

 

%d bloggers like this:
Visit Us On LinkedinVisit Us On TwitterVisit Us On Google PlusCheck Our Feed