Skip to contentSkip to conversation

udev: what's up with old /dev ?

DISCUSSION J.A. Magallon 10 participants 21 messages Oct 10, 2004 – Oct 13, 2004 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Hi all...

I have just remembered that udev mounts /dev as a tmpfs filesystem, _on top_ of the old /dev directory. I have just booted to single user mode, and checked that the old /dev is wasting around 13000 files (inodes) in my box. Space is not an issue, that is around 480 Kb.

A couple questions:

- Is it possible to boot with an empty /dev, until udev builds it ?
- If this is not the case, which are the minimal nodes that should be present ?
- For any answer to previous question, shouldn't the distro set up minimal /dev (empty or with a few nodes) and _delete_ the old /dev tree ?

I don't remember exactly, but there are scripts at initscripts run before udev. As I understand it, udev should be the very first thing to run, as anything after it will probably need a /dev/something....

Why my simple logic does not work ?

(As I CC both cooker and LKML, this is a cooker specific question: could anybody who has installed 10.1 from scratch, ie not an update, boot to runlevel 1 and list his /dev)

TIA

--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandrakelinux release 10.1 (Community) for i586
Linux 2.6.9-rc3-mm3 (gcc 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)) #2

#1 lore raw
Quoted 4 lines

- Is it possible to boot with an empty /dev, until udev builds it ?
- If this is not the case, which are the minimal nodes that should be present ?

Having just done this experiment myself: With kernel 2.6.8, udev 034, Debian unstable's init scripts, and no initramfs or initrd, it suffices to have /dev/console and /dev/null in the root filesystem's /dev.

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs. Thus, the only way to avoid having that node on the root filesystem would be to set up udev from initrd or initramfs. I'm sure that's possible but I don't know how to do it; and the boot scripts that exist right now in Debian unstable are not set up to handle that case.

It may not be necessary to have /dev/null on the root filesystem; I didn't try that. Libc and the shell frequently open /dev/null behind one's back, so I suspect it is wanted before udev starts up.

I have no idea what distros are planning in this area.

zw

#2 lore raw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init that could run udev before it does anything else?

Signature · 2 lines
Melior amare chemia
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
#3 lore raw
Quoted 4 lines · Hacksaw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init that could run udev before it does anything else?

I don't think it is needed. There is no problem (i am thinking on rootles nodes and PXE and so on...) on building a simple initrd with /dev/console, /dev/null and half a dozen standard devices if they are needed. Just to get udev run and have your real devices mounted there and overwrite them.

I just remember one other oddity. To clean up my system, I copied the running /dev to /dev-new, moved /dev to /dev-old and /dev-new to /dev. But on 'reboot', I got a complaint about /dev/initctl not opening. This could happen also with init. It opens real /dev/initctl on boot, mounts /dev and tries to use new /dev/inittclt on shutdown...

--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandrakelinux release 10.1 (Community) for i586
Linux 2.6.9-rc3-mm3 (gcc 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)) #2

#4 lore raw
Quoted 3 lines

I don't think it is needed. There is no problem (i am thinking on rootles nodes and PXE and so on...) on building a simple initrd with /dev/console, /dev/null

I'm looking for no initrd. I'm not a fan of them. It seems like having to use an electric drill to start your car.

I like the idea that someone could accidentally scribble all over /dev, and on reboot the system would just rebuild it. It makes /dev less of a vulnerability.

Signature · 3 lines
Sleepy, Dopey, Sneezy, Bashful, Grumpy, Happy, Doc
Just in case you'd forgotten...
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
#5 lore raw
In reply to J.A. Magallon
Quoted 14 lines · J.A. Magallon
Quoted 5 lines · Hacksaw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init that could run udev before it does anything else?

I don't think it is needed. There is no problem (i am thinking on rootles nodes and PXE and so on...) on building a simple initrd with /dev/console, /dev/null and half a dozen standard devices if they are needed. Just to get udev run and have your real devices mounted there and overwrite them.

Quoted 5 lines

I just remember one other oddity. To clean up my system, I copied the running /dev to /dev-new, moved /dev to /dev-old and /dev-new to /dev. But on 'reboot', I got a complaint about /dev/initctl not opening. This could happen also with init. It opens real /dev/initctl on boot, mounts /dev and tries to use new /dev/inittclt on shutdown...

What /dev/initctl? Why do you have a pipe in a directory which supposed to have device nodes only?

Get better init.
--
vda

#6 lore raw
In reply to Hacksaw
Quoted 5 lines · Hacksaw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init that could run udev before it does anything else?

