• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux & scripts.

  • How-to guides
    • Howto
    • Disk management
    • Configurations
  • OS
    • HPUX
    • Linux
  • Commands & tools
    • Commands
    • Software & Tools
    • System services
  • Cloud computing
    • AWS CSA associate quiz
    • AWS CSA preparation guide!
    • Cloud Services
  • Tips & Tricks
  • Linux commands
You are here: Home / Disk management

How to rescan disk in Linux after extending vmware disk

Published: June 23, 2017 | Modified: February 12, 2019 | 24642 views




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.

Rescan disk when vdisk in extended
Re-scan vdisk in Linux

Sometimes we get a disk utilization situations and needs to increase disk space. In 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 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 size of disk to 2GB at vmware level and then will add up this space in mount point /mydrive.

If you re using 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 single primary partition on it /dev/sdd1 which in turns forms vg01 as stated earlier. Always make sure you have data backup in place of the disk you are working on.

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x8bd61ee2
 
    Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         130     1044193+  83  Linux LVM
 
# ll /mydrive
total 24
drwx------. 2 root root 16384 Jun 23 11:00 lost+found
-rw-r--r--. 1 root root 0 Jun 23 11:01 shri
drwxr-xr-x. 3 root root 4096 Jun 23 11:01 .
dr-xr-xr-x. 28 root root 4096 Jun 23 11:04 ..
 


Step 2:

Now, change disk size at vmware level. We are increasing it by 1 more GB so 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 :

Shell
1
2
3
4
5
6
7
 
echo 1>/sys/class/block/sdd/device/rescan
 
OR
 
echo 1>/sys/class/scsi_device/X:X:X:X/device/block/device/rescan
 

Make sure you use correct disk name in command (before rescan). You can match your SCSI number (X:X:X:X) with vmare 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 helps to scan when new devices are attached to system. It will not help us to re-scan already identified devices.

Thats why we have to send “1” to /sys/class/block/XYZ/device/rescan to respective SCSI block device to refresh device information like size. So this will be helpful here since our device is already identified by kernel but we want 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.

Shell
1
2
3
4
5
6
7
8
9
10
11
 
Disk /dev/sdd: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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: 0x8bd61ee2
 
    Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         130     1044193+  83  Linux LVM
 


Step 3:

At this stage our kernel know new size of disk but out partition (/dev/sdd1) is still of old 1GB size. This left us no choice but 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 are marked as Linux LVM using hex code  8e or else your will mess up whole configuration.

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

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
# fdisk /dev/sdd
 
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-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261):
Using default value 261
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
 
Command (m for help): p
 
Disk /dev/xvdf: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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: 0x8bd61ee2
 
    Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         261     2095458+  83  Linux LVM
 

All fdisk prompt commands are highlighted in above output. Now you can see 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.

Shell
1
2
3
4
5
6
7
8
9
10
11
 
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.
 

You may see 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 ).

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


Step 4:

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

Shell
1
2
3
4
5
 
# pvresize /dev/sdd1
  Physical volume "/dev/sdd1" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
 

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

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
# vgdisplay vg01
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.00 GiB
  PE Size               4.00 MiB
  Total PE              511
  Alloc PE / Size       250 / 1000.00 MiB
  Free  PE / Size       261 / 1.02 GiB
  VG UUID               0F8C4o-Jvd4-g2p9-E515-NSps-XsWQ-K2ehoq
 

You can see our VG now have 2GB space i.e. what we have resized our disk to! 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 sittign on logical volumes.

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

Shell
1
2
3
4
5
6
7
8
 
# ll /mydrive
total 24
drwx------.  2 root root 16384 Jun 23 11:00 lost+found
-rw-r--r--.  1 root root     0 Jun 23 11:01 shri
drwxr-xr-x.  3 root root  4096 Jun 23 11:01 .
dr-xr-xr-x. 28 root root  4096 Jun 23 11:04 ..
 


⇠ Previous article
11 log files you should see on your Linux system
Next article ⇢
Enable debugging to log NFS logs in Linux

Related stuff:

  • Adding new storage LUN to integrity virtual machine (iVM) in HPUX
  • LVM commands tutorial : Part 2 : Volume group (vgextend, vgreduce, vgexport, vgimport)
  • How to mount ISO file in Linux?
  • LVM commands tutorial : Part 1 : Physical Volume (pvcreate, pvdisplay)
  • LVM commands tutorial : Part 3 : Logical Volume (lvcreate, lvdisplay, lvremove)
  • NFS configuration in Linux and HPUX
  • How to rename logical volume in Linux and HPUX
  • How to rename volume group
  • Host to guest disk mapping in HP iVM
  • LVM commands tutorial : Part 2 : Volume group (vgcfgbackup, vgcfgrestore, vgchange)
  • LVM commands tutorial : Part 2 : Volume group (vgcreate, vgdisplay, vgscan)
  • How-to guide : LVM snapshot

Filed Under: Disk management Tagged With: rescan disk in linux for new size, resize lvm partitions in vmware linux, resize mount point after extending vdisk, resize pv in linux after disk resizing

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Follow our Google+ page.
  • Add our RSS feed to your feed reader.

Comments

  1. Linek says

    January 16, 2019 at 3:41 pm

    Thank you ! I finally managed to rescan the disk after extend a raid5 logicaldrive.

    Reply
    • Shrikant Lavhate says

      January 21, 2019 at 10:09 pm

      Awesome!

      Reply
  2. Emmanuel says

    February 1, 2019 at 7:18 pm

    if you want to the whoke disk for lvm, there is no sense to create a partition and after the physical volume on the partition.

    Reply
    • Shrikant Lavhate says

      February 12, 2019 at 12:29 pm

      Completely agree Emmanuel. I wanted to make a point here that disk partitioned with fdisk and later used in LVM can also be extended without any data loss.. Since deleting & re-creating partition is only way to extend partition, beginners thinks extension will lead to data loss.

      Reply
      • Shrikant Lavhate says

        February 12, 2019 at 12:37 pm

        Ok, to avoid confusion I added quote to ignore step 1 & 3 for whole disk LVM approach.

        Reply

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • Google+
  • RSS
  • Twitter

Popular posts

  • mount.nfs: requested NFS version or transport protocol is not supported
  • How to reset iptables to default settings
  • How to rescan disk in Linux after extending vmware disk
  • 4 ways to check size of physical memory (RAM) in Linux
  • How to setup domain name in Linux server
  • 5 steps guide for SMTP configuration in Linux
  • How to remount filesystem in read write mode under Linux
  • How to enable repository using subscription-manager in RHEL
  • Difference between /etc/passwd and /etc/shadow
  • How to configure login banners in Linux (RedHat, Ubuntu, CentOS, Fedora)

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2017 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.

  • How to enter single user mode in SUSE 12 Linux?
  • How to disable iptables firewall temporarily
  • How to rename volume group
  • How to install sar in SUSE Linux
  • How to check and test APA in HPUX
  • How to check bad wrong login attempts in HPUX
  • xsos : a tool to read sosreport in RHEL/CentOS
  • 4 steps guide for SMTP configuration in HPUX
  • AutoFS configuration in Linux
  • AWS CloudFront, SNS, SQS revision before CSA exam