How to rescan disk in Linux after extending vmware disk
Published: | Modified: | 15470 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.
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.
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:1073MB,1073741824bytes
255heads,63sectors/track,130cylinders
Units=cylinders of16065*512=8225280bytes
Sector size(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Disk identifier:0x8bd61ee2
Device Boot Start EndBlocks IdSystem
/dev/sdd111301044193+83Linux LVM
# ll /mydrive
total24
drwx------.2root root16384Jun2311:00lost+found
-rw-r--r--.1root root0Jun2311:01shri
drwxr-xr-x.3root root4096Jun2311:01.
dr-xr-xr-x.28root root4096Jun2311: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 :
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:2147MB,2147483648bytes
255heads,63sectors/track,261cylinders
Units=cylinders of16065*512=8225280bytes
Sector size(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Disk identifier:0x8bd61ee2
Device Boot Start EndBlocks IdSystem
/dev/sdd111301044193+83Linux 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(mforhelp):d
Selected partition1
Command(mforhelp):n
Commandaction
eextended
pprimary partition(1-4)
p
Partition number(1-4):1
First cylinder(1-261,default1):
Using defaultvalue1
Last cylinder,+cylindersor+size{K,M,G}(1-261,default261):
Using defaultvalue261
Command(mforhelp):t
Selected partition1
Hex code(typeLtolist codes):8e
Command(mforhelp):p
Disk/dev/xvdf:2147MB,2147483648bytes
255heads,63sectors/track,261cylinders
Units=cylinders of16065*512=8225280bytes
Sector size(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Disk identifier:0x8bd61ee2
Device Boot Start EndBlocks IdSystem
/dev/sdd112612095458+83Linux 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(mforhelp):w
The partition table has been altered!
Calling ioctl()tore-readpartition table.
WARNING:Re-reading the partition table failed with error16:Device orresource busy.
The kernel still uses the old table.The newtable will be used at
the next reboot orafter you run partprobe(8)orkpartx(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 tore-readthe partition table on/dev/sdd(Device orresource busy).Asaresult,it may notreflect all of your changes untilafter 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.
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 Areas1
Metadata Sequence No3
VG Access read/write
VG Status resizable
MAX LV0
Cur LV1
Open LV0
Max PV0
Cur PV1
Act PV1
VG Size2.00GiB
PE Size4.00MiB
Total PE511
Alloc PE/Size250/1000.00MiB
Free PE/Size261/1.02GiB
VG UUID0F8C4o-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
total24
drwx------.2root root16384Jun2311:00lost+found
-rw-r--r--.1root root0Jun2311:01shri
drwxr-xr-x.3root root4096Jun2311:01.
dr-xr-xr-x.28root root4096Jun2311:04..
Комментариев нет:
Отправить комментарий
Примечание. Отправлять комментарии могут только участники этого блога.
Комментариев нет:
Отправить комментарий
Примечание. Отправлять комментарии могут только участники этого блога.