{"id":6034,"date":"2021-08-28T09:28:40","date_gmt":"2021-08-28T09:28:40","guid":{"rendered":"https:\/\/really.zonky.org\/?p=6034"},"modified":"2021-08-28T09:28:41","modified_gmt":"2021-08-28T09:28:41","slug":"linux-listing-disks-and-controllers","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=6034","title":{"rendered":"Linux: Listing Disks and Controllers"},"content":{"rendered":"\n<p>Dealing with a potentially problematic SATA controller, I came across a little issue &#8211; which disks were connected to which controller? Not a problem most people would have to deal with but I do have rather a lot of disks. What I wanted was a tool that would list the controllers (<em>lspci<\/em>) with disks (block devices) shown per controller (<em>lsblk<\/em>). <\/p>\n\n\n\n<p>I couldn&#8217;t find on, so I knocked up a quick and nasty shell script to do the job.<\/p>\n\n\n\n<p>This isn&#8217;t a proper product and probably has many bugs (in particular it doesn&#8217;t like disks that are members of a volume group), but it works well enough for my use case :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u00bb .\/print-block-tree \n01:00.0 USB controller: Advanced Micro Devices, Inc. &#91;AMD] X399 Series Chipset USB 3.1 xHCI Controller (rev 02)\n  sr0:  PIONEER BD-RW_BDR-UD04 41443030303030303030303030303030 1024M\n01:00.1 SATA controller: Advanced Micro Devices, Inc. &#91;AMD] X399 Series Chipset SATA Controller (rev 02)\n  sdi: 0x5000c50050ada74d ATA ST4000VN000-1H41 Z300H9GD 3.6T\n  sdl: 0x500003992be00c53 ATA TOSHIBA_MG04ACA4 39DFK8S4FJKA 3.6T\n  sdm: 0x500003992bf8077f ATA TOSHIBA_MG04ACA4 39CIK7DNFJKA 3.6T\n  sdn: 0x500a075102fce9c7 ATA C300-CTFDDAC128M 00000000103402FCE9C7 119.2G\n  sdo: 0x500003992bb80ede ATA TOSHIBA_MG04ACA4 39CAKCKDFJKA 3.6T\n09:00.0 SATA controller: Marvell Technology Group Ltd. 88SE9235 PCIe 2.0 x2 4-port SATA 6 Gb\/s Controller (rev 11)\n  sdp: 0x5002538f71100d76 ATA Samsung_SSD_870 S5STNG0R101271L 3.6T\n  sdq: 0x50000399ec700c31 ATA TOSHIBA_MG04ACA4 30BXKC00FJKA 3.6T\n41:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981\/PM981\/PM983\n  nvme0n1:  96G\n42:00.0 Serial Attached SCSI controller: Broadcom \/ LSI SAS2308 PCI-Express Fusion-MPT SAS-2 (rev 05)\n  sdb: 0x500080dc00b4e2e9 ATA TOSHIBA-TR200 28RB76F7K46S 223.6G\n  sdc: 0x500080dc00b4e3f6 ATA TOSHIBA-TR200 28RB76MOK46S 223.6G\n  sdd: 0x500080dc009263fa ATA TOSHIBA-TR200 976B607GK46S 223.6G\n  sde: 0x500080dc00926416 ATA TOSHIBA-TR200 976B6088K46S 223.6G\n  sdf: 0x50025388a09508a9 ATA Samsung_SSD_850 S1SMNSAG216528K 119.2G\n  sdg: 0x50025385a01c8379 ATA Samsung_SSD_840 S1ANNSAF214088T 119.2G\n  sdh: 0x500080dc009263f4 ATA TOSHIBA-TR200 976B607AK46S 223.6G\n  sda: 0x50025388a09508b4 ATA Samsung_SSD_850 S1SMNSAG216534V 119.2G\n44:00.3 USB controller: Advanced Micro Devices, Inc. &#91;AMD] Family 17h (Models 00h-0fh) USB 3.0 Host Controller\n  sdj:  Generic- USB3.0_CRW_-SD 201404081410 59.5G<\/code><\/pre>\n\n\n\n<p>The script itself :-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n#\n# Attempt at printing a \"tree\" of block devices\n\ncontrollers=$(ls \/dev\/disk\/by-path | awk -F- '{printf \"%s-%s\\n\", $1, $2}' | uniq)\nfor c in $controllers\ndo\n  rhs=$(echo ${c} | awk -F- '{print $2}')\n  lspci -s ${rhs}\n  blockdevices=$(ls -l \/dev\/disk\/by-path\/${c}* | grep -v part | awk '{print $NF}' | awk -F\/ '{print $NF}' | uniq)\n  for b in $blockdevices\n  do\n    exp=$(lsblk -no WWN,VENDOR,MODEL,SERIAL,SIZE \/dev\/${b} | head -1 | tr -s \" \")\n    if &#91; -n \"${exp}\" ]\n    then\n      echo \"  ${b}: ${exp}\"\n    fi\n  done\ndone<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"521\" src=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?resize=695%2C521&#038;ssl=1\" alt=\"\" class=\"wp-image-5970\" srcset=\"https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?resize=1024%2C768&amp;ssl=1 1024w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?resize=768%2C576&amp;ssl=1 768w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?resize=1536%2C1152&amp;ssl=1 1536w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?w=1867&amp;ssl=1 1867w, https:\/\/i0.wp.com\/really.zonky.org\/wp-content\/uploads\/2021-04-03-the-rower.jpeg?w=1390&amp;ssl=1 1390w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><figcaption>The Rower<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Dealing with a potentially problematic SATA controller, I came across a little issue &#8211; which disks were connected to which controller? Not a problem most people would have to deal with but I do have rather a lot of disks. What I wanted was a tool that would list the controllers (lspci) with disks (block <a href='https:\/\/really.zonky.org\/?p=6034' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[4,209],"tags":[2050,2049],"class_list":["post-6034","post","type-post","status-publish","format-standard","hentry","category-it","category-linux-it","tag-controllers","tag-disks","category-4-id","category-209-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-1zk","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6034"}],"version-history":[{"count":1,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6034\/revisions"}],"predecessor-version":[{"id":6035,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/6034\/revisions\/6035"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}