Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 04-20-2012, 10:14 PM   #1
Registered: Aug 2011
Posts: 30

Rep: Reputation: Disabled
Could I replace init with this script? (Look before you judge)

I understand what init does and how it performs but here is my story:

On my android device (an ePad, zenithink ZT280) I have the kernel source code, inside the kernel is an init binary which does all it's usual mounting and booting. However, would I be able to rename init to something, and then make a script named init that could run various commands and then finally invoke the original android init? Here's the script I'm thinking of:


# mount stuff needed by this script
mount -t proc proc /proc
mount -t sysfs sysfs /sys
if [ -d /newroot ]; then
	mount -t ext2 /dev/block/cardblksd1 /newroot
	mkdir /newroot
	mount -t ext2 /dev/block/cardblksd1 /newroot

#make sure we were able to mount linux and that init is available
if [ $? -eq 0 ] && [ -x /newroot/sbin/init ]; then
        echo "" >/dev/tty0
        echo "Linux rootfs mounted OK" >/dev/tty0
        echo "" >/dev/tty0
        echo "Unmounting proc..." >/dev/tty0
        umount /proc && echo "OK" >/dev/tty0

        echo "" >/dev/tty0
        echo "Hold on, switching root and starting Linux..." >/dev/tty0
        exec switch_root /newroot /sbin/init
        echo "" >/dev/tty0
        echo "Unable to mount SD Card!" >/dev/tty0
        sleep 3
        echo "" >/dev/tty0
        echo "Booting ANDROID from NAND..." >/dev/tty0
All feedback appreciated.
Old 04-21-2012, 11:40 AM   #2
Registered: Apr 2012
Distribution: Debian, Ubuntu, Slackware
Posts: 218

Rep: Reputation: 118Reputation: 118
/sbin/init is a pretty important program, so replacing that with a shell script might be a bit foolhardy. Not to say that it is not possible, though; there are many init replacements out there, so maybe you could start looking into them?
Old 04-26-2012, 11:56 AM   #3
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Rep: Reputation: 40
Yes you can !

however you need to ensure that /bin/sh is available on the system as well as all the libraries and subsystems/modules needed by /bin/sh at the time of boot.
this is because obviously you've a shebang set to "/bin/sh"

i don't know about android but in regular linux distros you simply change the boot parameter init=</path/to/script_or_binary> in grub.conf



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does upstart actually replace init? armandino Linux - General 10 01-26-2011 02:12 AM
SSH Script to replace RSH Script felton57 Linux - Enterprise 2 09-24-2010 11:06 AM
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 05:40 PM
LXer: Ubuntu and Fedora Replace init with Upstart LXer Syndicated Linux News 0 05-05-2009 04:50 AM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 11:37 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration