3

I was playing with Grub from its command line, I noticed something that grabbed my intention, I listed the devices through Grub's ls command and I noticed there's a virtual device named (proc):

grub> ls 
(proc) (hd0) (hd0, msdos1)

The interesting aspect of the (proc) device is that, it contains a compressed Linux kernel, and it's structure is just like is similar to the root directory,

(grub)> ls (proc) / 
Device proc: Filesystem type procfs - Sector size 512B - Total size 0Kid
lost+found/ swapfile etc/ bin/ boot/ dev/ home/ lib/ lib64/ mnt/ opt/
vmlinuz initrd.img
--snip-- 

I conclude that (proc) is an in-memory filesystem where Grub mounts its own root filesystem, it seems to me that grub also uses proc filesystem as usually found in Linux kernel as its root filesystem. What is (proc) device in Grub and why is it there?

1
  • I appreciate the down vote as much as I appreciate being corrected :) when I'm wrong.
    – direprobs
    Aug 28, 2017 at 17:11

1 Answer 1

2

No, the Grub 2 bootloader is not a customized Linux kernel. It has its own codebase and you can read more about Grub 2 in this Wikipedia article.

Why does it then use a proc folder? Answer: The procfs filesystem is nothing specific to Linux. Similar approaches are used in BSD and other OSes which are POSIX compliant (read here).

Grub 2 is something, that needs to manage ressources like disk devices (in order to load kernels), mouse and keyboard input. It needs to read and understand different fileformats (like the ELF format) and run decompression processes for the linux kernel for example.

This is why Grub 2 in its functionality is a subset of what we call an operating system (don't get it wrong: it is not actually an OS) and the developers maybe decided to use such an procfs to manage things.

Edit:

Note that the Grub command ls / does not give the contents of the root folder of the in-memory filesystem of Grub. Inside the Grub shell of my Ubuntu machine it simply gives the contents of the root directory of my main boot drive. This means that the linuz file you mentioned above is simply the kernel which grub is going to boot...

5
  • Yes proc is not limited to Linux, but what does the Linux kernel do inside proc in grub?
    – direprobs
    Aug 28, 2017 at 16:53
  • Plus the Wikipedia web page explains grub primitively.
    – direprobs
    Aug 28, 2017 at 17:24
  • FWIW, OpenBSD removed /proc as it was mainly used for the Linux compatibility layer (which nobody used). Also, don't mention /proc and POSIX in the same breath. /proc is indeed mentioned in POSIX, but as a "non-standard extension" that standard-conforming Unices are allowed to implement.
    – Kusalananda
    Aug 28, 2017 at 17:37
  • 2
    In your second ls command ls (proc) / you are passing two separate arguments to ls: (proc) and /. This is because you have a space between (proc) and /. ls responds with two lines, one with info on (proc), the second line displays the contents of /. vmlinuz is not inside proc. Aug 28, 2017 at 19:51
  • @JohanMyréen You got this right. Very very subtle.
    – direprobs
    Aug 28, 2017 at 21:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .