Generating device nodes using a device table
Multistrap includes a script to process device tables and generate device nodes in a root filesystem, without needing MAKEDEV. This allows full flexibility over the devices added, allows device nodes that MAKEDEV would not normally create and omits ones that MAKEDEV would create.
multistrap includes a device-table.pl helper script that can work around some of the issues with MAKEDEV. device-table.pl requires a device table file along the lines of the one in the mtd-utils source package.
# Device table entries take the form of: # <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count> # where name is the file name, type can be one of: # f A regular file # s symlink # h hardlink # d Directory # c Character special device file # b Block special device file # p Fifo (named pipe) # uid is the user id for the target file, gid is the group id for the # target file. The rest of the entried apply only to device special # file.
To identify which device nodes would be created, use the MAKEDEV -n option.
$ /sbin/MAKEDEV -n std create mem c 1 1 root:kmem 0640 create kmem c 1 2 root:kmem 0640 create null c 1 3 root:root 0666 create port c 1 4 root:kmem 0640 create zero c 1 5 root:root 0666 create core -> /proc/kcore create full c 1 7 root:root 0666 create random c 1 8 root:root 0666 create urandom c 1 9 root:root 0666 create tty c 5 0 root:tty 0666 create ram0 b 1 0 root:disk 0660 create ram1 b 1 1 root:disk 0660 create ram2 b 1 2 root:disk 0660 create ram3 b 1 3 root:disk 0660 create ram4 b 1 4 root:disk 0660 create ram5 b 1 5 root:disk 0660 create ram6 b 1 6 root:disk 0660 create ram7 b 1 7 root:disk 0660 create ram8 b 1 8 root:disk 0660 create ram9 b 1 9 root:disk 0660 create ram10 b 1 10 root:disk 0660 create ram11 b 1 11 root:disk 0660 create ram12 b 1 12 root:disk 0660 create ram13 b 1 13 root:disk 0660 create ram14 b 1 14 root:disk 0660 create ram15 b 1 15 root:disk 0660 create ram16 b 1 16 root:disk 0660 create ram -> ram1 create loop0 b 7 0 root:disk 0660 create loop1 b 7 1 root:disk 0660 create loop2 b 7 2 root:disk 0660 create loop3 b 7 3 root:disk 0660 create loop4 b 7 4 root:disk 0660 create loop5 b 7 5 root:disk 0660 create loop6 b 7 6 root:disk 0660 create loop7 b 7 7 root:disk 0660
The output is in two parts - the command to mknod and the options to commands like chmod that MAKEDEV runs after mknod. The data then needs to be remapped to a device table layout.
create loop7 b 7 7 root:disk 0660
The device table layout is:
DEVICE TYPE MODE UID GID MAJOR MINOR START INC COUNT /dev/loop b 660 0 0 7 0 0 1 2
(MINOR == 0 unless specified.)
The command needs to be parsed to:
mknod -m MODE DEVICE TYPE MAJOR MINOR chown UID:GID DEVICE
or
mknod -m 0660 loop7 b 7 7 chmod root:disk loop7
We start the parsing:
/dev/loop7 b 0660 root disk 7 0 0 0 -
Traditionally, device tables use the numerical UID instead of the username - lookuping the UID for the user in /etc/passwd and the GID for the group in /etc/group, gives a line:
/dev/loop7 b 0660 0 6 7 0 0 0 -
The full table for std would then be:
/dev d 755 0 0 - - - - - /dev/mem c 0640 0 15 1 1 0 0 - /dev/kmem c 0640 0 15 1 2 0 0 - /dev/null c 0666 0 0 1 3 0 0 - /dev/port c 0640 0 15 1 4 0 0 - /dev/zero c 0666 0 0 1 5 0 0 - /proc/kcore s /dev/core - - - - - - - /dev/full c 0666 0 0 1 7 0 0 - /dev/random c 0666 0 0 1 8 0 0 - /dev/urandom c 0666 0 0 1 9 0 0 - /dev/tty c 0666 0 5 5 0 0 0 - /dev/ram b 0660 0 6 1 0 0 1 16 /dev/ram1 s /dev/ram - - - - - - - /dev/loop b 0660 0 6 7 0 0 1 7
Notes:
- The repetition shortens the table
Symlinks are created by the device table - the name must exist, the target will be created using the string given in the mode column. i.e. (ln -s /proc/kcore core)
Symlinks and hardlinks are an extension to other device tables - if you use symlinks or hardlinks, ensure you use /usr/share/multistrap/device-table.pl as your parser.
- All lines have ten columns, separated with a single tab and nothing else
- Take care copying and pasting from this wiki page - replace all spaces only with a single tab for each column.
- Comments can be added - start each comment with #
If you want device-table.pl to create the top level /dev/ directory, make sure that your device table includes a d type command to create it at the top of the table.