FC3t2 boots from an "initrd" image that, among other things, mounts a tmpfs over "/dev" and creates "console", "null", "pts" and then proceeds to load "init".

#7 lore raw
Quoted 11 lines · Felipe Alfaro Solana
Quoted 6 lines · Hacksaw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init
that could run udev before it does anything else?

FC3t2 boots from an "initrd" image that, among other things, mounts a tmpfs over "/dev" and creates "console", "null", "pts" and then proceeds to load "init".

... and it ignores root= kernel cmdline option. rootfs is hardcoded in initrd which is very ugly.

Creating /dev entries on rootfs from initrd without hardcoding rootfs device is quite problematic.

Signature · 2 lines
Arkadiusz Miśkiewicz                    PLD/Linux Team
http://www.t17.ds.pwr.wroc.pl/~misiek/  http://ftp.pld-linux.org/
#8 lore raw
Quoted 9 lines · Arkadiusz Miskiewicz
Quoted 8 lines · Felipe Alfaro Solana
Quoted 6 lines · Hacksaw
Quoted 2 lines

The very first thing init does is open /dev/console, and if it doesn't exist the entire boot hangs.

This raises a question: Would it be a useful thing to make a modified init
that could run udev before it does anything else?

Quoted 5 lines
Quoted 3 lines

FC3t2 boots from an "initrd" image that, among other things, mounts a tmpfs over "/dev" and creates "console", "null", "pts" and then proceeds to load "init".

... and it ignores root= kernel cmdline option. rootfs is hardcoded in initrd which is very ugly.

I haven't seen any hardcoded root filesystem reference in the INITRD image. Instead, I see "/dev/root" which is supposed to be exactly the root filesystem passed to the kernel via "root=".

#9 lore raw
In reply to Felipe Alfaro Solana
Quoted 3 lines

FC3t2 boots from an "initrd" image that, among other things, mounts a tmpfs over "/dev" and creates "console", "null", "pts" and then proceeds to load "init".

Is that considered good? I like RedHat, but they are well known for doing things of dubious taste.

But I just dislike the whole "stopped dead because of the state of the disk" thing. I mean, sure, if there large amounts of stuff just missing, it might be hard to get anything done, but it sure would be nice if the kernel would try really hard to get to a shell so I can figure out what the problem is.

If the initrd gets corrupted, are we just hosed?

Signature · 2 lines
Is qui iacit in hamas marsupiales.
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
#10 lore raw
Quoted 7 lines · Hacksaw
Quoted 3 lines

FC3t2 boots from an "initrd" image that, among other things, mounts a tmpfs over "/dev" and creates "console", "null", "pts" and then proceeds to load "init".

Is that considered good? I like RedHat, but they are well known for doing things of dubious taste.

Quoted 6 lines

But I just dislike the whole "stopped dead because of the state of the disk" thing. I mean, sure, if there large amounts of stuff just missing, it might be hard to get anything done, but it sure would be nice if the kernel would try really hard to get to a shell so I can figure out what the problem is.

If the initrd gets corrupted, are we just hosed?

In some way, the answer is yes... I think the best is having a real, on-disk, full "/dev" hierarchy in case the INITRD gets lost or corrupted, which will still allow booting. Now, the INITRD can mount tmpfs over "/dev" and use udev to create needed device nodes.

#11 lore raw
Quoted 6 lines
Quoted 1 line

If the initrd gets corrupted, are we just hosed?

In some way, the answer is yes... I think the best is having a real, on-disk, full "/dev" hierarchy in case the INITRD gets lost or corrupted, which will still allow booting. Now, the INITRD can mount tmpfs over "/dev" and use udev to create needed device nodes.

And see, this is where I say, what if /dev is hosed too? If the kernel at this point gives up, then the user has to dig up a boot CD or something worse and start trying to fix the system.

If, however, the kernel just made /dev/console and maybe /dev/null, it could start a shell and say "/dev missing /console device, initrd corrupted. Hit enter for a shell or ctrl-alt-del to reboot."

As a sys-admin, I'd like that. Get me into single user mode the best you can. If a shell can be found, that's good enough.

Signature · 3 lines
The best is the enemy of the good  -- Voltaire
The Good Enough is the enemy of the Great -- Me
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
#12 lore raw
Quoted 10 lines · Hacksaw
Quoted 6 lines
Quoted 1 line

If the initrd gets corrupted, are we just hosed?

In some way, the answer is yes... I think the best is having a real, on-disk, full "/dev" hierarchy in case the INITRD gets lost or corrupted, which will still allow booting. Now, the INITRD can mount tmpfs over "/dev" and use udev to create needed device nodes.

