28

I have a CentOS 5 VM and I've just increased the VM disk from 10G to 20G, but I cannot get fdisk to see the new disk size without a reboot.

I've tried echo 1 > /sys/block/sda/device/rescan, it seems to indicate it can see the new size, but when I go to fdisk to create a new partion it still sees the disk as 10G.

Any ideas?

4
  • Depending on your virtualisation platform and storage method, this may or may not be possible. Details matter.
    – womble
    Aug 31, 2011 at 9:47
  • Which virtual disk type you've added: IDE or SCSI?
    – quanta
    Aug 31, 2011 at 9:48
  • That first command worked for me...
    – Rodo
    Mar 1, 2017 at 17:01
  • echo 1 > /sys/class/block/sdX/device/rescan worked for me , notice the /class inclusion.
    – AndyM
    Jul 8, 2021 at 10:01

9 Answers 9

17

You need to issue the rescan command to your SCSI bus.

In VMware the SCSI controller might be found in some unusual place. First find it:

find /sys -iname 'scan'

For me that returned

/sys/devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0/scan
/sys/devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1/scan
/sys/devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2/scan

Then just issue the rescan command

echo "- - -" >/sys/devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0/scan
echo "- - -" >/sys/devices/pci0000:00/0000:00:07.1/host0/scsi_host/host1/scan
echo "- - -" >/sys/devices/pci0000:00/0000:00:10.0/host0/scsi_host/host2/scan

That should help. :)

2
  • 7
    ls /sys/class/scsi_host maybe faster.
    – quanta
    Aug 31, 2011 at 9:52
  • 6
    9 years later... just wanna mention this made my VM go down with "ext4-fs ERROR" notices, had to stop and restart the VM. It all worked out, but still, gonna comment here to warn people this might happen. Aaaand after the reboot, the increased disk size was picked up of course.
    – KdgDev
    Mar 19, 2020 at 11:00
17

I had to deal with a similar problem, on a SLES 11 server. The LVM was built with raw disks, running on VMWare ESXi

# pvcreate /dev/sdd; vgextend ....

After a while I needed to increase LVM size, but I didn't add a supplemental disk and then pvcreate + vgextend as I've done before, but I chose to increase the size of an existing disk (/dev/sdd in this case). After doing the increase in VMWare, I executed a

# rescan-scsi-bus.sh

But pvdisplay was still showing the 'old' disk size. It was necessary to do a

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

for the kernel to learn the new disk size of /dev/sdd

2
  • 9
    echo 1 > /sys/block/sda/device/rescan worked for me on CentOS Apr 30, 2016 at 19:37
  • 1
    -bash: /sys/module/scsi_mod/parameters/scan: Permission denied, username is root
    – Sarz
    Sep 27, 2016 at 11:43
16

after first doing echo 1 > /sys/block/sda/device/rescan

pvresize /dev/sda did the trick for me

5

To detect changes to existing disk:

echo 1 > /sys/class/block/sdX/device/rescan

To detect new disk:

echo 1 > /sys/class/scsi_device/X:X:X:X/device/block/device/rescan

To find X in the first situation you can use fdisk -l.

https://kerneltalks.com/disk-management/how-to-rescan-disk-in-linux-after-extending-vmware-disk/

1
  • ls: cannot access '/sys/class/scsi_device/*/device/block/device/rescan': No such file or directory
    – SebMa
    May 31, 2023 at 16:54
3

If the partition table is directly in use (e.g. you have mounted filesystem using a base partition) the kernel will continue to use the old partition table until this is no longer the case. Someone once told me that if you are using LVM you can get around this....

3

Update: Centos 6 - not possible to update partition table of active disk online, Centos 7 - it is possible to extend last partition with growpart or create new partition with fdisk and make it visible without reboot with partprobe. Probably same on ubuntu/debian. - At some point after 2.6 kernel started supporting online reread of partition table of active disk. Since question is for Centos 5 I would say no way.

If you are using partitions then you have to reboot to use new space. I didn't find a way to avoid this. If someone has let me know.

However, reboot should be done after you extend last partition on the disk or add new partition. Doesn't make sense to reboot before.

First thing you should notice after rescan is bigger disk size in fdisk and in lsblk. If you don't see it you have to play with these echo 1 and echo - - - commands.

After you see more space you can extend/add partition, then reboot, extend vg, extend lv and fs.

If you want to avoid reboot you have to assign raw sda/b/c disk to volume group without partitioning it to sda1/2/3. Then there is no need for reboot.

Partitioning was necessary some time ago when linux could not boot from LVM, but now it can.

If you do lsblk you will see partitions or lvms depending on if you are using partitions or lvm, you can have all parts if you don't use lvm or all lvms if you don't use partitions. Here is one example:

root@srv4 ~ $ lsblk
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                           8:0    0  7.3T  0 disk
├─sda1                        8:1    0  500M  0 part /boot
└─sda2                        8:2    0  7.3T  0 part
  ├─vg_srv4-LogVol13 (dm-0) 253:0    0  7.1T  0 lvm  /
  ├─vg_srv4-LogVol05 (dm-1) 253:1    0  100G  0 lvm  /var/log
  ├─vg_srv4-LogVol04 (dm-2) 253:2    0   20G  0 lvm  /var
  ├─vg_srv4-LogVol01 (dm-5) 253:5    0   20G  0 lvm  /opt
  ├─vg_srv4-LogVol00 (dm-6) 253:6    0   20G  0 lvm  /home
  ├─vg_srv4-LogVol03 (dm-7) 253:7    0   20G  0 lvm  /usr
  └─vg_srv4-LogVol02 (dm-8) 253:8    0    8G  0 lvm  /tmp
1

On CentOS 7, I used rescan-scsi-bus.sh -s for this.

The -s switch specifically instructs rescan-scsi-bus.sh to scan for resized disks.

rescan-scsi-bus.sh -s can be found in the sg3_utils package.

[root@udplinux host0]# rescan-scsi-bus.sh -s
which: no multipath in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
Scanning SCSI subsystem for new devices
Searching for resized LUNs
RESIZED: Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware   Model: Virtual disk     Rev: 2.0
  Type:   Direct-Access                    ANSI SCSI revision: 06
0 new or changed device(s) found.
1 remapped or resized device(s) found.
        [0:0:0:0]
0 device(s) removed.
[root@udplinux host0]# 
0

I know this maybe a little late, but I'm running KVM on the host. To get the disk size change I had to trigger it on the host, not the guest. In my case it was

  • Use lvm to extend the volume space lvextend -L+4G /dev/<volume group>/<volume>
  • Get the disk / block info virsh qemu-monitor-command <vm name from virsh list> --hmp "info block"
  • Tell kvm of the changes virsh qemu-monitor-command <vm name> --hmp "block_resize drive-virtio-disk2 <new size>"

I had previously run commands like echo "- - -" > /sys/class/scsi_host/host1/scan but nothing changed until I ran the the virsh qemu-monitor-command -hmp command

-4

You have to reboot, there's no way around that.

6
  • How about the force system to rescan?
    – quanta
    Aug 31, 2011 at 9:50
  • I did have to reboot :-(
    – AndyM
    Sep 9, 2011 at 12:10
  • I had to reboot too.
    – ondra
    Jun 13, 2016 at 8:12
  • 1
    This is completely untrue. I have done this multiple times without rebooting. Jun 16, 2018 at 17:45
  • With CentOS7.5 running under VMware, I have tried all the suggestions above - all the echos to .../rescan and .../scan, and the new VMware disk size has not been recognized. Obviously, it works for some folks in presumably different circumstances. Nov 2, 2020 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .