\input{configpres}

\title{The Linux Boot Process}
\maketitle

\subsection{Boot Process}

\begin{frame}
\frametitle{Components of the Boot Process}
\begin{itemize}
\item Bootloader
\item Linux
\item ''Userspace''
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Boot Process Procedure}
\begin{enumerate}
\item bootloader initializes hardware
\item bootloader relocates kernel
\item bootloader provides parameters and starts kernel
\item Linux boots
\item Linux kernel mounts a RFS
\item Linux kernel starts first process (/sbin/init, /linuxrc, or specified with init= parameter)
\end{enumerate}
\end{frame}

\begin{frame}
\frametitle{Responsibilities of the Bootloader}
Low-Level Initialization:
\pause
\begin{itemize}
\item clocks (CPU, PLLs, peripherals...)
\item memory (DRAM-controller, NAND-controller...)
\item serial interface
\item provide parameters to the kernel
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{The Linux Kernel}
\begin{itemize}
\item setup interrupts (i.e. timer interrupt)
\item load drivers, initialize hardware
\item mount ''root filesystem'' to /
\item start the first process
\end{itemize}
\end{frame}

\subsection{init Systems}

\begin{frame}
\frametitle{The init System}
\begin{itemize}
\item System V init
\item systemd
\item busybox-init
\item OpenRC
\item upstart
\item \dots
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{System V init}
\begin{itemize}
\item behavior defined in /etc/inittab
\item start scripts in /etc/init.d
\item split into ''runlevels''
\item runlevels describe various system states (shutdown, single-user, multi-user with/without network, \dots)
\item System V does not understand dependencies, sequential calling of start scripts
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{systemd}
\begin{itemize}
\item starts processes in parallel (without explizitly configuring dependencies):
\begin{itemize}
\item creates sockets for communicating with the starting processes
\item data written so the sockets are buffered until the starting processes can receieve the data
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{systemd}
\begin{itemize}
\item configuration via invidividual text files (no shell code)
\item the actions to perform are based on the configuration and are performed by systemd (Linux executable)
\item this prevents starting many individual shell instances
\item administration via systemctl
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{systemd}
\begin{itemize}
\item ''targets'' replace the roll of ''runlevels'' (i.e. runlevel 0 == poweroff.target)
\item multiple targets can be activated simultaneously
\item configuration files in /etc/systemd and /lib/systemd
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{systemd}
\begin{itemize}
\item compatbile to System V init. Scripts in /etc/init.d will be started
\item uses ''control groups'' for starting/monitoring processes (systemd requires CGROUPS support in the kernel!)
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{systemd: Integrating own Services}
/lib/systemd/system/training.service
\begin{verbatim}
[Unit]
Description=Just a simple systemd service

[Service]
Type=oneshot
ExecStart=/home/devel/systemd_test.sh
StandardOutput=syslog
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{systemd: Integrating own Services}
/home/devel/systemd\_test.sh
\begin{verbatim}
#!/bin/sh

echo "Here I AM :)"
sleep 5
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{systemd: Integrating own Services}
/home/devel/systemd\_test.sh
\begin{verbatim}
$ systemctl enable training.service
ln -s '/lib/systemd/system/training.service'
     '/etc/systemd/system/multi-user.target.wants/training.service'
\end{verbatim}
\end{frame}

\subsection{Boot Time Analysis}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: Bootloader}
Use the scope, Luke! ;)
\begin{figure}[h]
\centering
\includegraphics[height=5cm]{images/at91_ipl_quiet_lpj_lzo.png}
\end{figure}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: Kernel}
\begin{itemize}
\item boot the target with initcall\_debug und printk.time=1
\item from the target: dmesg > bootlog.txt
\item copy bootlog.txt to the host
\item from the host:
\begin{verbatim}
perl linux-src/scripts/bootgraph.pl < bootlog.txt > bootlog.svg
\end{verbatim}
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: Kernel}
\begin{figure}[h]
\centering
\includegraphics[height=5cm]{images/bootlog.png}
\end{figure}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: System V}
Analyze the boot process with bootchart:
\begin{itemize}
\item boot the target with init=/sbin/bootchartd
\item after booting, stop bootchard on the target:
\begin{verbatim}
/sbin/bootchartd stop
\end{verbatim}
\item (for older versions) copy /var/log/bootchart.tgz to the host
\item (for older versions) from the host generate an SVG graphic file:
\begin{verbatim}
java -jar bootchart.jar -f svg bootchart.tgz
\end{verbatim}
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: System V / bootchart}
\begin{figure}[h]
\centering
\includegraphics[height=5cm]{images/bootchart.png}
\end{figure}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: systemd}
Analyze the boot process with systemd:
\begin{itemize}
\item boot the target via systemd
\item after booting, run systemd-analyze on the target
\begin{verbatim}
$ systemd-analyze blame
1897ms networking.service
1715ms vmware-tools.service
1234ms nfs-common.service

# or

$ systemd-analyze plot > boot.svg
\end{verbatim}
\item copy the output or plot to the host to analyze
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: systemd-analyze plot}
\begin{figure}[h]
\centering
\includegraphics[width=8cm]{images/debian_systemd_top.png}
\end{figure}
\end{frame}

\begin{frame}[fragile]
\frametitle{Boot Time Analysis: systemd-analyze plot}
\begin{figure}[h]
\centering
\includegraphics[width=8cm]{images/debian_systemd_bottom.png}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{Sources}
\begin{thebibliography}{1}
\bibitem{kof} Linux 2012, Michael Kofler, PEARSON Verlag
\bibitem{heise} http://www.heise.de/open/artikel/Das-Init-System-Systemd-Teil-1-1563259.html 
\end{thebibliography}
\end{frame}

\input{tailpres}
