Identical scripts, same permissions, one hangs one doesnt, How? Why? - linux

I've also posted this question on Super User, here: https://superuser.com/questions/1425657/identical-scripts-same-permissions-one-hangs-one-doesnt-how-why. Please answer on the site you believe the question is most appropriate for. This will help me learn which site I should use. Thank you.
I always forget the name of the inxi command so some time ago I created a bash script called sysinfo- (note the '-' at the end to distinguish my script from the linux command sysinfo.)
$ cat ~/scripts/sysinfo-
#!/bin/bash
# DESCRIPTION
#
# Display system info at the command promp
#
# Main Program
echo -e "#############\n# inxi -b #\n#############\n"
/usr/bin/inxi -b
echo -e "############"
This script stopped working when I upgraded my system and inxi was upgraded to version 3.0.27
The script hangs when it reached the inxi command and must be killed with CTRL+C
The developer of inxi advised me to upgrade it to version 3.0.33 which I did. Unfortunately upgrading has not changed the results when running the original script. HOWEVER, after some testing I have discovered something I can't explain: An exact copy of my script runs successfully when the original does not!?
jesse#Limbo ~ $ ~/scripts/sysinfo-
#############
# inxi -b #
#############
^C
jesse#Limbo ~ $ cat ~/scripts/sysinfo- > /tmp/inxi.test
jesse#Limbo ~ $ chmod +x /tmp/inxi.test
jesse#Limbo ~ $ /tmp/inxi.test
#############
# inxi -b #
#############
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 3879 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.32 TiB (57.7%)
Info: Processes: 316 Uptime: 56m Memory: 31.34 GiB used: 4.80 GiB (15.3%) Shell: inxi.test inxi: 3.0.33
############
jesse#Limbo ~ $ diff ~/scripts/sysinfo- /tmp/inxi.test
jesse#Limbo ~ $ ls -l ~/scripts/sysinfo- /tmp/inxi.test
-rwxr-x--- 1 jesse jesse 187 Apr 15 18:46 /home/jesse/scripts/sysinfo-
-rwxr-x--- 1 jesse jesse 187 Apr 15 19:09 /tmp/inxi.test
jesse#Limbo ~ $ md5sum ~/scripts/sysinfo- /tmp/inxi.test
a1356223d7bacb6d5b6d74cf44d733f2 /home/jesse/scripts/sysinfo-
a1356223d7bacb6d5b6d74cf44d733f2 /tmp/inxi.test
How is this possible?
If it was some sort of corruption of the original file wouldn't diff pick that up? How would I check this?
Is it possible for there to have been some sort of policy file created automatically, because I haven't made one, that prevents inxi from running from within a script in ~/scripts??
BIGO!!
jesse#Limbo ~ $ mv /tmp/inxi.test ~/scripts/
jesse#Limbo ~ $ ~/scripts/inxi.test
#############
# inxi -b #
#############
^C
Might this be an apparmor policy perhaps?
jesse#Limbo ~ $ apparmor_status | grep inxi
yields no results.
I tried placing env in both ~/scripts/sysinfo- and /tmp/inxi.test
#!/bin/bash
# DESCRIPTION
#
# Display system info at the command promp
#
env
# Main Program
echo -e "#############\n# inxi -b #\n#############\n"
/usr/bin/inxi -b
echo -e "############"
but the output of env from both scripts was identical.
jesse#Limbo ~ $ diff ~/scripts/sysinfo- /tmp/inxi.test
jesse#Limbo ~ $ ~/scripts/sysinfo- > /tmp/sysinfo.output
^C
jesse#Limbo ~ $ /tmp/inxi.test > /tmp/inxi.test.output
jesse#Limbo ~ $ diff /tmp/sysinfo.output /tmp/inxi.test.output
61a62,75
> System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
> Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
> Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
> date: 02/22/2014
> CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 1355 MHz min/max: 800/4000 MHz
> Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
> Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
> resolution: 1920x1080~60Hz, 1280x1024~60Hz
> OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
> Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
> Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
> Drives: Local Storage: total: 14.44 TiB used: 8.32 TiB (57.7%)
> Info: Processes: 315 Uptime: 1h 40m Memory: 31.34 GiB used: 4.97 GiB (15.9%) Shell: inxi.test inxi: 3.0.33
> ############
As you can see the issue is not a problem running bash scripts from ~/scripts but only with running inxi from a script in ~/scripts
~/scripts happens to be a bind mounted directory on my system. Perhaps that is the problem?
BINGO!!
jesse#Limbo ~ $ mv ~/scripts/sysinfo- ~/
jesse#Limbo ~ $ ~/sysinfo-
#############
# inxi -b #
#############
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 900 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.33 TiB (57.7%)
Info: Processes: 322 Uptime: 1h 52m Memory: 31.34 GiB used: 5.36 GiB (17.1%) Shell: sysinfo- inxi: 3.0.33
############
But hang on...
jesse#Limbo ~ $ mv ~/sysinfo- ~/scripts/
jesse#Limbo ~ $ cp ~/scripts/sysinfo- ~/
jesse#Limbo ~ $ chmod +x ~/sysinfo-
jesse#Limbo ~ $ ~/sysinfo-
#############
# inxi -b #
#############
^C
HUH ????
I moved the script back to the bind mounted ~/scripts directory, then copied (rather than moved) it to ~/, made the new file executable, and... inxi hangs!
Surely this behavior must be coming from a policy somewhere that is able to tell the difference between a file moved and a file copied. A program run from within a bash script rather than from the command line. What else besides apparmor could be capable of doing this??
jesse#Limbo ~ $ cd ~/scripts/
jesse#Limbo ~/scripts $ inxi -b
System: Host: Limbo Kernel: 4.15.0-47-generic x86_64 bits: 64 Desktop: Cinnamon 4.0.10 Distro: Linux Mint 19 Tara
Machine: Type: Desktop System: MSI product: MS-7823 v: 1.0 serial: <root required>
Mobo: MSI model: CSM-H87M-G43 (MS-7823) v: 1.0 serial: <root required> BIOS: American Megatrends v: 1.6
date: 02/22/2014
CPU: Quad Core: Intel Core i7-4790 type: MT MCP speed: 1500 MHz min/max: 800/4000 MHz
Graphics: Device-1: NVIDIA GM107GL [Quadro K2200] driver: nvidia v: 390.116
Display: x11 server: X.Org 1.19.6 driver: nvidia unloaded: fbdev,modesetting,nouveau,vesa
resolution: 1920x1080~60Hz, 1280x1024~60Hz
OpenGL: renderer: Quadro K2200/PCIe/SSE2 v: 4.6.0 NVIDIA 390.116
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Device-2: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169
Drives: Local Storage: total: 14.44 TiB used: 8.33 TiB (57.7%)
Info: Processes: 315 Uptime: 2h 01m Memory: 31.34 GiB used: 4.96 GiB (15.8%) Shell: bash inxi: 3.0.33
I can't see how the directory permissions could be having any effect
jesse#Limbo ~/scripts $ ls -ld /tmp/ ~/scripts/ ~/
drwxr-x--- 194 jesse jesse 20480 Apr 15 20:06 /home/jesse/
drwxrwx--- 18 jesse jesse 12288 Apr 15 20:06 /home/jesse/scripts/
drwxrwxrwt 20 root root 24576 Apr 15 20:32 /tmp/

Has anyone discovered the dmidecode, lshw, lspci, lsusb, lsblk, or blkid utilities attempting to call back the parent_script? No. For that matter any UNIX or Linux utility doing a call back to the parent_script. No. Surprise, surprise, surprise, the newer inxi version does.
The inxi developer believes it is perfectly normal to do a call back on the parent_script without any intimate knowledge of the parent_script. Common sense would be to never do a call back on the parent_script unless you have working knowledge of that script and how it will behave. You are just asking for a vicious recursive loop. If the vicious loop is left running long enough it could fill up the Linux proc table or exhausted all available memory. And the inxi developer has made a fundamental change to inxi using very bad assumptions and created this scenario.
The previous 2.x version of inxi never performed a call back on the parent_script. I can imagine many users or system admins have been using the inxi utility in a monthly script to help document their server(s). And, with the inxi 2.x it was properly working for them.
The 3.x version of the inxi utility changed the foundational behavior. Now, inxi will perform a call back to the parent_script --version. The inxi developer assumes the parent_script will respond in kind to the --version argument. Why would anyone expect the --version call back when the 2.x version of inxi fundamental behavior did not do this? This can be very nasty for a cronjob script.
The 3.x version has a very fundamental change that will catch many users off guard with a vicious recursive loop. I attempted to get the inxi developer to explain why he would change an existing foundational behavior, and what useful purpose does the parent_script --version provide. Good luck getting an answer.
How to reproduce the problem
In my example the /home/temp/bin directory resides in my PATH.
Place this simple "dltest" script in your one of your PATH directories, and it will reproduce the problem:
# cat dltest
#!/bin/bash
# Open another terminal and use ps -ft /dev/pts/? to view the spawned process.
echo -e "\nUsing `tty`.\nSleeping yawn. Taking five seconds...\n" ; sleep 5
echo -e "\nStarting inxi -Ixxx\n"
# for a test use a very basic inxi.
/usr/bin/inxi -Ixxx
$ pwd
/home/temp/bin
$
$ ./dltest
Using /dev/pts/0.
Sleeping yawn. Taking five seconds...
Starting inxi_3.0.32
Concurrently using another terminal:
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13068 1820 0 14:28 pts/0 00:00:00 /bin/bash ./dltest
temp 13070 13068 0 14:28 pts/0 00:00:00 sleep 5
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13068 1820 0 14:28 pts/0 00:00:00 /bin/bash ./dltest
temp 13072 13068 18 14:29 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi
temp 13081 13072 0 14:29 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13082 13081 0 14:29 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13084 13082 0 14:29 pts/0 00:00:00 sleep 5
# The longer it runs the deeper it will get.
$ ps -ft pts/0
UID PID PPID C STIME TTY TIME CMD
temp 1820 1816 0 11:02 pts/0 00:00:00 bash
temp 13622 1820 0 14:48 pts/0 00:00:00 /bin/bash ./dltest
temp 13625 13622 1 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13634 13625 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13635 13634 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13638 13635 1 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13647 13638 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13648 13647 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13652 13648 2 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13661 13652 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13662 13661 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13665 13662 20 14:48 pts/0 00:00:00 /usr/bin/perl /usr/bin/inxi -tty -Ixxx
temp 13674 13665 0 14:48 pts/0 00:00:00 sh -c /home/temp/bin/dltest --version 2>/dev/null
temp 13675 13674 0 14:48 pts/0 00:00:00 /bin/bash /home/temp/bin/dltest --version
temp 13677 13675 0 14:48 pts/0 00:00:00 sleep 5
temp#lm19:~$
To prevent this vicious loop you can add this workaround at the top of your script.
if [[ "${1}" == "--version" ]] ; then
# work around for inxi_3.0.32 parent --version anomaly
exit 1
fi

