Creating /dev/root - sane approach
PATCH 1/1 Creating /dev/root - sane approach
Hi there!
As udev now supports /dev/.udev/rules.d as always writable rule location here now is my reworked apporach on creating /dev/root.
It contains one c-program to get major/minor number of a directory. And it contains a script calling this binary for directory /, and writing a rule like this to /dev/.udev/rules.d/10-root-link.rules
SUBSYSTEM=="block", ENV{MAJOR}=="8", ENV{MINOR}=="1", SYMLINK+="root"
Matthias
Signature · 1 line
Matthias Schwarzott (zzam)
extras/root_link/get_dir_major_minor.c +52 -0
@@ -0,0 +1,52 @@ +// print out major/minor nr of the device the supplied dir +// is mounted on +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation version 2 of the License. +// +// (c) 2007 Matthias Schwarzott <[email protected]> + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <stdio.h> +#include <stdlib.h> + +// Getting major/minor +#include <sys/sysmacros.h> +int main (int argc,char **argv) +{ +struct stat stat_buf; +unsigned int dev_major=0 , dev_minor=0 ; +dev_t dev; + +if (argc !=2 ) { +printf ("Usage:\n" ); +printf (" get_dir_major_minor <directory>\n" ); +return EXIT_FAILURE ; + } + +if (stat (argv[1 ], &stat_buf) <0 ) { +perror ("stat" ); +return EXIT_FAILURE ; + } + + dev = stat_buf.st_dev; + + dev_major =gnu_dev_major (dev); + dev_minor =gnu_dev_minor (dev); + + +if (dev_major ==0 ) { +fprintf (stderr,"Major number is 0.\n" ); +return EXIT_FAILURE ; + }else +printf ("%d %d\n" , + dev_major, + dev_minor); + +return EXIT_SUCCESS ; +} +
extras/root_link/Makefile +70 -0
70 lines not on this page · raw message
extras/root_link/write_root_link_rule +30 -0
@@ -0,0 +1,30 @@ +#!/bin/sh +# +# This script should run before doing udevtrigger at boot. +# It will create a rule matching the device directory / is on, and +# creating /dev/root symlink pointing on its device node. +# +# This is especially useful for hal looking at /proc/mounts containing +# a line listing /dev/root as device: +# /dev/root / reiserfs rw 0 0 +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation version 2 of the License. +# +# (c) 2007 Matthias Schwarzott <[email protected]> + +PROG=/lib/udev/get_dir_major_minor +[ -x "${PROG}" ] && DEV=$(${PROG} "/") +if [ $? = 0 ]; then + MAJOR="${DEV% *}" + MINOR="${DEV#* }" + + [ -d /dev/.udev/rules.d ] || mkdir -p /dev/.udev/rules.d + RULES=/dev/.udev/rules.d/10-root-link.rules + + echo "# Created by /lib/udev/write_root_link_rule" > "${RULES}" + echo "# This rule should create /dev/root as link to real root device." >> "${RULES}" + echo "SUBSYSTEM==\"block\", ENV{MAJOR}==\"$MAJOR\", ENV{MINOR}==\"$MINOR\", SYMLINK+=\"root\"" >> "${RULES}" +fi +
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 8 lines · Matthias Schwarzott
As udev now supports
/dev/.udev/rules.das always writable rule location here now is my reworked apporach on creating/dev/root.It contains one c-program to get major/minor number of a directory. And it contains a script calling this binary for directory /, and writing a rule like this to
/dev/.udev/rules.d/10-root-link.rulesSUBSYSTEM="block", ENV{MAJOR}="8", ENV{MINOR}="1", SYMLINK+="root"
Yep, that looks fine.
I'm working on something that allows the mounting of hotpluggable devices, which are specified in /etc/fstab. There will be something like a "nofail" option to use, in fstab which ignores missing devices. When a device listed in fstab will be connected later, it can be fsck'd and mounted by udev. For that, fstab is parsed at bootup and rules that match on NAME= and SYMLINK= will be created to trigger the mounting, so we don't need to look into fstab with every block event.
The root symlink can be added in the same step. We can at least use the same program for doing the stat("/"), even when the automounting stuff will not be used. Sounds ok?
It's "conference season", so I got a bit busy with traveling, will look into that stuff this week, I hope.
Thanks,
Kay
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel