117
Embedded Systems KUT 1-1 Embedded Systems Shell Command & Script, Linux Directories & Files, Host Booting Process, Systemd & Demon Services, Ubuntu Kernel Compile Prof. Myung-Eui Lee (A-405) [email protected]

Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-1

Embedded Systems

Shell Command & Script, Linux Directories & Files, Host Booting Process, Systemd & Demon Services,

Ubuntu Kernel Compile

Prof. Myung-Eui Lee (A-405)[email protected]

Page 2: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-2

Linux Operating System

Computer Hardware

System Shared Libraries (API)

Applications: Graphics UI, Compilers, Media player

API

UI

BIOS

Text UI = Shell: sh, csh, ksh, bash, tcsh, zsh

Compiler libraries

Device DrivesKernel

File management

Memory management

Process management

Page 3: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-3

Linux System User Interface : command.com in DOS

» Interface between OS and User» Divided into text based and graphical based» Allow user to make commands to the system

System Shared Libraries(API)» Comprise a set of functions that can be used by the applications

and library routines to use the services provided by the kernel Kernel

» The part of an OS where the real work is done  Memory management

→ Memory in a computer is divided into main memory (RAM) and secondary storage (usually refer to hard disk)

→ Memory is small in capacity but fast in speed, and hard disk is vice versa→ Data that are not currently used should be saved to hard disk first, while

data that are urgently needed should be retrieved and stored in RAM→ The mechanism is referred as memory management

Page 4: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-4

Linux System  Process Management

→ For a multitask system, multiple programs can be executed simultaneously in the system

→ When a program starts to execute, it becomes a process→ Kernel manages processes in terms of creating, suspending, and

terminating them→ A process is protected from other processes and can communicate with

the others   File Management

→ Control the creation & removal of files, and provide directory maintenance

→ For a multiuser system, every user should have its own right to access files and directories

Device drivers» Interfaces between the kernel and the BIOS (Hardware if no bios)» Different device has different driver

Page 5: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-5

Shell Command Shell types supported in RH9

» vi /etc/shells : sh(bourne), ash, csh, bash(default), tcsh Some file names are special

» / The root directory (not to be confused with the root user)» . The current directory» .. The parent (previous) directory» ~ My home directory (cd)

  pwd : display absolute path of working directory » ./command_name - run a command in the current directory

when the current directory is not on the path Pathnames

» Absolute:   List of directory names from root directory to desired file or

directory name, each separated by / -> /usr/share/xpdf» Relative:

  List of directory names from working directory to desired file or directory name, each separated by / -> usr/share/xpdf

Page 6: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-6

Shell Command Shell variables

» Standard variables #man bash  DISPLAY – the name of X window display  HOME – the name of home directory : /etc/passwd  USERNAME – the name of user name  SHELL – path to shell (/bin/bash) : /etc/passwd  PS1 – shell’s prompt  PWD – shell’s current directory

» echo “My home is $HOME”» user variable : var=3; echo $var

  $ : to refer to a value Quoting

» Single quote : literal = constant  echo ‘ HOME has value $HOME’ -> HOME has value $HOME

» Double quotes : variable  echo “HOME has value $HOME” -> HOME has value /root

Page 7: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-7

Shell Command Escaping

» ₩ : backward slash (escape character)  Override variable : force literal

» Variable  echo “HOME has value $HOME” -> HOME has value /root

» Literal  echo “HOME has value ₩$HOME” -> HOME has value $HOME

Combining commands» command 1 ; command 2 ; command 3

  To invoke several commands in sequence on a single command line» command 1 && command 2 && command 3

  Stop execution if any of them fails» command 1 || command 2 || command 3

  Stop execution as soon as one succeeds

Page 8: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-8

Shell Command Redirection

» command > file direct output of command to file instead of to standard output (screen), replacing current contents of file

» command >> file as above, except output is appended to the current contents of file

» command < file command receives input from file instead of from standard input (keyboard)

» cmd1 | cmd2 "pipe" output of cmd1 to input of cmd2  ls | more, ls | grep test

» tee read from std input and write to std output and file  sort < unsorted | tee sorted

Page 9: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-9

Shell Command Control characters (special keystrokes)

» Ctrl-C break, kill almost any program that is running » Ctrl-D end-of-file(input from the keyboard) or logout from

current terminal» Ctrl-L refresh the window » Ctrl-S pause screen output. Ctrl-Q key to resume output » Ctrl-U erase the entire line you're typing. » Ctrl-Z suspend the job that is running

  To send it to run in the background, hit "Ctrl-Z", then type “bg". Control + Alt

» [Alt][Ctrl][F1] switch to the first virtual text console   [Alt][Ctrl][Fn] - switch to the nth virtual text console. Typically,

there are six on a Linux PC system. » [Alt][Ctrl][F7] switch to the first GUI console, if there is one

running.» [Alt][Ctrl][Del] switch to run level 6(reboot)

  text command mode only (logout menu display at x window)

Page 10: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-10

Shell Command Create a File

» cat > file enter text and end with ctrl-D» vi file edit file using the vi editor

Make a Directory» mkdir directory

Remove File / Directory» rm file remove (delete) a file » rmdir dir remove an empty directory » rm -rf dir remove a directory and its contents » rm -i file remove file, but prompt before deleting

  default : alias at .bashrc (rm, mv, cp) Move (or Rename) Files and Directories

» mv src-file dest-file rename src-file to dest-file» mv src-file dest-dir move a file into a directory » mv src-dir dest-dir rename src-dir (= move to dest-dir )» mv -i src dest prompt before overwriting

Page 11: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-11

Shell Command List Files and Directories

» ls list contents of directory » ls -a include files with "." (dot files) » ls -l list contents in long format (show modes) » ls -F list files in current directory and indicate the file type

  * - executable , @ - symbolic link, | - pipe, = - socket

Copy Files» cp src-file dest-file copy src-file to dest-file» cp src-file dest-dir copy a file into a directory » cp -r src-dir dest-dir copy one directory into another » cp -a src dest copy with archive option all copy with symbolic link

  a = dpr : no-dereference (no symbolic link source), preserve(mode), recursive

Comparing Files» diff file1 file2 line by line comparison » cmp file1 file2 byte by byte comparison

Page 12: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-12

Shell Command

Display File Contents» cat file display contents of file » more file display contents of file one screen full at a time. » view file read only version of vi » head file display the first 10 lines of file» head -20 file display the first 20 lines of file» tail file display the last 10 lines of file» tail -20 file display the last 20 lines of file

Printing» lpr file print file on default printer » lpr -Pprinter file print file on printer» lpr -c# file print # copies of file» lpq show print queue » lprm -# remove print request # (listed with lpq)

Page 13: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-13

Shell Command

Changing Access Modes» chmod mode file1 file2 ... (changes files) » chmod -R mode dir (changes all files and directories in dir )

  Mode Settings → u user (owner) : g group : o other → + add permission : - remove permission → r = 4 read : w = 2 write : x = 1 execute

  chmod go +rwx file→ Adds read, write, and execute permissions for group and other on file.

  chmod 755 file→ Full permission for the owner, read and execute access for the group

and others.  chmod +x file

→ Make the file executable to all users.

Page 14: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-14

Shell Command Search Files and Text within Files

» grep string file (or filelist) show lines containing string in any file in filelist

» grep -v string file (or filelist) show lines not containing string» grep -i string file (or filelist) show lines containing string, ignore

case» grep –r string /dir look for and list all files containing string (start

from /dir)» find / -name file starting with the root directory, look for file» find ./ -name dir –type d look for dir from current + subdir» which file show the subdirectory containing the executable file

called file : which vi» whereis file Locate the binary, source and man page files for a

command : whereis cp» updatedb create or update the database of files on all file systems

attached to the linux root directory» locate file find a file called file – this assumes you have already

used the command updatedb

“grep” : g /re/ psearch globally for lines matching the regular expression, and print them.

Page 15: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-15

Shell Command Compressing/Decompressing Files

» compress file encode file, replacing it with file.Z» uncompress file.Z decode file.Z, replacing it with file» tar -cvf file.tar file or dir compress file or directory» tar -xvf file.tar decompress file.tar» gzip file.tar resulted file is file.tar.gz» gzip –d file.tar.gz uncompressed file is file.tar» tar –czvf file.tar.gz file or dir compress file or directory, first

tar and then gzip» tar -xzvf file.tar.gz or tar -xzvf file.tgz decompress the files

contained in the zipped and tarred archive.» tar -xjvf file.tar.bz2 decompress the files contained in the

zipped and tarred archive.» zcat file.Z display compressed file

Page 16: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-16

Shell Command Filesystem Management

» dump Used to back up an ext2 filesystem. Complement is restore.

» restore Used to restore an ext2 filesystem.» fdisk Used to fix or create partitions on a hard drive.» fdformat Formats a floppy disk.» fsck Used to check and repair a Linux file system.

  Must not be run on a mounted file system ( use e2fsck ) » mkfs Initializes a Linux filesystem. This is a front end that runs a

separate program depending on the filesystem's type.  mke2fs Create a Linux second extended filesystem.

» mount Used to mount a filesystem. Complement is umount.» umount Unmounts a filesystem. Complement is mount.

Page 17: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-17

Shell Command Linux Job Management

» at Similar to cron but run only once.  at 23:55 12/31/09 < script file , at -l

» atq Lists the user's pending jobs. = at -l» atrm number Deletes at job number(at at –l command).» batch Executes commands when system load levels drop below

0.8 (/proc/loadavg). same as at>command [cnt+d] » cron A demon used to set commands to be run at specific times.

Starts the commands in the crontab file.   30 8 * * mon /root/scripts/backup.sh

→ run custom script every Monday at 8:30AM » nice Run a program with modified scheduling priority from

-20(hightest) to +19(lowest).-> 10 by default  nice -5 sort file1 > file2

» nohup Run a command immune to hangups (allows a process to continue after you log out).  nohup sleep 1000

“job” definitionPrograms and scripts run by users in a bash shell

Page 18: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-18

Shell Command Linux Process management

» bg Starts a suspended process in the background» fg Starts a suspended process in the foreground» jobs report current jobs and job-id numbers» kill pid or %job_id Kill a process or jobs» Kill -9 pid or %job_id The -9 flag forces the process to die» ps Lists all current running processes and pids» ps ax |more to see all processes including daemons» pstree Display the tree of running processes.» top Display the processes that are using the most CPU resources.» & Run a job in the background.

Information on Users» finger or finger user get information on a user » who who is currently logged in » w show who is logged in and what they are doing

Page 19: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-19

Shell Command Network setup and commands

» ftp File transfer program.» ifconfig Configure a network interface.» ifdown Shutdown a network interface.» ifup Brings a network interface up. » iptables Administration tool for packet filter and NAT

  iptables –F : flush all the rules, iptables –L : list» netconfig GUI step by step network configuration program.» netstat Displays information about the systems network

connections, including port connections, routing tables, and more. The command "netstat -r" will display the routing table.

» nslookup Used to query DNS servers for information about hosts.

» ping is there anybody out there? Check a host for existence» portmap RPC program number mapper. Must be running to

make RPC calls.

Page 20: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-20

Shell Command» route Show or manipulate the IP routing table.» showmount Show mount information for an NFS server.» tcpdump Dump traffic on a network. Prints out headers of

packets that match the boolean expression.» telnet User interface to the TELNET protocol.» traceroute show me how to get from here to there.

Starting & Stopping» shutdown -h now Shutdown the system now and do not reboot» halt Stop all processes - same as above» shutdown -r now Shutdown the system now and reboot» reboot Stop all processes and then reboot – same as above» Poweroff Shutdown the system now and power-off

Page 21: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-21

Shell Command Module and Kernel Management

» depmod Handle loadable modules automatically. Creates a makefile-like dependency file. /lib/modules/2.4.20-8smp/modules.dep

» insmod Install loadable kernel module.» modprobe Used to load a set of modules. first check module

dependency, and then install modules. » lsmod List currently installed kernel modules.» rmmod Unload loadable modules.» dmesg Print or control the kernel ring buffer. This shows the last

kernel startup messages.» genksyms Generate symbol version information. *.ver

Timesavers» alias string command : alias dir=‘ls –lF’, alias cls=‘clear’» history show command history

  !num - repeat command with history number num  !! - repeat previous command   !$ - the last parameter from the previous command

Page 22: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-22

Shell Command System Information

» arch Display machine architecture.» df Shows disk free space .» du Shows disk usage, disk directory and all its files contain.» free Display used and free memory on the system.» lsdev Display information about installed hardware via files in the

/proc directory(not in Redhat).» lsof List open files.» lspci List PCI devices .» procinfo Display system status gathered from proc(not in Redhat).» runlevel Find the current and previous system runlevel.» strace Trace sytem calls and signals for a binary program.

# strace ./hello-x86 » stty Display and change terminal line settings.» tty Print the filename of the terminal connected to standard input.» uname display the machine and operating system name

Page 23: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-23

Shell Command Linux User Management

» ac Print statistics about users' connect time(not in Redhat).» useradd Adds a user to the system» adduser same as useradd (symbolic link to useradd) » userdel Delete a user account and related files.» usermod Modify a user account.» users Print the user names of users currently logged in.» chgrp Changes the group ownership of file.» chown Change the owner of file to another user.» ash, bash, csh Change the login shell.» finger See what users are running on a system.» groupadd Create a new group.» groupdel Delete a group.» groupmod Modify a group.» passwd Set a user's pass word.

Page 24: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-24

Shell Command

» su Create a shell with substitute user ID» sulogin Single user mode login, need root password

  not part of any currently supported standard; it is an extension of AT&T System V

» vigr Edit the group file = vi /etc/group» vipw Edit the password file = vi /etc/passwd» wall Send a message to everybody's terminal.» whoami Print current user id.» quota Display users' limits and current disk usage.» quotacheck Used to check a filesystem for usage, and update

the quota.user file.» repquota Lists a summary of quota information on filesystems.

Environment» env Show all environment variables.» export Set the value of a variable so it is visible to all

subprocesses.» reset Restores runtime parameters for session to default values.

Page 25: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-25

Shell Command Miscellaneous Commands

» clear clear the screen» echo display a message on the screen» file Display file information» dd Convert and copy a file

  dd if=boot.img of=/dev/fd0» ln Make links(alias) between files

  Hard link : default, same size, same inode (ls –i)  Symbolic link : -s option, pointer(small size)

» mknod Make a block or character special file» touch Change file timestamps to the current time & Make the file

if it doesn't exist» patch Apply a diff file to an original» sleep number Delay for a specified number of second» wc file Count lines, words, characters in file

Page 26: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-26

Shell Command Linux Programming

» as GNU assembler. : more details in chap 4/6» ld GNU linker.» gcc GNU c and c++ compiler.» gdb Debugging program.» make GNU make utility to maintain a group of programs» as86 Assembler for as86 : apt install bin86» ld86 Linker for as86 : apt install bin86» awk programming utility - allows finding of lines with specific

characters (Pattern scanning and processing language)  awk '{sum+=$1} END {print sum}' file.txt  Sum the first column of numbers in a file.txt (cat > file.txt)

» gawk GNU's implementation of awk

Page 27: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-27

Shell Command System time

» cal Calendar.» clock Used to change or get current time. » date Print or set the system date and time.» hwclock Set or read the hardware CMOS clock.» uptime Reports how long the system has been running.

rpm : Redhat» rpm -ihv name.rpm Install the rpm package called name» rpm -Uhv name.rpm Upgrade the rpm package called name» rpm -e package Delete the rpm package called package» rpm -ql package List the files and state the installed version of

the package called package» rpm -qa list all packages installed

Page 28: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-28

Shell Command apt : Debian

» The first stable version of apt was released in the year 2014» Introduced in 2016 with the release of Ubuntu 16.40» Eventually many other distributions started to use apt instead of

apt-get» apt is the command that is being recommended by the Linux

distributions» Most important of all, it is easier to use with its fewer but easy to

remember options.» Package management commands are scattered across apt-get

and apt-cache» Apt shows the progress bar and the number of packages that can

be upgraded» While apt-get will still be used and will be continued, you should

start using apt more often* Note : https://itsfoss.com/apt-vs-apt-get-difference/http://www.linux-magazine.com/Issues/2018/208/apt-vs.-apt-get

Page 29: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-29

Function apt-get apt

Install package apt-get install <package> apt install <package>

Remove package apt-get remove <package> apt remove <package>

Remove package including configuration apt-get purge <package> apt purge <package>

Update a package lists from the repositories to get information on the newest versions of packages and their dependencies (/etc/apt/source.list)

apt-get update apt update

Upgrade packages (without removing or reinstalling)- new packages will be installed if required to satisfy dependencies, but existing packages will never be removed.

apt-get upgrade apt upgrade

Upgrade packages (with removing and reinstalling)- full-upgrade performs the function of upgrade but will remove currently installed packages if this is needed to upgrade the system as a whole.

apt-get dist-upgrade apt full-upgrade

Remove unnecessary dependencies apt-get autoremove apt autoremove

Search package apt-get search <package> apt search <package>

Display package information apt-cache show <package> apt show <package>

Display active package sources in detail apt-cache policy apt policy

Display available and installed package versions apt-cache policy <package> apt policy <package>

New Commands

Edit packages sources – apt edit-sources

List packages by criteria dpkg --get-selections > list.txt apt list

Shell Command : apt-get vs. apt

* Repositories are servers which contain sets of packages, and PPA(Personal Package Archive) is a repository of packages that uses Launchpad(http://ppa.launchpad.net)

Page 30: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-30

Shell Command Another Popular Package Tool

» aptitude : both command-line + menu driven(interactive) » dpkg : low level package manager for .deb packages

dpkg» “.deb” file contains the files needed by an application to run, as well

as "meta-data" that holds other information, such as the names of the dependencies the application needs.

» # dpkg -c package_name.deb : contents » # dpkg -I package_name.deb : meta data information» # dpkg -I package_name.deb | grep Depends : dependencies» dpkg just installs the .deb file, but will not install any its

dependencies because it doesn't have those files and it does not have access to "repositories"

» apt looks for the dependencies and install them. It even looks at the currently installed dependencies and determines ones that are not being used by any other packages

Page 31: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-31

Shell Command

dpkg –cont.» Because of that just installing a package with dpkg, may lead to a

later problem where dependency resolution may end up with a broken system

Editor» vi (vim), gedit, kedit, emacs, nano» vi editor

  Command mode – initial state  Insert mode – entered with a, i  Last line mode – entered with : ? , / - pattern search

» https://vimhelp.org/

Page 32: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-32

Documentations Documentation

» man command display on-line manual pages (/usr/share/man)» info command readable Info documents (/usr/share/info)» man -k string list one-line summaries of manual pages

containing string» apropos keyword - Show all commands with the keyword in

their description. The same as the "man -k" command.» whatis Search the whatis database using manual pages.

  /etc/cron.daily/makewhatis.cron makewhatis command

» /usr/share/doc & Kernel source /Documentation» https://www.kernel.org/doc/man-pages/» http://manpages.ubuntu.com/manpages/bionic/en/» https://manpages.debian.org/

Page 33: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-33

Shell Script

Shell script» Shell Script is series of command written in plain text

file(batch file)  Useful to create our own commands.   Save lots of time.   To automate some task of day to day life.   System Administration part can be also automated.

Following steps are required to write shell script:» 1. Use any editor like vi to write shell script.

  The first line of the file must be #!/bin/bash» 2. After writing shell script, set execute permission for the script

as follows:  chmod +x script-name

» 3. Execute the script as:  bash script-name, sh script-name, ./script-name

Page 34: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-34

Linux File Structure

그림 1‐3‐1. 커널소스트리구조

Page 35: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-35

Linux Directories

File System Standard (FSSTND) » Proposed in 1994, every LINUX system should contain a set of

standard files and directories» Defines the directory structure and directory contents in Linux

distributions » Maintained by the Linux Foundation» The latest version is 3.0, released on 3 June 2015» http://refspecs.linuxfoundation.org/fhs.shtml» https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard» https://wiki.debian.org/FilesystemHierarchyStandard

Page 36: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-36

Linux Directory Ubuntu : 3.0

Page 37: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-37

Linux Directories Linux Directories

» Requirements : The following directories, or symbolic links to directories, are required in /

» https://www.debian.org/doc/packaging-manuals/fhs/fhs-3.0.htmlDirectory Descriptionbin Essential command binariesboot Static files of the boot loaderdev Device filesetc Host-specific system configurationlib Essential shared libraries and kernel modulesmedia Mount point for removable mediamnt Mount point for mounting a filesystem temporarilyopt Add-on application software packagesrun Data relevant to running processessbin Essential system admin command binariessrv Data for services provided by this systemtmp Temporary filesusr Secondary hierarchyvar Variable data

Page 38: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-38

Linux Files Typical Linux Files

» Files in /bin» Requirements : /bin contains commands that may be used by

both the system administrator and usersCommand Descriptioncat Utility to concatenate files to standard outputchgrp Utility to change file group ownershipchmod Utility to change file access permissionschown Utility to change file owner and groupcp Utility to copy files and directoriesdate Utility to print or set the system data and timedd Utility to convert and copy a filedf Utility to report filesystem disk space usagedmesg Utility to print or control the kernel message bufferecho Utility to display a line of texthostname Utility to show or set the system's host namekill Utility to send signals to processesln Utility to make links between fileslogin Utility to begin a session on the systemls Utility to list directory contentsmkdir Utility to make directories

Page 39: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-39

Linux Directory Redhat 9.0

Page 40: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-40

Linux Directories

Linux Directories» root - The home directory for the root user » home - Contains the user's home directories» bin – shell command & essential command for both system admin

and normal users  all commands needed to boot the system or run it in single-user mode  cp, ls, cat, mv, grep, kill, ps, rm, rpm, vi, etc…

» sbin – system admin command(not intended for normal users)  fdisk, fsck, halt, shutdown, insmod, mkfs, etc…  Utilities used for system admin are stored in /sbin, /usr/sbin, and

/usr/local/sbin → /sbin : binaries essential for booting, restoring, recovering, and/or repairing

the system in addition to the binaries in /bin.→ /usr/sbin : binaries for graphic or Office program(less important)→ /usr/local/sbin : Locally-installed(source compiled) system administration

programs

system install program

user install program

Page 41: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-41

Linux Directories

» usr – User application program, most user command→ Contains all commands, libraries, man pages, games and static files for

normal operation(shareable and read-only data)  bin - Almost all user commands(gcc, gdb, vim,…), some commands are

in /bin or /usr/local/bin.  sbin - System admin commands not needed on the root filesystem. e.g.,

most server programs(httpd, pppd,..)  include - Include files used in C programs such as stdio.h .   lib - Libraries for programming and packages   local - The place for locally installed software and other files.

→ needs to be safe from being overwritten when the system software is updated

  man - Manual pages for user installed program → 실제 파일 /usr/share/man, #man –a printf : printf(1), printf(3)

  share - Architecture-independent data→ info - Info documents→ doc - Documentation

  src – source programs used to build system (linux-2.4.20-8)  X11R6 - The X windows system files.

Page 42: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-42

Linux Directories» etc - Configuration files specific to the machine.

  profile.d - contains scripts that are run by /etc/profile upon login.  init.d - contains most of the initialization scripts (crond, apmd,…)  xinetd.d – Super demon service directory (RH 7.0 later)   rc.d - contains a number of shell scripts that are run on bootup at

different run levels. → /etc/rc.d/init.d – Link to /etc/init.d→ /etc/rc.d/rc*.d – Contains script files for services to be started (S) and

stopped (K) at that run level (S?? : number means process sequence )» where ``*'' is a number corresponding to the default run level. » Run Level : “ init * ” command

0 Halt the system1 Single-user mode (for special administration)2 – 5 Normal operation (user defined)6 Reboot

» these files are symbolic links to the initialization scripts themselves, which are in /etc/rc.d/init.d.

  skel - When a home directory is created it is initialized with files from this directory(.bash_profile, .bashrc, …)

  sysconfig - Files that configure the linux system for devices( vi keyboard)

2 – Multiuser (without NFS)3 – Full multiuser mode4 – unused5 – X11

Demon

Page 43: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-43

Linux Directories

» var - Contains files that change for mail, news, printers log files, man pages, temp files  cache - Application cache data  lib - Variable state information  local - Variable data for programs installed in /usr/local  lock - Lock files

→ Used by a program to indicate it is using a particular device or file  log - Log files from programs such as login and syslog  run - Data relevant to running processes

→ information about the system that is valid until the system is next booted

  spool – Directory for mail/news, and application spool data(printer)  tmp - Temporary files preserved between system reboots  www – Web server directory (httpd - index.html)

» dev - Device files» boot - Files used by the bootstrap loader (GRUB or LILO). Kernel

images are often kept here. the binary of the Linux kernel is in /boot/vmlinux-2.4.20-8smp file.

Page 44: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-44

Linux Directories

» lib - Shared libraries needed by the programs on the root file system  modules - Loadable kernel modules

» proc – Kernel and process information(virtual file system), Each process has a directory below proc.  1 - A directory with information about process number 1= /sbin/init

» mnt - Mount points for temporary mounts by the system administrator.

» tmp - Temporary files. Programs running after bootup should use /var/tmp.

Page 45: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-45

Linux Files Typical Linux Files

» /boot/vmlinuz - the typical location and name of the Linux kernel( symbolic link to vmlinuz-2.4.20-8 )

» /dev/fd0 - first FDD, /dev/fd1 – second FDD» /dev/fd0H1440 - driver for the first floppy drive in high density

mode. » /dev/hda - first IDE HDD, /dev/sda – first SCSI/USB HDD» /dev/cdrom - the IDE cdrom drive. Most often, a symbolic link

to the true cdrom driver file (/dev/hdb). » /dev/null - a virtual-file that can be written to. Data written to

this file gets discarded. » /etc/rc.d/rc.sysinit - run once at boot time by /etc/inittab» /etc/rc.d/rc – run rc?.d directory Snn / Knn (K:kill / S:start)» /etc/rc.d/rc.local - bash script that is executed at the end of

login process (executed *after* all the other init scripts: S99local).» /etc/profile – system-wide environment variables for all users.» /etc/bashrc - system-wide default functions and aliases for the

bash shell.

Page 46: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-46

Linux Files

» /etc/modules.conf - aliases and options for configurable modules» /etc/crontab - shell script to run different commands periodically

(hourly, daily, weekly, monthly, etc.) » /etc/DIR_COLORS - used to store colors for different file types

when using ls command. The dircolors command uses this file when there is not a .dir_colors file in the user's home directory.

» /etc/exports - specifies hosts to which file systems can be exported using NFS. “man exports” contains information on how to set up this file for remote users.

» /etc/hosts - contains a list of host names and absolute IP addresses.

» /etc/resolv.conf - contains a list of domain name servers  /etc/sysconfig/network-scripts/ifcfg-eth0 확인

» /etc/hosts.allow - hosts allowed (by the tcpd daemon) to access Internet services

» /etc/hosts.deny - hosts forbidden (by the tcpd daemon) to access Internet services

Page 47: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-47

Linux Files» /etc/inittab – linux initialization table

id:runlevels:action:process -> man inittab  setting the default runlevel  running the rc.sysinit script contained in /etc/rc.d   running the rc script in l5:5:wait:/etc/rc.d/rc 5 → running the script in

/etc/rc.d/rc?.d   running the last rc.local script in /etc/rc.d → link to S99local  setting up virtual login terminals  running xdm for a graphical login prompt (only if the default runlevel is 5)

» /etc/issue - pre-login message. » /etc/motd - message of the day(motd) file, printed immediately after

login.» /etc/grub.conf - configuration file for grub(GRand Unified Bootloader)

boot loader » /etc/mtab - shows currently mounted devices and partitions and their

status» /etc/fstab - contains information on partitions and file systems used by

system to mount different partitions and devices

Page 48: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-48

Linux Files

Note : /etc/fstabman mount» 1. The name of the device such as "/dev/hda1"» 2. The mount point. Use "/" for root, "/dos" for DOS, "swap" or

"none" for the swap partition» 3. The type of filesystem. mini, ext, ext2(linux native), msdos,

hpfs, ntfs, fat32, iso9660(CD-ROM), NFS, vfat, swap.» 4. The mount options for use with the file system. defaults= rw,

suid, dev, exec, auto, nouser, and async.» 5. The frequency the file system needs to be dumped (backed

up) by the dump command. 0 or nothing means it is not dumped. If 1, it is backed up during a system backup.

» 6. the file systems should be checked at reboot time by the fsckprogram. Your root should be 1, others are in ascending order or 0 to not be checked.

Page 49: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-49

Linux Files» /etc/smb.conf - config file for the SAMBA server. » /etc/passwd - contains passwords and other information

concerning users who are registered to use the system. this is readable only by root and encoded password is in /etc/shadow.   passwd account name  melee:x:501:500::/home/melee:/bin/bash

→ login name : dummy passwd : user ID : group ID: user information : home directory : shell location

» /etc/group - similar to /etc/passwd but for groups » /etc/printcap - shows the setup of printers » /etc/termcap - ASCII database defining the capabilities and

characteristics of different consoles, terminals, and printers  console = physical keyboard and monitor(only one for one

computer)   terminal = can be physical as well as virtual.

» /etc/X11/XF86Config - X configuration file.» /proc/cpuinfo - cpu information

Page 50: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-50

Linux Files

» /proc/filesystems - prints filesystems currently in use » /proc/interrupts - prints interrupts currently in use » /proc/ioports - contains a list of the i/o addresses used by

various devices connected to the computer» /proc/kcore – contains the memory image for kernel debugging.

the command ls -l /proc/kcore will give the amount of RAM on the computer.

» /proc/version - prints Linux version and other info » /var/log/messages - used by syslog daemon to store kernel

boot-time messages » /var/log/dmesg – print the kernel ring buffer(bootup messages)

  “dmesg” command» /var/log/lastlog - used by system to store information about last

boot(binary data)

Page 51: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-51

Dot Files Typical Dot Files

» . files = Hidden Files  Not visible by default to normal directory-browsing

→ files named with a leading dot are not normally presented in directory listings ( “ls –a” command)

  For this reason, many programs define one or more dot files in which startup or configuration information may be optionally recorded. – gnome, x windows, mozilla,….

» .bash_logout - file executed by bash shell on logout (=clear)» .bash_history – bash shell command history» .bash_profile - initialization of bash shell run only on login.

  Bash looks first for a .bash_profile file when started as a login shell » .bashrc - initialization command run when bash shell starts up » .cshrc - initialization commands that are run automatically when

C shell is initiated Note : The process of executing start-up shell scripts

Redhat: 1. /etc/profile → 2. ~/.bash_profile → 3. /etc/bashrc → 4. ~/.bashrcUbuntu: 1. /etc/profile → 2. ~/.profile → 3. /etc/bash.bashrc → 4. ~/.bashrc

Page 52: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-52

Boot Terminology

Loader» Program that moves bits from disk (usually) to memory and then

transfers CPU control to the newly loaded” bits (executable). Boot loader / Bootstrap

» The computer term bootstrap began as a metaphor in the 1950s.» In computers, pressing a bootstrap button caused a hardwired

program to read a bootstrap program from an input unit and then execute the bootstrap program which read more program instructions and became a self-sustaining process that proceeded without external help from manually entered instructions.

» Program that loads the “first program” (the kernel)» LILO, GRUB, NTLDR

Boot ROM / ROM Monitor / BIOS» Persistent code that is “already loaded” on power-up

Boot Manager» Program that lets you choose the “first program” to load

Page 53: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-53

Linux Startup Process -Init Process

Init Process» Init is the parent of all processes on the system» Init is executed by the kernel and is responsible for starting all

other processes» Init is the parent of all processes» Init is "to get everything running the way it should be”» This includes checking and mounting file systems, starting up

necessary user services, and ultimately switching to a user-environment when system startup is completed

3 Major Init Methods» 1. System V init» 2. Upstart» 3. Systemd

Page 54: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-54

Linux Startup Process -Init Process

1. System V init» Inherited from UNIX System V» Strictly synchronous, blocking future tasks until the current one has

completed» Unable to handle various non-startup-tasks on a modern computer

2. Upstart» Written by Scott James Remnant, a former employee of Canonical

Ltd.» An event-based replacement for the traditional init daemon» An event-driven model allows it to respond to events asynchronously» Handles starting of the tasks and services during boot and stopping

them during shutdown» Supervises the tasks and services while the system is running» The design goals are easy transition and perfect backward

compatibility with System V init » Upstart can run unmodified System V init scripts

Page 55: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-55

History of Unix

* https://en.wikipedia.org/wiki/Unix

Page 56: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-56

Linux Startup Process -Init Process

2. Upstart – cont.» First included in Ubuntu in the 6.10 release in late 2006, replacing

System V init» Eventually removed from the Debian archives in December 2015

3. Systemd» Lennart Poettering and Kay Sievers, the software engineers working

for Red Hat who initially developed system from 2010» Improve the software framework for expressing dependencies, to

allow more processing to be done concurrently or in parallel during system booting, and to reduce the computational overhead of the shell

Page 57: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-57

Linux Startup Process -Init Process

3. Systemd – cont.» systemd is not just the name of the init daemon but also refers to the

entire software bundle around it.» In addition to the systemd init daemon, includes the daemons

journald, logind and networkd, and many other low-level components.

» In January 2013, Poettering described systemd not as one program, but rather a large software suite that includes 69 individual binaries.

» As an integrated software suite, systemd replaces the startup sequences and runlevels controlled by the traditional init daemon, along with the shell scripts executed under its control.

» Systemd also integrates many other services that are common on Linux systems by handling user logins, the system console, device hotplugging (see udev), scheduled execution (replacing cron), logging, hostnames and locales.

» Systemd executes elements of its startup sequence in parallel, which is supposed to be faster than sequential approaches.

Page 58: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-58

Linux Startup Process -Init Process

3. Systemd – cont.» Like the init daemon, systemd is a daemon that manages other

daemons, is the first daemon to start during booting and the last daemon to terminate during shutdown.

» For inter-process communication (IPC), systemd makes Unix domain sockets and D-Bus available to the running daemons.

https://en.wikipedia.org/wiki/Systemd

Page 59: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-59

Linux Startup Process -Init Process

3. Systemd – cont.» In May 2011 Fedora became the first major Linux distribution to

enable systemd by default.» In February 2014, Mark Shuttleworth(CEO of Canonical Ltd)

announced on his blog that Ubuntu would follow in implementing systemd(https://www.zdnet.com/article/after-linux-civil-war-ubuntu-to-adopt-systemd/).

» Ubuntu starts using systemd by default with 2015 release, Ubuntu 15.04

» Since 2015, many Linux distributions have adopted systemd.

Page 60: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-60

Linux Startup Process -Init Process

Criticism» Critics regard systemd as overly complex and suffering from the

excessive ongoing expansion or addition of new features.» Between October 2013 and February 2014, a long debate among the

Debian Technical Committee, discussing which init system to use as the default in Debian 8 "jessie".

» In November 2014 Debian Developer Joey Hess, Debian Technical Committee members Russ Allbery and Ian Jackson, and systemd package-maintainer Tollef Fog Heen resigned from their positions.

» In an August 2014 article published in InfoWorld, Paul Venezia wrote about the systemd controversy and attributed the controversy to violation of the Unix philosophy, and to "enormous egos who firmly believe they can do no wrong“.

» In a September 2014 ZDNet interview, prominent Linux kernel developer Theodore expressed his opinion that the dispute over systemd's centralized design philosophy, more than technical concerns, indicates a dangerous general trend toward uniformizing the Linux ecosystem.

Page 61: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-61

Linux Startup Process -Init Process

Criticism - cont.» Debian 8 was released in April 2015, using systemd as the new init

system.» This decision was very controversial and subsequently led to the

creation of Devuan, a fork of Debian without the mandatory dependency on the Systemd suite.

» Anti Leonard Poettering petition: Stop writing useless linux programs in 2011 : https://nosystemd.org/

» The systemd developer Poettering produced an initialization system that no one liked, but everyone adopted for use with Linux containers.

Poettering Blog Posts» http://0pointer.de/blog/projects/systemd.html» http://0pointer.de/blog/projects/the-biggest-myths.html» http://0pointer.de/blog/projects/why.html

Page 62: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-62

Booting Process

System V(init)

Page 63: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-63

Booting Process : System V(init)

1. Computer Turn On2. CPU jump to address of BIOS (0xFFFF0)3. BIOS runs POST (Power-On Self Test)4. Find bootable devices5. Loads and execute boot sector from MBR (INT 19/ Stage 1)6. GRUB loads the kernel into memory and passes control on to

the kernel (Kernel loader / Stage 2) refer to slide #547. Kernel running and /sbin/init start →/etc/inittab script start8. /etc/inittab →/etc/rc.d/rc.sysinit and /etc/rc.d/rc (rc 5)

script start* /etc/inittab script# System initialization.si::sysinit:/etc/rc.d/rc.sysinit.....l5:5:wait:/etc/rc.d/rc 5

* /etc/rc.d/rc script# Now run the START scriptsfor i in /etc/rc.d/rc$runlevel.d/S*; do

* /etc/rc.d/rc5.d/S99local last scriptlink to /etc/rc.d/rc.local

Page 64: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-64

Master Boot Record

OS is booted from a hard disk, where the Master Boot Record (MBR) contains the primary boot loader

The MBR is a 512-byte sector, located in the first sector on the disk (sector 1 of cylinder 0, head 0)

After the MBR is loaded into RAM, the BIOS yields control to it.

The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR

https://thestarman.pcministry.com/asm/mbr/GRUB.htm

Page 65: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-65

Linux kernel boot

1. With the kernel image in memory and control given from the stage 2 boot loader, the kernel stage begins

2. start() assembly routine does some basic hardware setup and invokes the startup_32() routine : currently no start, only startup_32

3. startup_32() sets up a basic environment (stack, etc.) and clears the Block Started by Symbol (BSS)

4. The kernel is then decompressed through a call to a C function called decompress kernel (located in … /compress/misc.c)

Page 66: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-66

Linux kernel boot

5. When the kernel is decompressed into memory, another startup_32() function(/arch/i386/kernel/head.S) is called. In the new startup_32() (also called the swapper or process 0), the page tables are initialized and memory paging is enabled. The type of CPU is detected.

6. With the call to start_kernel() (/init/main.c) , a long list of initialization functions are called to set up interrupts, perform further memory configuration, and load the initial RAM disk.

7. In the end of start_kernel(), a call is made to rest_init() →kernel_thread(init()) (/kernel/fork.c) to start the init()(/init/main.c) → /sbin/init , which is the first user-space process(= spawn init() process as a “kernel thread”)

8. After the call to cpu_idle() (=become idle process), the scheduler can now take control .

9. With interrupts enabled, the pre-emptive scheduler periodically takes control to provide multitasking.

Page 67: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-67

initrd

During the boot of the kernel, the initial-RAM disk (initrd) that was loaded into memory by the stage 2 boot loader is copied into RAM and mounted.

This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks.

Since the necessary modules needed to interface with peripherals can be part of the initrd, the kernel can be very small

After the kernel is booted, the root file system is pivoted (via pivot_root) where the initrd root file system is unmounted and the real root file system is mounted.

#man initrd or /usr/src/linux-2.4.20-8/Documentation

Page 68: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-68

sbin/init process

The first thing the kernel does is to execute /sbin/initprocess

/sbin/init process is the root/parent of all processes executing on Linux

/sbin/init process is identified by process id "1“ /sbin/init process is responsible for starting system

processes as defined in the /etc/inittab file

- Note –* init() begins life as a “kernel thread” and ends by starting

the user-level init process (/sbin/init)* kernel space program : init() in linux/init/main.c* user space program : /sbin/init

Page 69: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-69

Booting Process

systemd(init)

Page 70: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-70

Host Boot Sequence

Kernel Start Point : 4.19.60» Kernel Link Script File

  /usr/src/linux-4.19.60/arch/x86/boot/setup.lds  ENTRY(_start)

Page 71: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-71

Host Boot Sequence Kernel Start Point

» Head File  /usr/src/linux-4.19.60/arch/x86/boot  .globl “_start”

Page 72: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-72

Host Boot Sequence

::

start()./arch/x86/boot/header.S

start_of_setup()./arch/x86/boot/header.S

main()./arch/x86/boot/main.c

go_to_protected_mode()./arch/x86/boot/pm.c

protected_mode_jump()./arch/x86/boot/pm.c

in_pm32()./arch/x86/boot/pmjump.S

start_32() entrypoint ./arch/x86/boot/header.S

Page 73: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-73

Host Boot Sequence

./arch/x86/boot/pm.c

::

Page 74: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-74

Host Boot Sequence

./arch/x86/boot/pm.c

./arch/x86/boot/pmjump.S

Page 75: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-75

Host Boot Sequence

./arch/x86/boot/pm.c

./arch/x86/boot/pmjump.S

./arch/x86/boot/pm.c

Page 76: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-76

Host Boot Sequence

./arch/x86/boot/pm.c

./arch/x86/boot/pmjump.S

./arch/x86/boot/pmjump.S

Page 77: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-77

Host Boot Sequence

./arch/x86/boot/compressed/head_64.S

./include/linux/init.h

• Note [section flags] : https://sourceware.org/binutils/docs/as/Section.html#Section

./arch/x86/boot/compressed/vmlinux.lds

startup_32./arch/x86/boot/compressed/head_64.S

startup_64./arch/x86/boot/compressed/head_64.S

extract_kernel()./arch/x86/boot/compressed/misc.c

x86_64_start_kernel()./arch/x86/kernel/head64.c

x86_64_start_reservations()./arch/x86/kernel/head64.c

start_kernel()./arch/x86/kernel/head64.c

Page 78: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-78

Host Boot Sequence

./arch/x86/boot/compressed/head_64.S

Page 79: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-79

Host Boot Sequence

./arch/x86/kernel/head_64.S

::

Page 80: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-80

Host Boot Sequence

::

./arch/x86/kernel/head_64.S

./arch/x86/kernel/head64.c

Page 81: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-81

Host Boot Sequence

./arch/x86/kernel/head64.c

Page 82: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-82

Host Boot Sequence

start_kernel()./init/main.c

rest_init()./init/main.c

kernel_thread(kernel_init())./init.main.c

kernel_thread()./kernel/fork.c

::

./init/main.c

./init/main.c

B

A

Page 83: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-83

Host Boot Sequence -A

cpu_startup_entry()./kernel/sched/idle.c

do_idle()./kernel/sched/idle.c

./init/main.c

./kernel/sched/idle.c

Page 84: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-84

Host Boot Sequence -B

./init/main.c

kernel_init()./init/main.c

try_to_run_init_process()./init/main.c

run_init_process./init/main.c

do_execve()./init/main.c

::

Page 85: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-85

/sbin/init is symbolic link to /lib/systemd/systemd» The very first target executed by systemd is “default.target”

* Reference- https://en.wikipedia.org/wiki/X86_assembly_language- https://en.wikipedia.org/wiki/X86#x86_registers- https://software.intel.com/en-us/articles/intel-sdm- https://developer.amd.com/resources/developer-guides-manuals/- https://sourceware.org/binutils/docs-2.32/as/index.html- https://sourceware.org/binutils/docs-2.32/ld/index.html- https://github.com/0xAX/linux-insides/blob/master/SUMMARY.md- http://www.iamroot.org/ldocs/linux.html#- http://www.egr.unlv.edu/~ed/assembly64.pdf - yasm

Host Boot Sequence

Page 86: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-86

Registers : x86_64

General Purpose Registers : 8/16/32/64-bits long» AL/AH/AX/EAX/RAX: Accumulator» BL/BH/BX/EBX/RBX: Base index (for use with arrays)» CL/CH/CX/ECX/RCX: Counter (for use with loops and strings)» DL/DH/DX/EDX/RDX: Extend the precision of the accumulator

(e.g. combine 32-bit EAX and EDX for 64-bit integer operations in 32-bit code)

» SI/ESI/RSI: Source index for string operations.» DI/EDI/RDI: Destination index for string operations.» SP/ESP/RSP: Stack pointer for top address of the stack.» BP/EBP/RBP: Stack base pointer for holding the address of the

current stack frame.» IP/EIP/RIP: Instruction pointer. Holds the program counter, the

address of next instruction.» Eight additional 64-bit general registers (R8-R15)

Page 87: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-87

Registers : x86_64

Segment Registers : 16-bits long» CS: Code Segment» DS: Data Segment» SS: Stack Segment» ES: Extra data Segment» FS: Extra data #2 Segment» GS: Extra data #3 Segment

Page 88: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-88

Registers : x86_64

#gdb hello-x86 & (gdb)start

Page 89: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-89

Registers : x86_64

(gdb)info reg

Page 90: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-90

default.target» The very first target executed by systemd is default.target» Default.target is actually a symlink to graphical.target

» The contents of graphical.target

Booting Process : Systemd

Page 91: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-91

systemd : #man systemd » Systemd introduces the concept of systemd units. » These units are represented by unit configuration files located in 2

major directories  /lib/systemd/system : unit files distributed with installed packages  /etc/systemd/system : unit files added for extending a service by admin

» The following eleven unit types are available:  1. Service units : start and control daemons and the processes they consist of.

For details, see systemd.service(5)  2. Socket units : encapsulate local IPC or network sockets in the system, useful

for socket-based activation.   3. Target units : useful to group units, or provide well-known synchronization

points during boot-up, see systemd.target(5)  4. Device units : expose kernel devices in systemd and may be used to

implement device-based activation. For details, see systemd.device(5)  5. Mount units : control mount points in the file system, for details see

systemd.mount(5).  6. Automount units : provide automount capabilities, for on-demand mounting of

file systems as well as parallelized boot-up. See systemd.automount(5)

Booting Process : Systemd

Page 92: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-92

» The following eleven unit types are available: -- cont.  7. Timer units : useful for triggering activation of other units based on timers.

You may find details in systemd.timer(5)  8. Swap units : very similar to mount units and encapsulate memory swap

partitions or files of the operating system.   9. Path units : used to activate other services when file system objects change

or are modified. See systemd.path(5)  10. Slice units : used to group units which manage system processes in a

hierarchical tree for resource management purposes. See systemd.slice(5).  11. Scope units : similar to service units, but manage foreign processes instead

of starting them as well. See systemd.scope(5).

Booting Process : Systemd

Page 93: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-93

Unit : #man systemd.unit » The unit file may include a [Unit] section, which carries generic

information about the unit   Description= : descriptive information along with the unit name  Documentation= : list of URIs referencing documentation for this unit or its

configuration  Requires= : configures requirement dependencies on other units. If this unit

gets activated, the units listed here will be activated as well  Wants= : weaker version of Requires=. if the listed units fail to start or cannot

be added to the transaction, this has no impact on the validity of the transaction as a whole. this is the recommended way to hook start-up of one unit to the start-up of another unit

  Before= or After= : configure ordering dependencies between units

Booting Process : Systemd

Page 94: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-94

• https://www.freedesktop.org/software/systemd/man/bootup.html

Booting Process : Systemd

Page 95: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-95

Booting Process : Systemd

multi-user.target» Requires=basic.target» Requires=sysinit.target» Wants=local-fs.target» After=local-fs-pre.target

» Local-fs-pre.target : no user related services are started by this target unit, it handles core low level services only by systemd

Page 96: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-96

Booting Process : Systemd

systemd.special #man systemd.special» Special systemd units

Sys. V Runlevel Ubuntu Target Units Description0 runlevel0.target, poweroff.target Shut down and power off the system1 runlevel1.target, rescue.target Set up a rescue shell2 runlevel2.target, multi-user.target Set up a non-graphical multi-user system3 runlevel3.target, multi-user.target Set up a non-graphical multi-user system4 runlevel4.target, multi-user.target Set up a non-graphical multi-user system5 runlevel5.target, graphical.target Set up a graphical multi-user system6 runlevel6.target, reboot.target Shut down and reboot the system

Page 97: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-97

Booting Process : Systemd

systemd target control #man systemctl» #systemctl get-default : viewing the default target» #systemctl set-default graphical.target : change the default

target» #systemctl isolate multi-user.target : change the target in

current session» #systemctl rescue : change to rescue mode» #systemctl emergency : change to emergency mode» #systemctl halt : halt the system» #systemctl poweroff : power off the system» #systemctl reboot : restart the system» #systemctl suspend : suspend the system» #systemctl hibernate : hibernate the system» #systemctl hybrid-sleep : hibernate & suspend the system

Page 98: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-98

Booting Process : Systemd

systemd service control #man systemctl» #systemctl start name.service : start a service

or #service name start» #systemctl stop name.service : stop a service

or #service name stop» #systemctl restart name.service : restart a service

or #service name restart» #systemctl try-restart name.service : restart a service only if

running or #service name condrestart» #systemctl reload name.service : reload configuration

or #service name reload» #systemctl status name.service : check if a service is running

or #service name status» #systemctl list-units --type service --all : status of all services

or #service –status-all

Page 99: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-99

Booting Process : Systemd

systemd service control – cont. » #systemctl enable name.service : enable a service

or #chkconfig name on» #systemctl disable name.service : disable a service

or #chkconfig name off

Page 100: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-100

Demon Services – RedHat 9.0 Important Daemon Services ; ntsysv, ps -e

» amd - runs the automount daemon for remote filesystem mounting such as nfs (user)

» anacron - checks delayed `cron' tasks at boot time and executes them. Useful if you have cron jobs scheduled but don't run your machine all the time.

» apmd - Advanced Power Management daemon. For use on machines, especially laptops, that support apm. Monitors battery status and can shut down the system if power is too low.

» arpwatch - keeps watch for ethernet IP address pairings that are resolved using the ARP protocol(find mac address).

» atd - runs jobs at specific time by ‘at' command( run only once )» autofs - control the operation of automount daemons, used to

mount and unmount devices on demand (kernel)» bootparamd - allows computers to boot from a Linux machine

using the BOOTP network protocol. A server process that provides information to diskless clients necessary for booting.

Page 101: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-101

Demon Services – RedHat 9.0

» crond - automatic task scheduler. Manages the execution of tasks that are executed at regular(/etc/crontab).

» cups - daemon for print services under the Common Unix Printer System, a replacement for lpd

» dhcpd - implements the Dynamic Host Configuration Protocol (DHCP) and the Internet Bootstrap Protocol (BOOTP). Used to lease out IP addresses to remote machines.

» fetchmail - daemon to fetch mail at regular intervals from mail servers

» ftpd - ftp server daemon» gpm - useful mouse server for applications running on the Linux

console. » httpd - the Apache webserver hypertext transfer protocol

daemon» inetd – listens for service requests on network connections

  In the version of Red Hat 7.0, it has been replaced by xinetd.

Page 102: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-102

Demon Services – RedHat 9.0

» innd - Usenet news server daemon » ipchains - daemon for packet forwarding. Used for configuring a

gateway/firewall. » keytable - loads the appropriate keyboard map from

/etc/sysconfig/keyboard » kudzu - detects and configures new or changed hardware during

boot ( kudzu –s or -p)  detect the current hardware, and check it against

/etc/sysconfig/hwconf» lpd - line printer and print spooler daemon » mysql - database server daemon » named - provides DNS services » netfs - network filesystem mounter. Used for mounting nfs, smb

and ncp shares on boot. » numlock - locks numlock key at init runlevel change » pcmcia - generic services for pcmcia cards in laptops » portmap - needed for Remote Procedure Calls

Page 103: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-103

Demon Services – RedHat 9.0

» random - random number generating daemon, related to security and encryption

» sendmail - mail transfer agent. This is the agent that comes with Red Hat.

» smb - needed for running SAMBA » snmpd - provides Simple Network Management Protocol support » sound - daemon for managing sound » squid - web page proxy server daemon» network - activates all network interfaces at boot time by calling

scripts in /etc/sysconfig/network-scripts» nfsd - used for exporting nfs shares when requested by remote

systems » nfslock - starts and stops nfs file locking service » syslogd - manages system log files » telnetd - telnet server daemon

Page 104: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-104

Demon Services – RedHat 9.0

» usb - daemon for devices on Universal Serial Bus » xfs - X font server » xinetd – On-demand super demon(more modern replacement

for inetd)  xinetd replaces inetd as the default network services daemon in Red

Hat 7.0.   Service configuration files in /etc/xinetd.d/ directory : tftp, bootp, …

» xntpd - Network Time Protocol daemon. Provides a means to syncronize time over the network.

» ypbind - NIS binder. Needed if computer is part of Network Information Service domain(Sun directory service).

Page 105: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-105

Demon Services – Ubuntu

» #systemctl list-units --type service --all

Page 106: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-106

Demon Services – Ubuntu

» 110 loaded units listed

Page 107: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-107

Ubuntu Kernel Compile

Page 108: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-108

Ubuntu Kernel Compile Build Environment : Tools

» # apt install build-essential libncurses5-dev dkms flex bison libssl-dev libelf-dev kernel-package

Download Kernel Source[1]» Run Firefox Web Browser, & open https://www.kernel.org» Check current ver. : # uname –r 4.18.0-25-generic» Download “4.19.60” tarball

Page 109: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-109

Ubuntu Kernel Compile

Copy the kernel to the src dir. & Untar[1]» # cp /home/”user”/Downloads/linux-4.19.60.tar.xz

/usr/src» # cd /usr/src» # tar xvf linux-4.19.60.tar.xz» # cd linux-4.19.60

Download Kernel Source[2]» Run Firefox Web Browser, & open https://www.kernel.org» Check current ver. : # uname –r 4.18.0-25-generic» Move cursor to 4.19.60 “tarball”, & click the right button of mouse» Select “Copy Link Location”, & paste the link after wget command» # cd /usr/src download at /usr/src dir.» # wget https://cdn.kernel.org/pub/linux/kernel/v4.x/ linux-4.19.60.tar.xz

Page 110: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-110

Ubuntu Kernel Compile

Untar the kernel source[2]» # tar xvf linux-4.19.60.tar.xz» # cd linux-4.19.60

Page 111: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-111

Ubuntu Kernel Compile

Identify the current configuration file» # uname –r 4.18.0-25-generic» # ls –al /boot

Page 112: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-112

Ubuntu Kernel Compile

Copy the configuration file to .config » # cd /usr/src/linux-4.19.60» # cp /boot/config-4.18.0-25-generic ./.config

Run “menuconfig” » # make menuconfig

Page 113: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-113

Ubuntu Kernel Compile

Load the current configuration file » Move to “Load” » Load “.config” file & “OK”

* Note : actually “menuconfig” loads “.config” as a default automatically Modifying the configuration

» Modify your own kernel & “Save” » At this time, changed nothing !!!

Page 114: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-114

Ubuntu Kernel Compile

Kernel Compile : make the kernel image » # make-kpkg clean» # make-kpkg --J 4 --initrd --revision=1.0.custom

kernel_image 2>&1 | tee log-kernel-make.txt» --J job options : # grep -c processor /proc/cpuinfo» Compiling time depends on the hardware especially the CPU» It takes around 30 ~ 80 minutes» Once the compilation is complete, you can find your custom

kernel

Page 115: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-115

Ubuntu Kernel Compile Install New Kernel

» # cd /usr/src» # dpkg -i linux-image-4.19.60_1.0.custom_amd64.deb» # reboot

Check New Kernel» # uname –r» # cd /boot & # ls -al

* Note :https://www.debian.org/releases/jessie/amd64/ch08s06.html.en

Page 116: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-116

Extract vmlinuz-4.19.60» # cd /boot» # file vmlinuz-4.19.60

» # cp vmlinux-4.19.60 kernel.img» # /usr/src/linux-4.19.60/scripts/extract-vmlinux

kernel.img > vmlinux» #file vmlinux

» #objdump –D vmlinux > kernel-src.txt» #vi kernel-src.txt

Check make process : log-kernel-make.txt

- Etc. -

Page 117: Shell Command & Script, Linux Directories & Files, Host ...microcom.koreatech.ac.kr/lectures/IFC415/ES03-rpi.pdf · Embedded Systems 1-4 KUT Linux System Process Management →For

Embedded Systems KUT1-117

Extract initrd.img» # cd /boot» # mkdir initramdisk» # cd initramdisk» # cp ../initrd.img-4.19.60 .» # unmkinitramfs -v initrd.img-4.19.60 .» # cd main & # ls –al

- Etc. -