Chinaunix首页 | 论坛 | 博客
  • 博客访问: 717623
  • 博文数量: 235
  • 博客积分: 4309
  • 博客等级: 中校
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-17 11:25
个人简介

If you don\\\\\\\\\\\\\\\'t wanna do it, you find an EXCUSE; if you do, you\\\\\\\\\\\\\\\'ll find a WAY :-)

文章分类

全部博文(235)

文章存档

2014年(3)

2013年(2)

2012年(31)

2011年(199)

分类: LINUX

2011-02-17 18:25:56

一:RHEL安装全过程

1.【选择安装模式】:
press the key      -Graphical mode
Type:linux text   -Text   mode
Type: linux askmethod    -Ask   mode


Choose a Language  →→  Keyboard Type  →→  Installation Method:
Local CDROM / Hard drive / NFS image / FTP / HTTP (5 种安装方式 ! )
 →→  Manually partition with Disk Druid (手动分区)→→

2.【分区技巧】:
/etc, /lib, /bin, /sbin, /dev (这几个目录必须跟在 " / " 目录下, 在同一个分区里。)

/boot  单独挂载
/home  单独挂载
/usr  单独挂载
/var 单独挂载
/tmp  单独挂载
/usr/local  单独挂载
/opt  单独挂载


『swap』
File System Type: swap
Size(MB): 512

『 /』
Mount Point: /
File System Type: ext3
Size(MB): 10000

『/boot』
Mount Point: /boot
File System Type: ext3
Size(MB): 200


『/home』
Mount Point: /home
File System Type: ext3
Size(MB): 1000

 

 →→ Boot Loader Configuration(开机管理程序, 可以通过ADD 添加对其他系统的管理。) →→ 
Network Configuration:Set the hostname / manually(rhel5.com) →→ 
Firewall Configuration(SELinux = Security Enhanced Linux) →→ Additional Language Support →→ Time Zone Selection →→ Set Root Password →→ Package Installation Defaults →→ Editors(以不同颜色显示文字, 很方便哦 ! ) →→Next →→ Remove any installation media(diskettes or CD-ROMs) used during the installation process →→ Reboot →→ Finish..

 

3.【Hardware Overview】:(Kernel 控制着PC 的硬件设备)

『Block Devices』:→→  Unit: Block(512/1024 bytes) One block is accessed or occurred each time; Fast access and Random access  
/dev/hda  -IDE Drives
/dev/sda  -SCSI Drives
/dev/fd0   -standard floppy drives

『Character Devices』:→→ Unit: Character(1 bytes) One character for each access; Slow access and Sequential accesses 
/dev/tty [0-6] -virtual consoles
/dev/st0  -SCSI tape drive

『Property』:
[root@rhel5 ~]# ls -l /dev/sd*  →→    列出以sd 开头的文件, 看到文件类型为 :" d "  
brw-rw----  1 root disk 8, 0 Jul 10 2009 /dev/sda
brw-rw----  1 root disk 8, 1 Jul 10 2009 /dev/sda1
brw-rw----  1 root disk 8, 2 Jul 10 2009 /dev/sda2

[root@rhel5 ~]# ls -l /dev/tty* | more →→    列出以tty 开头的文件, 看到文件类型为 :" c "  
crw-rw----  1 root tty 4, 11 Jul 10 2009 /dev/tty11
crw-rw----  1 root tty 4, 12 Jul 10 2009 /dev/tty12
crw-rw----  1 root tty 4, 13 Jul 10 2009 /dev/tty13

『Symbolic links』:
[root@rhel5 ~]# ls -l /usr/ | grep ^ l | more  →→    列出以" l "  开头的文件, 看到文件类型为 :" l "  
lrwxrwxrwx 1  root  root 10 Jul 8  22:22  tmp -> ../var/tmp

——————————————————————————————————————

二:RHEL 开机全过程

1.【Partition Structure】:

1.1.【MBR】
(512bytes, 存放于第一块硬盘的第 0 轨上)  →→  boot loader + partition table + magic(三个部分组成了 MBR ! )(446+64+2)

1.1.1.『boot loader(446bytes, boot Information) 选择启动分区』

