LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-02-2012, 10:59 PM   #1
4dummies
LQ Newbie
 
Registered: May 2009
Location: Central coast of California.
Distribution: Xubuntu
Posts: 10

Rep: Reputation: 1
What is really in /dev when the system is off?


Background: I'm using Ubuntu and Xubuntu, and I'm working on bash scripts to back up my various systems.

I take the backups on a live system, mostly, and live with the consequences.

I'm aware that udev, or whatever is current along those lines, creates most of the device entries in the /dev directory on the fly, and they therefore not only are not needed in a backup, but they might even be harmful. I'm also under the impression that there are some entries that are in there on disk, that never go away. This leads to my questions:

Is it always the same ones that are permanent entries on disk?
Is there a list of them somewhere? Better, is there a program to generate them?
Is there anything else about these that I should know?
Should I be asking this in another place?

++ 4dummies
 
Old 05-03-2012, 04:20 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
/dev is created/generated/populated during the boot, the system is scanned and all the available hardwares are listed (and also you can have pseudo or virtual devices ...)
 
Old 05-03-2012, 05:17 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,688
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
...and as for your title question of
Quote:
Originally Posted by 4dummies View Post
What is really in /dev when the system is off?
that would be easy to find out: boot another Linux distribution if you have one on disk or else boot an installer or Live CD, mount the file system and 'ls -al' /mountpoint/dev.
 
1 members found this post helpful.
Old 05-03-2012, 06:07 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,651
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
AFAIK, on modern distributions the /dev directory is mounted to a (dev)tmpfs, so the /dev directory should be empty.
 
Old 05-04-2012, 10:51 AM   #5
4dummies
LQ Newbie
 
Registered: May 2009
Location: Central coast of California.
Distribution: Xubuntu
Posts: 10

Original Poster
Rep: Reputation: 1
Question I'd like corroboration

Thanks for answers. However, let me clarify...

I also understood that the on-disk /dev could be empty, but when I went to look using a live disk, it was not empty but had IIRC entries for serial ports of various speeds, floppies of different layouts, and some other stuff. Now, I've had this machine for a long time, through periods of change for the handling of /dev, and don't remember everything I've ever done to it or with it, so I don't know if that's an artifact of my incompetence or the way it should be.

If anyone running Ubuntu can do it, I'd really appreciate a report of what's in their /dev directory when booting from a different partition or from a live disk.
 
Old 05-04-2012, 02:32 PM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
/dev, /sys, /proc are all, shall we say, "phantom" file-systems. They behave like a directory, and the contents of the same might behave like files, but in fact when you interact with them you are interacting with the Linux kernel itself. If you, say, cat /proc/12345/cmdline (or what have you ...), the kernel provides you with this information on-the-fly (if you are authorized to see it).

This is, in other words, a particularly elegant and convenient way to rendezvous with the system in quest of various kinds of information. These "directories" are what has also been called namespaces, and requests to (read | write | control) a particular "file" or "directory" (i.e. name...) in that namespace, actually corresponds to a system call.
 
Old 05-05-2012, 08:02 PM   #7
dru8274
Member
 
Registered: Oct 2011
Location: New Zealand
Distribution: Debian
Posts: 105

Rep: Reputation: 36
It doesn't surprise me that the dev directory is not empty. But to understand why, I think you would need to look into the bootup process. What happens between when "init", the very first process is started, and when the udev daemon is started?

I surmise that those persistent entries in /dev must represent access to kernel resources that are needed prior to when the udev daemon is activated.

And I think the same is true of initramfs. Initramfs are basically very small OS, and very similar to the larger system. And if you extract the contents of an initramfs, its /dev comes preloaded too.
 
1 members found this post helpful.
Old 05-06-2012, 11:40 AM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,608

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
On my Fedora and RHEL-6 clone machines, /dev in the root file system is an empty directory, and in the initramfs the only thing in dev is an empty dev/pts directory.
 
1 members found this post helpful.
Old 05-06-2012, 01:42 PM   #9
4dummies
LQ Newbie
 
Registered: May 2009
Location: Central coast of California.
Distribution: Xubuntu
Posts: 10

Original Poster
Rep: Reputation: 1
Unhappy still puzzled

Okay, so some Linux-en have populated /dev but not RedHat-derived ones. All using udev?

I'm trying to verify on my Ubuntu, but I'm not sure where to find an initramfs. I tried the initrd things in /boot, but gunzipped they appear to be cpio archives(!) according to file(1), but cpio(1) barfs on them. Please help me here.

Remember, the point of all this is that I'm writing backup scripts using tar, dd, ntfsclone and such and I want to have the right stuff in the backup.
 
Old 05-06-2012, 04:05 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,608

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
Yes, my RedHat-derived systems all use udev.

The details of what is inside the initramfs should not concern you. The /dev directory that gets built there is the one in the initial ramfs, and that all gets thrown away when the switch to the real root file system occurs. You should be able to look inside those compressed cpio archives with
Code:
zcat /boot/initramfs-{whatever}.img | cpio -itv
Those files should contain a subset of what is legal in a cpio archive, the main difference being that the kernel's built-in cpio code doesn't automatically create needed directories.