And see, this is where I say, what if /dev is hosed too? If the kernel at this point gives up, then the user has to dig up a boot CD or something worse and start trying to fix the system.

What if kernel image is hosed instead?

Having corrupted initrd is not so diffirent from having corrupted kernel image and usually they are both located on the same medium...

Quoted 12 lines

If, however, the kernel just made /dev/console and maybe /dev/null, it could start a shell and say "/dev missing /console device, initrd corrupted. Hit enter for a shell or ctrl-alt-del to reboot."

As a sys-admin, I'd like that. Get me into single user mode the best you can. If a shell can be found, that's good enough.
--
The best is the enemy of the good -- Voltaire
The Good Enough is the enemy of the Great -- Me

http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD

#13 lore raw
Quoted 1 line

What if kernel image is hosed instead?

Well, there's only so far we can go. If the alternator on a car is bad, we can run on the battery for a little bit to get to the auto parts store. If the engine is cracked, we're going to need an engine hoist and a good mechanic. :-)

Quoted 2 lines

Having corrupted initrd is not so diffirent from having corrupted kernel image and usually they are both located on the same medium...

The hosing I am imagining is one done by the fat fingers of the sys-admin, not so much because of disk corruption.

Signature · 1 line
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
#14 lore raw
In reply to J.A. Magallon
Quoted 4 lines · J.A. Magallon

Hi all...

I have just remembered that udev mounts /dev as a tmpfs filesystem, _on top_ of the old /dev directory.

Well, that's the way _your_ distro does it. Mine has an empty /dev on the root filesystem, and the init scripts create a ramfs on top of /dev at boot time, which udev fills up.

thanks,

greg k-h

#15 lore raw
Quoted 4 lines · Greg KH
Quoted 2 lines · J.A. Magallon

Hi all...

Quoted 8 lines
Quoted 2 lines

I have just remembered that udev mounts /dev as a tmpfs filesystem, _on top_ of the old /dev directory.

Well, that's the way _your_ distro does it. Mine has an empty /dev on the root filesystem, and the init scripts create a ramfs on top of /dev at boot time, which udev fills up.

I don't like this "my distro is better than yours". Any pointer to some code online?

Thanx very much

Harri

#16 lore raw
Quoted 10 lines · Harald Dunkel
Quoted 9 lines · Greg KH
Quoted 5 lines · J.A. Magallon

Hi all...

I have just remembered that udev mounts /dev as a tmpfs filesystem, _on top_
of the old /dev directory.

Quoted 5 lines
Quoted 3 lines

Well, that's the way _your_ distro does it. Mine has an empty /dev on the root filesystem, and the init scripts create a ramfs on top of /dev at boot time, which udev fills up.

I don't like this "my distro is better than yours".

I'm not trying to imply this at all. All I'm saying is this is a distro specific issue, not a kernel issue, so it isn't a linux-kernel topic.

Quoted 1 line

Any pointer to some code online?

Look at the gentoo init package, or read the documentation in the udev tarball for how to do this for Red Hat. I've successfully done this on both distros.

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#21 lore raw
Quoted 17 lines · Greg KH
Quoted 11 lines · Harald Dunkel
Quoted 2 lines · Greg KH

Yeah, the documentation is out there, somewhere...

What I really do not like for initramfs is that the cpio file is compiled into the kernel. Extremely unflexible. Why should I use modules then?

Is it possible to load the initramfs like an initrd on the grub command line?

Why post this in private?

Quoted 8 lines

Care to ask this on the linux-kernel mailing list and CC me? That way I can answer it in public to enable everyone else to know the answer, and let the search engines pick it up.

thanks,

greg k-h

Sorry, somewhere in this thread I had clicked the wrong reply button.

Talking about initramfs: I am still trying to become familiar with this stuff. I have found a lot of small pieces of information (still reading), and the cpio stuff in the kernel usr directory. But I have 2 questions:

Why is the initramfs built at the beginning of the kernel build procedure? Wouldn't it be more reasonable to build it when all kernel modules are available?

And why is it compiled into the kernel at all? The README in Documentation/early-userspace says

<quote>
"Early userspace" is a set of libraries and programs that provide various pieces of functionality that are important enough to be available while a Linux kernel is coming up, but that don't need to be run inside the kernel itself.
</quote>

So why compile it into the kernel? IMHO it would be more flexible to load the early-userspace stuff similar to initrd via the grub command line. Compiling it into the kernel could be optional.

Regards

Harri

