H5VKe

            ..if you're using Linux you need
            to remember two words: search and read.

            http://www.linuxquestions.org/questions/debian-26
                /%27invalid-magic-number%27-grub2-debian-879211/

Foreword
========

Job purposes are:

  + To build tiny but self sufficient linux distro based on actual components (latest versions of kernel, busybox, grub). Documents, found on web lead to either huge system (LFS linux from scratch, or are quit old and needs to be revised (2012 or earlier)).

  + To demonstrate the use of important linux commands (student explains syntax and semantics for each line of the process).

  + To document and publish the Debian Jessie installation process on virtual machine. I need this related with such topics like Raspberry Pi and OpenPLC:

    https://www.raspberrypi.org/
    http://www.openplcproject.com/

1. PROLOG
=========

1.1 Debian Jessie 8.8
---------------------

  http://ftp.ee.debian.org/debian/dists/jessie
       /main/installer-amd64/current/images/netboot/mini.iso

Hostname:   JESSIE
DomainName:

User:       root/root
            virtu/virtu

Software:   [ ] Debian desktop environment
            [ ] ... Gnome
            [ ] ... Xfce
            [ ] ... KDE
            [ ] ... Cinnamon
            [ ] ... Mate
            [ ] ... LXDE
            [ ] web server
            [ ] print server
            [*] SSH server
            [ ] standard system utilities

GRUB on /dev/sda

1.2 sudo
--------

  # apt-get sudo vim
  ..libgpm2 sudo vim vim-runtime

  # cat /etc/group | grep sudo
  sudo:x:27:virtu
  # cat /etc/sudoers | grep NOPASSWD
  root    ALL=(ALL) NOPASSWD:ALL
  %sudo   ALL=(ALL) NOPASSWD:ALL

1.3 GUI (optional)
------------------

  # apt-get install task-gnome-desktop

Installing Guest Additions on Debian
....................................

  https://virtualboxes.org/doc/installing-guest-additions-on-debian/

  # apt-get install build-essential module-assistant \
                    linux-headers-$(uname -r)
  # m-a prepare
  # mount -o ro -t iso9660 VBoxGuestAdditions.iso /media/cdrom
  # sh /media/cdrom/VBoxLinuxAdditions.run

Plank
.....

  # apt-get install automake gnome-common intltool pkg-config valac \
                   libbamf3-dev libdbusmenu-gtk3-dev \
                   libgdk-pixbuf2.0-dev libgee-dev libglib2.0-dev \
                   libgtk-3-dev libwnck-3-dev libx11-dev libgee-0.8-dev

  wget https://launchpadlibrarian.net/313003786/plank-0.11.4.tar.xz

  apt-get install dconf-editor
  net -> launchpad -> plank -> docks -> dock1 -> show-dock-item [v]

2. TASK
=======

2.1 Custom Linux
----------------

Based on

  https://revcode.wordpress.com/2012/02/25
    /booting-a-minimal-busybox-based-linux-distro/

  wget --no-check-certificate \
    http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.7.tar.bz2
  tar jxf linux-3.2.7.tar.bz2
  cd linux-3.2.7/
  make defconfig && make    # ~10 min

  mkdir rootfs
  cd rootfs
  mkdir bin dev proc sys tmp
  mknod dev/console c 5 1

  cd bin
  wget --no-check-certificate \
    https://busybox.net/downloads/binaries/1.26.2-i686/busybox
  chmod +x busybox
  sh mkbblinks.sh   # see 2.4
  ./ls

  cat init
  #!/bin/ash
  mount -t proc none /proc
  mount -t sysfs none /sys
  /bin/ash

  chmod +x init

  find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz

  fdisk /dev/sdb        # np1aw
  mkfs.ext3 /dev/sdb1
  mount /dev/sdb1 /mnt
  grub-install --root-directory=/mnt /dev/sdb

  ..

Kernel panic.. We need to populate /bin with mount, ash,.. links. What is the proper location for init script?

2.2 Nasir's notes (2012)
------------------------

Links are dead. Use archive.org wayback machine or Annex A here.

2.3 Bruce Perens solution (2001)
--------------------------------

  http://www.linuxjournal.com/article/4335
  http://www.linuxjournal.com/article/4395
  http://www.linuxjournal.com/article/4528

