0% found this document useful (0 votes)
9 views118 pages

Linux Fundamental

Uploaded by

abdel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views118 pages

Linux Fundamental

Uploaded by

abdel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 118

Security Level: B

Linux Fundamental

ISSUE1.0
www.huawei.com

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential


This course introduces the history and features
of the Linux OS, methods of setting up the
environment where the Linux OS runs and
commands that are commonly used for system
management. Also, some basic commands and
tips for daily operation and maintenance of the
Linux OS are mentioned in the course.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 2


Reference

 Linux Bible 2007

 Linux in a Nutshell , 5th Edition

 Tips And Techniques For Everyday

Use

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 3


After learning this course, you will:
 Learn the features of the Linux operating system.
 Master the method of setting up the environment where the
Linux operating system runs.
 Get familiar with commands that are commonly used for
system management and common operation skills.
 Learn the method of locating the common problems about the
Linux operating system.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 4


Chapter 1 Environment Setup

Chapter 2 System Management

Chapter 3 Common Operation Skills

Chapter 4 Common Problem Handling

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 5


Chapter 1 Environment Setup

1.1 Overview

1.2 Installing the Linux


Operating System

1.3 Starting and Shutting down


Linux

1.4 How to Learn Linux

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 6


The history of Linux
Small file server
system of Ken
Thompson in 1969
BSD in 1977 Small
Smallarchives
archivessystem
system
and system V
The first and formal
in 1980
Unix
Unix
Unix kernel in 1973

Solaris 、 AIX Some


Someimportant
importantUnix
Unixbranches
branches
and HP_UNIX
etc.
Kinds
Kindsofofdifferent
differentUnix
Unixversions
versions GNU and FSF
organizations are
created by Stallman in
Linus Torvalds of GNU
GNUand
andFSF
FSF 1984
Finland College in
1991
Linux
Linux

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 7


Linux characteristics
Open : The system keeps to the standards in the world.

Multi-user : The system resource can be occupied by different users.

Multi-task : Different tasks can be executed simultaneously and separately.

Friendly user interface : System kernel can be invoked friendly via user
interface (compared to Unix).

Independency of devices : All devices is looked as a file.


Plenty of network function : FTP,HTTP and TELNET etc can be supported.
Reliable system security : PAM etc.
Good transplantable ability : Linux can be executed in different platform.
Free : Linux is a free software and any one can get and do with the source
codes .

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 8


Mainstream version of Linux

Red Hat Enterprise Linux Fedora Core

Suse Linux Enterprise Server OpenSuse

Debian Ubuntu

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 9


Linux components

Linux Shell

Linux
Kernel
Practical
tools

Linux kernel: It is the core of the Linux operating system and provides the functions such as process
management, memory management, file system management, device control, and network management.
 Utilities: The tools that are used by users for software development and system management,
including the GCC and KDE.
Linux shell: It is an interface that allows users to interact with the operating system. It is the general
term for command language, command interpreter, and programming language. By default, the Bourne
Again shell (BASH) is used. The BASH has many features. For example, it provides the functions such as
command completion, command edition, and command history table. Other common Linux shells are
CSH and KSH.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 10


Linux login and exit

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 11


Common directories of Linux
Dir Explanation
/ The root directory
/bin The directory that stores executable files of user commands.
/dev The directory that stores device files.
/etc The directory that stores system executable files and configuration files.
/home The directory that stores configuration files of users.
/lib The directory that stores the library files that are required to boot the system and required to run
commands in the root file system.
/mnt The directory that stores file systems (such as CD drives and floppy drives) that are temporarily
mounted.
/sbin The directory that stores executable files used only by the root user and executable files used to boot or
install the files in the /usr directory.
/tmp The directory that stores temporary files.
/usr The directory that stores executable files, header files, shared libraries, help files, and local programs
(in the /usr/local directory) that are used by users and system commands.
/var The directory that stores files that expand ceaselessly, such as logs and mails.
/opt The directory that stores additional application software packages. It is usually the installation directory
of large-scale software of third parties.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 12


Linux virtual console
Users can hold down Ctrl + Alt+Fn, n=1~7, to switch to the designated virtual
console virtual terminals .

Virtual consoles can be added or deleted for login as required through the
configuration file /etc/inittab. One point, however, should be mentioned, that is,
you should skip virtual console 7 because this virtual console is used by X-
Window.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 13


X Window(1)

 X Window is the complete graphical user interface (GUI) of the UNIX or


Linux operating system. It uses the client/server (C/S) technology.
 X Window is mainly composed of the following items: X server, X clients,
and X protocol.
 The relationship among these three items is as follows:

X Client Keyboard

X Client X Server Mouse