You can create a new script that first creates a temporary copy of the original script and then runs the temporary script for you.
So you could name the script ~/scripts/sysinfo2 and it would look like this:
#!/bin/bash
cat $HOME/scripts/sysinfo- > /tmp/inxi.test
chmod +x /tmp/inxi.test
/tmp/inxi.test
Don't forget to make it executable: chmod +x ~/scripts/sysinfo2 and then you can run
~/scripts/sysinfo2
and it should execute without hanging up.

Related

udev rules for sd* and dm-* device not working as expected

# cat /etc/oracle-release
Oracle Linux Server release 7.8
uname -a
Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
cat 99-custom.rules
ACTION!="add|change", GOTO="rule_end"
ENV{ID_VENDOR}=="NETAPP*", RUN+="/bin/sh -c 'echo 4096 > /sys%p/queue/max_sectors_kb'"
LABEL="rule_end"
----2nd option using KERNEL option just for dm-* devices
ACTION!="add|change", GOTO="rule_end"
KERNEL=="dm-[0-9]*",ENV{ID_VENDOR}=="NETAPP*", RUN+="/bin/sh -c 'echo 4096 > /sys%p/queue/max_sectors_kb'"
LABEL="rule_end"
udevadm control --reload-rules && udevadm trigger
/sbin/udevadm trigger --type=devices --action=change
Issue : We don't see udev rule applied to all dm-* device
/sys/block/dm-19/queue/max_sectors_kb:512
/sys/block/dm-9/queue/max_sectors_kb:512
We even tried to remove ENV{ID_VENDOR}=="NETAPP*" from rule
What we need to apply max_sectors_kb to 4096 to all dm-* ( multipath devices )
and all sd* devices can be left default of 512
Any idea what could be wrong ?

Suspend / Hibernate cannot resume laptop

