Hot answers tagged

68

Try getent passwd "$uid" | cut -d: -f1


44

You might enjoy this little ditty. $ id -nu [number] 3.17.3-1-ARCH #1 SMP PREEMPT Fri Nov 14 22:56:01 CET 2014 i686 GNU/Linux I can confirm that it returns a corresponding user name, if one exists, on Arch Linux. I can also confirm that it does not work on Ubuntu when run as a normal user, although I have not tested this as the superuser. It also does ...


36

ls already performs that lookup. You can perform a user information lookup from the command line with getent passwd. If ls shows a user ID instead of a user name, it's because there's no user by that name. Filesystems store user IDs, not user names. If you mount a filesystem from another system, or if a file belongs to a now-deleted user, or if you passed a ...


29

On Linux, the util-linux/util-linux-ng package offers a command to generate UUIDs: uuidgen. $ uuidgen 5528f550-6559-4d61-9054-efb5a16a4de0 To quote the manual: The uuidgen program creates (and prints) a new universally unique identifier (UUID) using the libuuid(3) library. The new UUID can reasonably be considered unique among all UUIDs created on ...


27

Put a line like this in a file in /etc/udev/rules.d: KERNEL=="sd*", ATTRS{vendor}=="Yoyodyne", ATTRS{model}=="XYZ42", ATTRS{serial}=="123465789", RUN+="/pathto/script" Add a clause like NAME="subdir/mydisk%n" if you want to use a custom entry path under /dev. Run udevadm info -a -n sdb to see what attributes you can match against (attribute=="value"; ...


23

With the program btrfstune, which is part of more recent versions of the normal btrfs-tools, the UUID of a offline file system can be changed. If the partition is eg. /dev/sda1, use following command to generate a new, random UUID: btrfstune -u /dev/sda1 To specify which value should be used, use an uppercase -U followed by a (valid) UUID string, for ...


23

The first one reports the UUID of the ext4 filesystem on the md block device. It helps the system identify the file system uniquely among the filesystems available on the system. That is stored in the structure of the filesystem, that is in the data stored on the md device. The second one is the UUID of the RAID device. It helps the md subsystem identify ...


23

Firstly, please note that the CPUID is definitely not a commonly accessible uniquely identifying marker for any system later than an Intel Pentium III. While hashing it with MAC addresses may lead to unique markers certainly, this is due only to the unique qualities of the MACs themselves and the CPUID in that case is nothing more than circumstantial. ...


22

Just to clarify UUIDs are the only reliable way for the kernel to identify hard drives. There are two types: UUID, which is stored in the filesystem and is not available to the kernel at boot-time, and PARTUUID, which is stored in the partition table and IS available at boot time. So you have to use root=PARTUUID=SSSSSSSS-PP as /dev/sd?? can change with ...


22

How about these two: $ sudo dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' 52060201FBFBEBBF $ ifconfig | grep eth1 | awk '{print $NF}' | sed 's/://g' 0126c9da2c38 You can then combine and hash them with: $ echo $(sudo dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g') \ $(ifconfig | grep eth1 | awk '{print $NF}' | sed 's/://g') | sha256sum ...


21

Many modern distributions ship a file /etc/machine-id containing a most probably unique hexadecimal 32-character string. It originates from systemd, where a manpage has more information, and may be appropriate for your purpose.


20

Strictly speaking, UUID is not addressing at all. Addressing is very, very simple: read drive X sector Y - or else. Read memory address Z - or else. Addressing is simple, fast, leaves not much room for interpretation, and it's everywhere. UUID is not addressing. Instead it's searching, finding, sometimes waiting for devices to appear, and also ...


16

The parameter you have to pass to boot from UUID is PARTUUID. So it should be root=PARTUUID=666c2eee-193d-42db-a490-4c444342bd4e. The documentation explains why it's coming back with unknown-block(0,0): kernel-parameters.txt: root= [KNL] Root filesystem See name_to_dev_t comment in init/do_mounts.c. init/do_mounts.c: /* * Convert ...


14

I looked into /lib/udev/rules.d for examples of disk related rules. On an Ubuntu system one rule file provides the environment variable ID_FS_UUID_ENC which you can use in own rule files. Thus I put a custom rule file under /etc/udev/rules.d/foodevice.rules. Since it is not prefixed with a number, it is ran at last by udev. Btw, the udev daemon watched /etc/...


14

Have you formatted the swap partition? Once you part your disk and reserve a partition for swap you have to: sudo mkswap /dev/sdb5 after that your swap's UUID should be displayed when entering blkid command.


13

Use: tune2fs -U random /dev/sdb1 if it's an ext filesystem, or xfs_admin -U generate /dev/sdb1 if it's an xfs filesystem. The reason the second partition has the same UUID is because dd just copies data from one file to another (dd if=/dev/sda1 of=/dev/sdb1 = cat /dev/sda1 > /dev/sdb1); dd doesn't know what a partition is, or how to generate a UUID, ...


13

That's what's supposed to happen. There are two colloquial uses of the term "disk" or "drive" in play here: the first one refers to a physical device such as a usb stick. The second refers to a filesystem partition, of which there may be several on one physical device. Device nodes like /dev/sda refer to the first sense (physical devices); device nodes ...


13

The plain numbering scheme is not actually used in recent systems (with "recent" being Ubuntu 9 and later, other distributions may have adapted in that era, too). You are correct in observing the root partition is set with the plain numbering scheme. But this only is a default or fall-back setting which is usually overridden with the very next command, such ...


12

Ethernet cards might have (supposedly) unique MAC addresses, but what about virtual interfaces like aliases (e.g. eth0:0), bridges or VPNs? They need an ID too, so an UUID would be a good fit. By the way, since the question is about NetworkManager and NetworkManager deals with connections, there are scenarios where you can have multiple connections for a ...


12

The symlinks under /dev/disk/by-uuid/ are created by udev rules based on filesystems UUIDs. If you look at /usr/lib/udev/rules.d/60-persistent-storage.rules you will find entries like: ...... ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" To reference a disk you could use the disk serial number and the ENV{ID_SERIAL_SHORT} key. The ...


11

Mountpoint /dev is devtmpfs filesystem and managed by udev completely. So for details we have to go to udev configuration. 2 udev rules are handling this typically $ grep -ri '/dev/disk' /usr/lib/udev/rules.d/ /usr/lib/udev/rules.d/60-persistent-storage.rules:# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path} /usr/lib/udev/rules.d/13-dm-...


11

Besides of ext2 /ext3 / ex4 and xfs, you can also change UUID of the following filesystem or block device. Swap swaplabel -U $NEW_UUID Software RAID (md raid) For MD RAID, you must stop the RAID first, then update the UUID when re-assembling. So if your RAID is mounted to /, you need update UUID in offline mode -- use a live CD to do it. mdadm --stop $...


10

@Kusalananda is right. https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html The commands sort -u and sort | uniq are equivalent, but this equivalence does not extend to arbitrary sort options. For example, sort -n -u inspects only the value of the initial numeric string when checking for uniqueness, whereas sort -n | uniq ...


9

Note that's the UUID of the filesystem (or other structured data with a UUID the udev scripts know about) on the partition, not the UUID of the partition itself (not all partitioning schemes give UUIDs to partition anyway). See also Difference between UUID from blkid and mdadm?. A few options on Linux-based systems to get the FS UUID: fs_uuid=$(blkid -o ...


9

You should find your device UUID in /dev/disk/by-uuid: xfs_repair /dev/disk/by-uuid/198s5364-a29c-429e-b16d-e772acd


8

One option is stat + findmnt combo: findmnt -n -o UUID $(stat -c '%m' "$path") Here -n disables header, and -o UUID prints only UUID value. Option -c '%m' of stat is present to output only mountpoint of given path.


8

For changing the file system UUID you have to decrypt /dev/sda1 and then run tune2fs on the decrypted device mapper device. sda1 itself does not have a UUID thus it cannot be changed. The LUKS volume within sda1 does have a UUID (which is of limited use because you probably cannot use it for mounting), though. It can be changed with cryptsetup luksUUID /...


8

Yes, nowadays. This is covered in the systemd manual. The value in /etc/machine-id was originally not a valid UUID, because the systemd people did not originally write correct code for generating a version 4 UUID. But this has since been fixed. If you bind a licence to the machine ID, be aware that it can change … … if someone deletes /etc/...


7

No and yes. The command to create the filesystem is the one that generates the UUID. So, before running it there is no UUID to use to name the filesystem. However, it is posible to use an specific UUID to create the filesystem: $ uuid=$(uuidgen) $ echo "$uuid" 9a7d78e5-bc6c-4b19-94da-291122af9cf5 $ mkfs.ext4 -U "$uuid" The uuidgen program which is part ...


6

The reason it's not using your actual MAC address is because the code is poorly written. The mac_address function in uuid_mac.c has this block of code: if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) return FALSE; sprintf(ifr.ifr_name, "eth0"); if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { close(s); return FALSE; }...


Only top voted, non community-wiki answers of a minimum length are eligible