X Client Display

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 14


X Window(2)
 X server: * X server is the core of the X Window system. It performs the following tasks:
1) Support of the display adapter and monitor;
2) Resolution, refresh rate, and color depth of the X Window;
3) Basic window management: display and close windows, track mouse movement and keystrokes.
Optional configurations: Xfree86, Metro X, and Accelerated.

 X client: All applications running on the GUI are X clients. X clients include the window manager,
desktop environment, and file manager.
1) Window manager: provides the GUIs that the X server lacks.
Typical examples are Enlightenment, FVWM, fvwm95, and twm.
2) Desktop environment: provides a uniform operating platform for users to manage the system,
configure the system, and run applications. Main examples are Gnome desktop and KDE desktop.
3) File manager: manages files and subdirectories through menus, icons, and windows and provides
detailed file data. Examples are Nautilus and Konqueror.

 X protocol: X protocol is the protocol used for information transmission between the X server and an X
client.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 15


Chapter 1 Environment Setup

1.1 Overview

1.2 Installing the Linux


Operating System

1.3 Starting and Shutting down


Linux

1.4 How to Learn Linux

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 16


Linux installation mode

Installation through CD or DVD media

Installation through the local hard disk

Installation through network

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 17


The installation process through CD or DVD media

 Set system boot from the installation media in BIOS

 Select the system language

 Configure the installation settings

 Partition and format the hard disk

 Install system and related software packages

 Configure the system

 the root password


 Configure the network

 Set system update and system services

 Manage users
 Configure hardware

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 18


Chapter 1 Environment Setup

1.1 Overview

1.2 Installing the Linux


Operating System

1.3 Starting and Shutting down


Linux

1.4 How to Learn Linux

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 19


System boot process
Phase Phase
1 3

poweron

FLOPPY BIOS CDROM

harddisk SCSI sda Loading kernel

MBR Detect hardware


Init hardware
Bootloader
grub
rc.local
rc.sysinit

Init
Phase Phase /etc/inittab
2 4

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 20


Run levels
 Different run-level can determine the application that the host can be offered. (See
/etc/inittab).

RUNLEVEL ACTION
0 Power-off

1 Single-user mode

2 Local multi-user mode (network cannot be used)

3 Network multi-user mode (default run-level of M2000 )

4 Free mode
5 Network multi-user mode with graphic interface

6 Restart

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 21