I'm trying to configure Suspend/Hibernate with my laptop and I issued some troubles.
I noticed the following troubles:
Suspend :
- Switching the lid off of my laptop : When I switch the lid on of the laptop, nothing happens. I must push down the power button to force the shutdown and then switch on the laptop.
- Typing systemctl suspend : same as previously.
Hibernate :
- Typing systemctl hibernate : the laptop seems to shutdown
I read those following links for helping me :
Hibernate with swap file
Suspend and hibernate
My system :
4.13.0-38-generic #43-Ubuntu SMP Wed Mar 14 15:20:44 UTC 2018 x86_64 GNU/Linux
My swap :
$ cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=403661c1-c7b4-47a8-9493-c5c0262ce14e / ext4 errors=remount-ro 0 1
UUID=BF40-CD4F /boot/efi vfat umask=0077 0 1
/swapfile none swap sw 0 0
/swap swap swap defaults 0 0
What I've done :
Create swap file
$ fallocate -l 8g /swap
$ mkswap /swap
Add swappiness
sysctl -w vm.swappiness=1
$ cat /etc/sysctl.conf | grep swappiness
vm.swappiness=1
$ swapon /swap
Configure grub
$ cat /etc/default/grub | grep -i grub_cmdline_linux_default
GRUB_CMDLINE_LINUX_DEFAULT="resume=/swap resume_offset=60354560 quiet splash"
$ sudo filefrag -v /swap | head -n4
Filesystem type is: ef53
File size of /swap is 8589934592 (2097152 blocks of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 0: 60354560.. 60354560: 1:
According to previous links I could configure /etc/mkinitcpio.conf but there is no file like this in my system.
So, I don't really know how to configure my initramfs.
Here is my configuration from /sys/power :
$ cat /sys/power/disk
[platform] shutdown reboot suspend test_resume
$ cat /sys/power/mem_sleep
s2idle [deep]
$ cat /sys/power/image_size
3261943808
$ cat /sys/power/resume
0:0
Could you give me some hints to make a step forward. Thanks you.

FATAL: Module sg not found

When I was installing uptime monitoring agent, I got the error messages:
Probing 'sg' devices
FATAL: Module sg not found.
But lsmod shows the sg module is loaded:
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.1 (Santiago)
# uname -r
2.6.32-131.0.15.el6.x86_64
# cat /proc/scsi/sg/version
30534 3.5.34 [20061027]
# find /lib/modules -name sg.ko
/lib/modules/2.6.32-131.0.15.el6.x86_64/kernel/drivers/scsi/sg.ko
# lsmod |grep sg
sg 30186 0
# modprobe -lv|grep sg
#
# cat /boot/config-`uname -r` | grep CONFIG_CHR_DEV_SG
CONFIG_CHR_DEV_SG=m
Following is the device and file system information:
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg0 lvm2 a- 499.51g 113.51g
# df -hF ext4
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv_root
99G 7.9G 86G 9% /
/dev/sda1 485M 36M 425M 8% /boot
/dev/mapper/vg0-lv_opt
99G 189M 94G 1% /opt
/dev/mapper/vg0-lv_var
148G 114G 27G 82% /var
# grep kernel /var/log/messages | grep sg
Jul 21 03:25:04 server810 kernel: imklog 4.6.2, log source = /proc/kmsg started.
# ls /dev/sg*
/dev/sg0 /dev/sg1
# ls -l /dev/sg*
crw-rw---- 1 root cdrom 21, 0 Jul 14 11:10 /dev/sg0
crw-rw---- 1 root disk 21, 1 Jul 14 11:10 /dev/sg1
The server is a VMWare guest.
Any help will be highly appreciated.
Thanks in advance,
Alex
Is there a specific SCSI device you are trying to use? SCSI drivers are built in tiers, so it's possible you are hitting an error with a more specific driver for the device you are trying to access.
Are there any /dev/sg* devices?
Are there any sg messages/errors in /var/log/messages or in dmesg?
You could try:
grep kernel /var/log/messages | grep sg

Hudson server always stopped every morning day

I've got this regular problem every morning that my build server (Hudson) is always stopped every morning so I have to manually start it, is there any reason why or any location that I can started to look for the error message?
Here's the error diagnostic that I did:
ascari:~# ps -ef | grep -i hud
root 5959 5944 0 09:00 pts/0 00:00:00 grep -i hud
ascari:~# cd /etc/init.d
ascari:/etc/init.d# ./hudson start
ascari:/etc/init.d# ps -ef | grep -i hud
hudson 6004 1 0 09:00 ? 00:00:00 /usr/bin/daemon --name=hudson -- inherit --env=HUDSON_HOME=/var/lib/hudson --output=/var/log/hudson/hudson.log -- user=hudson --pidfile=/var/run/hudson/hudson.pid -- /usr/bin/java -Xms512m -Xmx1 024m -Dhttp.proxyHost=proxy.domain.com -Dhttp.proxyPort=3128 -Dhttp.nonProxyHo sts="localhost|ascari|*.domain.com" -jar /usr/share/hudson/hudson.war --webroo t=/var/run/hudson/war
hudson 6005 6004 48 09:00 ? 00:00:01 /usr/bin/java -Xms512m -Xmx1024m -Dhttp.proxyHost=proxy.domain.com -Dhttp.proxyPort=3128 -Dhttp.nonProxyHosts= "localhost|ascari|*.domain.com" -jar /usr/share/hudson/hudson.war --webroot=/v ar/run/hudson/war
root 6008 5944 14 09:01 pts/0 00:00:00 grep -i hud
ascari:/etc/init.d# df -k -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 327M 125M 185M 41% /
tmpfs 1.5G 0 1.5G 0% /lib/init/rw
udev 10M 96K 10M 1% /dev
tmpfs 1.5G 0 1.5G 0% /dev/shm
/dev/sda9 4.7G 295M 4.1G 7% /home
/dev/sda8 4.2G 155M 3.8G 4% /tmp
/dev/sda5 4.6G 3.0G 1.4G 69% /usr
/dev/sda6 65G 32G 30G 52% /var
ascari:/etc/init.d# uname -a
Linux ascari 2.6.26-2-686 #1 SMP Sun Jun 21 04:57:38 UTC 2009 i686 GNU/Linux
ascari:/etc/init.d#
Have you checked the logfile (referenced above) and set the --logfile argument (as documented here) ?
Rescheduling the project build solve the problem.
The Hudson process was killed by the Linux kernel due to the memory over consumption.

knowing a device special file major and minor numbers in linux

All files in /dev are special files... they represent devices of the computer.
They were created with the mknod syscall. My question is: How can I know the minor and
major numbers that were used to create this special file?
The list is called the LANANA Linux Device List, and it is administered by Alan Cox.
You can find the latest copy online (direct link), or in the Linux source. Its filename in the kernel tree is Documentation/devices.txt.
To see the major and minor numbers that created a node in /dev (or any device node for that matter), simply use ls with the -l option:
22:26 jsmith#undertow% ls -l /dev/xvd?
brw-rw---- 1 root disk 202, 0 Nov 1 20:31 /dev/xvda
brw-rw---- 1 root disk 202, 16 Nov 1 20:31 /dev/xvdb
brw-rw---- 1 root disk 202, 32 Nov 1 20:31 /dev/xvdc
In this example, 202 is the three devices' major number, and 0, 16, and 32 are minors. The b at left indicates that the node is a block device. The alternative is c, a character device:
crw-rw-rw- 1 root tty 5, 0 Nov 22 00:29 /dev/tty
$ ls -l /dev/fd0 /dev/null
brw-rw---- 1 root floppy 2, 0 Nov 22 19:48 /dev/fd0
crw-rw-rw- 1 root root 1, 3 Nov 22 19:48 /dev/null
$ stat -c '%n: %F, major %t minor %T' /dev/fd0 /dev/null
/dev/fd0: block special file, major 2 minor 0
/dev/null: character special file, major 1 minor 3
Most device numbers are fixed (i.e. /dev/null will always be character device 1:3) but on Linux, some are dynamically allocated.
$ cat /proc/devices
Character devices:
...
10 misc
...
Block devices:
...
253 mdp
254 device-mapper
$ cat /proc/misc
...
57 device-mapper
...
For example, on this system, it just so happens that /dev/mapper/control will be c:10:57 while the rest of /dev/mapper/* will be b:254:*, and this could differ from one boot cycle to another -- or even as modules are loaded/unloaded and devices are added/removed.
You can explore these device registrations further in /sys.
$ readlink /sys/dev/block/2:0
../../devices/platform/floppy.0/block/fd0
$ cat /sys/devices/platform/floppy.0/block/fd0/dev
2:0
$ readlink /sys/dev/char/1:3
../../devices/virtual/mem/null
$ cat /sys/devices/virtual/mem/null/dev
1:3
You can also use stat.
$ stat -c 'major: %t minor: %T' <file>
Especially for block devices:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 90G 0 disk
├─sda1 8:1 0 4G 0 part [SWAP]
├─sda2 8:2 0 4G 0 part /
Alternative that doesn't depend on stat:
$ cat /sys/class/*/random/dev
1:8

Resources