2.4 Creating Busybox Links
--------------------------

  http://www.thelinuxdaily.com/2012/08/creating-busybox-links/

mkbblinks.sh

  #!/bin/bash

  ./busybox  --help | \
  sed -e '1,/^Currently defined functions:/d' \
      -e 's/[ \t]//g' -e 's/,$//' -e 's/,/\n/g' | \
  while read app ; do
    if [ "$app" != "" ]; then
      printf "linking %-12s ...\n" "$app"
      ln -sf "./busybox" "$app"
      ls -ld "$app"
    fi
  done

Links
-----

1. Debian Gnome

  https://wiki.debian.org/Gnome

  https://revcode.wordpress.com/2012/02/25
    /booting-a-minimal-busybox-based-linux-distro/

2. Nasir's Notes

    https://web.archive.org/web/20120701184956/
      http://blog.nasirabed.com:80/2012/01/minimal-linux-kernel.html
    https://web.archive.org/web/20120701184338/
      http://blog.nasirabed.com:80/2012/01/minimal-linux-busybox.html
    https://web.archive.org/web/20120601223451/
      http://blog.nasirabed.com:80/2012/01/minimal-linux-filesystem.html

3. Perens tiny Linux

    http://www.linuxjournal.com/article/4335
    http://www.linuxjournal.com/article/4395
    http://www.linuxjournal.com/article/4528

4. install Plank on Jessie (2015, dead)

    http://www.techbear.co/installing-plank-dock-on-debian-jessie
    http://compizomania.blogspot.com/2016/03/plank-eddy-0110.html

Annex A. Nasir's Notes
----------------------

Just sharing my notes with you.
Monday, January 2, 2012

Minimal Linux: Kernel
.....................

The way I like to do things is to start with minimalistic configuration and enable just what I need. So this is how I download, extract and run make with allnoconfig option:

  wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.6.tar.bz2
  tar xjvf linux-3.1.6.tar.bz2
  cd linux-3.1.6/
  make allnoconfig

As far as I know I only need to enable ELF and initial ram file system support. Because I do not have a gui, but just a console I use:

  make menuconfig

And enable:

  General setup ---> Initial RAM filesystem and RAM disk
                     (initramfs/initrd) support

  Executable file formats / Emulations ---> Kernel support for
                                            ELF binaries

That is all I need for now. Exit and make sure to save the configuration. We are ready now to build our minimal linux kernel:

  make

If everything went well we get a freshly compiled kernel in arch/x86/boot/bzImage ready for use. Lets continue with the minimal linux and build BusyBox.

Linux Kernel 3.1.6 was used while taking notes.

Monday, January 2, 2012
Minimal Linux: BusyBox

If you did read my previous post by now you know that the way I like to do things is to start with minimalistic configuration and enable just what I need. So this is how I download, extract and run make with allnoconfig option:

  wget http://busybox.net/downloads/busybox-1.19.3.tar.bz2
  tar xjvf busybox-1.19.3.tar.bz2
  cd busybox-1.19.3/
  make allnoconfig

We need to enable one option:

  Busybox Settings --->
      Build Options --->
          Build BusyBox as a static binary (no shared libs)

However this will not give us a very useful build. You also want to have some applications. For example I want a shell (ash), some tools (cat, cp, df, ls, mkdir, mknod, mv, rm, sleep, tail, uname, vi, grep, init, mount, ps). Of course you are free to choose whatever you want, just keep in mind that it is wise to have some core tools, like a shell and being able to start the system with init and maybe mount a filesystem with mount.

When you are done exit and make sure to save the configuration. You are ready to build:

  make
  make install

BusyBox is now ready to be used. In the same directory we have _install which will be used for our next step which is building a filesystem.

BusyBox 1.19.3 was used while taking notes.

Tuesday, January 3, 2012
Minimal Linux: Filesystem

After building BusyBox you should end up with a directory named _install. Lets move the directory and rename it to something more usefull:

  mv _install ../rootfs

In rootfs we create dev, proc, sys and tmp directories. We need at least one device, which is the console and we need an init script as well. I also remove linuxrc.

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

The last file we need to create is init. Before giving a shell to the user lets 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. Archive the initramfs with cpio and compress it with gzip:

  find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz
  cd ..

That is all you need.
