Embedded System Design Lecture 10 Jaeyong Chung Systems-on-Chips (SoC) Laboratory Incheon National University
Environment Variables Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer They are part of the operating environment in which a process runs Examples of environment variables include: PATH a list of directory paths. When the user types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command HOME indicate where a user s home directory PWD this variable points to the current directory LD_LIBRARY_PATH
Environment Variables (cont.) Use and display Echo $HOME Echo $PATH Assignment export VARIABLE=value // for bash and related shells setenv VARIABLE value // for csh and related shells
Environment Variables #include <stdio.h> #include <stdlib.h> int main () { printf("path : %s\n", getenv("path")); printf("home : %s\n", getenv("home")); printf("root : %s\n", getenv("root")); } return(0);
Users and Groups Linux is a multi-user system Each user (account) has a numeric ID (UID) This is defined in /etc/passwd Most users has their home directory Root user -> /root Non-root users -> /home/username ~ in path means the home directory $ cd ~ $ cd ~/Downloads A group is a collection of users Each group has a numeric ID (GID) This is defined in /etc/group
Ownership Each file belongs to a user Each file belongs to a group By default, all files are "owned" by the user who creates them and by that user's default group To change the ownership of a file, use the chown command in the "chown user:group /path/to/file" format. To change the group ownership, use the chgrp command In the following example, the ownership of the "list.html" file will be changed to the "cjones" user in the "marketing" group chown cjones:marketing list.html
Permission Permissions are the "rights" to act on a file or directory. The basic rights are read, write, and execute. Read - A readable permission allows the contents of the file to be viewed. A read permission on a directory allows you to list the contents of a directory. Write - A write permission on a file allows you to modify the contents of that file. For a directory, the write permission allows you to edit the contents of a directory (e.g. add/delete files). Execute - For a file the executable permission allows you to run the file and execute a program or script. For a directory, the execute permission allows you to change to a different directory and make it your current working directory. Users usually have a default group, but they may belong to several additional groups.
Mode A mode is a set of permissions for the owner, the group owner, and the others To change the mode Use the chmod command
Mode
File System a file system (or filesystem) is used to control how data is stored and retrieved. Without a file system, information placed in a storage area would be one large body of data with no way to tell where one piece of information stops and the next begins By separating the data into individual pieces, and giving each piece a name, the information is easily separated and identified Taking its name from the way paper-based information systems are named, each piece of data is called a "file". The structure and logic rules used to manage the groups of information and their names is called a "file system
Types of File systems File system types can be classified into disk/tape file systems, network file systems and special-purpose file systems Disk file systems FAT (FAT12, FAT16, FAT32), exfat, NTFS, HFS and HFS+, HPFS, UFS, ext2, ext3, ext4, XFS, btrfs, ISO 9660, Files-11, Veritas File System, VMFS, ZFS, ReiserFS and UDF Flash file systems JFSS, JFSS2, YAFFS, YAFFS2 Network file systems NFS, AFS, SMB Device file systems A device file system represents I/O devices and pseudo-devices as files, called device files
Virtual File System Provides an abstraction layer between the application program and the filesystem implementations Provides support for many different kinds and types of filesystems Disk-based, network, and special filesystems
Directory structures in the root file system Filesystem Hierarchy Standard (FHS) Started by Dennis Ritchie, 1993 Defines the main directories and their contents in most Linuxbased systems Current Version: 2.3, 29 Jan 2004.
The / The primary hierarchy in FHS The root of tree of file system All paths start form here There is only one / in file system / boot bin dev etc lib proc root sbin tmp usr var
/boot Linux kernel Boot loader configuration If you lost boot You cannot boot your OS boot vmlinuz-2.6.12 config-2.6.12 grub grub.conf
/bin Essential programs Need for system startup Basic commands for Navigating in filesystem File management bin bash bzip2 cat... gzip ls mv rm
/dev Everything is file Hardware components (devices) are file Hard disk Key board All device files are here Direct interaction with device driver Open the device file Read & Write dev hda fda sda... tty random null
/etc System configuration directory What is done by the registry in Windows All configuration file are text files You can view and edit it manually etc bashrc fstab inittab passwd shadow init.d X11 network named httpd X11.conf
/home Home directory of user Each user has a directory /home/bahador /home/hamed All files of user are stored here
/lib Programs need libraries Dynamically linked libraries Programmers need libraries All essential libraries are here Needed for system startup lib libc libm libcrypt libpthread modules
/proc Kernel s interface Kernel pseudo-directory Special directory It is NOT a directory on hard disk Kernel Configuration Kernel State monitoring proc cpuinfo meminfo devices interrupts net sys 1 129 tcp udp net kernel
/sbin System configuration programs Format hard disk Manage hardware Only root can run the programs sbin fsck mkfs mount... adduser poweroff
/tmp Temporary directory All temp files are created by programs Your temp files It is emptied regularly
/usr Secondary hierarchy Very useful programs We usually use them compiler, tools Are not essential for system startup usr bin doc include lib local sbin src Linux-2.6.14
/var The variable directory All dynamic files User cannot change the files var cache lib lock log www named message boot.log
Drives in Windows A physical device maps to one or more drives A hard disk can be partitioned into two logical drives USB disk, CD rom disk etc becomes a new drive There is no drive in linux Each drive has its own root : c:\,d:\
Multiple filesystems in Linux ext2 CDFS / / bin home mnt photos cdrom photos1 photos2
Mount Add a filesystem to another / bin home mnt The root file system cdrom photos Mount point photos1 photos2
Mount How? mount <options> <device> <mount point> mount -t vfat /dev/sdb1 /mnt/flash Don t forget the umount umount <mount point> umount /mnt/flash
Network setup (Manual) $ sudo -i $ ifconfig eth0 10.80.94.xx nemask 255.255.255.0 $ route add default gw 10.80.94.254 $ vi /etc/resolve.conf