fdisk -l
[root@mylinuxdbserver1 ~]# fdisk -l
Disk /dev/sda: 19.3 GB, 19327352832 bytes
255 heads, 63 sectors/track, 2349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2349 18763920 8e Linux LVM
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@mylinuxdbserver1 ~]#
fdisk /dev/sdb
[root@mylinuxdbserver1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): l
0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
Command (m for help):
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044): 200
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (201-1044, default 201):
Using default value 201
Last cylinder or +size or +sizeM or +sizeK (201-1044, default 1044): 400
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (401-1044, default 401):
Using default value 401
Last cylinder or +size or +sizeM or +sizeK (401-1044, default 1044): 600
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (601-1044, default 601):
Using default value 601
Last cylinder or +size or +sizeM or +sizeK (601-1044, default 1044): 800
Command (m for help): n
You must delete some partition and add an extended partition first
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 200 1606468+ 83 Linux
/dev/sdb2 201 400 1606500 83 Linux
/dev/sdb3 401 600 1606500 83 Linux
/dev/sdb4 601 800 1606500 83 Linux
Command (m for help):
Command (m for help): d
Partition number (1-4): 4
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (601-1044, default 601):
Using default value 601
Last cylinder or +size or +sizeM or +sizeK (601-1044, default 1044):
Using default value 1044
Command (m for help): n
First cylinder (601-1044, default 601):
Using default value 601
Last cylinder or +size or +sizeM or +sizeK (601-1044, default 1044): 800
Command (m for help): n
First cylinder (801-1044, default 801):
Using default value 801
Last cylinder or +size or +sizeM or +sizeK (801-1044, default 1044):
Using default value 1044
Command (m for help):
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 200 1606468+ 83 Linux
/dev/sdb2 201 400 1606500 83 Linux
/dev/sdb3 401 600 1606500 83 Linux
/dev/sdb4 601 1044 3566430 5 Extended
/dev/sdb5 601 800 1606468+ 83 Linux
/dev/sdb6 801 1044 1959898+ 83 Linux
Command (m for help):
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044): 200
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-200, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-200, default 200): 100
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (101-200, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-200, default 200):
Using default value 200
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
Partition 1 is already defined. Delete it before re-adding it.
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (201-1044, default 201):
Using default value 201
Last cylinder or +size or +sizeM or +sizeK (201-1044, default 1044): 400
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (401-1044, default 401):
Using default value 401
Last cylinder or +size or +sizeM or +sizeK (401-1044, default 1044): 600
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Selected partition 4
First cylinder (601-1044, default 601):
Using default value 601
Last cylinder or +size or +sizeM or +sizeK (601-1044, default 1044): 800
Command (m for help): n
No free sectors available
Command (m for help):
可以创建4个主分区或者3个主分区1个扩展分区(可以创建很多逻辑分区)
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 200 1606468+ 83 Linux
/dev/sdb2 201 400 1606500 83 Linux
/dev/sdb3 401 1044 5172930 5 Extended
/dev/sdb5 401 600 1606468+ 83 Linux
/dev/sdb6 601 800 1606468+ 83 Linux
/dev/sdb7 801 1000 1606468+ 83 Linux
/dev/sdb8 1001 1044 353398+ 83 Linux
Command (m for help):
Command (m for help): t
Partition number (1-8): 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS)
Command (m for help): t
Partition number (1-8): 4
Partition 4 does not exist yet!
Command (m for help): t
Partition number (1-8): 2
Hex code (type L to list codes): 83
Command (m for help): t
Partition number (1-8): 5
Hex code (type L to list codes): 83
Command (m for help):
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@mylinuxdbserver1 ~]#
[root@mylinuxdbserver1 ~]# fdisk -l
Disk /dev/sda: 19.3 GB, 19327352832 bytes
255 heads, 63 sectors/track, 2349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2349 18763920 8e Linux LVM
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 200 1606468+ 7 HPFS/NTFS
/dev/sdb2 201 400 1606500 83 Linux
/dev/sdb3 401 1044 5172930 5 Extended
/dev/sdb5 401 600 1606468+ 83 Linux
/dev/sdb6 601 800 1606468+ 83 Linux
/dev/sdb7 801 1000 1606468+ 83 Linux
/dev/sdb8 1001 1044 353398+ 83 Linux
[root@mylinuxdbserver1 ~]#
Command (m for help): a
Partition number (1-8): 1
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 200 1606468+ 7 HPFS/NTFS
/dev/sdb2 201 400 1606500 83 Linux
/dev/sdb3 401 1044 5172930 5 Extended
/dev/sdb5 401 600 1606468+ 83 Linux
/dev/sdb6 601 800 1606468+ 83 Linux
/dev/sdb7 801 1000 1606468+ 83 Linux
/dev/sdb8 1001 1044 353398+ 83 Linux
Command (m for help):
Command (m for help): b
There is no *BSD partition on /dev/sdb.
Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 63 3212999 1606468+ 7 HPFS/NTFS
/dev/sdb2 3213000 6425999 1606500 83 Linux
/dev/sdb3 6426000 16771859 5172930 5 Extended
/dev/sdb5 6426063 9638999 1606468+ 83 Linux
/dev/sdb6 9639063 12851999 1606468+ 83 Linux
/dev/sdb7 12852063 16064999 1606468+ 83 Linux
/dev/sdb8 16065063 16771859 353398+ 83 Linux
Command (m for help):
逻辑卷管理LVM
rpm -qa|grep lvm
[root@mylinuxdbserver1 ~]# rpm -qa|grep lvm
lvm2-2.02.32-4.el5
system-config-lvm-1.1.3-2.0.el5
[root@mylinuxdbserver1 ~]#
Hex code (type L to list codes): 8e
Command (m for help): t
Partition number (1-8): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-8): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-8): 3
Hex code (type L to list codes): 8e
You cannot change a partition into an extended one or vice versa
Delete it first.
Command (m for help): t
Partition number (1-8): 4
Partition 4 does not exist yet!
Command (m for help): t
Partition number (1-8): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-8): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 200 1606468+ 8e Linux LVM
/dev/sdb2 201 400 1606500 8e Linux LVM
/dev/sdb3 401 1044 5172930 5 Extended
/dev/sdb5 401 600 1606468+ 8e Linux LVM
/dev/sdb6 601 800 1606468+ 8e Linux LVM
/dev/sdb7 801 1000 1606468+ 83 Linux
/dev/sdb8 1001 1044 353398+ 83 Linux
Command (m for help):
Command (m for help): w
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@mylinuxdbserver1 ~]#
pvcreate
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb3
Device /dev/sdb3 not found (or ignored by filtering).
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb6
Physical volume "/dev/sdb6" successfully created
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb7
Physical volume "/dev/sdb7" successfully created
[root@mylinuxdbserver1 ~]# pvcreate /dev/sdb8
Physical volume "/dev/sdb8" successfully created
[root@mylinuxdbserver1 ~]#
vgcreate
[root@mylinuxdbserver1 ~]# vgcreate web_document /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8
Volume group "web_document" successfully created
[root@mylinuxdbserver1 ~]#
vgchange
[root@mylinuxdbserver1 ~]# vgchange -a y web_document
0 logical volume(s) in volume group "web_document" now active
[root@mylinuxdbserver1 ~]#
pvdisplay
[root@mylinuxdbserver1 ~]# pvdisplay /dev/sdb7
--- Physical volume ---
PV Name /dev/sdb7
VG Name web_document
PV Size 1.53 GB / not usable 836.50 KB
Allocatable yes
PE Size (KByte) 4096
Total PE 392
Free PE 392
Allocated PE 0
PV UUID ii2YIY-EhxU-KMw9-UWuV-dHX0-Q1eL-R3Vfwf
[root@mylinuxdbserver1 ~]#
[root@mylinuxdbserver1 ~]# pvdisplay /dev/sda2
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 17.89 GB / not usable 20.14 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 572
Free PE 0
Allocated PE 572
PV UUID ynQu3O-O4T6-m0Ws-u2AW-6xaR-xH1k-0OMszN
[root@mylinuxdbserver1 ~]#
vgreduce
[root@mylinuxdbserver1 ~]# vgreduce web_document /dev/sdb7
Removed "/dev/sdb7" from volume group "web_document"
[root@mylinuxdbserver1 ~]#
vgextend
[root@mylinuxdbserver1 ~]# vgextend web_document /dev/sdb7
Volume group "web_document" successfully extended
[root@mylinuxdbserver1 ~]#
lvcreate
[root@mylinuxdbserver1 ~]# vgdisplay web_document| grep "Total PE"
Total PE 2046
[root@mylinuxdbserver1 ~]# lvcreate -l 2046 web_document -n www1
Logical volume "www1" created
[root@mylinuxdbserver1 ~]#
mkfs -t ext3 /dev/web_document/www1
[root@mylinuxdbserver1 web_document]# mkfs -t ext3 /dev/web_document/www1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
192000 inodes, 384000 blocks
19200 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=394264576
12 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mylinuxdbserver1 web_document]#
[root@mylinuxdbserver1 dev]# mkdir -p /data/wwwroot
mount /dev/web_document/www1 /data/wwwroot
[root@mylinuxdbserver1 dev]# mount /dev/web_document/www1 /data/wwwroot
df
[root@mylinuxdbserver1 web_document]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
16188328 11838888 3513856 78% /
/dev/sda1 101086 13203 82664 14% /boot
tmpfs 481976 0 481976 0% /dev/shm
/dev/md0 8254136 149632 7685216 2% /mnt/md-test
/dev/mapper/web_document-www1
1511856 35068 1399988 3% /data/wwwroot
rpm -qa | grep raid
[root@mylinuxdbserver1 ~]# rpm -qa | grep raid
dmraid-1.0.0.rc13-9.el5
[root@mylinuxdbserver1 ~]#
Linux中tty、pty、pts的概念区别
Linux中tty、pty、pts的概念区别
基本概念:
1> tty(终端设备的统称):
tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘与显示器取代,所以现在叫终端比较合适。
终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。
2> pty(虚拟终端):
但是如果我们远程telnet到主机或使用xterm时不也需要一个终端交互么?是的,这就是虚拟终端pty(pseudo-tty)
3> pts/ptmx(pts/ptmx结合使用,进而实现pty):
pts(pseudo-terminal slave)是pty的实现方法,与ptmx(pseudo-terminal master)配合使用实现pty。
Linux终端:
在Linux系统的设备特殊文件目录/dev/下,终端特殊设备文件一般有以下几种:
1、串行端口终端(/dev/ttySn)
串行端口终端(Serial Port Terminal)是使用计算机串行端口连接的终端设备。计算机把每个串行端口都看作是一个字符设备。有段时间这些串行端口设备通常被称为终端设备,因为那时它的最大用途就是用来连接终端。这些串行端口所对应的设备名称是/dev/tts/0(或/dev/ttyS0), /dev/tts/1(或/dev/ttyS1)等,设备号分别是(4,0), (4,1)等,分别对应于DOS系统下的COM1、COM2等。若要向一个端口发送数据,可以在命令行上把标准输出重定向到这些特殊文件名上即可。例如,在命令行提示符下键入:echo test > /dev/ttyS1会把单词”test”发送到连接在ttyS1(COM2)端口的设备上。可接串口来实验。
2、伪终端(/dev/pty/)
伪终端(Pseudo Terminal)是成对的逻辑终端设备(即master和slave设备, 对master的操作会反映到slave上)。
例如/dev/ptyp3和/dev/ttyp3(或者在设备文件系统中分别是/dev/pty/m3和 /dev/pty/s3)。它们与实际物理设备并不直接相关。如果一个程序把ptyp3(master设备)看作是一个串行端口设备,则它对该端口的读/ 写操作会反映在该逻辑终端设备对应的另一个ttyp3(slave设备)上面。而ttyp3则是另一个程序用于读写操作的逻辑设备。
这样,两个程序就可以通过这种逻辑设备进行互相交流,而其中一个使用ttyp3的程序则认为自己正在与一个串行端口进行通信。这很象是逻辑设备对之间的管道操作。对于ttyp3(s3),任何设计成使用一个串行端口设备的程序都可以使用该逻辑设备。但对于使用ptyp3的程序,则需要专门设计来使用 ptyp3(m3)逻辑设备。
例如,如果某人在网上使用telnet程序连接到你的计算机上,则telnet程序就可能会开始连接到设备 ptyp2(m2)上(一个伪终端端口上)。此时一个getty程序就应该运行在对应的ttyp2(s2)端口上。当telnet从远端获取了一个字符时,该字符就会通过m2、s2传递给 getty程序,而getty程序就会通过s2、m2和telnet程序往网络上返回”login:”字符串信息。这样,登录程序与telnet程序就通过“伪终端”进行通信。通过使用适当的软件,就可以把两个甚至多个伪终端设备连接到同一个物理串行端口上。
在使用设备文件系统 (device filesystem)之前,为了得到大量的伪终端设备特殊文件,使用了比较复杂的文件名命名方式。因为只存在16个ttyp(ttyp0—ttypf) 的设备文件,为了得到更多的逻辑设备对,就使用了象q、r、s等字符来代替p。例如,ttys8和ptys8就是一个伪终端设备对。不过这种命名方式目前仍然在RedHat等Linux系统中使用着。
但Linux系统上的Unix98并不使用上述方法,而使用了”pty master”方式,例如/dev/ptm3。它的对应端则会被自动地创建成/dev/pts/3。这样就可以在需要时提供一个pty伪终端。目录 /dev/pts是一个类型为devpts的文件系统,并且可以在被加载文件系统列表中看到。虽然“文件”/dev/pts/3看上去是设备文件系统中的一项,但其实它完全是一种不同的文件系统。
即: TELNET ---> TTYP3(S3: slave) ---> PTYP3(M3: master) ---> GETTY
=========================================================================
实验:
1、在X下打开一个或N个终端窗口
2、#ls /dev/pt*
3、关闭这个X下的终端窗口,再次运行;比较两次输出信息就明白了。
在RHEL4环境下: 输出为/dev/ptmx /dev/pts/1存在一(master)对多(slave)的情况
=========================================================================
3、控制终端(/dev/tty)
如果当前进程有控制终端(Controlling Terminal)的话,那么/dev/tty就是当前进程的控制终端的设备特殊文件。可以使用命令”ps –ax”来查看进程与哪个控制终端相连。对于你登录的shell,/dev/tty就是你使用的终端,设备号是(5,0)。使用命令”tty”可以查看它具体对应哪个实际终端设备。/dev/tty有些类似于到实际所使用终端设备的一个联接。
4、控制台终端(/dev/ttyn, /dev/console)
在Linux 系统中,计算机显示器通常被称为控制台终端 (Console)。它仿真了类型为Linux的一种终端(TERM=Linux),并且有一些设备特殊文件与之相关联:tty0、tty1、tty2 等。当你在控制台上登录时,使用的是tty1。使用Alt+[F1—F6]组合键时,我们就可以切换到tty2、tty3等上面去。tty1–tty6等称为虚拟终端,而tty0则是当前所使用虚拟终端的一个别名,系统所产生的信息会发送到该终端上(这时也叫控制台终端)。因此不管当前正在使用哪个虚拟终端,系统信息都会发送到控制台终端上。你可以登录到不同的虚拟终端上去,因而可以让系统同时有几个不同的会话期存在。只有系统或超级用户root可以向 /dev/tty0进行写操作 即下例:
1、# tty(查看当前TTY)
/dev/tty1
2、#echo "test tty0" > /dev/tty0
test tty0
5 虚拟终端(/dev/pts/n)
在Xwindows模式下的伪终端.
6 其它类型
Linux系统中还针对很多不同的字符设备存在有很多其它种类的终端设备特殊文件。例如针对ISDN设备的/dev/ttyIn终端设备等。这里不再赘述。
FAQ: 终端和控制台
Q:/dev/console 是什么?
A:/dev/console即控制台,是与操作系统交互的设备,系统将一些信息直接输出到控制台上。目前只有在单用户模式下,才允许用户登录控制台。
Q:/dev/tty是什么?
A:tty设备包括虚拟控制台,串口以及伪终端设备。
/dev/tty代表当前tty设备,在当前的终端中输入 echo “hello” > /dev/tty ,都会直接显示在当前的终端中。
Q:/dev/ttyS*是什么?
A:/dev/ttyS*是串行终端设备。
Q:/dev/pty*是什么?
A:/dev/pty*即伪终端,所谓伪终端是逻辑上的终端设备,多用于模拟终端程序。例如,我们在X Window下打开的终端,以及我们在Windows使用telnet 或ssh等方式登录Linux主机,此时均在使用pty设备(准确的说在使用pty从设备)。
Q:/dev/tty0与/dev/tty1 …/dev/tty63是什么?它们之间有什么区别?
A:/dev/tty0代表当前虚拟控制台,而/dev/tty1等代表第一个虚拟控制台,例如当使用ALT+F2进行切换时,系统的虚拟控制台为/dev/tty2 ,当前的控制台则指向/dev/tty2
Q:如何确定当前所在的终端(或控制台)?
A:使用tty命令可以确定当前的终端或者控制台。
Q:/dev/console是到/dev/tty0的符号链接吗?
A: 目前的大多数文本中都称/dev/console是到/dev/tty0的链接(包括《Linux内核源代码情景分析》),但是这样说是不确切的。根据内核文档,在2.1.71之前,/dev/console根据不同系统的设定可以链接到/dev/tty0或者其他tty*上,在2.1.71版本之后则完全由内核控制。目前,只有在单用户模式下可以登录/dev/console(可以在单用户模式下输入tty命令进行确认)。
Q:/dev/tty0与/dev/fb*有什么区别?
A: 在Framebuffer设备没有启用的系统中,可以使用/dev/tty0访问显卡。
Q:关于终端和控制台的区别可以参考哪些文本
A: 可以参考内核文档中的 Documents/devices.txt 中关于”TERMINAL DEVICES” 的章节。另外,《Linux内核源代码情景分析》的8.7节 以及《Operating Systems : Design and Implementation》中的3.9节(第3版中为3.8节)都对终端设备的概念和历史做了很好的介绍。另外在《Modern Operating system》中也有对终端设备的介绍,由于与《Operating Systems : Design and Implementation》的作者相同,所以文本内容也大致相同。需要注意的一点是《Operating Systems : Design and Implementation》中将终端设备分为3类,而《Modern Operating system》将终端硬件设备分为2类,差别在于前者将 X Terminal作为一个类别。
PS:
只有2410的2.6才叫ttySAC0,9200等的还是叫ttyS0
本篇文章来源于:开发学院 http://edu.codepub.com 原文链接:http://edu.codepub.com/2010/0125/20051.php
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/95429/viewspace-668911/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/95429/viewspace-668911/