Rescan block devices linux

Linux: Rescan for new and changes of devices

Additionally , resize the filesystem to the maximum size. 2 steps necessary. Increase the partition and then the filesystem. Be sure your backup is up to date!
Delete (YES DELETE, you just edit the partition table. That is no problem if you do not call mkfs.ext4)the current partition and create a new with the maximum size. Get the old partition info by fdisk especially the start block of the partition.

root@debdev # fdisk -l Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x1649ccd6 Device Boot Start End Blocks Id System /dev/sdb1 1 13054 104856223+ 83 Linux

Delete Partition 1 (command d) and create a new primary partition (command n) at the same start block(cylinder). In this example Block 1

root@debdev # umount /deb/sdb1 root@debdev # fdisk /dev/sdb Command (m for help): d Selected partition 1 Command (m for help): n Partition number (1-4): 1 First cylinder (1-26108, default 1): 1 Last cylinder: Command (m for help): p Disk /dev/sdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x1649ccd6 Device Boot Start End Blocks Id System /dev/sdb1 1 26108 209712478+ 83 Linux Command (m for help): w The partition table has been altered! root@debdev # partx /dev/sdb

Or use growpart. This command grows partition 1 (if it is the last partition on the disk) to the maximum size

root@debdev # growpart /dev/sda 1

Check volume integrity and resize the filesystem.

root@debdev # e2fsck -f /dev/sdb1 root@debdev # resize2fs -p /dev/sdb1

Источник

Linux Rescan SCSI Bus

If you have added one to many disks to a Linux server or added partitions to an existing disk and the operating system has not yet recognized them, you might need to rescan the SCSI bus. You could simply reboot the Linux server, but that’s usually not an option for production systems.

Below are three different methods for rescanning SCSI devices that I have tested on RHEL 5 and RHEL 6.

Rescan Specific SCSI Device

This command consistently rescanned the specific SCSI device.

Replace $DEVICE with sda, sdb, sdc, etc.

echo 1 > /sys/block/$DEVICE/device/rescan 

Rescan Entire Host SCSI Bus

This command never consistently rescanned the host SCSI bus.

Replace $HOST with the SCSI host you want to scan which could be host0, host1, host2, etc. Typically $HOST is host0.

echo "- - -" > /sys/class/scsi_host/$HOST/scan 

The triple dashes, — — —, are wildcards that rescan every channel, every target, and every LUN on the specified SCSI host.

Читайте также:  Linux tutorials for beginners

Rescan Specific SCSI Device (Deprecated)

This command never consistently rescanned the specific SCSI bus, and it has been deprecated by Red Hat.

Host:Bus:Target:LUN (0:0:2:0 in this example) might be different for your system. Run ls -al /dev/disk/by-path to find it.

echo "scsi remove-single-device 0:0:2:0" > /proc/scsi/scsi echo "scsi add-single-device 0:0:2:0" > /proc/scsi/scsi 

References

If you found this post useful and would like to help support this site — and get something for yourself — sign up for any of the services listed below through the provided affiliate links. I will receive a referral payment from any of the services you sign-up for.

Get faster shipping and more with Amazon Prime: About to order something from Amazon but want to get more value out of the money you would normally pay for shipping? Sign-up for a free 30-day trial of Amazon Prime to get free two-day shipping, access to thousands of movies and TV shows, and more.

Thanks for reading and take care.

Источник

How to rescan disk in Linux after extending VMware disk

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.

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 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 :

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 the correct disk name in command (before rescan). You can match your SCSI number (X:X:X:X) with VMware disk using this method.

Читайте также:  Установка cryptopro jcp linux

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.

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 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:

# 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 (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 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.

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 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 ).

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 tackled by LVM. You need to resize PV so that LVM identifies this new space. This can be done with pvresize command.

# 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.

# 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! 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.

Читайте также:  Сборки tiny core linux

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

# 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 ..
  • LVM commands tutorial : Part 1 : Physical Volume (pvchange, pvmove)
  • Upgrade EXT filesystem in Linux (RHEL, CentOS, Ubuntu)
  • How to mount ISO file in Linux?
  • How-to guide: LVM snapshot
  • LVM commands tutorial : Part 1 : Physical Volume (pvcreate, pvdisplay)
  • Basics of LVM legends
  • HPUX: Add persistent device names in VG
  • Ultimate guide: swap addition in Linux (LVM, parted)
  • LVM commands tutorial: Part 3: Logical Volume (lvsync, lvlnboot)
  • How to rename logical volume in Linux and HPUX
  • How to scan new lun / disk in Linux & HPUX
  • LVM cheatsheet

Источник

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