LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2018, 09:21 AM   #1
nkd
Member
 
Registered: Oct 2006
Location: india
Distribution: fedora 8, ubuntu 10.10
Posts: 318

Rep: Reputation: 34
Building a small linux system from a kernel and busybox


Hi all,
I am trying to build a basic linux system from kernel and busybox, using my debian 9 linux machine. I am referring to the tutorial at Basically, there are four things which I am doing.
1. Compiling the kernel from source :-
Quote:
make defconfig && make
The kernel bzImage is stored in the folder /arch/x86/boot/ folder after successful make.
2. Next I download the busybox source code and build it statically :-
Quote:
make allnoconfig
make menuconfig
Enabling satic linking under Settings -> Build Options -> Build static binary(no shared library)
Quote:
make
After the binary is ready, I check whether it is statically linked by using :-
Quote:
ldd busybox
the system responds with "not a dynamic executable"
3. I then create a root filesystem as under:-
Quote:
mkdir rootfs
cd rootfs
mkdir dev proc sys tmp
mknod dev/console c 5 1
I also create a init file as under :-
Quote:
cat >> init << EOF
#!/bin/ash
mount -t proc none /proc
mount -t sysfs none /sys
/bin/ash
EOF
Change it's permissions
Quote:
chmod +x init
Finally, I issue the commands :-
Quote:
find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz
4. After this I take a usb drive and load grub onto it :-
Quote:
mkfs.ext3 /dev/sdb1
mount /dev/sdb1 /mnt
grub-install --root-directory=/mnt /dev/sdb
Lastly, I just copy the files created in steps 1 -3 in the root partition of the usb
bzImage, busybox, rootfs.cpio.gz
Then as I insert my usb disk into a system and choose to boot from it, I get a grub prompt where I give the following commands :-
Quote:
set root=(hd0,msdos1)
linux /bzImage
initrd /rootfs.cpio.gz
The system boots up but halts with a kernel panic message as under :-
Quote:
kernel panic - not syncing: No working init found. Try passing init= option to kernel
Can someone help me sort this problem and get the kernel to find init and execute it correctly.
I am sorry for the unusually long post. But thought the details would be needed to help me properly.

thanks in advance
 
Old 04-16-2018, 12:37 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
The message is pretty clear. By default the kernel searches a default path in the root filesystem for an executable named "init" to start up user space. If it doesn't find it, you get that message. It's not clear from your description what the root filesystem is, or how you are creating it, or what executable will run as init.
 
1 members found this post helpful.
Old 04-16-2018, 01:01 PM   #3
nkd
Member
 
Registered: Oct 2006
Location: india
Distribution: fedora 8, ubuntu 10.10
Posts: 318

Original Poster
Rep: Reputation: 34
Firstly, thanks for your response. I will try and explain how I created the root filesystem and I am using busybox as the executable for init.
Quote:
After building BusyBox I get a directory named _install. I move the directory and rename it:

mv _install ../rootfs

In rootfs we create dev, proc, sys and tmp directories. Create one device, which is the console. I also remove linuxrc.

cd ../rootfs
mkdir dev proc sys tmp
rm linuxrc
sudo mknod dev/console c 5 1

The last file I create is init. Before giving a shell to the user it mount proc and sys:

cat >> init << EOF
#!/bin/ash
mount -t proc none /proc
mount -t sysfs none /sys
/bin/ash
EOF
chmod +x init

That is it. I then Archive the initramfs with cpio and compress it with gzip:

find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz
I just followed the post at:-
as I didn't understand much, and I am still figuring out the concept.

Last edited by nkd; 04-16-2018 at 01:03 PM.
 
Old 04-17-2018, 07:51 PM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Where is init stored?
 
Old 04-19-2018, 10:06 AM   #5
nkd
Member
 
Registered: Oct 2006
Location: india
Distribution: fedora 8, ubuntu 10.10
Posts: 318

Original Poster
Rep: Reputation: 34
Hi everyone,
I solved the problem, it was an issue with the permission of init .I have a working system of 20 MB size only.
The link in my last post works perfectly.Anyone who wants to give it a shot, can just follow the link. The result is a 20MB
bootable minimal linux.
Quote:
Where is init stored?
Well there are two init, one is inside /sbin and the other one in /. I am sort of confused which one is working. The one I wrote is in the /
and finally I get a shell prompt, so I assume my one which is inside the / folder is the one which is working.
Thanks all for taking the effort to help me out.
 
Old 04-19-2018, 01:21 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,985

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Thanks for the update and solution. Good going.
 
Old 01-17-2024, 05:23 PM   #7
rufwoof
Member
 
Registered: Nov 2017
Distribution: Kernel+busybox+ssh+vnc+alsa (framebuffer)
Posts: 201

Rep: Reputation: Disabled
Quote:
Originally Posted by nkd View Post
Hi everyone,
I solved the problem, it was an issue with the permission of init .I have a working system of 20 MB size only.
The link in my last post works perfectly.Anyone who wants to give it a shot, can just follow the link. The result is a 20MB
bootable minimal linux.

Well there are two init, one is inside /sbin and the other one in /. I am sort of confused which one is working. The one I wrote is in the /
and finally I get a shell prompt, so I assume my one which is inside the / folder is the one which is working.
Thanks all for taking the effort to help me out.
For reference, the kernel invokes /init, within which you might set up /proc ....etc. and then invoke (hand over PID 1 to) busybox's init

exec setsid cttyhack /sbin/init

where /sbin/init is a symbolic link to busybox

If you don't create a /etc/inittab busybox has its own internal inittab that is uses instead, part of which invokes /etc/init.d/rcS, along with setting up tty's ..etc.

So in /etc/rcS you might call mount -a .... and create a /etc/fstab for that ...etc.

20MB is quite large for what you have, mine is 16MB which includes ssh/ssl, vnc, alsa/sndio ... and that 16MB is combined initramfs and kernel, and all modules/firmware for my laptop built in. With that I can boot, wifi net connect, set up ssh tunnel(s) and use vnc to connect to full gui desktops. I use the vesa framebuffer for that.
 
Old 01-18-2024, 03:11 AM   #8
___
Member
 
Registered: Apr 2023
Posts: 139
Blog Entries: 1

Rep: Reputation: Disabled
See: http://DistroWatch.com/mll 7MB .iso (kernel+busybox)
Has all scripts to build it from src, defconfig kernel
Run as a Vbox VM, to see most minimal basics. Cool!
 
Old 01-18-2024, 05:01 PM   #9
rufwoof
Member
 
Registered: Nov 2017
Distribution: Kernel+busybox+ssh+vnc+alsa (framebuffer)
Posts: 201

Rep: Reputation: Disabled
My 15MB comes with SSL, full SSH, vnc, alsa/sndio and wifi/ethernet connecting all ready to go. Boot, wifi net connect, ssh/vnc to a vnc server and a full chrome/libre/etc. desktop running in the framebuffer. Or overlayfs mount a local sfs as a headless, running vnc server, and vnc into that.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Tiny Core Linux 8.0 Operating System Arrives with BusyBox 1.25.1 and GCC 6.2.0 LXer Syndicated Linux News 0 04-11-2017 08:02 AM
Tradition Linux using vanilla kernel, Init and busybox only. patrick295767 General 4 02-24-2017 04:26 PM
[SOLVED] Where to get completely minimal Linux image (kernel and Busybox only)? skykooler Linux - General 15 03-09-2012 12:38 PM
Need help with building kernel module in domu, would pay a small $fee$ for help aulix Linux - Enterprise 1 11-25-2007 02:34 AM
new to linux, building a small lab... bellman LinuxQuestions.org Member Intro 3 02-26-2007 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:49 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