1.1.2.『partition table(64bytes, 存放着每个 partition起始 与结束 的磁柱分区表, 
而且记录磁柱信息占用16bytes  因此 64 / 16 = 4 partition, 亦即最多能有4个主分区。
Recommend:3P(primary partition) + 1E(extended partition) , 将extended partition 划分为 Logical Partition;
第一个 Logical Partition 也会记录 Starting and ending sectors(起始与结束的磁柱, 
并且记录:下一个Logical Partition 起始的磁柱; 第二个分区同样会记录 起始与结束的磁柱, 
以及下一个Logical Partition 起始的磁柱。)

1.1.3.『magic(2 bytes, BIOS magic number)』

 

2.『Boot Sequence Overview』

BIOS(开机后进入BIOS的作用:侦测Cpu、Memory、风扇速度等)  →→  
MBR(boot Loader, 选择要启动的分区)  →→  Kernel(Loaded device driver 用以控制硬件, 接着读取根目录 " / " 分区)  →→  
init(启动 init程序 PID = 1, 并根据 Run level 执行不同的程序)

 

2.1.『BIOS Initialization』
Power on self test(POST, 开机自检) -Peripherals detected(侦测Cpu、Memory、风扇速度等外部设备)
Boot device selected  -检测由哪个设备来引导系统
First sector of boot device read and executed -读取开机设备的第一个磁区(亦即:MBR)

 

2.2.『Boot Loader』
Boot Loader 可以安装到MBR 或者 硬盘的(Boot Sector)开机磁区上(有时MBR会被其他程序(SPFDisk)占用)
MBR = boot loader + partition table + magic

Boot Loader会进入GRUB选择开机系统; 如果MBR 被(SPFDisk)占用, Boot Loader会被安装到硬盘(Boot Sector)开机磁区上, 同样会进入 GRUB

管理程序进行开机系统选择。

2.2.1【GRUB(the GRand Unified Bootloader)】

在GRUB 管理界面, 
" c "键进行命令的输入

grub > root (hd0,0)

grub > kernel /xen.gz-2.6.18-164.2.1.el5

grub > module /vmlinuz-2.6.18-164.2.1.el5xen ro root=/dev/VolGroup00/LogVol00 rhgb quiet

grub > module /initrd-2.6.18-164.2.1.el5xen.img

grub > boot
" a "键进行kernel 启动参数的修改
例如:grub append > ro root = LABEL = / 1 →→  " 1 "表示(Single User Mode) 单用户模式, 以ROOT用户登入并不需要输入密码 
TIPS:此方法常用于忘记ROOT密码时进行重设密码。(为:防止任何人修改ROOT, 需要设置 GRUB密码。)
sh -3.00# whoami
root
sh -3.00# passwd
Changing password for user root.
设置 GRUB密码后, 进入GRUB界面时:按下 " p " 键输入GRUB密码

如何使用MD5加密GRUB密码:
sh -3.00# grub-md5-crypt
Password:
Retype password:
$1$9rGtz0$Kdq/tkpLsrhwB1FdaDKgY →→  将此密码复制到GRUB配置文件即可 

[root@rhel5 ~]# echo '$1$9rGtz0$Kdq/tkpLsrhwB1FdaDKgY' >> /boot/grub/grub.conf
配置文件:/boot/grub/grub.conf


[root@rhel5 ~]# cp /boot/grub/grub.conf  /boot/grub/grub.conf.bak  →→  备份GRUB 配置文件   
[root@rhel5 ~]# vi  /boot/grub/grub.conf →→  编辑GRUB配置文件   

基本设定:
default = 0              -默认使用第一个系统开机(索引从 " 0 "开始)
timeout =5              -等待时间
splashimage = (hd0,0)/grub/splash.xpm.gz
password --md5 $1$9rGtz0$Kdq/tkpLsrhwB1FdaDKgY→→ 设置 GRUB密码(防止恶意修改启动参数)#hiddenmenu        -是否隐藏开机选单
————————————————————————
多个系统开机设定:
 title Red Hat Enterprise Linux ES(2.6.9-5.EL)

 password --md5 $1$9rGtz0$Kdq/tkpLsrhwB1FdaDKgY→→ 设置菜单密码(防止他人破译GRUB随便开机)
 root (hd0,0)
 kernel /vmlinuz-2.6.9-5.EL ro root=LABEL=/ rhgb(RedHatGraphicalBoot) quiet →→  " ro " =Read Only 方式读取根目录  
 initrd /initrd-2.6.9-5.EL.img→→加载驱动到内存→→rhgb显示图形界面, quiet表示不显示错误信息

 title Windows OS
 root (hd0,1)     

makeactive       -设置C盘为活动分区

chainloader +1 -使用chainloader调用windows分区引导器引导系统,+1表示第一扇区

PS: 

其实在GRUB启动菜单不能工作的时候,进入GRUB命令行(可按C),中间输入关于kernel initrd要利用TAB键补齐写好,最后只要boot一下就行了.

解决问题:

像上面说的当GRUB不工作的时候,可以进入GRUB命令行一步步的解决,这样作的前提是你知道问题出在那里!当不知道问题在那时,还是使用livecd进入系统,查看出问题在那里,然后修改grub.conf或者menu.lst.

————————————————————————————————————————

 

2.3.【Kernel Initialization】

Device detection   -检测设备
Device driver initialization  -初始化设备驱动并载入到kernel
Mounts root filesystem as read only -以只读方式挂载 Root 目录
Loads initial process(init)  -执行 init 程序
   
2.4.【Init Initialization】

Init 首先读取 /etc/inittab 配置文件
# Default runlevel. The runlevels used by RHS are:
#0 - halt (Do NOT set initdefault to this)
#1 - Single user mode
#2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#3 - Full multiuser mode →→  Text mode 
#4 - unused
#5 - X11   →→  X Window 默认启用此模式 
#6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:  →→  " 5 " 默认启用此模式

#System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

10:0:wait:/etc/rc.d/rc 0
11:1:wait:/etc/rc.d/rc 1
12:2:wait:/etc/rc.d/rc 2
13:3:wait:/etc/rc.d/rc 3
14:4:wait:/etc/rc.d/rc 4
15:5:wait:/etc/rc.d/rc 5 →→  (runlevel 5)将会执行 /etc/rc.d/rc 5.d 目录下的程序   
16:6:wait:/etc/rc.d/rc 6

#Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

→→  Uninterruptible Power Supply 不间断电源(UPS), 当电源供电不正常会使用UPS继续供电保证正常关机。 

pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure;System Shutting Down" →→  电源异常执行关机动作 

pf:12345:powerokwait:/sbin/shutdown -c "Power Restored;Shutdown Cancelled" →→  电源恢复正常取消关机 

#Run gettys in standard runlevels(产生 6 个虚拟控制台)
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

#Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon(启动图形界面)
2.4.1.【Init 初始化流程表, 每一步操作都会有详解 见下面。】:
id:5:initdefault:
           ↓         
/etc/rc.sysinit
           ↓         
/etc/rc5.d→→ (/etc/rc.local) 
           ↓         
/sbin/mingetty(启动 6 个虚拟控制台)
           ↓         
           ^
       <  5  > —N→Text mode
           V 
        Y ↓      
/etc/X11/prefdm   (启动图形界面)

 

2.4.2.【Run Levels】:
0   - halt (Do NOT set initdefault to this)
1,S,emergency  - Single user mode(Only the root user can be logged on.Used to perform Maintenance)
2   - Multi-user, without NFS 
3   - Full multi-user mode.(Includes networking) →→  Text mode 
4   - User definable,but duplicate of runlevel 3 by default
5   - X11(Includes networking)  →→  X Window 默认启用此模式 
6   - reboot (Do NOT set initdefault to this)
【TIPS】:
Run Level 1 →→ init → /etc/rc.sysinit →/etc/rc1.d→→ 
Run Level S →→ init → /etc/rc.sysinit  (仅仅初始化系统)
Run Level emergency →→ init →some /etc/rc.sysinit (仅仅执行必要的程式)

 

2.4.3.【切换和查看Run Level】:
[root@rhel5 ~]# init 3 →→  切换到 Text mode  
[root@rhel5 ~]# runlevel →→  查看当前:Run Level  
5 3 →→  " 5 "表示前一个, " 3 "表示目前Run Level  
[root@rhel5 ~]# init 5 →→  切换到 图形模式 

 

2.4.4.【/etc/rc.d/rc/sysinit】:
[root@rhel5 ~]# less /etc/rc.d/rc.sysinit →→  查看sysinit 所作所为  
→→ *
设定系统时间、载入键盘设定、启用swap、设定HOSTNAME、
(
[root@rhel5 ~]#  cat /etc/sysconfig/network →→  查看HOSTNAME 设定值  
NETWORKING=yes
HOSTNAME=rhel5

GATEWAY=192.168.0.1
)
设定ROOT根目录 并重新挂载成可 读写的模式、挂载其他可挂载点、最后清除 开机暂存档案和没用的文件。
 

#Rerun ourselves through initlog
if [ -z "$IN_INITLOG" -a -x /sbin/initlog]; then
 exec /sbin/initlog -r /etc/rc.d/rc.sysinit
fi

HOSTNAME=` /bin/hostname `
HOSTTYPE=` uname -m `
unamer=` uname -r `
eval version=` echo $unamer | awk -F ' . '  '{  print "(" $1 " " $2 ")" }' `

if [ -f  /etc/sysconfig/network ];  then
 . /etc/sysconfig/network
fi
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
 HOSTNAME = localhost
fi

2.4.5.【/etc/rc.d/rc】:(根据 Run Level 执行相应的程式)
10:0:wait:/etc/rc.d/rc 0
11:1:wait:/etc/rc.d/rc 1
12:2:wait:/etc/rc.d/rc 2
13:3:wait:/etc/rc.d/rc 3
14:4:wait:/etc/rc.d/rc 4
15:5:wait:/etc/rc.d/rc 5  →→  执行 /etc/rc.d/rc5.d→→  目录下的程序   
16:6:wait:/etc/rc.d/rc 6
TIPS:" d " = Daemon

2.4.6【/etc/rc.local】:
Run Level 执行后都会执行 /etc/rc.local 里的程式

——————————————————————————————————————

三:RHEL 管理服务 ( Controlling Services )

1.【Daemon Processes】:
一个在后台执行的程序、为系统提供服务(当有使用者请求服务便会执行相应的Daemon程序。)

1.1.『StandaloneDaemon』方式:当有请求服务时, Standalone 会自行提供服务
1.2.『Transient    Daemon』方式:
User请求服务→Xinetd(Super Daemon)→Transient→提供服务 →User
例如:telnet指令 → Xinetd(Super Daemon)呼叫 →In.telnetd(In.telnetd Daemon)提供服务 →User


1.3.管理服务

[root@rhel5 ~]# less /etc/services →→  查看服务使用的协议/端口号

常用端口及协议:
ftp-data 20/tcp
ftp-data 20/udp
ftp 21/tcp
ftp 21/udp

ssh 22/tcp
ssh 22/udp

smtp 25/tcp 
smtp 25/udp

domain 53/tcp  #name-domain server (DNS)
domain 53/udp

http 80/tcp
http 80/udp

pop3 110/tcp
pop3 110/udp

netbios-ns 137/tcp #(Samba Server)
netbios-ns 137/udp
netbios-dgm 138/tcp
netbios-dgm 138/udp
netbios-ssn 139/tcp
netbios-ssn 139/udp

https 443/tcp
https 443/udp

——————————————————————————————————————

1.3.1. 键入全路径管理服务 (安全性、效率都高)

[root@rhel5 ~]# less /etc/rc.d/init.d →→  本机可管理的服务 

[root@rhel5 ~]# /etc/init.d/httpd status →→  查看服务状态 " status  "


[root@rhel5 ~]# /etc/init.d/httpd start →→  启动服务 " start  " 
[root@rhel5 ~]# /etc/init.d/httpd stop →→  停用服务 " stop  "

[root@rhel5 ~]# /etc/init.d/httpd restart→→  重启服务 " restart  "


1.3.2.chkconfig、ntsysv and service

文本模式:

[root@rhel5 ~]# ntsysv →→ 只会设定目前Run Level 的预设启动服务

[root@rhel5 ~]# ntsysv --level 35 →→设定Run Level " 3 " 和" 5 " 的预设启动服务

[root@rhel5 ~]# setup →→ 管理本机所有配置

命令模式:

[root@rhel5 ~]# chkconfig named --level 345 on →→ 开启Run Level 345 的named 服务开机启动

[root@rhel5 ~]# chkconfig named --list →→ 查看named服务的预设启动状态

[root@rhel5 ~]# service named status →→ 查看named服务的预设启动状态

[root@rhel5 ~]# service named start →→ 开启named服务


1.3.3. 使用 system-config-services →→ 图形界面工具管理服务

[root@rhel5 ~]# system-config-services

——————————————————————————————————————

 四:RHEL系统管理

1.【System Shutdown 】:
shutdown       -h now -选择在什么时候关机(" -h "= halt)
halt                  -马上关机
poweroff         -关机
init 0                -切换到Run Level 0, 也就是关机
TIPS:以上指令执行后会自动执行 [root@rhel5 ~]# sync(进行同步, 将内存资料写到硬盘 避免资料丢失。)

shutdown  -h 09:30 "Going down for scheduled maintenance. Expected downtime is 1 hour."
shutdown  -h +15 "Going down for emergency disk repair."

1.1.【System Reboot 】:
shutdown          -r now -选择在什么时候重启(" -r "= reboot)
reboot                -马上重启
init 6                   -切换到Run Level 6, 也就是重启
Ctrl + Alt + Del   -在 Virtual Console下可以使用此 按键 进行重启动作

 ——————————————————————————————————————

2.whois

查看域名的注册备案情况

[root@rhel5 ~]# whois baidu.cn
Domain Name: baidu.cn
ROID: 20030312s10001s00062053-cn
Domain Status: serverDeleteProhibited
Domain Status: serverUpdateProhibited
Domain Status: serverTransferProhibited
Registrant Organization: 百度在线网络技术(北京)有限公司
Registrant Name: 徐勇
Administrative Email: fengyongxiao@baidu.com
Sponsoring Registrar: 厦门东南融通在线科技有限公司
Name Server:proxy.baidu.com
Name Server:dns.baidu.com
Registration Date: 2003-03-17 12:20
Expiration Date: 2018-03-17 12:48

——————————————————————————————————————

 3.显示系统运行时间 和 负载情况
[root@rhel5 ~]# uptime
11:47:04 up 85 days,  2:10,  1 user,  load average: 2.40, 2.18, 2.34

——————————————————————————————————————

4.执行脚本

rc=run command 启动脚本

ttp = Teletype

我们编写一个脚本:

[root@rhel5 ~]# vi hello.sh

#!/bin/sh

echo "Hello Bruce.Ko I love u.."

~

~

:wq →→保存退出

[root@rhel5 ~]# source hello.sh→→执行脚本

[root@rhel5 ~]# . hello.sh→→执行脚本

 ——————————————————————————————————————

5.计算 md5sum and cksum
[root@rhel5 ~]# cksum hosts →→计算文件的CRC 值。

[root@rhel5 ~]# md5sum hosts →→计算文件的MD5值。

 ——————————————————————————————————————

6.【Kernel Modules Configuration】:(/lib/modules)

6.1.『Module Configuration』
[root@rhel5 ~]# less /etc/modprobe.conf →→ 查看模组信息

记录了ethernet interface、sound card、usb controller信息,action:记录了执行哪些动作。

6.2.『动态管理modules』

[root@rhel5 ~]# lsmod /* 查看载入的模组 */
[root@rhel5 ~]# insmod →→  动态载入模组  
[root@rhel5 ~]# rmmod  →→  动态移除模组 


[root@rhel5 ~]# depmod -a →→重新识别本机硬件

[root@rhel5 ~]# insmod ipt_REJECT →→动态载入模组

[root@rhel5 ~]# rmmod  pcnet32 →→动态移除模组


[root@rhel5 ~]# less /var/log/dmesg →→ 用于查看  kernel 的引导信息

[root@rhel5 ~]# less /etc/sysconfig/hwconf →→ 存放检测到的硬件信息


——————————————————————————————————————


7.【/proc】:(虚拟目录, 保存了目前的系统状况; 目录下档案大小均是:" 0 ")
[root@rhel5 ~]# cat /proc/cpuinfo →→   查看CPU 目前状态   可查看系统硬件设备、网络设定、正在运行的程序、内存使用状况等。

[root@rhel5 ~]# less /proc/meminfo →→  查看内存相关资讯 

 7.1.【/proc/sys configuration with sysctl】:
/etc/sysctl.conf                          -用于设定/proc/sys 配置kernel的参数

/proc/sys 是临时目录所以设定后不会永久保存,在这里进行永久性配置
系统启动后会 呼叫 rc.sysinit → 接着会呼叫 → /etc/sysctl.conf

——————————————————————————————————————

7.2.【General Hardware Resources】:(检测硬件设备)
Kernel → Klogd → ring buffer→ /var/log/dmesg -系统启动加载kernel ,引导信息通过klogd服务写入到ring buffer(环形缓冲区)→→ ring buffer 空间有限 会继续写入到 /var/log/dmesg 存放 kernel引导信息  

——————————————————————————————————————

 8.【Disk Partitioning】:分区管理
IDE drives 最多支持63个 partition;  SCSI drives 最多支持15 个partition。


为什么要分区?
1、方便管理资料
2、考虑到硬盘定位资料的性能(分区越小定位则越快)
3、Quotas 功能, 管理每个用户最大使用空间
4、资料恢复 -Backup/Restore(例如: /home存放用户资料, 仅备份这个分区即可)

——————————————————————————————————————

8.2.【Managing Partitions】:
【fdisk】:(分区管理工具)

[root@rhel5 ~]# fdisk -l /dev/sda  →→  查看分区状况  
[root@rhel5 ~]# fdisk /dev/sda  →→  管理分区   " m "查看帮助

Command ( m for help ): m -执行帮助指令显示帮助
Command action
d -delete a partition  →→  删除分区  
n -add a new partition  →→  创建新分区  
p -print the partition table →→  打印分区表信息   
q  -quit without saving changes →→ 退出不保存更改  
t  -change a partition's system id →→  改变Partition ID  
w -write table to disk and exit →→  保存更改写入到分区表并离开  
——————————————————————————————————————

Command ( m for help ): p →→  打印分区表信息  
Disk  /dev/sda: 13.9 GB , 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks  Id System
/dev/sda1   * 1 25 200781  83 Linux
/dev/sda2    26 1300 10241437+ 83 Linux
/dev/sda3    1301 1427 1020127+ 83 Linux
/dev/sda4    1428 1697 2168775  5 Extended
/dev/sda5    1428 1492 522081  82 Linux swap

Command ( m for help ): n →→  创建新分区  
First cylinder (1493-1697, default 1493) →→  输入起始磁柱编号 " default 1493"表示默认使用了 1493 
Using default value 1493
Last cylinder or +size or +sizeM or +sizeK (1493-1697,default 1697): +100M →→  输入:" +100M "表示切割100MB空间给当前分区。 

Command ( m for help ): p →→  打印分区表信息  
Disk  /dev/sda: 13.9 GB , 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks  Id System
/dev/sda1   * 1 25 200781  83 Linux
/dev/sda2    26 1300 10241437+ 83 Linux
/dev/sda3    1301 1427 1020127+ 83 Linux
/dev/sda4    1428 1697 2168775  5 Extended
/dev/sda5    1428 1492 522081  82 Linux swap
/dev/sda6    1493 1505 104391  83 Linux →→  切割后出现了/dev/sda6分区 

Command ( m for help ): d →→  删除分区  
Partition number (1-6):6 →→  删除Partition 6 

Command ( m for help ): p →→  删除后, 重新打印分区表信息  
Disk  /dev/sda: 13.9 GB , 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks  Id System
/dev/sda1   * 1 25 200781  83 Linux
/dev/sda2    26 1300 10241437+ 83 Linux
/dev/sda3    1301 1427 1020127+ 83 Linux
/dev/sda4    1428 1697 2168775  5 Extended
/dev/sda5    1428 1492 522081  82 Linux swap
        →→  /dev/sda6分区已删除  
Command ( m for help ): n →→  创建新分区  
First cylinder (1493-1697, default 1493) →→  输入起始磁柱编号 " default 1493"表示默认使用了 1493 
Using default value 1493
Last cylinder or +size or +sizeM or +sizeK (1493-1697,default 1697): 1505 →→  一个磁柱占 8MB, 所以分区 = 8*(1505-1493)=96MB 

Command ( m for help ): w →→  确认无误后退出:这个操作将会把分区表重新写入到MBR的 Partition table 里面。  
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING:Re-reading the partition table failed with error 16:Device or resource busy.
The kernel still uses the old table.  →→  提示:目前仍使用旧的分区表  
The new table will be used at the next reboot. →→  提示:重启后生效  
Syncing disks.

[root@rhel5 ~]# partprobe  →→  不重启系统更新对分区表的改动 !  "【绝密】" 

——————————————————————————————————————

8.3.【Virtual Memory】:(Linux Swap) →→  因为有相关内容,所以插入到这里 

8.3.1.【1、Partition  -分区作为Swap】:

[root@rhel5 ~]# fdisk /dev/sda   →→  管理分区   " m "查看帮助 
Command(m for help):n  →→  " n "命令创建新分区  
...创建完毕后( Partition ID 默认是83 )

Command(m for help):t  →→  修改Partition ID  
Partition number (1-7):7  →→  我们将要修改7号分区  
Hex code (type L to list codes):  →→   输入" L " 查看所有ID 都代表了什么信息 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82  Linux swap. . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
Hex code (type L to list codes): 82 →→   输入82 设定Partition ID 
Command ( m for help ): p →→  打印分区表信息  
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  
/dev/sda7  1506 1518 104391 82 Linux swap

Command ( m for help ): w →→  确认无误后退出:这个操作将会把分区表重新写入到MBR的 Partition table 里面。  
[root@rhel5 ~]# partprobe  →→  不重启系统更新对分区表的改动 !  "【绝密】" 

[root@rhel5 ~]# mkswap /dev/sda7 →→  写入一个代表 swap分区的识别标志(signature) 

[root@rhel5 ~]# vi /etc/fstab
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
LABEL=SWAP-sda5 swap  swap defaults 0 0→→ 将这行 " yy "键*后复制/
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
/dev/sda6   /data  ext3 defaults 1 2
/dev/sda7   swap  swap defaults 0 0→→  " p "键 粘帖到这里, 并根据实际情况修改相应的值  
/dev/hdc   /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
/dev/fd0   /media/floppy auto pamconsole,exec,noauto,managed 0 0
      ↓         ↓       ↓        ↓             ↓  
设备或标签名  挂载目录                文件系统 默认参数 dump_freq → 0 = never ,1= daily , 2= every other day,etc. :wq 

→→  保存并退出     

[root@rhel5 ~]# swapon -s  →→  查看目前所有 Swap的状态  
Filename  Type Size Used Priority
/dev/sda5  partition 522072 0 -1
[root@rhel5 ~]# swapon -a  →→  重新启用所有 Swap分区  
Filename  Type Size Used Priority
/dev/sda5  partition 522072 0 -1
/dev/sda7  partition 104380 0 -2 →→  设定成功 

——————————————————————————————————————

8.3.2.【2、File  -文件作为Swap】:

[root@rhel5 ~]# dd if=/dev/zero of=/swapfile bs=1M count=100 →→  dd(转换并复制档案) if(input file) of(output file) bs(block size) count=100(建立

100 个 block) , 建立出来的档案大小:(bs * count =1M * 100=100MB) 

