List all ids linux

linux: How can I view all UUIDs for all available disks on my system?

There are several other disks on this system, and not all disks are being mounted to the correct location (For example, /dev/sda1 and /dev/sdb1 are sometimes reversed). How can I see the UUIDs for all disks on my system? Can I see the UUID for the third disk on this system?

12 Answers 12

There’s a tool called blkid (use it as root or with sudo ),

# blkid /dev/sda1 /dev/sda1: LABEL="/" UUID="ee7cf0a0-1922-401b-a1ae-6ec9261484c0" SEC_TYPE="ext2" TYPE="ext3" 

you can check this link for more info

Just a minor comment: looks like being a member of group disk is sufficient to run blkid ; no need for full superuser privileges.

If you want only the UUID (like for parsing in a script), you can do blkid /dev/sda1 -s UUID -o value .

Quick comment here : in my distro (Debian 8) this yields UUID as well as «PARTUUID», which is rather confusing. I used commands which gives only one value.

This one saves a great deal of time, though I prefer to do blkid /dev/sd* to list all drives.. The info that spits out is generally more than enough to find the drive you need. 🙂

PARTUUID for GPT-partitioned disks is the GPT UUID for the partition, not for the filesystem in it. Might be useful when a filesystem is not created yet. On a MBR-partitioned disk, PARTUUID is not a real UUID, but simply a Windows Disk Signature from the MBR + a dash + partition number.

In /dev/disk/by-uuid there are symlinks mapping each drive’s UUID to its entry in /dev (e.g. /dev/sda1 )

You can view these with the command ls -lha /dev/disk/by-uuid

LVM already uses long UUID-like identifiers (although presented differently) in its structure. I think the only reason for using filesystem UUIDs with LVM would be as an unified interface for some sort of automation, as LVM already does the mapping of LVs to human-friendly names for you.

Just for reference, the result has changed and will be different from blkid and won’t work for booting: i.imgur.com/ocgoi3g.png

I often use this approach, especially becuase blkid needs SU privileges. But /dev/disk/by-uuid unfortunately has much less information and it will get you into trouble for some cases. For me this was working with RAID and btrfs volumes as different partitions share a uuid, but there is only one entry for each UUID in the symlinks.

Читайте также:  Fifo in linux example

The best command to use is lsblk -f . It will list all the devices and partitions, how they are mounted (if at all) and the tree structure of the devices in the case of using LVM, crypto_LUKS, or multiple volume groups on the same drive.

An addition: I had to put sudo in front of this, otherwise it was unable to get the UUID of the partition and the column was empty.

For me, from an arch linux minimal boot disk, this does show a pretty tree with free space and mount points but no UUIDs, even when i add «-o UUID»

To only get the UUID of a specific disk device (for example to be used in a script) you can use:

sudo blkid -s UUID -o value /dev/sdXY 

where /dev/sdXY is the name of the device.

If you want to check what type the partition is, use:

and it will show you if you have ext3 or ext2. Today it helped me because there was a formatted ext2 partition and I thought it was ext3, which was causing the mount to fail.

You can see all the outputs that can be added to the -o ( —output ) with

Also this will do the job

The previous answers do not work for multiple devices or for devices with identical UUIDs.

A universally unique identifier (UUID) should always be unique. The entire purpose of a UUID is to be a unique, universally. If not, there’s a problem. I have seen duplicated UUIDs in cloned VMs, at least for network devices.

If you clone a partition with the dd command the copy will have the same uuid and yes, that is a problem. The other answers here wouldn’t show that.

With the following command line you can see UUID plus the mapping to partitions.

ls /dev/disk/by-uuid -lt lrwxrwxrwx 1 root root 10 Sep 1 18:51 57eacf4e-1940-436e-b945-85f8d4833aa5 -> ../../sda2 lrwxrwxrwx 1 root root 10 Sep 1 18:51 656f4cae-8527-43a0-a80f-00ac82818744 -> ../../sda1 lrwxrwxrwx 1 root root 9 Sep 1 18:51 d627595d-4060-440e-8380-a1fe9f3f2a81 -> ../../md0 lrwxrwxrwx 1 root root 10 Sep 1 18:51 0dfd6dfe-1852-460d-852c-676a5b9035ed -> ../../sda4 lrwxrwxrwx 1 root root 10 Sep 1 18:51 b1ddf850-8f81-429f-a653-38ae4a4ebb6f -> ../../sda3 lrwxrwxrwx 1 root root 9 Sep 1 18:51 b4b729f7-5699-411c-8f5a-424bbc7c89fc -> ../../sdb 