Startup and shutdown of Linux
 For Linux, when you determine to shutdown the hosts, you should:

 know who is using the host (w)


 notify that you will shutdown the host (optional) (wall, write)
 Use the most secure shutdown mode (run sync to synchronize the data before shutdown).
 The procedure for shutting down the Linux operating system securely:

 Run sync to write memory data into the hard disk


 Send shutdown signal to the host and notify the users
 Stop all the processes in the host
 unload all the devices
 Commands for shut down Linux

 init 0(the safest mode to shutdown the host)


 shutdown -h now
 halt ( the most violent mode to shut down the host, equivalent to press the power-off button.
 Commands to restart Linux

 init 6
 shutdown -r now
 reboot

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 22


Chapter 1 Environment Setup

1.1 Overview

1.2 Installing the Linux


Operating System

1.3 Starting and Shutting down


Linux

1.4 How to Learn Linux

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 23


Use terminals in desktop environment

 Use the terminal program to enter the traditional command line operation interface. The preceding figure is the
window that appears when you run the kosole terminal program. In the window, you can enter the shell command
to finish tasks quickly.
 The method of starting a command line terminal varies with the desktop environment. To start a command line
terminal in the KDE desktop environment, choose system > Terminal on the system main menu or click the icon
on the desktop. To start a command line terminal in the Gnome desktop environment, choose More Applications…
> System > Gnome Terminal on the system main menu or click the icon on the desktop.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 24


Example for logging in to the system by using remote login tools-1

 By default, Linux port 22 is open. In this case, you can log in to the system through the SSH protocol.
SSH is an encryption protocol that is recommended for remote management.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 25


Example for logging in to the system by using remote login tools-2

 Before logging in to the system through Xmanager, you need to enable remote system
management. The recommended method is as follows: Enter yast on the textual interface and
then choose Network Services > Remote Administration > Allow Remote Administration.
HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 26
Where to get help
 Learn to use man and whatis commands. Remember that Linux is a case-
sensitive system.
 For other Linux information resources, you are recommended to search on
www.google.com, www.linux.org, and www.linux.com.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 27


Questions
 What is Linux?

 How to install Linux?

 What runlevels does the Linux operating system have? What are the
differences between these runlevels?
 How to obtain the full spelling of a command when you know only the first few
letters of the command? How to get help when you do not know how to use a
command?

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 28


Chapter 1 Environment Setup

Chapter 2 System Management

Chapter 3 Common Operation Skills

Chapter 4 Common Problem Handling

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 29


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 30


User Management and Group Management -
using YaST

 YaST to manage users and groups, use yast2 in desktop environments or


use yast in command line environments.
 Security and Users

− User Management
− Group Management

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 31


Commands for user management

Name Meaning Common Usage and Specific Meaning Example


useradd Adds a useradd -d Adds user xxxx whose useradd -d
user /home/xxxx xxxx main directory is /home/db2inst
/home/xxxx. db2inst

userdel Deletes a userdel -rf Deletes a user by force a userdel -rf db2inst
user username nd deletes the main direct
ory of the user.
usermod Modifies a usermod -d xxxx Modifies the main director usermod -d
user xxxx y of a user. /etc/db2inst db2inst
username

passwd Sets a passwd username Sets a user password. passwd db2inst


user
password

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 32


Commands for group management

Name Meaning Common Usage and Specific Meaning Example


groupadd Adds a groupadd -g gid Adds group xxxx whose groupadd -g 200
group xxxx gid is xxxx. utest

groupdel Deletes a groupdel Deletes a group groupdel utest


groupr groupname

groupmod Modifies a groupmod -A user Adds users to a specified groupmod -A test


group group group. utest

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 33


Configuration files for User Management and
Group Management

 Information about users and groups is stored in the following three files:
 /etc/passwd
 /etc/shadow
 /etc/group
 You can modify the information through the GUI or command lines.

 However, it is not recommended to modify these files manually because it


may cause unpredicted errors.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 34


/etc/passwd

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 35


/etc/passwd

UID:
0–99: Used by the system.
100–499: Used by special system users (for example: services and
programs).
In the SLES 10, the UID of an ordinary user begins with 1000.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 36


/etc/shadow

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 37


/etc/shadow

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 38


/etc/group

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 39


/etc/group

When a user logs in to the system, the system obtains the


GID from the /etc/passwd file instead of the /etc/group file.
Therefore, the /etc/group file should be consistent with the
/etc/passwd file.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 40


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 41


File system of Linux(1)

 The operating system uses a file system to make clear of the data structure and o
peration method of the files on a disk or partition. The Linux operating system sup
ports such file systems as EXT2 and EXT3.
 EXT2 is a highly-scalable and high-performance file system. Before year 2000,
the file system of the Linux/GNU supports a file name as long as 256 bytes, a
maximum of 2048 GB (2 TB) size of a single file, and a maximum of 6384 GB
theory file system capacity.
 EXT3 is a log file system that ensures the integrity of data in case of power fai
lure or other system failures. Compared to EXT2, EXT3 has a new log functio
n, that is, the function of recording metadata.
 Other file systems are ReiserFs and XFS.These file systems support:

 1) More efficient operations on small files


 2) A maximum of 16 TB file system size
 3) Quick file access

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 42


File system of Linux(2)

 Ordinary file (-): Indicates ASCII or binary streams stored


on storage medias.
 Directory file (d): Indicates files that contain some files Root node
and subdirectories.
 Device file (b,c): Indicates physical devices that are
connected to the system. Page node1 Child node 1 Page node 2
 Character device (c): Also called raw device. It features
no buffer and reads/writes 1byte each time. An example
is tapes. Page node 3 Page node4
 Block device (b): Indicates devices that feature some
buffer and read/write one block each time. Examples are
Each directory contains a quote that
terminals and disk devices.
direct to the directory itself (".") and a
 Symbolic link (l): Indicates files that direct to another file. quote that direct to its parent directory
("..").

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 43


Details of file attributes

drwxr-xr-x 2 root sys 4096 2003-7-29 backup

Rights File owner File size Timestamp File name

File type Link number Group owner

R: Read
d r w x r - x r - x W : Write
X : Execute

Rights of other users


Rights of users in the same group
Rights of the file users
File type, e.g. d, c, b, l .

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 44


Rights of files(1)

 File access permissions: rwxrwxrwx

 Read - 4

Allows users to open and view files.


 Write - 2

Allows users to open and edit files.


 Execute -1

Allows users to execute files.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 45


Rights of files(2)

 Default permission of a new file is rw-r-r.

 The default file right is set based on the value of umask (the
default value is 022).
 The right of a new file is rw-r-r (644)
 666 – 022 = rw-r-r
 The default right of a new group is rwxr-xr-x.

 The default directory right is set based on the value of umask


(the default value is 022).
 The right of a new directory is rwxr-xr-x.
 777 - 022 = rwxr-xr-x

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 46


