VMware Cloud Community
hyvecom
Contributor
Contributor

VCenter/VSphere CentOS 6.X or Redhat 6.X disk resize without downtime

Hi,

In VCenter, we can easily "edit settings", select the virtual hard disk give it more space. We shutdown and boot the server with a live disk and tell the OS to use this extra space by running a series of commands. For those who dont know how to do this, you can see this via this Kb Article here: Resize Linux Disk

However this involves some downtime. MS Windows 2008 Server allows this to be completed without a reboot in no time at all which puts Linux to shame.

So my question is:

Does anyone know if you can resize disks on CentOS 6.X or Redhat 6.X without rebooting

Thanks in advance!

www.hyve.com
0 Kudos
6 Replies
csteenerson
Contributor
Contributor

to rescan the partition table of /dev/sdb:

# echo 1 > /sys/block/sdb/device/rescan

0 Kudos
hyvecom
Contributor
Contributor

Hi,

Thanks for your response, can you kindly elaborate on this, just to let you know the device is /dev/sda

When I run your command on a test server the disk isnt resized.

# echo 1 > /sys/block/sda/device/rescan

When I run the command as so, just get permission denied.

# /sys/block/sda/device/rescan

www.hyve.com
0 Kudos
csteenerson
Contributor
Contributor

/sys/block/sda/device/rescan is a special file that is root write only. If you overwrite the contents with a 1, and it rescans the partition table for the device.

# echo 1 > /sys/block/sda/device/rescan

I just tested increasing the /dev/sda size on a Centos 6 VM and it works fine for me. Are you running the command as root, either by switching to root user or using sudo?

0 Kudos
hyvecom
Contributor
Contributor

Hi

I am logged in as root.

When I run:

#echo 1 > /sys/block/sda/device/rescan

Nothing happens and df - h just reports the same size. Is that all you need to do to resize it?

Are you resizing the disk which your OS is mounted on? See the output of df -h below

From looking at some other blogs it seems that I need to use partprobe to reload the partiton table after running fdisk and recreating /dev/sda but that just gives an error:

# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.

#df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                      195G  2.7G  182G   2% /

tmpfs                 499M     0  499M   0% /dev/shm

/dev/sda1             485M   72M  389M  16% /boot

#blockdev --rereadpt /dev/sda
BLKRRPART: Device or resource busy
#umount /dev/mapper/VolGroup-lv_root
umount: /: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
#umount /dev/VolGroup/lv_root
umount: /: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
#lsof shows nothing
Tried
#fuser -m /dev/sda
Still cant resize the partition table.
Any ideas?
www.hyve.com
0 Kudos
hyvecom
Contributor
Contributor

Output of fdisk:

Command (m for help): p
Disk /dev/sda: 216.9 GB, 216895848448 bytes
255 heads, 63 sectors/track, 26369 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: 0x0003ae21
   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       26369   211295968+  8e  Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

www.hyve.com
0 Kudos
csteenerson
Contributor
Contributor

Reloading the partition table should make the new space available to fdisk, but the existing partitions are all going to still be the same size. The easiest way to use the space is to create a new partition, then format and mount it where you need the space.

You can also add the volume to your existing LVM and use it to grow a LVM volume, then in turn grow your filesystem without unmounting anything, but this process is pretty lengthy and I haven't done it enough times to explain very well.

0 Kudos