Linux rescan disk size

How to rescan disk in Linux after extending VMware disk

Published: June 23, 2017 | Modified: June 24, 2020

Learn to rescan disk in Linux VM when its backed vdisk in VMware is extended. This method does not require downtime and no data loss.

Sometimes we get a disk utilization situations and needs to increase disk space. In the VMware environment, this can be done on the fly at VMware level. VM assigned disk can be increased in size without any downtime. But, you need to take care of increasing space at OS level within VM. In such a scenario we often think, how to increase disk size in Linux when VMware disk size is increased? or how to increase mount point size when vdisk size is increased? or steps for expanding LVM partitions in VMware Linux guest? or how to rescan disk when vdisk expanded? We are going to see steps to achieve this without any downtime.

In our example here, we have one disk /dev/sdd assigned to VM of 1GB. It is part of volume group vg01 and mount point /mydrive is carved out of it. Now, we will increase the size of the disk to 2GB at VMware level and then will add up this space in the mount point /mydrive .

If you re using the whole disk in LVM without any fdisk partitioning, then skip step 1 and step 3.

Step 1:

See below fdisk -l output snippet showing disk /dev/sdd of 1GB size. We have created a single primary partition on it /dev/sdd1 which in turn forms vg01 as stated earlier. Always make sure you have data backup in place of the disk you are working on.

Step 2:

Now, change disk size at VMware level. We are increasing it by 1 more GB so the final size is 2GB now. At this stage disk need to be re-scanned in Linux so that kernel identifies this size change. Re-scan disk using below command :

Make sure you use the correct disk name in command (before rescan). You can match your SCSI number (X:X:X:X) with VMware disk using this method.

Note : Sending “– – -” to /sys/class/scsi_host/hostX/scan is scanning SCSI host adapters for new disks on every channel (first -), every target (second -), and every device i.e. disk/lun (third -) i.e. CTD format. This will only help to scan when new devices are attached to the system. It will not help us to re-scan already identified devices.

That’s why we have to send “1” to /sys/class/block/XYZ/device/rescan to respective SCSI block device to refresh device information like the size. So this will be helpful here since our device is already identified by the kernel but we want the kernel to re-read its new size and update itself accordingly.

Now, kernel re-scan disk and fetch its new size. You can see new size is being shown in your fdisk -l output.

Step 3:

At this stage, our kernel know the new size of the disk but our partition ( /dev/sdd1 ) is still of old 1GB size. This left us no choice but to delete this partition and re-create it again with full size. Make a note here your data is safe and make sure your (old & new) partition is marked as Linux LVM using hex code 8e or else your will mess up the whole configuration.

Delete and re-create partition using fdisk console as below:

All fdisk prompt commands are highlighted in the above output. Now you can see the new partition /dev/sdd1 is of 2GB size. But this partition table is not yet written to disk. Use w command at fdisk prompt to write table.

You may see the warning and error like above. If yes, you can use partprobe -s and you should be good. If you still below error with partprobe then you need to reboot your system (which is sad ).

Читайте также:  Виртуал бокс установка windows server 2012

Step 4:

Now rest of the part should be tackled by LVM. You need to resize PV so that LVM identifies this new space. This can be done with pvresize command.

As new PV size is learned by LVM you should see free/extra space available in VG.

You can see our VG now have 2GB space! Now you can use this space to create new lvol in this VG or extend existing lvol using LVM commands. Further you can extend filesystem online which is sitting on logical volumes.

You can observe all lvol in this VG will be unaffected by this activity and data is still there as it was previously.

Источник

Rescanning the Disk for a Block Volume or Boot Volume

The Oracle Cloud Infrastructure Block Volume service lets you expand the size of block volumes and boot volumes while they are online and attached to instances, for more information, see Online Resizing of Block Volumes Using the Console. After the volume is provisioned, you need to run commands to rescan the disk, so that the operating system identifies the expanded volume size. You will need to run different rescan commands depending on the operating system of the attached instance. This topic describes some procedures you can use to rescan the disk.

Required IAM Policy

