In this how to, the following steps are tested on CentOS 5.11 running on VMware ESXi 5.5 host. We will extend an existing 5GB disk partition (not LVM) without rebooting. Below image shown is the target hard disk to extend the partition: –
Always take a backup of virtual machine VMDK before proceed. Take note of the Virtual Device Node “SCSI (2:0) Hard disk 4” highlighted in Red on above image. We are going to extend the 5GB partition of Hard disk 4 to 10GB like image below: –
Run the command below to list out all SCSI disk drive: –
# cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: VMware Model: Virtual disk Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 00 Lun: 00 Vendor: VMware Model: Virtual disk Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 01 Lun: 00 Vendor: VMware Model: Virtual disk Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: VMware Model: Virtual disk Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02
The target SCSI disk drive is “Host: scsi2 Channel: 00 Id: 01 Lun: 00” and it is /dev/sdd here below: –
# fdisk -l /dev/sdd Disk /dev/sdd: 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 /dev/sdd1 1 652 5237158+ 83 Linux
Run command below to rescan the Hard disk 4: –
# echo 1 > /sys/class/scsi_disk/2:0:0:0/device/rescan
Run command below to print partition table: –
# fdisk -l /dev/sdd Disk /dev/sdd: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 652 5237158+ 83 Linux
You will notice the disk size is extended to 10.7 GB from 5368 MB. Run command below to display /dev/sdd1 disk usage report: –
# df -h|grep sdd /dev/sdd1 5.0G 139M 4.6G 3% /media
Run command below to unmount the partition: –
# umount /media
Run command below to check and repair targeted file system: –
# fsck -n /dev/sdd1 fsck 1.39 (29-May-2006) e2fsck 1.39 (29-May-2006) /dev/sdd1: clean, 11/655360 files, 55936/1309289 blocks
Now run command below to remove existing partition and create the new 10.7 GB partition: –
# fdisk /dev/sdd The number of cylinders for this disk is set to 1305. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): d Selected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): Using default value 1305 Command (m for help): p Disk /dev/sdd: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 1305 10482381 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Run command below to check the extended file system: –
# e2fsck -f /dev/sdd1 e2fsck 1.39 (29-May-2006) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdd1: 11/655360 files (9.1% non-contiguous), 55936/1309289 blocks
Now run command below to resize file system: –
# resize2fs /dev/sdd1 resize2fs 1.39 (29-May-2006) Resizing the filesystem on /dev/sdd1 to 2620595 (4k) blocks. The filesystem on /dev/sdd1 is now 2620595 blocks long.
Next, run command below to check and repair targeted file system: –
# fsck -n /dev/sdd1 fsck 1.39 (29-May-2006) e2fsck 1.39 (29-May-2006) /dev/sdd1: clean, 11/1310720 files, 76817/2620595 blocks
Run command below to mount the partition: –
# mount /dev/sdd1 /media
Run command below to display /dev/sdd1 disk usage report: –
# df -h|grep sdd /dev/sdd1 9.9G 140M 9.3G 2% /media
Finally, you will noticed usable disk size is extended to 9.9GB.