There is one UUID for a file system per partition. On sda, i have 4 partitions so, I had 4 UUID. wiki.debian.org/Part-UUID

Читайте также:  Linux bonding how to

I have the same problem as you: renaming by kernel of /dev/sd** after a reboot:

Of course all my automatic mounting in /etc/fstab are referenced by LABEL or by UUID, so basically there is no problem for that. And all the commands above ,blkid or lsblk, give this kind of information.

But the trouble begins as in my case, when you are using partition in RAW mode, in the currently booted system point-of-view: for example either: the partition is used as raw device, to make a virtual disk for VirtualBox (so the reference to this partition is something like: /dev/sdf3 ) or the partition is used as raw device, to make a LUN for iSCSI (so the reference to this partition is something like: /dev/sdc6 )

So now at boot , for example in rc.local, you have to find in a reliable manner, what is the /dev/sdXX device of your dedicated RAW partition, and adapt some file:

The VirtualBox disk *.vmk description of this raw disk, in the part something like:

\# Extent description RW 488397167 FLAT "/dev/sdXX" 0 

and then restart the VirtualBox service

in tgtd configuration, a target :target0 was associated to /dev/sdd6 at build time. After reboot you get the same partition renamed /deb/sdc6 This happens with a removable disk, USB or eSATA! So how to find the new device automatically ? Again in /etc/rc.d/rc.local

So in this case we need a reliable manner to find what is the new device name. GPT partition offers unique GUID for any GPT partition, written in GPT table.

gdisk does not provide this info with listing mode, but only in interactive mode with: i command. Fortunately, blkid does it!

So you need to write a shell script, to look in all your disks, which is the device /dev/sdXX , associated to the GUID noticed at partition creation time.

Something like, search_device_by_partUUID.sh:

\#!/bin/bash PART_UUID=$1 if [ "$PART_UUID" = "" ] then echo "Syntax: $0 " exit 3 fi lsblk | grep '^sd' | awk '' | while read DISK_DEVICE do INFO=`blkid /dev/$* | grep "PARTUUID=\"$PART_UUID\"" ` if [ "$INFO" != "" ] then echo INFO : "$INFO" BLK_DEVICE=`echo "$INFO" | awk ''` echo $BLK_DEVICE > /dev/shm/blkdevice echo -n "BLK_DEVICE : " ; cat /dev/shm/blkdevice fi done 

and then use /dev/shm/blkdevice , in your rc.local script.

Источник

How to list all users in a Linux group?

I’m new here, I found out that SF exists right after I posted the question. I agree it belongs either to SF or SO.

Читайте также:  Linux mint and active directory

20 Answers 20

It is portable across both Linux and Solaris, and it works with local group/password files, NIS, and LDAP configurations.

Unfortunately, there is no good, portable way to do this that I know of. If you attempt to parse /etc/group, as others are suggesting, you will miss users who have that group as their primary group and anyone who has been added to that group via a mechanism other than UNIX flat files (i.e. LDAP, NIS, pam-pgsql, etc.).

If I absolutely had to do this myself, I’d probably do it in reverse: use id to get the groups of every user on the system (which will pull all sources visible to NSS), and use Perl or something similar to maintain a hash table for each group discovered noting the membership of that user.

Edit: Of course, this leaves you with a similar problem: how to get a list of every user on the system. Since my location uses only flat files and LDAP, I can just get a list from both locations, but that may or may not be true for your environment.

Edit 2: Someone in passing reminded me that getent passwd will return a list of all users on the system including ones from LDAP/NIS/etc., but getent group still will still miss users that are members only via the default group entry, so that inspired me to write this quick hack.

 #!/usr/bin/perl -T # # Lists members of all groups, or optionally just the group # specified on the command line # # Copyright © 2010-2013 by Zed Pobre (zed@debian.org or zed@resonant.org) # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # use strict; use warnings; $ENV = "/usr/bin:/bin"; my $wantedgroup = shift; my %groupmembers; my $usertext = `getent passwd`; my @users = $usertext =~ /^([a-zA-Z0-9_-]+):/gm; foreach my $userid (@users) < my $usergrouptext = `id -Gn $userid`; my @grouplist = split(' ',$usergrouptext); foreach my $group (@grouplist) < $groupmembers-> = 1; > > if($wantedgroup) < print_group_members($wantedgroup); >else < foreach my $group (sort keys %groupmembers) < print "Group ",$group," has the following members:\n"; print_group_members($group); print "\n"; >> sub print_group_members < my ($group) = @_; return unless $group; foreach my $member (sort keys %<$groupmembers>) < print $member,"\n"; >> 

Источник

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