LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   What is the linux loader ? (https://www.linuxquestions.org/questions/linux-general-1/what-is-the-linux-loader-4175662690/)

ychaouche 10-17-2019 09:59 AM

What is the linux loader ?
 
According to wikipedia, "a loader is the part of an operating system that is responsible for loading programs and libraries."

What is it in linux ?

hazel 10-17-2019 10:48 AM

Depends. There are several. The one most people use these days is GRUB, which will boot Windows too. Old-fashioned people like me use LILO which won't boot any modern Windows. Then there's syslinux, which is used mainly for usb memory sticks and its cousin isolinux which is used for Cds and DVDs. And that's just for traditional BIOS booting. For UEFI, you can use GRUB again or ELILO, or just use a self-booting kernel .

Or are you talking about after booting when the system is already running? In that case, the answer is the kernel. A process requests to fork off another process and the kernel creates a task structure for it. The child process requests to execute a new program and the kernel loads it.

dugan 10-17-2019 12:19 PM

Looks like it's the kernel itself. Using an internal routine called load_elf_binary.

How programs get run: ELF binaries

https://github.com/torvalds/linux/bl...fmt_elf.c#L667

yancek 10-17-2019 03:45 PM

The Linux Loader is a boot loader which was generally used after loadlin which was generally used with initial Linux systems.

https://en.wikipedia.org/wiki/LILO_(boot_loader)

https://www.interserver.net/tips/kb/what-is-lilo/

frankbell 10-17-2019 07:43 PM

The LInux LOader is LILO. GRUB has replaced it in the great majority of distros. Slackware still defaults to LILO, but offers GRUB as an alternative.

Every OS has a boot loader. Operating systems that expect never to share the computer, such as Windows and MacOS, just don't let it come to the screen. Never versions of Ubuntu hide the GRUB menu unless Ubuntu is installed for dual-booting.

ychaouche 10-18-2019 04:55 AM

Hazel, Dugan,

The only ressource I found so far that *explicitly* uses the term "loader" and clearly defines what it is, is this technical article from Embedded Artistry (annotated link) :

Quote:

On Linux or OS X, the loader is a function in the exec() family typically execve() or execvp().

@dugan

The lwn article you linked to : I've already skimmed through it sarching for "loader", but since I couldn't find any result I just skipped it. But since you mentioned it in your post I've searched it again, this time for just "load", and found this sentence :

Quote:

Loading an ELF binary is handled by the load_elf_binary() function,

Neither articles mention *fork* as being *the* loader or part of the loader, I think fork happens before the actual loading.

So is it the exec system call or is it the load_elf_binary internal kernel function ? or maybe exec calls load_elf_binary ?

ychaouche 10-18-2019 05:03 AM

Searching further, I also found this article from linuxjournal, mistakingly calling execve "a program"

Quote:

The loader is a program called execve, which loads the code and data of the executable object file into memory and then runs the program by jumping to the first instruction.

hazel 10-18-2019 11:34 AM

Quote:

Originally Posted by ychaouche (Post 6048071)
Neither articles mention *fork* as being *the* loader or part of the loader, I think fork happens before the actual loading.

So is it the exec system call or is it the load_elf_binary internal kernel function ? or maybe exec calls load_elf_binary ?

OK, let's take it in steps. First of all both fork and execve are system calls: that is they are functions called by a program in user space but executed by the kernel. While the kernel is executing them, the user process halts.

Fork causes the kernel to duplicate the task structure for the process. The task structure is a data structure inside the kernel which contains everything the kernel knows about that process. The first field is the process's unique ID (PID) and the second is the PID of the parent process (PPID). Other fields include a link to the executing program, a link to the current working directory, a link to the process's memory map, fields for user and group IDs, and one for environmental variables. There are also dynamic fields like elapsed time and core time. When the task structure is first created, most of these fields are simple duplicates of those in the parent's task structure, but there is a new PID and PPID, and all the time fields are zeroed.

The child process then calls execve (or a C-library wrapper for it like execv or execl) and this causes the link to the currently executing program to be replaced by one to the new program. A new memory map is created and the first page of the new program's executable image is loaded. Et voila!


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