Rescanning the disk does not require a specific IAM policy. However, you may need permission to run the necessary commands on the instance’s guest OS. Contact your system administrator for more information.

Rescanning the Disk for Volumes Attached to Linux-Based Instances

For volumes attached to Linux-based instances, run the following commands rescan the disk for a block volume:

These commands are also displayed in the dialog that opens after you click Save Changes in the Edit Size or Performance dialog, and you can copy them from that dialog.

Next Steps

After you’ve rescanned the disk, you need to extend the partition. See Extending the Partition for a Block Volume on a Linux-Based Image for block volumes. For boot volumes, use the oci-growfs operation from OCI Utilities.

Rescanning the Disk for Volumes Attached to Windows Instances

Using Disk Management or diskpart

For volumes formatted as FAT32 or NTFS, you can rescan the disk using the Windows interface, in Disk Management, or you can use the diskpart utility’s rescan command from the command line.

Open a command prompt as administrator on the instance.

Run the following command to start the diskpart utility:

At the DISKPART prompt, run the following command:

Open the Disk Management system utility on the instance.

Click Action, and then click Rescan Disks.

Using Cygwin

For volumes formatted with a non-native Windows file system, such as volumes formatted using Oracle Automatic Storage Management (Oracle ASM), you can’t use the Windows interface or the diskpart utitily. Instead, you can use the dd process from a Cygwin terminal to rescan the disk. You can also use this for native Windows file systems. For more information, see Cygwin.

Next Steps

After you’ve rescanned the disk, you need to extend the partition. See Extending the Partition for a Block Volume on a Windows-Based Image for block volumes, see Extending the System Partition on a Windows-Based Image for boot volumes.

Источник

How do I get Centos VM to re-read its increased Disk size WITHOUT a reboot

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.

8 Answers 8

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:

For me that returned

Then just issue the rescan command

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

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

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

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

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

pvresize /dev/sda did the trick for me

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.

Читайте также:  Ошибка при установке windows 10 с флешки 0x0000098

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:

Источник

Rescan SCSI bus on Linux System

SCSI stands for Small Computer System Interface and is a set of standards for transferring data and connecting devices and computers. Sometimes you make changes to disk devices on your Linux box while online which is even more often nowadays using virtual machines. Sometimes you also add a new disk and do not want to restart your Linux system. Wether you need to add a new disk or increase an existing disk size of your virtual machine, the changes will not be instantly visible from the Linux operating system because you need to rescan SCSI bus on Linux to see the change. It is quite easy to rescan SCSI bus on Linux, you can do it with a simple one line command (depending on the number of SCSI devices you have connected).

Rescan SCSI bus on Linux

Follow the steps described below and you will see the new size of your disk.

Rescan SCSI bus on Linux

Please note that the rescan SCSI bus on Linux does not interrupt operating system operation nor remove any of the disks. Rescanning SCSI bus on Linux with the below procedure will add/freshen devices but not remove them.

When Adding a New Disk

When adding a new disk to your Linux system you need to rescan SCSI host.

You can do this with the following command:

..where X is the number of SCSI host to scan.

You probably have more than one SCSI host available so to make it right you should repeat the above command for each SCSI host available.

Below is a practical example on how to rescan SCSI bus on Linux and and see the newly added disk:

The “- – -” part is where you tell the SCSI host what exactly to rescan and the hyphens are wildcards which tell SCSI host to rescan all controllers, channels and LUNs.

When Increasing Existing Disk Size

If you changed the size of an existing disk you might notice that the operating system can not see the new disk size until you rescan SCSI bus on Linux operating system.

The easiest way i’ve found is to rescan the specific device with the following command:

..where X is the device you increased and want to rescan.

Below is a practical example on how to rescan SCSI bus on Linux and and see the newly added disk:

The “1” is a flag which causes the SCSI host to rescan the “sdb” block device and therefore refresh the data about the disk size. Please note that i choose this command due to the human readable “sdb” naming which is really easy to remember.

Otherwise the command could also be triggered as follows:

..but in the last case you should know which device you want to rescan by the SCSI bus ID.

Источник

extending linux disk vmware hyper-v centos/redhat on the fly live

1) Checking if you can extend the current disk or need to add a new one

This is rather important step, because a disk that has been partitioned in 4 primary partitions already can not be extended any more. To check this, log into your server and run fdisk -l at the command line.

If it looks like that, with only 2 partitions, you can safely extend the current hard disk in the Virtual Machine.

Читайте также:  Alt linux не обновляется

However, if it looks like this:

It will show you that there are already 4 primary partitions on the system, and you need to add a new Virtual Disk to your Virtual Machine. You can still use that extra Virtual Disk to increase your LVM size, so don’t worry.

2) The “hardware” part, “physically” adding diskspace to your VM

Do that in your VMWare / esx / hyper-v console.
If the option is greyed out to expand ? Add a new disk or shutdown the vm and extend the disk as such.

3) Partitioning the unallocated space: if you’ve increased the disk size

Once you’ve changed the disk’s size in VMware, boot up your VM again if you had to shut it down to increase the disk size in vSphere. If you’ve rebooted the server, you won’t have to rescan your SCSI devices as that happens on boot. If you did not reboot your server, rescan your SCSI devices as such.

First, check the name(s) of your scsi devices.

Then rescan the scsi bus. Below you can replace the ‘0\:0\:0\:0’ with the actual scsi bus name found with the previous command. Each colon is prefixed with a slash, which is what makes it look weird.

That will rescan the current scsi bus and the disk size that has changed will show up.

3) Partitioning the unalloced space: if you’ve added a new disk

If you’ve added a new disk on the server, the actions are similar to those described above. But instead of rescanning an already existing scsi bus like show earlier, you have to rescan the host to detect the new scsi bus as you’ve added a new disk.

Your host device is called ‘host0’, rescan it as such:

It won’t show any output, but running ‘fdisk -l’ will show the new disk.

Create the new partition

Once the rescan is done (should only take a few seconds), you can check if the extra space can be seen on the disk.

So the server can now see the 10GB hard disk. Let’s create a partition, by start fdisk for the /dev/sda device.

Now enter ‘n’, to create a new partition.

Now choose “p” to create a new primary partition. Please note, your system can only have 4 primary partitions on this disk! If you’ve already reached this limit, create an extended partition.

Choose your partition number. Since I already had /dev/sda1 and /dev/sda2, the logical number would be 3.

Note; the cylinder values will vary on your system. It should be safe to just hint enter, as fdisk will give you a default value for the first and last cylinder (and for this, it will use the newly added diskspace).

Now type t to change the partition type. When prompted, enter the number of the partition you’ve just created in the previous steps. When you’re asked to enter the “Hex code”, enter 8e, and confirm by hitting enter.

Once you get back to the main command within fdisk, type w to write your partitions to the disk. You’ll get a message about the kernel still using the old partition table, and to reboot to use the new table. The reboot is not needed as you can also rescan for those partitions using partprobe. Run the following to scan for the newly created partition.

If that does not work for you, you can try to use “partx” to rescan the device and add the new partitions. In the command below, change /dev/sda to the disk on which you’ve just added a new partition.

If that still does not show you the newly created partition for you to use, you have to reboot the server. Afterwards, you can see the newly created partition with fdisk.

3) Extend your Logical Volume with the new partition

Now, create the physical volume as a basis for your LVM. Please replace /dev/sda3 with the newly created partition.

Now find out how your Volume Group is called.

Let’s extend that Volume Group by adding the newly created physical volume to it.

With pvscan, we can see our newly added physical volume, and the usable space (7GB in this case).

Now we can extend Logical Volume (as opposed to the Physical Volume we added to the group earlier). The command is “lvextend /dev/VolGroupxx /dev/sdXX“.

If you’re running this on Ubuntu, use the following.

All that remains now, it to resize the file system to the volume group, so we can use the space. Replace the path to the correct /dev device if you’re on ubuntu/debian like systems.

If you got an error like this, it may mean your filesystem is XFS instead of standard ext2/ext3.

In that case, you’ll need to increase the XFS partition. Read here for more details: Increase/Expand an XFS Filesystem in RHEL 7 / CentOS 7 .

Источник

Оцените статью