Make lsblk list devices by-id

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















I'm constantly having the situation where I want to correlate the output of lsblk which prints devices in a tree with their name in the scheme of /dev/sdXY with the drives /dev/disk/by-id/ names.










share|improve this question




























    2















    I'm constantly having the situation where I want to correlate the output of lsblk which prints devices in a tree with their name in the scheme of /dev/sdXY with the drives /dev/disk/by-id/ names.










    share|improve this question


























      2












      2








      2








      I'm constantly having the situation where I want to correlate the output of lsblk which prints devices in a tree with their name in the scheme of /dev/sdXY with the drives /dev/disk/by-id/ names.










      share|improve this question
















      I'm constantly having the situation where I want to correlate the output of lsblk which prints devices in a tree with their name in the scheme of /dev/sdXY with the drives /dev/disk/by-id/ names.







      linux lsblk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 23 '17 at 11:28







      Rovanion

















      asked Aug 23 '17 at 11:08









      RovanionRovanion

      1988




      1988




















          2 Answers
          2






          active

          oldest

          votes


















          3














          The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list:



          lsblk -o name,model,serial


          The output of this command will look something like this:



          NAME MODEL SERIAL
          sda SAMSUNG HD203WI S1UYJ1VZ500792
          ├─sda1
          └─sda9
          sdb ST500DM002-1BD14 W2APGFP8
          ├─sdb1
          └─sdb9
          sdc ST500DM002-1BD14 W2APGFS0
          ├─sdc1
          └─sdc9


          For posterity here's also a longer command with some commonly used columns:



          sudo lsblk -o name,size,fstype,label,model,serial,mountpoint


          The output of which could be:



          NAME SIZE FSTYPE LABEL MODEL SERIAL MOUNTPOINT
          sda 1,8T zfs_member SAMSUNG HD203WI S1UYJ1VZ500792
          ├─sda1 1,8T zfs_member storage /home
          └─sda9 8M zfs_member
          sdb 465,8G btrfs ST500DM002-1BD14 W2APGFP8
          ├─sdb1 465,8G btrfs
          └─sdb9 8M btrfs
          sdc 465,8G btrfs ST500DM002-1BD14 W2APGFS0
          ├─sdc1 465,8G btrfs rpool /
          └─sdc9 8M btrfs





          share|improve this answer

























          • Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

            – Gerald Schade
            Feb 24 at 12:51


















          0














          As found here, the device ids can be seen by ls -l /dev/disk/by-id.

          So, Your task could be accomplished e.g. by something like:



          lsblk |awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;gsub("[^[:alnum:]]","",dev);printf $0"tt";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'


          or



          lsblk -r|awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;printf $0" ";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'





          share|improve this answer






















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f387855%2fmake-lsblk-list-devices-by-id%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list:



            lsblk -o name,model,serial


            The output of this command will look something like this:



            NAME MODEL SERIAL
            sda SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1
            └─sda9
            sdb ST500DM002-1BD14 W2APGFP8
            ├─sdb1
            └─sdb9
            sdc ST500DM002-1BD14 W2APGFS0
            ├─sdc1
            └─sdc9


            For posterity here's also a longer command with some commonly used columns:



            sudo lsblk -o name,size,fstype,label,model,serial,mountpoint


            The output of which could be:



            NAME SIZE FSTYPE LABEL MODEL SERIAL MOUNTPOINT
            sda 1,8T zfs_member SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1 1,8T zfs_member storage /home
            └─sda9 8M zfs_member
            sdb 465,8G btrfs ST500DM002-1BD14 W2APGFP8
            ├─sdb1 465,8G btrfs
            └─sdb9 8M btrfs
            sdc 465,8G btrfs ST500DM002-1BD14 W2APGFS0
            ├─sdc1 465,8G btrfs rpool /
            └─sdc9 8M btrfs





            share|improve this answer

























            • Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

              – Gerald Schade
              Feb 24 at 12:51















            3














            The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list:



            lsblk -o name,model,serial


            The output of this command will look something like this:



            NAME MODEL SERIAL
            sda SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1
            └─sda9
            sdb ST500DM002-1BD14 W2APGFP8
            ├─sdb1
            └─sdb9
            sdc ST500DM002-1BD14 W2APGFS0
            ├─sdc1
            └─sdc9


            For posterity here's also a longer command with some commonly used columns:



            sudo lsblk -o name,size,fstype,label,model,serial,mountpoint


            The output of which could be:



            NAME SIZE FSTYPE LABEL MODEL SERIAL MOUNTPOINT
            sda 1,8T zfs_member SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1 1,8T zfs_member storage /home
            └─sda9 8M zfs_member
            sdb 465,8G btrfs ST500DM002-1BD14 W2APGFP8
            ├─sdb1 465,8G btrfs
            └─sdb9 8M btrfs
            sdc 465,8G btrfs ST500DM002-1BD14 W2APGFS0
            ├─sdc1 465,8G btrfs rpool /
            └─sdc9 8M btrfs





            share|improve this answer

























            • Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

              – Gerald Schade
              Feb 24 at 12:51













            3












            3








            3







            The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list:



            lsblk -o name,model,serial


            The output of this command will look something like this:



            NAME MODEL SERIAL
            sda SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1
            └─sda9
            sdb ST500DM002-1BD14 W2APGFP8
            ├─sdb1
            └─sdb9
            sdc ST500DM002-1BD14 W2APGFS0
            ├─sdc1
            └─sdc9


            For posterity here's also a longer command with some commonly used columns:



            sudo lsblk -o name,size,fstype,label,model,serial,mountpoint


            The output of which could be:



            NAME SIZE FSTYPE LABEL MODEL SERIAL MOUNTPOINT
            sda 1,8T zfs_member SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1 1,8T zfs_member storage /home
            └─sda9 8M zfs_member
            sdb 465,8G btrfs ST500DM002-1BD14 W2APGFP8
            ├─sdb1 465,8G btrfs
            └─sdb9 8M btrfs
            sdc 465,8G btrfs ST500DM002-1BD14 W2APGFS0
            ├─sdc1 465,8G btrfs rpool /
            └─sdc9 8M btrfs





            share|improve this answer















            The by-id names consists of the drive model together with the serial something which lsblk can be instructed to list:



            lsblk -o name,model,serial


            The output of this command will look something like this:



            NAME MODEL SERIAL
            sda SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1
            └─sda9
            sdb ST500DM002-1BD14 W2APGFP8
            ├─sdb1
            └─sdb9
            sdc ST500DM002-1BD14 W2APGFS0
            ├─sdc1
            └─sdc9


            For posterity here's also a longer command with some commonly used columns:



            sudo lsblk -o name,size,fstype,label,model,serial,mountpoint


            The output of which could be:



            NAME SIZE FSTYPE LABEL MODEL SERIAL MOUNTPOINT
            sda 1,8T zfs_member SAMSUNG HD203WI S1UYJ1VZ500792
            ├─sda1 1,8T zfs_member storage /home
            └─sda9 8M zfs_member
            sdb 465,8G btrfs ST500DM002-1BD14 W2APGFP8
            ├─sdb1 465,8G btrfs
            └─sdb9 8M btrfs
            sdc 465,8G btrfs ST500DM002-1BD14 W2APGFS0
            ├─sdc1 465,8G btrfs rpool /
            └─sdc9 8M btrfs






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 23 '17 at 11:27

























            answered Aug 23 '17 at 11:08









            RovanionRovanion

            1988




            1988












            • Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

              – Gerald Schade
              Feb 24 at 12:51

















            • Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

              – Gerald Schade
              Feb 24 at 12:51
















            Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

            – Gerald Schade
            Feb 24 at 12:51





            Unfortunately, on my current opensuse and ubuntu systems, lsblk -o serial did not output anything. Furtheron, the output of lsblk -o model did not exacty match that in /dev/disk/by-id/.

            – Gerald Schade
            Feb 24 at 12:51













            0














            As found here, the device ids can be seen by ls -l /dev/disk/by-id.

            So, Your task could be accomplished e.g. by something like:



            lsblk |awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;gsub("[^[:alnum:]]","",dev);printf $0"tt";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'


            or



            lsblk -r|awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;printf $0" ";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'





            share|improve this answer



























              0














              As found here, the device ids can be seen by ls -l /dev/disk/by-id.

              So, Your task could be accomplished e.g. by something like:



              lsblk |awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;gsub("[^[:alnum:]]","",dev);printf $0"tt";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'


              or



              lsblk -r|awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;printf $0" ";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'





              share|improve this answer

























                0












                0








                0







                As found here, the device ids can be seen by ls -l /dev/disk/by-id.

                So, Your task could be accomplished e.g. by something like:



                lsblk |awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;gsub("[^[:alnum:]]","",dev);printf $0"tt";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'


                or



                lsblk -r|awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;printf $0" ";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'





                share|improve this answer













                As found here, the device ids can be seen by ls -l /dev/disk/by-id.

                So, Your task could be accomplished e.g. by something like:



                lsblk |awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;gsub("[^[:alnum:]]","",dev);printf $0"tt";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'


                or



                lsblk -r|awk 'NR==1print $0" DEVICE-ID(S)"NR>1dev=$1;printf $0" ";system("find /dev/disk/by-id -lname "*"dev"" -printf " %p"");print "";'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 24 at 12:00









                Gerald SchadeGerald Schade

                26837




                26837



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f387855%2fmake-lsblk-list-devices-by-id%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay