2

I need to create a serial number for my application in a Unix machine.

  1. The generated serial number should be unique
  2. Do not change over time (Only changes after hard drive or mother board changes)
  3. Do not need root privilege.

I found that, in Ubuntu there are some information about hard drives under the following folder:

/dev/disk/by-id

These files seem to be serial numbers of attached hard disks to the machine. I want to use the following command to generate a unique finger print of the machine.

ls /dev/disk/by-id | grep  -v 'part'

Is this possible? Does this command meets the conditions I specified above?

a.toraby
  • 121
  • 4
  • 1
    Because a computer is made up of several parts, are you going to be combining the unique ID of all the various parts to make one long serial number? Or are you just keeping track of the individual unique id/serial numbers from all the various parts? – CIA Nov 01 '15 at 06:23
  • You'll have a hard time getting that without root. – Konrad Gajewski Nov 01 '15 at 14:10
  • You can get any such value without root. Provided you first use root to place the value in a world-readable file. Personally I'd go with MAC addresses, because where I've worked these only ever change when the entire chassis does. Hard drives are changed comparatively rapidly. – Julian Fondren Nov 03 '15 at 01:38

1 Answers1

2

A good method to uniquely identify a machine is by SMBios UUID value. In linux, it can be accessed using the dmidecode tool.

# dmidecode -s system-uuid 1E00CBE0-008C-5900-FBCE-C86000B2350B

Another alternative, would be to use the UUID of the root file system. File-system UUID's can be accessed in "/dev/disks/by-uuid". This has the advantage of not requiring root privileges.

Yet another method is using blkid:

rootNode="$(mount | grep " / ")"; blkid -s UUID -o value ${rootNode%% *}

  • tune2fs -U allows you to change the UUID of a filesystem ... – user9517 Nov 01 '15 at 19:21
  • Thanks for your answer. But How can I find the uuid of the root file system. In `/dev/disks/by-uuid` I have several UUID's. Which one is for root? What happens if user attaches a cool disk or external hard drive? Do they change? – a.toraby Nov 02 '15 at 05:23
  • I updated my answer. –  Nov 03 '15 at 00:53