#22 lore raw

"Harald Dunkel" <[email protected]> disait dernièrement que :

Quoted 6 lines
Quoted 1 line · Greg KH

On Tue, Oct 12, 2004 at 10:16:54PM +0200, Harald Dunkel wrote:

Sorry, somewhere in this thread I had clicked the wrong reply button.

Quoted 8 lines

Talking about initramfs: I am still trying to become familiar with this stuff. I have found a lot of small pieces of information (still reading), and the cpio stuff in the kernel usr directory. But I have 2 questions:

Why is the initramfs built at the beginning of the kernel build procedure? Wouldn't it be more reasonable to build it when all kernel modules are available?

because for now, the initramfs built into the kernel is quasi-empty and isn't used as-is.

Quoted 10 lines

And why is it compiled into the kernel at all? The README in Documentation/early-userspace says

<quote>
"Early userspace" is a set of libraries and programs that provide various pieces of functionality that are important enough to be available while a Linux kernel is coming up, but that don't need to be run inside the kernel itself.
</quote>

the last statement just says it does not run in _kernelspace_ but in _userspace_.
it has to be in the kernel.
I use it to mount my dm-crypt'd / and no initrd is needed. (well as I wasn't able to get a small cryptsetup binary, my kernels are ~1850kB worth of size)

Quoted 4 lines

So why compile it into the kernel? IMHO it would be more flexible to load the early-userspace stuff similar to initrd via the grub command line. Compiling it into the kernel could be optional.

huh, well initrd is / that is mounted over the so-called _rootfs_ initramfs is here to _be_ that rootfs. So no pivot_root needed and the run-it program included in klibc tarballs takes care of wiping-out everything that could waste memory into the initramfs before mounting the real /. If it was to compiled out of the kernel, it would just be an initrd....

rootfs is _needed_ for mounting the real root, so is initramfs.

have a nice day,

Mathieu

Signature · 4 lines
"My pan plays down an unprecedented amount of our national debt."

George W. Bush
February 27, 2001
Quoted 1 line

From a speech concerning the proposed federal budget.

#23 lore raw
Quoted 8 lines · Mathieu Segaud

huh, well initrd is / that is mounted over the so-called _rootfs_
initramfs is here to _be_ that rootfs. So no pivot_root needed and the run-it
program included in klibc tarballs takes care of wiping-out everything that
could waste memory into the initramfs before mounting the real /. If it was to compiled out of the kernel, it would just be an initrd....

rootfs is _needed_ for mounting the real root, so is initramfs.

So the kernel boots, activates the initramfs somehow to become the first /, and then starts /sbin/init (e.g. kinit from the klibc package).

And then?

The sources of kinit show that its job is parse the kernel command line arguments, configure the NIC, mount the root filesystem via NFS, etc. Other configurations might require a different init to start hotplug and udev, or to handle the LVM and crypto magic, for example. My point is that if there is no one-for-all init process to handle _every_ possible startup procedure, then it might be necessary to rebuild the initramfs. This would be easier (and easier to test) if initramfs is not compiled into the kernel, but a separate image to be loaded at boot time "somehow".

Or did I miss something?

Regards

Harri

#24 lore raw

"Harald Dunkel" <[email protected]> disait dernièrement que :

Quoted 14 lines

And then?

The sources of kinit show that its job is parse the kernel command line arguments, configure the NIC, mount the root filesystem via NFS, etc. Other configurations might require a different init to start hotplug and udev, or to handle the LVM and crypto magic, for example. My point is that if there is no one-for-all init process to handle _every_ possible startup procedure, then it might be necessary to rebuild the initramfs. This would be easier (and easier to test) if initramfs is not compiled into the kernel, but a separate image to be loaded at boot time "somehow".

yep to test it would be helpful. To setup mine, it took not long, but sure such a facility could help. But you know, if you do not run make clean, and you have edited usr/Makefile to not rebuild initramfs, puting your custom cpio archive into usr and typing 'make' won't take long to rebuild the new kernel :) I did that to get it working.

As to know if having an external archive file loaded by grub or so, I don't know much that part of the kernel code... Hum, I really did not try to under- stand the code involving initrd's and initramfs in init/do_mounts_initrd.c. I wonder whether putting an executable /init in an initrd is sufficient to have it recognized as an initramfs and not an initrd....

The important thing is /init executable script in initramfs, this is what tells the kernel to override the "standard" way it boots.

Mathieu

Signature · 3 lines
The policy is not to have policy. It works as well in kernel design as politics.

	- Alan Cox on linux-kernel