Linux Containers - /proc mounting and other queries


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Linux Containers - /proc mounting and other queries
# 1  
Old 12-02-2018
Linux Containers - /proc mounting and other queries

Hi guys, I am confused about how containers work in Linux, especially how chrooting works and about how /proc filesystems are mounted.

So please feel to migrate this question to another forum if this is not the right one.

Now, to business.

Okay Dockers can be confusing to the uninitiated especially when everyone thinks that they are just lightweight VMs. A good talk on youtube helped me get a clearer picture. It is "Build your own container from scratch".

It showed a lot of useful things namespace creation, but where I really got confused was when the virtual filesystem /proc had to be mounted to a separate directory.

I have am completely confused about how this works the way it does.

The part that confused was this in the video.

Questions are as follows:
  • Can't ps be namespaced? As in it will by default show the process in the current namespace from which it can be invoked from?
  • When we mount /proc into another new rootfs are we creating a new /proc for the namespace or are we creating a new /proc for that namespace?
  • I don't have much idea about Linux virtual filesystems, but I believe it is a way for the kernel to communicate information to the user space. If that is correct, then does that mean that when we have a new /proc mounted the kernel is now writing out to two different /proc directories? I am really confused with this.
  • I have used chroot to get into a system for repair purposes but I have not completely understood most of it. Take for instance when I mount the /proc from my LiveCD into a broken OS, that is just mapping my existing /proc into the broken OS, it does not create a new /proc AFAIK. Does that have any similarity to what is shown on the video here, or are we creating a new /proc. Which does not make sense since container processes are also can be viewed from the host.

Please let me know if any further information is required from my side.
# 2  
Old 12-02-2018
ps looks into /proc, so having a namespace in /proc is the correct way.
(Having a namespace in ps would be inconsistent.)

Each mount of /proc is a new interface to the kernel. There is no "fowarding" of an existing mount. The only mount forwarding is the bind mount (it should work with all file system types including /proc).

/proc works a bit like /dev where each file is a driver.
The kernel is not writing out but mapping out. If you access a file it is actually written out.
# 3  
Old 12-03-2018
Quote:
Originally Posted by MadeInGermany
ps looks into /proc, so having a namespace in /proc is the correct way.
(Having a namespace in ps would be inconsistent.)
Is there any documentation that tells how /proc behaves when given a namespace? Also can a system have /proc mounted on 2 different places? How is that even allowed?

Quote:
Originally Posted by MadeInGermany
Each mount of /proc is a new interface to the kernel. There is no "fowarding" of an existing mount. The only mount forwarding is the bind mount (it should work with all file system types including /proc).
Could you please explain what you mean by "forwarding" of a an existing mount point? Also what is the difference between a normal mount and a bind mount? No one has clear answer for that.

Quote:
Originally Posted by MadeInGermany
/proc works a bit like /dev where each file is a driver.
The kernel is not writing out but mapping out. If you access a file it is actually written out.
What do you mean by "mapping out" ? Does that mean that whenever I query /proc the kernel actually "puts" information there for the program that is querying the info?
# 4  
Old 12-03-2018
Quote:
Originally Posted by sreyan32
Hi guys, I am confused about how containers work in Linux, especially how chrooting works and about how /proc filesystems are mounted.
You already got some excellent answers to your questions at hand but you might profit from a little "theory" behind all that, so here it goes:

Whenever we talk about virtualisation we need to keep in mind that there are to fundamentally different ways of doing so: "full virtualisation" and "para-virtualisation".

Full-virtualisation is what i.e. VMWare or the DOSbox emulator do: a program is started which emulates a certain hardware platform. On this emulated hardware an OS is installed and "runs" more or less independently from the host hardware. The advantage this has is that you can mix arbitrary platforms because it only depends on the availability of the emulator programs. You can install a PC-emulator onto Linux and run a WIndows guest in it, start it a second time and install another Linux to it, then start a third instance and install DOS onto that. Fully virtualised systems are not "aware" that they are virtualised. For the virtualised system it is like running on non-virtualised hardware.

Para-virtualisation on the other hand, does not work like this: hardware is only emulated up to a certain point. For instance, take the file system driver: if you work on a real disk you need to do all sorts of checks inside this driver because disk blocks could be failing, filesystems can get corrupted, etc.. The driver makes up for that to some extent by these checks. Now, a fully virtualised system has usually a fully virtualised disk which is in fact a file in the host systems filesystem. The driver of the virtualised machine wouldn't have to do all these checks because "under" it the disk driver of the host system (which really does the writing) will do it anyway. A para-virtualised disk driver is "aware" that it works on virtual hardware so it skips all these checks (and a lot of other unnecessary work) which makes the load the emulation places on the host system considerably lighter. The same goes for network drivers, etc.. The final development in this is to have not even a separate kernel for the guest OS but set aside some "space" in the host kernel where all the processes of the guest system go. At this point we usually do not call the guest systems "guest systems" any longer but call these "containers". The big advantage of paravirtualised systems is: the load produced by emulating the hardware itself is much lighter than in fully virtualised systems, so you get to run more guest systems from a given amount of host resources. On the downside, having only one kernel for all guests means that you can't have different OSes running but are limited to what the host system runs. Examples for para-virtualisation software are OpenVZ/Virtuozzo but also Docker.

What is chroot and how does it enter the picture: UNIX, since its earliest stages, has the chroot command, which creates a system environment limited to some separated part of the filesystem. Historically this was done to be able to safely operate FTP servers: in a certain directory a replica of the (important parts of the) main filesystem (like /usr/lib, /bin, etc.) was created and the absolute minimum of libs, commands, etc. were placed there. Then the FTP server process was started in a way so that this directory was the "root" of tis environment and it could not access any other file outside of this. This was done with the chroot command. This way users could access the FTP server and transfer files to ad from it - they might even mess up the FTP server itself, but this "chrooted" part only, not the "underlying" system. Para-virtualised guest systems - in specific containers - more or less resemble this and para-virtualisation is therefore sometimes regarded as "richly dressed up chroot environment".

I hope that connects a few loose ends.

bakunin

Last edited by bakunin; 12-03-2018 at 10:10 AM.. Reason: typo
# 5  
Old 12-03-2018
Quote:
Originally Posted by sreyan32
Is there any documentation that tells how /proc behaves when given a namespace? Also can a system have /proc mounted on 2 different places? How is that even allowed?
Try yourself:
Code:
mount -t proc proc /mnt
mount | grep proc
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
proc on /mnt type proc (rw,relatime)
ls /mnt
ls /proc

After your tests do not forget to umount the 2nd mount point
Code:
umount /mnt

Quote:
Originally Posted by sreyan32
ICould you please explain what you mean by "forwarding" of a an existing mount point? Also what is the difference between a normal mount and a bind mount? No one has clear answer for that.
Hard to explain. An example is a disk mount (filesystem like ext3,ext4,reiserfs,xfs,...), that is only allowed once, because writes to the two mount points would cause a corruption in the filesystem on the disk. But: a bind mount of the primary disk mount to another mount point is allowed; all writes occur at the primary mount point.

Quote:
Originally Posted by sreyan32
IWhat do you mean by "mapping out" ? Does that mean that whenever I query /proc the kernel actually "puts" information there for the program that is querying the info?
Yes, at least the contents of the files is created by a little kernel routine when accessed. Some files are even reverse-handled: by writing a value into it, the kernel routine patches the corresponding location in kernel memory.
# 6  
Old 12-07-2018
Quote:
Originally Posted by bakunin
You already got some excellent answers to your questions at hand but you might profit from a little "theory" behind all that, so here it goes:

I hope that connects a few loose ends.

bakunin
It does connect a few loose ends. But I really didn't think docker was a para-virtualization product. I thought they were just implemented as jailed processes.

AFAIK Docker mainly uses Linux Namespaces and Cgroups to create a virualized environment for execution.

One more thing that is bugging me is : When you install a software within a docker container does it get installed into the host OS also? Intution tells me that is how it should be since a Docker mainly shares the host kernel. If so, then shouldn't it share the host package management system.

Where this logic falls apart is when on an Ubuntu system we can run a Debian or Alpine docker. How is that possible? How can debian binaries even run on an Ubuntu system?

Lastly, why does docker need the root filesystem of the OS that it is trying to emulate on disk? What does it mean to have a rootfs of an OS and again how can utilities within in run an another OS. This refers mostly to the video that I have linked in my original question. If it is at all possible please watch it ( I have marked the actual place where it got generated)- you will know why I am getting confused.

--- Post updated at 04:47 PM ---

Quote:
Originally Posted by MadeInGermany
Hard to explain. An example is a disk mount (filesystem like ext3,ext4,reiserfs,xfs,...), that is only allowed once, because writes to the two mount points would cause a corruption in the filesystem on the disk. But: a bind mount of the primary disk mount to another mount point is allowed; all writes occur at the primary mount point.
Didn't get what you explained. Let me tell you of what idea I have of the Linux mount process then may be you will get a better idea of why I am failing to grasp the concept.

Any block device that the kernel identifies can be mounted to a location in the VFS. The location, which is just a directory is called a mount point.

Now one question is that can an already mounted device be mounted twice? A partition that is mounted twice? If so I don't see why it would cause corruption as you say it would. You writing to the same block device, the kernel just identifies it to the user by 2 mount points.

Next, is what is a primary mount point? Is the first mount of the block device? Can a mount point be mounted again? Why would you want to do that?

Where does bind mount fit into all of this?
# 7  
Old 12-07-2018
The filesystem driver can deny a second mount. But in fact ext3, ext4, xfs allow mutiple primary mounts.
Code:
# ls -ldi /boot /mnt
     2 drwxr-xr-x  4 root root 3072 May 24  2014 /boot
260609 drwxr-xr-x  5 root root 4096 Sep 25 11:40 /mnt
# df /boot
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1               101146     37017     58907  39% /boot
# mount /dev/sda1 /mnt
# ls -ldi /boot /mnt
2 drwxr-xr-x  4 root root 3072 May 24  2014 /boot
2 drwxr-xr-x  4 root root 3072 May 24  2014 /mnt
# mount | grep /dev/sda1
/dev/sda1 on /boot type ext3 (rw)
/dev/sda1 on /mnt type ext3 (rw)
# umount /mnt

The same exercise with a bind mount:
Code:
# mount --bind /boot /mnt
# ls -ldi /boot /mnt
2 drwxr-xr-x  4 root root 3072 May 24  2014 /boot
2 drwxr-xr-x  4 root root 3072 May 24  2014 /mnt
# mount | grep /dev/sda1
/dev/sda1 on /boot type ext3 (rw)
# mount | grep /mnt
/boot on /mnt type none (rw,bind)
# umount /mnt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Looking for equivalent of Solaris containers/zones in RHEL7 Linux

Hi, I come from a legacy Solaris background with lots of experience with Solaris Containers/zones that we use for network and process isolation from each other. Currently we have a RHEL7 Linux VM running on VMWare, but we would like to segment that VM with some form of containers and achieve... (1 Reply)
Discussion started by: ckmehta
1 Replies

2. IP Networking

IP Address Linux Containers

Hello All, Please, i have a problem i try to find a solution since days i'm a beginner with linux (networking) In our cluster (10 nodes), we deploy the same image file on each node. So each node has a different ip address. In each image, there are several LXC containers. When I deploy the... (0 Replies)
Discussion started by: chercheur111
0 Replies

3. Programming

Linux 11.2 to 10.2 Proc Compile error

I am trying to compile a proc++ program on linux using an 11.2 client and pointing to a 10.2 database running on Solaris. The compiler is able to connect to the database but the semantic checks fail as if it cannot see any objects in the database. I tried a test, only selecting 'X' into a... (0 Replies)
Discussion started by: rdudash
0 Replies

4. Linux

Tripwire Nightware on Linux (proc filesystem)

Hello, I am having a nightmare with Tripwire on Linux..... I cannot get it to ignore the /proc filesystem, which I want to completely ignore for now Has anyone here successfully configured Tripwire on Linux and completed ignored the /proc filesystem ? If so, please reply and tell me how... (0 Replies)
Discussion started by: Neo
0 Replies

5. UNIX for Dummies Questions & Answers

_/proc/stat vs /proc/uptime

Hi, I am trying to calculate the CPU Usage by getting the difference between the idle time reported by /proc/stat at 2 different intervals. Now the 4th entry in the first line of /proc/stat will give me the 'idle time'. But I also came across /proc/uptime that gives me 2 entries : 1st one as the... (0 Replies)
Discussion started by: coderd
0 Replies

6. Linux

Kernal panic error& setuproot:error mounting /proc&/sys

Hi all, I am new to redhat/fedora linux. In fedora linux 6,we created one file system(hda3 - /fs). in this mount poing we were installed mounta vista os. while booting we are getting below error messages. 1) Booting 'mountaVisat(2.6.18_pro 500_pc_target-x86_586 smp)' root(hd0,1)... (2 Replies)
Discussion started by: arjunreddy3
2 Replies

7. Red Hat

mounting ISO in linux

Hi Guys, I'm having a bit of trouble and im not sure what is the deal, I'm trying to mount an ISO on my RHEL box and it is not letting me... mount -o loop -t iso9660 /home/bgalante/rhel-5-server-i386-disc3.iso /mnt mount: Not a directory any idea what i am doing wrong? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

8. OS X (Apple)

mounting linux

firstly... sorry xDDD. now, how could i mount a linux partition on my mac os x ( i assume ill use terminal). i begins... i have my ubuntu linux partition on disk0s4. i tried: sudo mount /dev/disk0s4 /Volumes/Ubuntu and the system told me ;), "mount: exec /usr/sbin/mount_ext for... (1 Reply)
Discussion started by: Jariya
1 Replies

9. UNIX for Dummies Questions & Answers

CD mounting problems with linux

Hi guys I'm a newbie with linux i recently installed mandrake linux 10.0 double boot(win 98se) on a pIII 300mhz 128mb ram PC I have a standard cd rom and for some reason, linux refuses to mount the CD drive it worked perfectly for the first cople of monthes and than suddenly it didn't it... (0 Replies)
Discussion started by: bentzi
0 Replies

10. UNIX for Advanced & Expert Users

mounting /proc or /usr

i am not quite sure what the purpose of mounting a filesystem that is already mounted.. i know you may want to mount /usr read only but do not know the true purpose behind this.. and why would /proc be mounted on /proc itself.. this is all new to me.. I have been reading up on it from various... (5 Replies)
Discussion started by: moxxx68
5 Replies
Login or Register to Ask a Question