Rights of files(3)

 Change file access permissions:chmod

− chmod u+x security.sh


− chmod u=rwx,g=rw,o=r/chmod 764 hello.txt
− chmod o-r hello.txt

Category Operation Permission


u (user) + (adds a permission) r (read)
g (group) - (removes a permission) w (write)
o (other) = (makes a permission equal to) x (execute)

a (all categories)

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 47


Rights of files(4)

 Change file owner : chown

 chown user[:[group]] file

− chown newbie:users hello.txt


− chown newbie hello.txt
− chown opensuse /home/test
 Change group : chgrp

 chgrp group file

− chgrp users /home/opensuse


− chgrp users test

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 48


File common operations(1)
 Copy a file : cp [-options] src_file_list dst_file

 Move a file : mv src_file_list dst_file

 Delete a file : rm file_list

 Create a file : touch filename

 Create a link file :ln –s link file source file

 -f
Search :
 -I
 Find a file
 -r
 find / –name *.c
 Grep matching

 ps –ef |grep sendmail

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 49


File common operations(2)

 Show current directory: pwd

 Change current directory: cd

 Create a directory : mkdir

 Delete a directory: rmdir

 The rmdir command will remove an empty directory but, if a


directory contains files, the option –r should be added.
 When the option –p is added, the parent directory will be
deleted if it is empty.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 50


File common operations(3)
Text editor :
 vi is a text editor shared by all UNIX systems. It works in two modes:
 Command mode: When you enter vi for the first time, press ESC in the edit mode to enter the command mode.
 Edit mode: Hold down iIaAoO in the command mode to enter the edit mode.
 Common vi commands include vi filename that enables you to open or create a file and locate the cursor on the
beginning of the first line.


Insert 
Search
i : before the cursor
/pattern : Search from the cursor to the
I : at the beginning of current cursor
end of the file.
a : after the cursor
?pattern : Search from the cursor to
A : at the end of current cursor
the beginning of the file.
o : insert a new line after the current line 
Save and exit
O : insert a new line before the current line
:w Save the current file

Delete
:x Save the current file and exit
Deletion command x or dd: x allows you to
:q exit the vi editor
delete a character where the cursor is located
:q! not save the file and exit the
and dd allows you to delete the line where the
vi editor
cursor is located.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 51


Tips for file and fold operation

Use “cd -”command to go back to the folder last entered.

Use “ls -R” command to get the layer relation between files and folders.

Use “tree” command to show the structure of the folder.

Use “cat”, “tail” “more”and “less” command to show the file.

 Remove some files with odd name.

 Remove the file with name “–a”: rm ./-a rm -- -a


 Remove the file with name “\a” : rm \\a
 Add the execution right to the file: chmod +x aaa, Run $aaa

 Find and kill the process occupying the file you want to delete.

 fuser filename
 fuser –k filename

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 52


System backup through YaST(1)

 Create a backup system

 Full backup of non-system files only backs up:

− Modifications on software packages


− Important storage devices
− Configuration files
 yast2SystemSystem Backup

− Set backup parameters


 yast2 System  System Restoration

− Select a backup archive to restore your system.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 53


System backup through YaST(2)

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 54


Commands for backup(1)

 tar ( tape archive )

 tar czvf test1.tar.gz /test1


− c create
− x decompress
− z gunzip/gzip .tar.gz or .tgz
− j bzip2
− t show the compressed files
− r append files to the compressed file
 tar -cvf /dev/st0 /home
− Back up the files under “/home” to a tape device
 tar -xvf /test/test.tar -C /test2
− Decompress the test.tar file to the specified directory “/test2”

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 55


Commands for backup(2)

 rsync

 A data synchronization tool for backing up incremental data


 dd

 dd if=“source file” of=“destination file” bs=block size

dd if=/home/budget/month of=/dev/fd0 bs=600

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 56


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software


Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 57


Partition type

 Hard disk naming

 /dev/hda Primary Master ( IDE )


 /dev/hdb Primary Slave ( IDE )
 /dev/hdc Secondary Master ( IDE )
 /dev/hdd Secondary Slave ( IDE )
 /dev/sda the 1st SCSI hard disk
 /dev/sdd the 4th SCSI hard disk

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 58


Partition through YaST

 Run yast2System Partitioner

 create
 edit
 delete

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 59


Commands for partition
 df
 df -hT
− Displays how the disk space of the file system is used.
 du
 du -sh
− Displays how the disk space is used by the files.
 fdisk
 fdisk /dev/sda
− Partitions /dev/sda.
 fdisk -l
− Displays the information about the system partition table.
 mkfs
 ext2, ext3, VFAT, MSDOS, XFS, MINIX,BFS
 mke2fs, mkdosfs
 -t Selects the type of the file system.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 60


File system mount(1)

 mount -t filesystem_type -o options device mountpoint

 mount /dev/hda9 /space


 /mnt/

 Mounts directories of remote and local file systems


 /media/

 Mount mobile devices


 /media/cdrom
 /media/floppy
 /media/USB-*

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 61


File system mount(2)

 mount -a

 Re-read the /etc/fstab file and mount the partitions


 mount -f

 Uninstall a file

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 62


LVM(1)
 LVM

 Logical Volume Management


 Dynamically adjust and move logic volumes

 Manage logic volumes by name

 Maximum of 256 logic volumes

 The ID of the LVM partition file system is 0x8E Linux LVM

 PV 、 VG 、 LV

 PV
 VG
 LV

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 63


LVM(2)

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 64


LVM(3)
Function of the LVM:
 Combine many hard disks or partitions into a large logic volume (LV).

 Extend the LV when the free space is used up if the configuration is suitable.

 Add hard disks or LVs to a running system through the LVM. This, however,
requires hot-swappable hardware that can perform this operation.
 Activate the striping mode that distributes the data of a logic volume in many
physical volumes. If these physical volumes reside on different disks, you
improve the read/write performance of the disk by activating the striping mode.
On this point, the LVM is similar to the RAIDO.
 Back up running systems consistently by using the snapshot function (this is
especially suitable for servers)
 Add a maximum of 256 LVs that can be either used by file systems or
databases as raw devices.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 65


LVM through YaST
 Run yast2SystemLVM or yast2 lvm

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 66


Commands for LVM
 PV management
 fdisk -- Formats hard disks. Be sure to set the partition ID to 8e (type of the LVM) when using this command.
 pvcreate – Create a physical volume, for example, pvcreate-ff/dev/sdd1.
 pvscan --Scans what pvs are available on the array, what pvs are used by volume groups, and what pvs are
not used by volume groups. To scan what pvs are not used by volume groups, use the pvscan -n command.

 VG management
 vgcreate -- Creates a volume group, for example, vgcreate -s 64M -v datavg1 /dev/sdd1
 vgextend -- Extends a volume group.
 vgreduce – Reduces a volume group.
 vgdisplay -- Displays volume groups and logic volumes. Usually, the -v parameter is used.

 LV management
 lvcreate -- Creates a logic volume, for example, lvcreate -L 5120M -n db2lv2 datavg1
 lvscan -- Scans logic volumes.
 lvextend -- Extends a logic volume.
 lvreduce – Reduces a logic volume.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 67


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 68


Network configuration through YaST
 Run : yastNetwork
DevicesNetwork Card
 Overview

 Choose a network card


 Configure a network
card
 Delete a network card
 Hostname/DNS

 Modify hostname
 Add a DNS server

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 69


Commands for network card configuration
 Create the corresponded configuration file under /etc/sysconfig/network .
shelf-slot4:/etc/sysconfig/network # vi ifcfg-eth-id-00\:18\:82\:2c\:85\:cf
 BOOTPROTO='static'
 BROADCAST=''
 ETHTOOL_OPTIONS=''
 IPADDR='10.69.5.101'
 MTU=''
 NAME=''
 NETMASK='255.255.255.0'
 NETWORK=''
 REMOTE_IPADDR=''
 STARTMODE='auto'
 UNIQUE='JNkJ.rsqdmH2KSr4'
 USERCONTROL='no'
 _nm_name='bus-pci-0000:03:04.1'
shelf-slot4:/etc/sysconfig/network # /etc/xinetd.d/rcnetwork restart

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 70


Commands for route configuration

 route

 Add or delete a route


 Add a gateway
− route add -net 172.16.0.0 netmask 255.255.255.0 gw
192.168.4.249
 Add a network
− route add default gw 192.168.4.249
 Add a default route
− Edit /etc/sysconfig/network/routes

default 192.168.0.1 - -

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 71


Route test
opensuse:~ # route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0 192.168.0.1 255.255.255.0 UG 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
opensuse:~ # netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
172.16.0.0 192.168.0.1 255.255.255.0 UG 00 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 00 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 00 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 00 0 lo
0.0.0.0 192.168.0.1 0.0.0.0 UG 00 0 eth0

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 72


Network connection test(1)
 ifconfig check the IP configuration .
opensuse:~ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:BF:45:DD
inet addr:192.168.0.4 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:febf:45dd/64 Scope:Link
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:52987 errors:0 dropped:0 overruns:0 frame:0
TX packets:72273 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4823891 (4.6 Mb) TX bytes:81579082 (77.7 Mb)
Interrupt:16 Base address:0x2000

lo Link encap:Local Loopback


inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:44283 errors:0 dropped:0 overruns:0 frame:0
TX packets:44283 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:79526136 (75.8 Mb) TX bytes:79526136 (75.8 Mb)

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 73


Network connection test(2)
 ethtool check connection status of the network card.

# ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pg
Wake-on: g
Link detected: yes

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 74


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software


Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 75


Install software packages through YaST

 Run yast2, choose Software > Installation Source, and set the path where the
installation package is located.
 Run yast2 and then choose Software > Software Management or run yast2
sw_single to start the software package management module.
 Auto-arrange the dependencies between packages automatically.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 76


Install RPM software packages(1)

 Format of RPM software packages

 name-version-release.architecture.rpm
 The RPM library

 Information of RPM software package is saved in /var/lib/rpm


 Rebuild the RPM library

rpm --rebuilddb

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 77


Install RPM software packages(2)

 rpm -i ha.rpm

 Install
 rpm -e ha

 delete
 rpm -U ha.rpm

 update
 rpm -F ha.rpm

 Delete the old file and install the new file.


 Revise configuration files and save the original configuration
as .rpmsave or .rpmorig.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 78


Install RPM software packages(3)

 rpm -q
 Queries what software packages have been installed.
 rpm -q --changelog rpm_package
 Displays detailed update information about software packages.
 rpm -qa
 Displays all installed software packages.
 rpm -qi ha
 Displays detailed information about the specific software package.
 rpm -qf /opt/ha/bin/hapasswd
 Queries what rpm package the command belongs to.
 rpm -ql ha
 Displays the RPM software package list.
 rpm -qip package.rpm

 Displays the content of the RPM software package (not install the RPM software
package).

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 79


Install RPM software packages(4)
 rpm -V rpm_package

 Verify software packages

rpm -V wget
S.5…T c /etc/wgetrc
 Tag meanings

− S file size
− 5 MD5 checksum
− T modification time
− c configuration file
− L symbolic link is mismatched
− U user
− G group
− D the number of the master device or of the slave device is mismatched

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 80


Install source packages
 In the Linux operating system, almost all software that appears as source codes is a .tar.gz file.
Other software that appears as source codes is similar and should be zipped and then
compressed. Before installing a certain software, you need to run the tar command and the
gzip command to unzip the package.

 Compiling and installing a source package usually involves three steps. This, however, varies
with the README or INSTALL document in the software package. Therefore, you are
recommended to view the README or INSTALL document in the software package before the
installation.
 Configure the new software package
./configure [-options]
--prefix The prefix parameter allows you to set the basic subdirectory for installing the
software package. By default, the software package is installed in the lower-level
subdirectory of the /usr/local subdirectory. After the configuration, a special file "makefile"
is created, which is the cornerstone in the compiling phase.
 Compile the new software package
Compiling a new software package is easy. You just need to run the make command and
then the make script will read all makefiles created by the configure program.
 Install new software packages
 After the compilation, run the following command to install the software package: make
install

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 81


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 82


Manage system services through YaST

 Run : yastSystemSystem Services ( Runlevel )

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 83


/etc/inittab

 Define operations under runlevels 1 to 6

 id:5:initdefault:
 id:runlevel:action:process
 ca::ctrlaltdel:/sbin/shutdown -r -t 4 now
 Call the corresponding scripts in the /etc/init.d/rc (run level)

 id: Indicates the identification name. It can be any name within


four characters. Remember that an id should be unique.
 runlevels: Indicates the levels (levels 1 to 6) that can be run on
this line. This parameter allows multiple options, e.g. to run
levels 1, 2, and 3, select 1, 2, and 3.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 84


Init scripts

 Service management

 /etc/xinetd.d/<service name> start|stop|reload|status


 rc<service name> start|stop|reload|status
 chkconfig

 Checks and sets the running status of a service.


 chkconfig -l
 chkconfig daytime off/on
 netstat -an

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 85


Concepts of process management
Process definitions
 Program

 Commands in an executable file


 Process

 A program running in the CPU

• User process
− Programs running on the terminal
• Daemon process
− Processes that are independent of the terminal
 Process ID (PID)

 The unique process number

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 86


Commands for process management(1)

 ps
 Displays user processes
 ps aux
 Displays all the running precesses

 pstree
 Displays the process content in tree structure

 top
 Views how the process resources are used

 lsof
 Views what files, directories, and sockets are opened by the running process

 kill
 Kills a thread according to the pid
 killall
 Kills a group of threads according to the name

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 87


Commands for process management(2)

 ctrl + z

 Stops a process
 jobs

 Displays processes
 fg

 Enable background tasks to run on the foreground


 bg

 put tasks to run on the background

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 88


Chapter 2 System Management

2.1 User Management and Group Management

2.2 File System Management

2.3 Storage Device Management

2.4 Network Management

2.5 Installation and Management of Software Packages

2.6 System Service Management

2.7 Others

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 89


Hostname- Show the host name

Comman Meaning Common usage and description Example


d
hostname Show or hostname Show the host name hostname
modify the
host name

hostname name1 Modify the host name hostname


hle_db01

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 90


who ( w ) - Show the user online

Comman Meaning Common usage and description Example


d
who Show the who show the online user information who
user online
Show the online user information,
including current operation and
w CPU overload etc. w

Who –r Show current run-level who -r

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 91


Last-Displays users who logged in to the system

Comman Meaning Common usage and description Example


d

last Displays the last Displays the current user and last
current user and users who logged in to the
users who logged system previously.
in to the system
previously.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 92


Date-Display or modify current time of the system

Comman Meaning Common usage and example


d description
date Display of modify date Query current date
current time settings time

date Modify current


[MMDDhhmm[ time settings date 112711162007
[CC]YY][.ss]]

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 93


hwclock ( clock ) -Display or set current time of the hardware

Comman Meanin Common usage and description Example


d g
hwclock Display hwclock Query the time hwclock
or set
current Synchronize the time of
time of hwclock –w system with hardware hwclock –w
the
hardware hwclock –s Synchronize the hardware hwclock –s
time with system

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 94


Scp- Copy the file remotely
Comman Meaning Common usage and description Example
d
scp file1 IP:/dir Copy local file file1 scp a.txt
scp Copy the file to remote host with 172.17.128.0:/tmp
remotely host ip IP and /dir
folder

scp Copies /dir2/file2 scp


IP : /dir2/file2 /dir1 from the remote 172.17.128.0:/tmp/a.txt /
host with host ip IP tmp
to the local /dir
directory.
scp -r IP : /dir2 Copies all files in scp
/dir1 the directory of dir2 172.17.128.0:/var/log
in the remote host /tmp
with host ip IP to
the local /dir
directory.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 95


Questions

 How to set the file right? How to perform user

 How to view the current users of the system and history operation records?

 How to view the current network configuration of the system? How to obtain the
current network connection information? How to transfer data among hosts?
 How to query how the disk is partitioned, how the disk partitions are mounted,
and how the space of the file system is used?

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 96


Chapter 1 Environment Setup

Chapter 2 System Management

Chapter 3 Common Operation Skills

Chapter 4 Common Problem Handling

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 97


Chapter 3 Common Operation Skills

3.1 Setting Timer Tasks

3.2 Installing Hardware Drivers

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 98


Timer tasks

 System timer tasks

 /etc/crontab
/etc/cron.hourly /etc/cron.weekly
/etc/cron.daily /etc/cron.monthly
 User timer tasks

 Set user timer tasks through the crontab command.

crontab -eEdits or adds timer tasks


crontab -l Displays timer tasks
crontab -r Clears timer tasks
 man 5 crontab

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 99


Examples of timer tasks
 Minute: Hour: Day: Month: Week: User: Script name

* 09,11,14,16 10 03,09 01,02,04 chkquotas


 Run the chkquotas script at 9, 11, 14, and 16 on on March 10 and September
10 which must be Monday, Tuesday, or Thursday.
 00 /5 * * * sent /usr/sales

00 /5 * * * sent /usr/sales
The sent user runs the /usr/sales script every five hours.
 Solutions to common crontab problems:

 The crontab command is not running after it is set: Check whether the path of
the command is correct.
 View the content of the /var/log/messages log.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 100


Chapter 3 Common Operation Skills

3.1 Setting Timer Tasks

3.2 Installing Hardware Drivers

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 101


Installing Hardware Drivers

 Download the corresponding driver according to the hardware model.

 For the detailed installation method, see the driver file.


 dmesg
 Displays the information about the kernel and views the detailed information
about the hardware.
 lsmod
 Displays the information about the current system module.
 modprobe
 Loads modules according to /etc/modprobe.conf.
 insmod
 Loads modules
 modinfo
 Views information about modules and parameters that may be used.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 102


Chapter 1 Environment Setup

Chapter 2 System Management

Chapter 3 Common Operation Skills

Chapter 4 Common Problem Handling

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 103


Chapter 4 Common Problem Handling

4.1 Collection of System Information

4.2 Network Failures

4.3 Failing to Logging In to the System as the


root User

4.4 Destroyed File System

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 104


Monitor the System Performance

 top

 Display Linux tasks


 uptime

 Tell how long the system has been running


 free

 Display amount of free and used memory in the system


 vmstat

 Report virtual memory statistics

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 105