[root@rhel5 ~]# ls -lh /swapfile →→  " -h "(Human)     
-rw-r--r-- 1 root root 100M Sep 18 22:28 /swapfile

[root@rhel5 ~]# mkswap /swapfile →→  写入一个代表 swap文件的识别标志(signature)  
Setting up swapspace version 1............ →→  写入成功 

[root@rhel5 ~]# vi /etc/fstab
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 代表开机自检的顺序(1表示第一个检查,以此类推。)         

                          ↑
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .      ↑
LABEL=SWAP-sda5 swap  swap defaults 0 0→→ 将这行 " yy "键*后复制/
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
/dev/sda6   /data  ext3 defaults 1 2
/dev/sda7   swap  swap defaults 0 0
/swapfile   swap  swap defaults 0 0→→  " p "键 粘帖到这里, 并根据实际情况修改相应的值  
/dev/hdc   /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
/dev/fd0   /media/floppy auto pamconsole,exec,noauto,managed 0 0
      ↓         ↓       ↓        ↓             ↓  
设备或标签名  挂载目录                文件系统 默认参数 dump_freq → 0 = never ,1= daily , 2= every other day,etc. :wq 

→→  保存并退出   

[root@rhel5 ~]# swapon -s  →→  查看目前所有 Swap的状态  
Filename  Type Size Used Priority
/dev/sda5  partition 522072 0 -1
/dev/sda7  partition 104380 0 -2
[root@rhel5 ~]# swapon /swapfile →→  指定启用 " /swapfile "这个档案 

