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

Notices

Reply
 
Search this Thread
Old 04-20-2012, 09:14 PM   #1
abtekk
Member
 
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:

Code:
#!/bin/sh

# 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
else
	mkdir /newroot
	mount -t ext2 /dev/block/cardblksd1 /newroot
fi

#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
else
        echo "" >/dev/tty0
        echo "Unable to mount SD Card!" >/dev/tty0
        sleep 3
        echo "" >/dev/tty0
        echo "Booting ANDROID from NAND..." >/dev/tty0
        exec init.android
fi
All feedback appreciated.
 
Old 04-21-2012, 10:40 AM   #2
zakame
Member
 
Registered: Apr 2012
Distribution: Debian, Ubuntu, Slackware
Posts: 121

Rep: Reputation: 42
/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, 10:56 AM   #3
entz
Member
 
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

regards
 
  


Reply


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 01:12 AM
SSH Script to replace RSH Script felton57 Linux - Enterprise 2 09-24-2010 10:06 AM
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 04:40 PM
LXer: Ubuntu and Fedora Replace init with Upstart LXer Syndicated Linux News 0 05-05-2009 03:50 AM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM


All times are GMT -5. The time now is 01:25 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration