Your SlideShare is downloading. ×
0
Linux Minimal OS For X86   Facebook group: Learn To Be   Official website: www.L2b-egypt.org   Prepared By: SHATRIX   E-Ma...
2          A Very Expert Was Once A Beginner              Learn The Way, Forget It, Then                   Find Your Own W...
3Introduction  • This tutorial will show you how to create your own    "Minimal Linux Distribution" on a USB Flash memory....
4Prerequisites:  • You will need to install these packages first on Ubuntu    10.10      ▫ sudo apt-get update      ▫ sudo...
5Basic Linux Structure  • Any Linux distribution consists of some main components:      ▫ Root Filesystem (main directorie...
6Creating Root Filesystem /  • Open a new Terminal, you will be right now inside your    home directory. Assume that the u...
7Creating Root Filesystem /  • Execute these commands:      ▫ mkdir   bin   boot   dev   etc   lib   proc         root    ...
8Configuration Files & Startup Scripts ( /etc )  • Inside (/etc), create these files & fill them with these    contents:  ...
9Configuration Files & Startup Scripts ( /etc )  • gedit inittab      ▫   null::sysinit:/bin/mount -t proc proc /proc     ...
10Configuration Files & Startup Scripts ( /etc )  • gedit rc      ▫   #!/bin/sh      ▫   PATH=/sbin:/bin:/usr/sbin:/usr/bi...
11Configuration Files & Startup Scripts ( /etc )  • gedit profile      ▫   export PS1=‘LearnToBe #       ▫   export USER=`...
12Linux Kernel & initrd  • To make your own Linux kernel is not easy like 1 2 3.  • Now, we can just use the Linux kernel ...
13Linux Commands (BusyBox)  • Any Linux distribution need some basic commands to    operate correctly, like (mount, ls, pw...
14Linux Commands (BusyBox)  • BusyBox combines tiny versions of many common    UNIX utilities into a single small executab...
15Linux Commands (BusyBox)  • Put the tar file in your home dir and open a new Terminal:      ▫ tar xvf busybox-1.17.2.tar...
16Linux Commands (BusyBox)  • make menuconfig  • This command will open a window like thatLearn To Be                     ...
17Linux Commands (BusyBox)  • Using arrows Enter the first choise (Busybox Settings),    then choose the second choise (Bu...
18Linux Commands (BusyBox)  • On the first choise in that menu press (Space) to    choose to build busubox as a static bin...
19Linux Commands (BusyBox)  • Exit the configuration, but don’t forget to save your    new configurations.Learn To Be     ...
20Linux Commands (BusyBox)  • Then execute this command to compile and install BusyBox    inside our system:      ▫ make C...
21C & GCC Libraries  • As we have compiled the BusyBox as a static    executable, we won’t need shared libraries in our sm...
22Whats Next ?  • Till now this system can run on any x86 cpu, and it can    be copied to any storage (Flash memory, parti...
23Boot Loader (Grub)  • We will use the grub already installed in our Linux    distribution, we just need to write the gru...
24Boot Loader (Grub)  • copy and paste these lines in the grub.cfg file      ▫ set menu_color_normal=yellow/red      ▫ set...
25Putting System on Flash Memory  • Plug the USB Flash in, It will take a namelike that sdx.  • First we need to format an...
26Putting System on Flash Memory  • Copy all the OS files from the </home/shatrix/minimal-linux> to    the mounted partiti...
27Final step: Editing grub.cfg (UUID)  • To get the UUID for any partition or Flash:      ▫ sudo blkid  • copy the UUID fo...
28Congratulations, You Did It                      YATTA  • If you make all these steps as it is, your flash memory    can...
Thank You   Facebook group: Learn To Be   Official website: www.L2b-egypt.org   Prepared By: SHATRIX   E-Mail: eng.shatrix...
Upcoming SlideShare
Loading in...5
×

linux minimal os tutorial - by shatrix

3,674

Published on

Published in: Education
6 Comments
2 Likes
Statistics
Notes
  • Hi Sir Sherif Mousa,
    Great article, I am studying it. Thanks you very much!
    I have some doubts.
    My sourceforge http://sourceforge.net/u/richardlumscio/profile/
    I work mini linux with intreper lua, python and lisp to works.
    If you can add me in facebook to talk about some ideas.

    Steps that I use:

    Steps in Building Base Mini Linux Distro

    My WAY BUILD(some steps):

    0. as root user;
    1. Create empty img (linux.img) file for system;
    2. Mount linux.img;
    3. Creation root directory empty, rootfs, (command used dd) for instalation busybox and file configurations;(in next step rootfs is compressed with 'gzip -9 rootfs' creating rootfs.gz
    4. Configuration (with support init) and Instalation BusyBox in directory mounted of rootfs.img in /mnt (with command line # mount -o loop linux.img /mnt/);
    5. Configurarion and build bzImage ('make menuconfig' -> configuration, 'make bzImage' -> build image of kernel
    6. copy file syslinux.cfg, bzImage, rootfs.gz into linux.img;
    7. command 'syslinux -s linux.img';
    8. qemu linux.img (for test mini distro linux).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi Sir Sherif Mousa,
    Great article, I am studying it. Thanks you very much!
    I have some doubts.
    My sourceforge http://sourceforge.net/u/richardlumscio/profile/
    I work mini linux with intreper lua, python and lisp to works.
    If you can add me in facebook to talk about some ideas.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @undefined please follow the new updated tutorials, it may help you. If not, feel free to contact me again :)
    http://www.slideshare.net/sherif_mosa/003-embedded-linuxminiosx86
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello everyone
    I am facing exactly the same issue as mentioned by Hanis Ahmad

    OS: ubuntu 12.04
    Kernel: 3.5.0-49-generic
    Busybox: busybox-1.22.1.tar.bz2
    Gcc: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

    For the timing I have skkped installing busybox and continued the further steps.
    This resulted with the kernel message
    :/sbin/init No such file or directory.
    Please help.

    Thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @realslumberjer I'm really sorry for being late to see that comment.
    could you please tell me more about your development desktop environment (OS, distribution, OS version, busybox version, GCC version) to be more familiar with your error.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,674
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
129
Comments
6
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "linux minimal os tutorial - by shatrix"

  1. 1. Linux Minimal OS For X86 Facebook group: Learn To Be Official website: www.L2b-egypt.org Prepared By: SHATRIX E-Mail: eng.shatrix@gmail.comLearn To Be Embedded Linux Training
  2. 2. 2 A Very Expert Was Once A Beginner Learn The Way, Forget It, Then Find Your Own WayLearn To Be Embedded Linux Training
  3. 3. 3Introduction • This tutorial will show you how to create your own "Minimal Linux Distribution" on a USB Flash memory. • You will learn about: ▫ The FHS (Filesystem Hierarchy Standard). ▫ Linux minimal common commands that make the system start and operate well. ▫ How to deal with Grub bootloader (install, edit configuration files). ▫ How to use the Linux kernel. ▫ Dealing with some root commands (mount, mkfs.ext2, grub-install) • It is considered a good start for those people who want to enter the field of Embedded Linux Systems PS: Development on UBUNTU 10.10Learn To Be Embedded Linux Training
  4. 4. 4Prerequisites: • You will need to install these packages first on Ubuntu 10.10 ▫ sudo apt-get update ▫ sudo apt-get install ncurses-dev bison texinfo flex • You should be good in working with at least one Linux distribution like UBUNTU, and can understand the command you write and its options.Learn To Be Embedded Linux Training
  5. 5. 5Basic Linux Structure • Any Linux distribution consists of some main components: ▫ Root Filesystem (main directories and sub directories). ▫ Linux Kernel image with or without initram filesystem (initrd.img). ▫ Configuration files and startup scripts in the (/etc) directory. ▫ Essential Linux commands needed for system to start and operate well. ▫ C & GCC Shared Libraries needed for any C or C++ application to run. ▫ Boot Loader to start the system from its storage media. ▫ GUI system or not. ▫ Extra Programs. • So, we will minimize all these components to get the minimal Linux distribution that works very well on any X86 CPU.Learn To Be Embedded Linux Training
  6. 6. 6Creating Root Filesystem / • Open a new Terminal, you will be right now inside your home directory. Assume that the user name currently running is (shatrix), you will be in: /home/shatrix • Create any directory to contain the whole OS files and enter it ▫ mkdir minimal-linux ▫ cd minimal-linux ▫ pwd • Now you are in: /home/shatrix/minimal-linuxLearn To Be Embedded Linux Training
  7. 7. 7Creating Root Filesystem / • Execute these commands: ▫ mkdir bin boot dev etc lib proc root sbin ▫ mkdir media sys tmp var usr ▫ mkdir usr/bin usr/sbin usr/lib var/log ▫ touch var/log/messages ▫ chmod 1777 tmp • Now you have the main filesystem directories to contain the whole systemLearn To Be Embedded Linux Training
  8. 8. 8Configuration Files & Startup Scripts ( /etc ) • Inside (/etc), create these files & fill them with these contents: ▫ gedit group  copy and paste this line inside it:  root:x:0: ▫ gedit passwd  copy and paste this line inside it:  root:x:0:0:root:/root:/bin/sh ▫ gedit shadow  copy and paste this line inside it:  root::10:0:0:0::: ▫ gedit hostname  copy and paste this line inside it:  LearnToBeLearn To Be Embedded Linux Training
  9. 9. 9Configuration Files & Startup Scripts ( /etc ) • gedit inittab ▫ null::sysinit:/bin/mount -t proc proc /proc ▫ null::sysinit:/bin/mkdir -p /dev/pts ▫ null::sysinit:/bin/mount -a ▫ null::sysinit:/sbin/ifconfig lo 127.0.0.1 up ▫ null::sysinit:/sbin/ifconfig eth0 192.168.1.13 up ▫ ::sysinit:/etc/rc ▫ tty1::respawn:/sbin/getty 38400 tty1 ▫ null::sysinit:/bin/touch /var/log/messages ▫ null::respawn:/sbin/syslogd -n -m 0 ▫ null::respawn:/sbin/klogd -n ▫ tty2::respawn:/usr/bin/tail -f /var/log/messages ▫ ::ctrlaltdel:/sbin/reboot ▫ null::shutdown:/usr/bin/killall klogd ▫ null::shutdown:/usr/bin/killall syslogd ▫ null::shutdown:/bin/umount -a -rLearn To Be Embedded Linux Training
  10. 10. 10Configuration Files & Startup Scripts ( /etc ) • gedit rc ▫ #!/bin/sh ▫ PATH=/sbin:/bin:/usr/sbin:/usr/bin ▫ export PATH ▫ /bin/hostname LearnToBe ▫ /sbin/hwclock -s ▫ /bin/echo " " ▫ /bin/echo " Y A T T A " ▫ /bin/echo " My First Embedded Linux " ▫ /bin/echo " " • chmod +x rcLearn To Be Embedded Linux Training
  11. 11. 11Configuration Files & Startup Scripts ( /etc ) • gedit profile ▫ export PS1=‘LearnToBe # ▫ export USER=`id -un` ▫ export LOGNAME=$USER ▫ export HOSTNAME=`/bin/hostname` ▫ export HISTSIZE=1000 ▫ export HISTFILESIZE=1000 ▫ alias c=clear ▫ alias df=df -h ▫ alias ll=ls -lh ▫ alias ping=ping -w 5‘ • After Finishing back to the main dir: ▫ /home/shatrix/minimal-linuxLearn To Be Embedded Linux Training
  12. 12. 12Linux Kernel & initrd • To make your own Linux kernel is not easy like 1 2 3. • Now, we can just use the Linux kernel already exists in our Ubuntu distribution. • So, copy the kernel & initrd file from /boot: ▫ cp /boot/vmlinuz-2.6.35-22-generic boot/ ▫ cp /boot/initrd.img-2.6.35-22-generic boot/Learn To Be Embedded Linux Training
  13. 13. 13Linux Commands (BusyBox) • Any Linux distribution need some basic commands to operate correctly, like (mount, ls, pwd, ifconfig, cd, mkdir, touch, file, rm, vi) and more. Our distribution should contain these commands, so there are two ways to get these commands inside our OS: ▫ Getting the source code for each command needed, compile it separately and copy it to any bin directory inside the distribution. ▫ Using BusyBox.Learn To Be Embedded Linux Training
  14. 14. 14Linux Commands (BusyBox) • BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system. • Get Busybox (busybox-1.17.2.tar.bz2): ▫ http://www.busybox.net/downloads/busybox-1.17.2.tar.bz2Learn To Be Embedded Linux Training
  15. 15. 15Linux Commands (BusyBox) • Put the tar file in your home dir and open a new Terminal: ▫ tar xvf busybox-1.17.2.tar.bz2 ▫ cd busybox-1.17.2/ • Configure Busybox as required: ▫ make defconfig ▫ make menuconfig • The command (make menuconfig) will open a GUI terminal-based configuration for the BusyBox program, you can choose what to be installed and what not to be installed, or you can just choose to exit this configuration and remember to save your configuration settings on exit. • We will choose to combile the busybox as a statically linked application to avoid using shared libs for C & GCC apps.Learn To Be Embedded Linux Training
  16. 16. 16Linux Commands (BusyBox) • make menuconfig • This command will open a window like thatLearn To Be Embedded Linux Training
  17. 17. 17Linux Commands (BusyBox) • Using arrows Enter the first choise (Busybox Settings), then choose the second choise (Build Options)Learn To Be Embedded Linux Training
  18. 18. 18Linux Commands (BusyBox) • On the first choise in that menu press (Space) to choose to build busubox as a static binary.Learn To Be Embedded Linux Training
  19. 19. 19Linux Commands (BusyBox) • Exit the configuration, but don’t forget to save your new configurations.Learn To Be Embedded Linux Training
  20. 20. 20Linux Commands (BusyBox) • Then execute this command to compile and install BusyBox inside our system: ▫ make CONFIG_PREFIX=/home/shatrix/minimal-linux install • After finishing, close this Terminal and get back to the main Terminal and execute these commands ▫ ls bin ▫ ls sbin ▫ ls usr/bin ▫ ls usr/sbin • You will see that the commands have been installed inside the binary directories of our system. Also you need to know that all these commands are linked to one executable file named busybox inside /bin and all these commands shown are just symbolic links to that command.Learn To Be Embedded Linux Training
  21. 21. 21C & GCC Libraries • As we have compiled the BusyBox as a static executable, we won’t need shared libraries in our small system till now.Learn To Be Embedded Linux Training
  22. 22. 22Whats Next ? • Till now this system can run on any x86 cpu, and it can be copied to any storage (Flash memory, partition, CD) to be a stand alone operating system. • Now, we just need a bootloader to start the system. • We can use the bootloader already installed on UBUNTU (grub).Learn To Be Embedded Linux Training
  23. 23. 23Boot Loader (Grub) • We will use the grub already installed in our Linux distribution, we just need to write the grub configuration file manually. • grub.cfg: ▫ This is a text file contains the menu entries or the list of operating systems that grub should list them when the computer starts. We will create it manually. ▫ Go to the PATH of our system ▫ Create (boot/grub) dir ▫ Create (boot/grub/grub.cfg) file  cd /home/shatrix/minimal-linux  mkdir boot/grub  gedit boot/grub/grub.cfgLearn To Be Embedded Linux Training
  24. 24. 24Boot Loader (Grub) • copy and paste these lines in the grub.cfg file ▫ set menu_color_normal=yellow/red ▫ set menu_color_highlight=black/light-gray ▫ menuentry LINUX Minimal OS FOR X86 { ▫ set root=(hd0,1) ▫ linux /boot/vmlinuz-2.6.35-22-generic root=UUID=<disk-uuid> rw ▫ initrd /boot/initrd.img-2.6.35-22-generic ▫ } • The red text <disk-uuid> will be replaced with a value after that, don’t forget.Learn To Be Embedded Linux Training
  25. 25. 25Putting System on Flash Memory • Plug the USB Flash in, It will take a namelike that sdx. • First we need to format and partition it, from Terminal run these commands only if you are sure about the flash device name: ▫ sudo umount /media/flash-disk-mounted-folder ▫ sudo mkfs.ext2 /dev/sdx1 • If you have one hard disk and you have connected only one flash disk, it will take the name sdb, the command should be: • sudo mkfs.ext2 /dev/sdb1 • Then mount the flash back again ▫ sudo mkdir /media/flash ▫ sudo mount /dev/sdb1 /media/flashLearn To Be Embedded Linux Training
  26. 26. 26Putting System on Flash Memory • Copy all the OS files from the </home/shatrix/minimal-linux> to the mounted partition. ▫ cd /home/shatrix/minimal-linux ▫ cp -a * /media/flash • Finally install grub to the Flash device: ▫ sudo grub-install --root-directory=/media/flash /dev/sdb • Remember that the sdb will be the Flash disk device name in /dev, and /media/flash is the directory where the flash disk is mountedLearn To Be Embedded Linux Training
  27. 27. 27Final step: Editing grub.cfg (UUID) • To get the UUID for any partition or Flash: ▫ sudo blkid • copy the UUID for the required device and paste it in its correct place in the grub.cfg file on the Flash memory. ▫ sudo gedit /media/flash/boot/grub/grub.cfg • In the kernel line (root=UUID=<disk-uuid>) • make it ( root=UUID=the-result-uuid-from-blkid )Learn To Be Embedded Linux Training
  28. 28. 28Congratulations, You Did It YATTA • If you make all these steps as it is, your flash memory can now boot with the new Linux OS. • Restart your computer, and select to boot from the USB flash from your BIOS settings. • The Grub from the Flash memory should start now, with one selection: ▫ (LINUX Minimal OS FOR X86) • Press Enter to start the system, and enjoy. • When the system starts, go to the first console by typing Ctrl+Alt+F1 ,it will ask for login, type ( root ) and press enter, the system will start without asking for password.Learn To Be Embedded Linux Training
  29. 29. Thank You Facebook group: Learn To Be Official website: www.L2b-egypt.org Prepared By: SHATRIX E-Mail: eng.shatrix@gmail.comLearn To Be Embedded Linux Training
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×