LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-25-2015, 09:36 AM   #1
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
/bin/bash as primary init


I am curious if anyone is running /bin/bash (or other shell) as PID1 on their systems.
 
Old 05-25-2015, 10:05 AM   #2
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,493

Rep: Reputation: Disabled
That is usually kept for emergency situations.
 
Old 05-25-2015, 10:29 AM   #3
Head_on_a_Stick
Senior Member
 
Registered: Dec 2014
Location: London, England
Distribution: Debian stable (and OpenBSD-current)
Posts: 1,187

Rep: Reputation: 285Reputation: 285Reputation: 285
I have an old eee pc running SliTaz that uses busybox as PID1 -- does that count?

In a similar vein:
https://bbs.archlinux.org/viewtopic....78903#p1378903
 
Old 05-25-2015, 06:43 PM   #4
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
Just something I've been messing with. Managed to get a system up and running into X using /bin/dash as PID1.
 
Old 05-25-2015, 08:44 PM   #5
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
/bin/bash as init/PID1 is usually reserved as a recovery/emergency mode, because after you get bash going, you then need to manually mount drives in read/write mode, enable swap, load device drivers, and such all manually. It gives you complete control of the system, but you have to know what all to do.

To be honest, if you know how to script things, you technically could load everything from a shell script and then have it parse out as needed, other scripts to handle things.

Stuff like this is slowly becoming a lost art.
 
Old 05-25-2015, 08:50 PM   #6
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
I used to make a live cd based on Linux From Scratch back about 8 years now that just used busybox. Never thought to try to use /bin/bash as PID 1. I am sure it slims down a system even more than I previously thought.
 
Old 05-26-2015, 10:02 AM   #7
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Or you can use a bash script to initialize the system and execute to bash shell at the end.
 
Old 05-26-2015, 02:48 PM   #8
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
I'm just testing a simple shell script at the moment. It basically loads the important stuff, then starts a tty login. Whether or not I use it on my main system, give me a chance to improve my shell scripting, and learn more of the basics of Linux.
 
Old 05-26-2015, 04:30 PM   #9
brebs
Member
 
Registered: May 2013
Posts: 89

Rep: Reputation: Disabled
Busybox works great as a DIY init.
 
Old 05-27-2015, 03:52 PM   #10
Head_on_a_Stick
Senior Member
 
Registered: Dec 2014
Location: London, England
Distribution: Debian stable (and OpenBSD-current)
Posts: 1,187

Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by brebs View Post
Busybox works great as a DIY init.
Hey brebs!

See the link in my post (#3), it may look familiar
 
Old 05-27-2015, 05:52 PM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I-F you are running the system in an extremely-minimalized "single-user mode," for last-ditch recovery purposes, then it conceivably m-i-g-h-t make sense to run "bash" as process #1. (i.e. "because the system is not running in multi-user mode, and it never will.")

But, otherwise: "bash is simply not capable of fulfilling the unique technical requirements that Linux/Unix has for its "process #1." The 'init' executable, on the other hand, is specifically engineered to fill that role. (As is "systemd.")

One of the most-basic requirements of "process #1" is that it is "the Grim Reaper of last resort." If any process finds itself an orphan, it gets killed and automagically parented to "process #1," whose sole responsibility is to reap its moldering remains. "bash" knows nothing of this. The "init" process is also special in the sense that, if it dies, the entire system will kernel-panic. ("Tried to kill 'init!'") "bash," once again, knows nothing of this, and cannot fulfill the technical requirements of this role.

Last edited by sundialsvcs; 05-27-2015 at 05:55 PM.
 
Old 05-28-2015, 01:54 PM   #12
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
What would be the difference in using busybox vs a shell with coreutils? Also, is the scripts what were linked, I see busybox mentioned, but not specifically called.
 
Old 05-28-2015, 03:32 PM   #13
brebs
Member
 
Registered: May 2013
Posts: 89

Rep: Reputation: Disabled
Busybox becomes the ultra-special *PID 1* by being called by the kernel - the historical default is /sbin/init:

Code:
$ ll /sbin/init
lrwxrwxrwx 1 root root 12 Mar 23 06:52 /sbin/init -> /bin/busybox
The point about busybox is that it is able to fulfill the simple but crucial role of PID 1.

The point about using busybox rather than coreutils etc. is that busybox is an all-in-one executable, no need to spawn other processes, and is therefore *faster*. Also smaller & simpler (similar to why Debian converted to using DASH in preference to BASH). Also much easier to debug, because you've got a hope of understanding its code (basically the opposite of the leviathan that systemd has grown into).

KISS is a good thing. Busybox as init works beautifully, and I have no craving to change
 
Old 05-28-2015, 04:07 PM   #14
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126

Original Poster
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
I didn't even think of linking /sbin/init > /bin/busybox. I had tried init=/bin/busybox, and would get a kernel panic, so I was using init=/bin/dash instead.
 
Old 05-28-2015, 04:21 PM   #15
brebs
Member
 
Registered: May 2013
Posts: 89

Rep: Reputation: Disabled
Busybox is a rare app that behaves *differently*, based on the filename that it was called as

This is why the symlinks are important.
 
  


Reply



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
shutting down after init=/bin/bash michapma Linux - General 5 10-28-2017 07:16 PM
Combine two or more bin files into another bin file at specific addresses in bash WSRaptor Programming 1 04-20-2015 02:36 PM
[SOLVED] New install- no root password! init=/bin/bash crashes! keithostertag Debian 4 02-20-2013 11:13 AM
[SOLVED] /usr/bin/xterm: Could not exec /bin/bash: Permission Denied suheng Linux - Newbie 2 09-24-2010 05:31 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

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

All times are GMT -5. The time now is 07:13 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
Open Source Consulting | Domain Registration