Dmesg-Query the boot message

Command Meaning Common usage and description example

dmesg Query the dmesg > /dir/file Query the boot dmesg >
boot message and save /tmp/dmesg.txt
message the query result to
the file /dir/file

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 106


Obtain system hardware information
 Obtain the information about the version of the operating system

 uname -a

 Obtain the information about the CPU of the system

 cat /proc/cpuinfo

 Obtain the information about the memory of the system

 cat /proc/meminfo

 Obtain the information about the partition of system devices

 cat /proc/partitions

 Obtain the information about the PCI devices in the system

 lspci

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 107


Obtain system status information
 Display the first 10 processes that consume the most CPU

 ps aux |head -1 ;ps aux |sort -rn +2 |head -10

 Display the first 10 processes that consume the most memory space

 ps aux |head -1 ;ps aux |sort -rn +3 |head -10

 Display the first 10 processes in the system in the order that the processes are handled

 ps vx |head -1 ;ps vx |grep -v PID |sort -rn +3 |head -10

 Display the first 10 processes in the system that use the most or least memory actually

 ps vx |head -1 ;ps vx |grep -v PID |sort -rn +6 |head -10

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 108


Common logs

/var/log/boot.msg : This log is generated each time the system is started. It


contains all output data of the system when the kernel is loaded. We can
directly view this log by running the dmesg command.
/var/log/messages : This is a standard system log. It records the output of
most system services and contains some non-core output when the system is
started.
/var/log/wtmp : An item is recorded in this log at each system login. As a
binary file, this log cannot be altered by anybody and can only be read by
using the last command.
/var/log/lastlog : This log records how the user logs in to the system from
what location.
/var/log/faillog : This log records all failed logins.

/var/log/YaST2 : This log records yast2 executing results.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 109


Chapter 4 Common Problem Handling

4.1 Collection of System Information

4.2 Network Failures

4.3 Failing to Logging In to the System as the


root User

4.4 Destroyed File System

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 110


General Methods of Locating Network Failures

Run the PING command

Check whether the physical connection is normal

Check whether the network adapter status is normal

Check whether the network card configuration is normal

Run netstat to check the network connection

Run tcpdump to check the network traffic

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 111


Chapter 4 Common Problem Handling

4.1 Collection of System Information

4.2 Network Failures

4.3 Failing to Logging In to the System as the


root User

4.4 Destroyed File System

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 112


Failing to Log In to the System as the root User

The possible reasons are as follows: one is that the user forgets the password and the other is
that the password is changed. No matter what reason causes the login failure, you can set a new
root password by doing as follows:

Start the system from the CD (enter the single-user mode)

mount /dev/sda2 /mnt Run the mount /dev/sda2 /mnt command to mount the root file
system to /mnt (change the root disk name according to the actual situation)

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 113


HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential
fsck failed
Phenomenon Description
The system cannot be started and the following error is displayed:
fsck failed . Please repair manually and reboot. the root file system is currently mounted
read-only. To remount if read-write do:
bash# mount -n -o remount,rw /
Give root password to login:
Cause Analysis
This occurs mainly because the /etc/fstab file is wrong configured and thus disk devices cannot
be mounted on the Linux operating system. Other reasons are as follows:
1) The disk has a large volume and many bad blocks and thus the file system fails to be
repaired due to insufficient memory.
2) The super block of the disk partition is damaged.
Handling Process
1)Enter the root password as prompted to display the bash# prompt page.
2)Enter the mount -n -o remount,rw / command under the bash# prompt. This command remounts
the root directory to make the files in the directory readable and writable.
3)Check the /etc/fstab file according to the actual configuration of the system disks. If an error
exists, run the vi command to re-edit the /etc/fstab file. Save the file and exit. Then, restart the
system.
4)If the /etc/fstab file is correct, check whether records similar to "sda : READ CAPACITY failed."
is available in the /var/log file. If any such record is found in the /var/log file, try to use the fsck
command to recover the file system.

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 115


Summary

 Linux principals

 Common commands

 Common tips

 Handling method for common


problems

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 116


Appendix: Download Addresses of Remote Access
Tools and SuSE Linux Help Modes

 SSH clients - Putty

 http://www.chiark.greenend.org.uk/~sgtatham/putty/
 SFTP client– WinSCP

 http://winscp.net/eng/index.php
 Hotline for post-sale support of Novell : 800-810-6500

 Email address for post-sale support of Novell :


[email protected]

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential Page 117


Security Level: B

Thank You
www.huawei.com

www.huawei.com

HUAWEI TECHNOLOGIES CO., LTD. HUAWEI Confidential

You might also like