[root@rhel5 ~]# swapon -s  →→  查看目前所有 Swap的状态  
Filename  Type Size Used Priority
/dev/sda5  partition 522072 0 -1
/dev/sda7  partition 104380 0 -2
/swapfile  file 102392 0 -3

——————————————————————————————————————


8.4.【Format】分区管理
Low Level Format  →→rarely needed
[root@rhel5 ~]# fdformat /dev/fd0H1440   →→ 格式化指定设备


【mke2fs】:(分区格式化工具)

当创建一个分区后 为什么不格式化就不能使用呢?

格式化(Format) 会将分区切成一格一格的 block(存取数据的最小单位);

并检测出有多少Inodes(index node )。


[root@rhel5 ~]# mke2fs /dev/sda6  →→   格式化分区   
. . . . . . . . . . 
. . . . . . . . . . 
13 block groups  →→  block达到一定数量会自动分组  
8192 blocks per group →→    
2008 inodes per group →→    
Superblock backups stored on blocks: →→  Superblock用于 记录partition有多少block和inode、block和inode的使用状况等讯息。 
 8193,24577,40961,57345,73729→→  Superblock 如果损毁,将无法存取数据;因此会自动备份一定数量的Superblock 。  
. . . . . . . . . . 
. . . . . . . . . . 

mke2fs [  options ] device
-b -指定格式化后block的大小(默认值:1024byte, 最大值:4096byte)
-c -格式化前检查是否有损毁的block
-i -设定inode的大小
-N -设定inode的总数量
-m -设定保留多少block空间给super user(Root),默认值:5.00%
-L -设定分区的标签(Label)亦即显示名称
-j -创建" ext3 "类型 partition

[root@rhel5 ~]# mke2fs -b 4096 /dev/sda6 →→  设定block的大小  
[root@rhel5 ~]# mke2fs -i 4096 /dev/sda6 →→  设定inode的大小  
[root@rhel5 ~]# mke2fs -N 20000 /dev/sda6 →→  设定inode的总数量  
[root@rhel5 ~]# mke2fs -m 10 /dev/sda6 →→  定保留10% 的 block空间给super user(Root) 
[root@rhel5 ~]# mke2fs -L data /dev/sda6 →→  设定分区的标签为:data  
[root@rhel5 ~]# mke2fs -j  /dev/sda6 →→  创建" ext3 "类型 partition 

——————————————————————————————————————

8.4.2.【ext2 和 ext3 的区别】:( ext3 比 ext2 多了journal 功能)

 

8.4.3.【Tune2fs】:(不损毁文件情况下从 ext2 转换为 ext3)
[root@rhel5 ~]# tune2fs -j /dev/sda8 →→  将 /dev/sda8 进行无损转换到 ext3 

 

8.4.4.【Dumpe2fs】:
[root@rhel5 ~]# dumpe2fs /dev/sda6 | more  →→  查看分区表信息  
[root@rhel5 ~]# dumpe2fs -h /dev/sda6 →→  " -h "只显示 super block 的讯息  
[root@rhel5 ~]# fdisk -l /dev/sda  →→  查看分区状况 

——————————————————————————————————————

8.4.5.【Adding a Drive】:(添加新硬盘)
首先连接硬盘到电脑上 → 开机后使用新硬盘创建Partitions → 使用partprobe 指令不重启系统更新对分区表的改动
 → 格式化分区(如果建立的是Swap分区 写入一个Signature)  → 建立目录并挂载Partition → 配置/etc/fstab(使得开机正确挂载分区)

——————————————————————————————————————

8.4.6.【Filesystem Labels】:(管理文件系统的标签)【一般不进行Label的修改】
[root@rhel5 ~]# e2label /dev/sda1 →→  查看 /dev/sda1分区的标签名  
/boot
[root@rhel5 ~]# e2label /dev/sda6 data →→  设定 /dev/sda6分区的Label为:data 

 

8.4.7.【分区格式化后不能马上使用】:
首先建立一个目录例如:/data  接着将 新分区例如(/dev/sda6) Mount 到目录 " /data "。
操作步骤:

——————————————————————————————————————
8.4.8.【mount】:(虽然是挂载好了,但是重启后仍需重新挂载;怎么办呢?答案是:修改配置文件" /etc/fstab "下面会详细介绍。 )
[root@rhel5 ~]# mkdir /data  →→  在根分区建立目录:" /data " 
[root@rhel5 ~]# mount /dev/sda6 /data →→  使用 " mount " 指令进行挂载 

[root@rhel5 ~]# mount →→ 显示目前所有的挂载项   
[root@rhel5 ~]# umount /data →→  卸载 " /data " 目录 

[root@rhel5 ~]# e2label /dev/sda6 →→  显示分区的" Label " 值  
data
[root@rhel5 ~]# mount -L data /data  →→  使用" Label " 的值进行挂载 , " data "为标签名, " /data "为挂载点 
[root@rhel5 ~]# df -h →→  " -h "(Human)以友好的方式显示 磁盘信息

——————————————————————————————————————

8.4.9.【Umount】:
umount device | mount_point (指定设备 或 挂载点)

[root@rhel5 ~]# umount /dev/sda6 →→  指定:要卸载 的设备  
[root@rhel5 ~]# umount /data →→  指定:要卸载 " /data " 目录 

fuser -User fuser to check and/or kill processes
[root@rhel5 ~]# fuser -v /data →→  " -v "显示谁在使用" /data "目录下的文件系统   
[root@rhel5 ~]# fuser -km /data →→  " -km "(To kill all actions on a filesystem), 停止所有对" /data "目录下 文件系统的动作 

[root@rhel5 ~]# mount -o remount,ro /data →→  " ro "(read only)改变文件系统的状态为只读  
[root@rhel5 ~]# mount -o noexec /dev/sda6 /data →→  挂载" /dev/sda6 "到" /data "目录" noexec "使得该文件系统不能执行任何程序

——————————————————————————————————————  
8.5.【挂载ISO文件】:
[root@rhel5 ~]# ls →→    
anaconda-ks.cfg linux.iso Desktop grep install.log 
[root@rhel5 ~]# mkdir /iso →→  创建目录 " /iso "用于挂载" linux.iso "文件 


[root@rhel5 ~]# mount -t iso9660 -o ro,loop linux.iso /iso →→  " -t "(Type)," ro "(read only)," loop "光碟是一圈一圈的读所以用loop  
[root@rhel5 ~]# mount →→  查看目前所有的挂载情况  
. . . . . . . . . . 
. . . . . . . . . . 
/root/linux.iso on /iso type iso9660 (ro,loop=/dev/loop0)

8.5.1.【CD/DVD文件】:

CD/DVD Reader  CD/DVD Writer
mount /media/cdrom        mount /media/cdrecorder

[root@rhel5 ~]#mount /dev/hdc cdrom  →→  
[root@rhel5 ~]#umount cdrom  →→  
[root@rhel5 ~]#mount /dev/hdc /media/cdrom  →→ 挂载DVD  
[root@rhel5 ~]#eject /media/cdrom  →→ 

『USB』
/dev/sdaX  -X代表数字
[root@rhel5 ~]#mount /dev/sda1  →→ 挂载USB 
[root@rhel5 ~]#unmount /media/usbdisk  →→ 

『Floppy』
[root@rhel5 ~]#mount /media/floppy  →→ 挂载Floppy 
[root@rhel5 ~]#unmount /media/floppy  →→  

——————————————————————————————————————

8.6.【/etc/fstab】:(设定系统开机后要挂载哪些文件系统, 实现永久性挂载-mount是临时挂载命令。)
[root@rhel5 ~]# cat /etc/fstab【 当使用mount指令时会先进入" /etc/fstab "查看目录或设备是不是已经被设定挂载,如果没有则进入
" /etc/mtab "(Current mounted目前挂载的目录)查找 】

[root@rhel5 ~]# cp /etc/fstab /etc/fstab.bak →→  进行备份  
[root@rhel5 ~]# vi /etc/fstab →→  VI编辑器进行编辑  
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
LABEL=/home /home  ext3 defaults 1 2→→ 将这行 " yy "键*后复制/
. . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . .
/dev/sda6  /data  ext3 defaults 1 2→→  " p "键 粘帖到这里, 并根据实际情况修改相应的值  
/dev/hdc  /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
/dev/fd0  /media/floppy auto pamconsole,exec,noauto,managed 0 0
      ↓        ↓       ↓        ↓             ↓  
设备或标签名 挂载目录                文件系统 默认参数 dump_freq → 0 = never ,1= daily , 2= every other day,etc.  :wq 

→→  保存并退出     

  ——————————————————————————————————————

8.7.【Filesytem Maintenance】:(检查 与 维护文件系统, 其实电脑开机时会进行Power on self test=POST=开机自检。)
[root@rhel5 ~]# umount /dev/sda6 →→  检测前需要先卸载设备  
[root@rhel5 ~]# fsck -y /dev/sda6 →→  " -y " 询问时自动回答 YES, " /dev/sda6 "指定要检查的文件系统。  
→→  检查到有问题的档案会先放到" lost + found "目录里进行备份 


TIPS:当" /etc/fstab " 配置文件出错时系统无法进入并进行Repair filesystem模式


(Repair filesystem) 3 # mount -o remount,rw /dev/sda2→→  由于/root 目录是 read only模式挂载,无法修改后保存/etc/fstab配置文件;
使用该指令重新以 rw(read and write) 方式挂载 /root 目录(/dev/sda2) 并进行配置文件修改回正确的设定。  
(Repair filesystem) 4 # vi /etc/fstab 

——————————————————————————————————————

阅读(621) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~