{"id":5013,"date":"2017-10-17T23:11:36","date_gmt":"2017-10-17T21:11:36","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=5013"},"modified":"2025-08-11T07:25:19","modified_gmt":"2025-08-11T05:25:19","slug":"linux-rescan-for-new-and-changes-of-devices","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/linux-rescan-for-new-and-changes-of-devices\/","title":{"rendered":"Linux: Rescan for new and changes of devices"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_5013 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_5013')){$('.twoclick_social_bookmarks_post_5013').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Linux%3A%20Rescan%20for%20new%20and%20changes%20of%20devices\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Awith%20virtualization%20it%20simply%20possible%20to%20change%20systems%20within%20a%20few%20mouse%20clicks.%20For%20example%20adding%20new%20disks%20or%20increasing%20the%20disk%20size%20of%20a%20hard%20disk%20without%20a%20reboot.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/linux-rescan-for-new-and-changes-of-devices\\\/\",\"post_id\":5013,\"post_title_referrer_track\":\"Linux%3A+Rescan+for+new+and+changes+of+devices\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>with virtualization it simply possible to change systems within a few mouse clicks. For example adding new disks or increasing the disk size of a hard disk without a reboot.<br \/>\n<!--more--><\/p>\n<p>When you do such changes you have to tell linux that something has been changed.<br \/>\nTo scan for new disks, determine the host bus adapter to which the disk is connected<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # ls -l \/sys\/class\/scsi_host\/host*\/proc_name\r\n-r--r--r-- 1 root root 4096 Oct 17 23:05 \/sys\/class\/scsi_host\/host0\/proc_name\r\n-r--r--r-- 1 root root 4096 Oct 17 22:48 \/sys\/class\/scsi_host\/host1\/proc_name\r\n-r--r--r-- 1 root root 4096 Oct 17 23:05 \/sys\/class\/scsi_host\/host2\/proc_name\r\nroot@debdev # cat \/sys\/class\/scsi_host\/host*\/proc_name\r\nata_piix\r\nata_piix\r\nvmw_pvscsi\r\n<\/pre>\n<p>And rescan the bus i.e. vmw_pvscsi <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # echo &quot;- - -&quot; &gt; \/sys\/class\/scsi_host\/host2\/scan\r\n<\/pre>\n<p>Let us assume you have changed the disk size of the harddisk \/dev\/sdb and \/dev\/sdb1 is the only partition at this disk.<br \/>\nDetermine the sysfs path<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # ls -l \/sys\/class\/scsi_device\/*\/device\/block\r\n\/sys\/class\/scsi_device\/1:0:0:0\/device\/block:\r\ntotal 0\r\ndrwxr-xr-x 7 root root 0 Oct 17 18:30 sr0\r\n\r\n\/sys\/class\/scsi_device\/2:0:0:0\/device\/block:\r\ntotal 0\r\ndrwxr-xr-x 10 root root 0 Oct 17 18:30 sda\r\n\r\n\/sys\/class\/scsi_device\/2:0:1:0\/device\/block:\r\ntotal 0\r\ndrwxr-xr-x 8 root root 0 Oct 17 18:30 sdb\r\nroot@debdev # cat \/sys\/class\/scsi_device\/*\/device\/model\r\nVMware IDE CDR10\r\nVirtual disk\r\nVirtual disk\r\n<\/pre>\n<p>To scan for disk changes at disk \/dev\/sdb<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # echo 1 &gt; \/sys\/class\/scsi_device\/2:0:1:0\/device\/rescan\r\n<\/pre>\n<p>Check if the change is recognized by the kernel<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # dmesg|tail -n 10\r\nata2: soft resetting link\r\nata2.00: configured for UDMA\/33\r\nata2: EH complete\r\nsd 2:0:0:0: &#x5B;sda] Cache data unavailable\r\nsd 2:0:0:0: &#x5B;sda] Assuming drive cache: write through\r\nsd 2:0:1:0: &#x5B;sdb] 419430400 512-byte logical blocks: (214 GB\/200 GiB)\r\nsd 2:0:1:0: &#x5B;sdb] Cache data unavailable\r\nsd 2:0:1:0: &#x5B;sdb] Assuming drive cache: write through\r\nsdb: detected capacity change from 107374182400 to 214748364800\r\n<\/pre>\n<p>Here is some python code to rescan all adapters<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\n\r\nsSCSIPath=&quot;\/sys\/class\/scsi_host&quot;\r\nSCSIHosts=os.listdir(sSCSIPath)\r\n\r\nfor SCSIHost in SCSIHosts:\r\n        with open(sSCSIPath+&quot;\/&quot;+SCSIHost+&quot;\/scan&quot;, &quot;w&quot;) as f:\r\n\t    f.write(&quot;- - -\\n&quot;)\r\n<\/pre>\n<p>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!<br \/>\nDelete (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.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # fdisk -l\r\nDisk \/dev\/sdb: 214.7 GB, 214748364800 bytes\r\n255 heads, 63 sectors\/track, 26108 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x1649ccd6\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sdb1               1       13054   104856223+  83  Linux\r\n<\/pre>\n<p>Delete Partition 1 (command d) and create a new primary partition  (command n) at the same start block(cylinder). In this example Block 1<br \/>\n<!-- to test parted: https:\/\/www.tecmint.com\/parted-command-to-create-resize-rescue-linux-disk-partitions\/ --><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # umount \/deb\/sdb1\r\nroot@debdev # fdisk \/dev\/sdb\r\nCommand (m for help): d\r\nSelected partition 1\r\nCommand (m for help): n\r\nPartition number (1-4): 1\r\nFirst cylinder (1-26108, default 1): 1\r\nLast cylinder:\r\nCommand (m for help): p\r\n\r\nDisk \/dev\/sdb: 214.7 GB, 214748364800 bytes\r\n255 heads, 63 sectors\/track, 26108 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x1649ccd6\r\n\r\n   Device Boot      Start         End      Blocks   Id  System\r\n\/dev\/sdb1               1       26108   209712478+  83  Linux\r\n\r\nCommand (m for help): w\r\nThe partition table has been altered!\r\nroot@debdev # partx \/dev\/sdb\r\n<\/pre>\n<p>Or use growpart. This command grows partition 1 (if it is the last partition on the disk) to the maximum size<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # growpart \/dev\/sda 1\r\n<\/pre>\n<p>Check volume integrity and resize the filesystem (ext4).<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # e2fsck -f \/dev\/sdb1\r\nroot@debdev # resize2fs -p \/dev\/sdb1\r\n<\/pre>\n<p>For xfs (-n does a readonly check)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev # xfs_growfs \/dev\/sdb1 -n\r\nroot@debdev # mount \/dev\/sdb1\r\nroot@debdev # xfs_growfs \/dev\/sdb1 -n\r\nroot@debdev # xfs_growfs \/dev\/sdb1\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, with virtualization it simply possible to change systems within a few mouse clicks. For example adding new disks or increasing the disk size of a hard disk without a reboot.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[873,199,224,144,52,556,1100],"class_list":["post-5013","post","type-post","status-publish","format-standard","hentry","category-linux","tag-changes","tag-disk","tag-linux-2","tag-new","tag-partition","tag-rescan","tag-resize"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=5013"}],"version-history":[{"count":20,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5013\/revisions"}],"predecessor-version":[{"id":10124,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5013\/revisions\/10124"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=5013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=5013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=5013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}