You can look inside a directory that is hidden by an active mount point by taking advantage of a bind-mount ignoring possible submounts.
Code:
mount --bind / /mnt/tmp
ls -l /mnt/tmp/dev
will show you what, if anything, was in /dev prior to the devfs pseudo-filesystem being mounted on top of it.
 
1 members found this post helpful.
Old 05-07-2012, 03:11 AM   #11
dru8274
Member
 
Registered: Oct 2011
Location: New Zealand
Distribution: Debian
Posts: 105

Rep: Reputation: 36
Quote:
Originally Posted by rknichols View Post
On my Fedora and RHEL-6 clone machines, /dev in the root file system is an empty directory, and in the initramfs the only thing in dev is an empty dev/pts directory.
Fair enough. And to be honest, I haven't actually extracted the contents of an initramfs lately.

But it is curious, because some initramfs and initrd certainly did have preloaded entries in /dev in the past. For example, this "Initrd Overview" contains a simple mkinitrd script, which shows files being added into /dev.
http://www.ibm.com/developerworks/li...rary/l-initrd/

Code:
# Grab the necessary dev files
cp -a /dev/console /mnt/initrd/dev
cp -a /dev/ramdisk /mnt/initrd/dev
cp -a /dev/ram0 /mnt/initrd/dev
cp -a /dev/null /mnt/initrd/dev
cp -a /dev/tty1 /mnt/initrd/dev
cp -a /dev/tty2 /mnt/initrd/dev
 
Old 05-07-2012, 08:55 AM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,608

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
When I look at the "init" script in my initramfs I find a bunch of mknod and mkdir commands to set up the needed entries in /dev. It's just the result of different design decisions. To me, the "Start with an empty /dev and create everything in the init script" method seems preferable since it insulates the initramfs from whatever weirdness might be present in the building system's /dev, but I don't see a strong argument either way.

There are almost always several ways to accomplish any given end. You shouldn't be surprised when not everyone follows the same path.
 
Old 05-07-2012, 09:19 AM   #13
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
One of the improvements that was made to Linux had to do with dynamic device-discovery and configuration. I remember all too well the headaches of configuring (mainframe) operating systems to match the actual device configurations that were attached to it ... and of having to rebuild the entire OS when anything changed. Even Linux used to be that way.

Now, what are colloquially called "coldplug" and "hotplug" mechanisms run automatically to detect actual installed devices at startup, and also to handle the insertion and removal of USB- and Firewire-attached devices.

The mechanisms first detect that the devices are there, then use various software-menu mechanisms to locate drivers for them.

The most extreme example of this process is what many "stock" Linux distros actually do: they boot to a sort of temporary RAMdisk with a barely-functional system that is just functional enough to "try to get any computer up-and-running successfully, no matter what might be attached to it, knowing nothing at all in advance." There are ways to simplify that process; even greatly. But they require more knowledge and intervention on your part. (I have a Linux system that goes from power-off to running in eleven seconds flat.)

Last edited by sundialsvcs; 05-07-2012 at 09:22 AM.
 
Old 05-08-2012, 12:43 PM   #14
4dummies
LQ Newbie
 
Registered: May 2009
Location: Central coast of California.
Distribution: Xubuntu
Posts: 10

Original Poster
Rep: Reputation: 1
Lightbulb Solved. as far as I'm concerned

How odd. My desktop root partition was created as Ubuntu, within the last year or so when I moved from Gentoo.

I'm using the ideas from rknichols, and find:
Ubuntu uses a different naming scheme for the initrd's (not initramfs), but the zcat | cpio mantra worked fine. There's no mention of /dev in them.

Using a bind mount, I see that the on-disk /dev has 91 entries, all from April or November of 2011. Similar to the Ubuntu release cycle, but I'm running Natty (11.04).

Anyway, this closes the issue as far as I'm concerned. I feel safe taking a backup from the bind-mount, which was the whole point of the inquiry for me. I'll --exclude /dev, and back up the bind mount separately. Right or wrong I'll have an image of what was actually there.

Thanks to all, this has been very informative.

Last edited by 4dummies; 05-08-2012 at 12:44 PM. Reason: partial subject
 
  


Reply

Tags
backups, devices, images, software


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What creates /dev/pts, /dev/loopx, and other /dev devices - Fedora Core 2 rickpo12 Linux - General 5 02-11-2012 09:50 PM
pseudo terminals: /dev/ptmx <-> /dev/pts/ vs. /dev/ptyp <-> /dev/ttyp rtspitz Linux - Software 2 12-02-2011 03:07 PM
using flash drive changes device /dev/sr0 to /dev/sr1 for mapping to /dev/pktcdvd/0? lugoteehalt Linux - Software 3 10-24-2007 11:27 AM
/dev/audio, /dev/dsp and /dev/mixer missing in Debian Etch 1337_penguin Debian 2 04-11-2007 12:33 PM
[SOLVED] system disk moves from /dev/sda to /dev/sdm gdevaucorbeil Linux - Hardware 4 03-10-2007 10:30 AM


All times are GMT -5. The time now is 01:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration