LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-17-2019, 09:59 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 367
Blog Entries: 1

Rep: Reputation: 48
Red face 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 ?
 
Old 10-17-2019, 10:48 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,566
Blog Entries: 19

Rep: Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447
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.

Last edited by hazel; 10-17-2019 at 10:52 AM.
 
Old 10-17-2019, 12:19 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
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

Last edited by dugan; 10-17-2019 at 01:18 PM.
 
Old 10-17-2019, 03:45 PM   #4
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,492

Rep: Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488Reputation: 2488
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/
 
Old 10-17-2019, 07:43 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
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.

Last edited by frankbell; 10-17-2019 at 07:50 PM. Reason: More information
 
Old 10-18-2019, 04:55 AM   #6
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 367

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Exclamation

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 ?
 
Old 10-18-2019, 05:03 AM   #7
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 367

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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.
 
Old 10-18-2019, 11:34 AM   #8
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,566
Blog Entries: 19

Rep: Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447Reputation: 4447
Quote:
Originally Posted by ychaouche View Post
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!

Last edited by hazel; 10-18-2019 at 11:36 AM.
 
  


Reply

Tags
loader



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
Linux boot loader entry in Windows boot loader abhikohokade Linux - Newbie 6 02-22-2013 06:12 AM
How to change from grub boot loader to lilo boot loader linuxjamil Linux - Software 1 05-27-2008 01:47 PM
How to change my Grub Loader to Lilo loader in REDHAT LINUX 9.0 skumar.v Linux - Newbie 3 04-04-2008 10:38 AM
replace lilo loader with windows loader Mickaletto Linux - Newbie 9 11-25-2005 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:52 AM.

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
Open Source Consulting | Domain Registration