设为首页 收藏本站
查看: 742|回复: 0

[经验分享] linux学习命令总结⑩②

[复制链接]

尚未签到

发表于 2018-5-24 07:51:08 | 显示全部楼层 |阅读模式
  
  #fdisk命令:磁盘分区工具
  fdisk –l:查看机器所挂硬盘个数及分区情况
[root@VM_168_102_centos ~]# fdisk -l
Disk
/dev/xvda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x70068116
Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1044     8385898+  83  Linux
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x00000000

Disk
/dev/xvdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x00000000

  针对某一个挂载设别查看:

[root@VM_168_102_centos ~]# fdisk -l /dev/xvda
Disk
/dev/xvda: 8589 MB, 8589934592 bytes  #该设备空间80G
255 heads, 63 sectors/track, 1044 cylinders   #255个磁头;63个扇区;1044个柱面
Units = cylinders of 16065 * 512 = 8225280 bytes #每个柱面的大小约为8.225280M
Sector size (logical/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x70068116
Device
#分区序列 Boot#引导 Start#开始柱面 End#结束柱面 Blocks#容量   Id#分区类型ID    System#分区类型
/dev/xvda1        *         1            1044      8385898+        83              Linux


通过fdisk分区工具,对指定挂载设备进行操作:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a
new DOS disklabel with disk identifier 0xcc40c7dc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won
't be recoverable.

Warning: invalid flag
0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS
-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command
'u').
Command (m
for help): #这里输入m或者help进入帮助界面

  进入到此界面我们可以输入m或者help来获取使用帮助

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
#输入d删除分区
   l   list known partition types #输入l列出内核支持的分区类型ID
   m   print this menu
n   add a
new partition #输入n新建分区
o   create a
new empty DOS partition table
p   print the partition table
#输入p列出当前分区信息
   q   quit without saving changes #输入q不保存退出
   s   create a new empty Sun disklabel
t   change a partition
's system id #输入t调整分区类型ID
u   change display/entry units
v   verify the partition table
w   write table to disk and exit
#输入w保存退出
x   extra functionality (experts only)


  创建一个主分区

Command (m for help): p #列出当前分区信息         
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xd0807ba8
Device Boot      Start         End      Blocks   Id  System
#当前无分区
Command (m
for help): n #新建分区
Command action
e   extended #扩展分区(无法格式化)
p   primary partition (
1-4) #主分区(最多四个
p #选择创建主分区
Partition number (
1-4): 1 #创建第一个主分区
First cylinder (
1-1305, default 1): #起始柱面(始终由1开始)
Using
default value 1
Last cylinder,
+cylinders or +size{K,M,G} (1-1305, default 1305): 200 #结束柱面(每个柱面大小约8.22M,再乘以起始柱面到结束柱面的个数就等于该分区的大小;也可以自定大小如输入+1000M/+1G  
Command (m
for help): p #列出当前分区信息
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xd0807ba8
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  83  Linux

  创建一个扩展分区

Command (m for help): n
Command action
e   extended
p   primary partition (
1-4)
e
Partition number (1-4): 2
First cylinder (
201-1305, default 201):
Using
default value 201
Last cylinder,
+cylinders or +size{K,M,G} (201-1305, default 1305): +3G      
Command (m
for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xd0807ba8
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  83  Linux
/dev/xvdb2             201         593     3156772+   5  Extended

  创建一个逻辑分区

Command (m for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x5855c29e
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  83  Linux
/dev/xvdb2             201         593     3156772+   5  Extended
Command (m
for help): n
Command action
l   logical (
5 or over) #逻辑分区
p   primary partition (
1-4)
l
First cylinder (
201-593, default 201):
Using
default value 201
Last cylinder,
+cylinders or +size{K,M,G} (201-593, default 593): +1G #输入大小不可超过扩展分区的总容量  

Command (m
for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x5855c29e
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  83  Linux
/dev/xvdb2             201         593     3156772+   5  Extended
/dev/xvdb5             201         332     1060258+  83  Linux

  调整指定分区的分区类型

Command (m for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xcd0ac78c
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  83  Linux
/dev/xvdb2             201         593     3156772+   5  Extended
Command (m
for help): l #列出内核内支持的分区类型ID
0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         
5  Extended        42  SFS             86  NTFS volume set da  Non-FS data   
6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         
9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
a  OS
/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
b  W95 FAT32      
52  CP/M            9f  BSD/OS          e4  SpeedStor      
c  W95 FAT32 (LBA)
53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
e  W95 FAT16 (LBA)
54  OnTrackDM6      a5  FreeBSD         ee  GPT            
f  W95 Ext
'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS   
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3
75  PC/IX           bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3
80  Old Minix       be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1
Command (m
for help): t #调整分区类型
Partition number (
1-5): 1 #输入要调整的分区序列
Hex code (type L to list codes): 8e
#选择分区类型ID
Changed system type of partition 1 to 8e (Linux LVM)
Command (m
for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xcd0ac78c
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  8e  Linux LVM
/dev/xvdb2             201         593     3156772+   5  Extended

  删除指定分区

Command (m for help): d #删除分区
Partition number (
1-5): 2 #输入要删除的分区序列
Command (m
for help): p
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xcd0ac78c
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         200     1606468+  8e  Linux LVM
Command (m
for help):

  分区完成后查看目前目前机器磁盘分区情况

[root@VM_168_102_centos ~]# cat /proc/partitions
major minor  #blocks  name
202        0    8388608 xvda
202        1    8385898 xvda1
202       16   10485760 xvdb
202       17    1606468 xvdb1
202       18          1
xvdb2
202       21    1060258
xvdb5
202       32    2097152 xvdc

  #mke2fs命令:格式化(配置文件:/etc/mke2fs.conf)

[root@VM_168_102_centos ~]# mke2fs /dev/xvdb1 #把该设备格式化成ext2文件系统
mke2fs
1.41.12 (17-May-2010)
Filesystem label
=   #卷标名称
OS type: Linux  #操作系统类型
Block size
=4096 (log=2) #块大小
Fragment size
=4096 (log=2)
Stride
=0 blocks, Stripe  style="color: #000000"> blocks
100464 inodes, 401617 blocks
20080 blocks (5.00%) reserved for the super user #预留管理员空间的百分比,默认百分5%
First data block
=0
Maximum filesystem blocks
=415236096
13 block groups
32768 blocks per group, 32768 fragments per group
7728 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every
26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

  #blkid命令:查看设备属性,UUID和TYPE

[root@VM_168_102_centos ~]# blkid /dev/xvdb1
/dev/xvdb1: UUID=&quot;8f74e3ce-552f-4d1f-a88f-2c7ef02b25cc&quot; TYPE=&quot;ext2&quot;

  mke2fs –t 指定文件系统类型,如ext2,ext3,ext4

[root@VM_168_102_centos ~]# mke2fs -t ext4 /dev/xvdb1
mke2fs
1.41.12 (17-May-2010)
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
Fragment size
=4096 (log=2)
Stride
=0 blocks, Stripe  style="color: #000000"> blocks
100464 inodes, 401617 blocks
20080 blocks (5.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=415236096
13 block groups
32768 blocks per group, 32768 fragments per group
7728 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
36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@VM_168_102_centos ~]# blkid /dev/xvdb1
/dev/xvdb1: UUID=&quot;84af93e0-0047-4ad4-9982-31bddda925c1&quot; TYPE=&quot;ext4&quot;

  mke2fs –L 设置文件系统卷标

[root@VM_168_102_centos ~]# mke2fs -t ext4 -L wanghan /dev/xvdb1
mke2fs
1.41.12 (17-May-2010)
Filesystem label
=wanghan

  mke2fs –b 指定块大小,如1024、2048、4096单位字节

[root@VM_168_102_centos ~]# mke2fs -t ext4 -L wanghan -b 2048 /dev/xvdb1
mke2fs
1.41.12 (17-May-2010)
warning:
418 blocks unused.
Filesystem label
=wanghan
OS type: Linux
Block size
=2048 (log=1)
Fragment size
=2048 (log=1)
Stride
=0 blocks, Stripe  style="color: #000000"> blocks
100744 inodes, 802816 blocks
40161 blocks (5.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=537919488
49 block groups #调整了块大小,块组数量随之变化
16384 blocks per group, 16384 fragments per group
2056 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368
Writing inode tables: done                           
Creating journal (
16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every
25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

  mke2fs –m 设置预留管理员的空间百分比

[root@VM_168_102_centos ~]# mke2fs -t ext4 -L wanghan -b 2048 -m 3 /dev/xvdb1
mke2fs
1.41.12 (17-May-2010)
warning:
418 blocks unused.
Filesystem label
=wanghan
OS type: Linux
Block size
=2048 (log=1)
Fragment size
=2048 (log=1)
Stride
=0 blocks, Stripe  style="color: #000000"> blocks
100744 inodes, 802816 blocks
24097 blocks (3.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=537919488
49 block groups
16384 blocks per group, 16384 fragments per group
2056 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368
Writing inode tables: done                           
Creating journal (
16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every
35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

  #e2label 查看卷标

[root@VM_168_102_centos ~]# e2label /dev/xvdb1
wanghan


  更改卷标

[root@VM_168_102_centos ~]# e2label /dev/xvdb1 test      
[root@VM_168_102_centos
~]# e2label /dev/xvdb1
test


  #dumpe2fs命令:显示当前的磁盘状态 (dumpe2fs –h 仅查看超级快中保存的信息

[root@VM_168_102_centos ~]# dumpe2fs /dev/xvdb1
dumpe2fs
1.41.12 (17-May-2010)
Filesystem volume name:   test
Last mounted on:         
<not available>
Filesystem UUID:          f071494a
-55da-4fe1-a93e-6627d69f085f
Filesystem magic number:  
0xEF53
Filesystem revision #:   
1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              
100744
Block count:              
802816
Reserved block count:     
24097
Free blocks:              
769619
Free inodes:              
100733
First block:              
0
Block size:               
2048
Fragment size:            
2048
Reserved GDT blocks:      
512
Blocks per group:         
16384
Fragments per group:      
16384
Inodes per group:         
2056
Inode blocks per group:   
257
Flex block group size:   
16
Filesystem created:       Thu Aug
21 17:05:26 2014
Last mount time:          n
/a
Last write time:          Thu Aug
21 17:15:55 2014
Mount count:              
0
Maximum mount count:      
35
Last checked:             Thu Aug
21 17:05:26 2014
Check interval:           
15552000 (6 months)
Next check after:         Tue Feb
17 17:05:26 2015
Lifetime writes:         
58 MB
Reserved blocks uid:      
0 (user root)
Reserved blocks gid:      
0 (group root)
First inode:              
11
Inode size:              
256
Required extra isize:     
28
Desired extra isize:      
28
Journal inode:            
8
Default directory hash:   half_md4
Directory Hash Seed:      da63c13e
-d2d3-450b-ba50-5bc62847a2cc
Journal backup:           inode blocks
Journal features:         (none)
Journal size:             32M
Journal length:           
16384
Journal sequence:         
0x00000001
Journal start:            
0

Group
0: (Blocks 0-16383) [ITABLE_ZEROED]
Checksum
0xbddb, unused inodes 2045
Primary superblock at
0, Group descriptors at 1-1
Reserved GDT blocks at
2-513
Block bitmap at
514 (+514), Inode bitmap at 530 (+530)
Inode table at
546-802 (+546)
11716 free blocks, 2045 free inodes, 2 directories, 2045 unused inodes
Free blocks:
4668-16383
Free inodes:
12-2056
后面省略
  #tune2fs命令:调整查看文件系统参数
  tune2fs –l 查看超级块中的信息;与dumpe2fs –h 命令一样
  tune2fs –L 更改卷标

[root@VM_168_102_centos ~]# e2label /dev/xvdb1
test
[root@VM_168_102_centos
~]# tune2fs -L wanghan /dev/xvdb1
tune2fs
1.41.12 (17-May-2010)
[root@VM_168_102_centos
~]# e2label /dev/xvdb1
wanghan


  tune2fs –m 更改预留管理员的空间百分比

[root@VM_168_102_centos ~]# tune2fs -m 6 /dev/xvdb1
tune2fs
1.41.12 (17-May-2010)
Setting reserved blocks percentage to
6% (48168 blocks)

  #fsck命令:磁盘修复
  fsck –a 自动修复错误
  

[root@VM_168_102_centos ~]# fsck -a /dev/xvda1
fsck from util
-linux-ng 2.17.2
/dev/xvda1 is mounted.  
WARNING
!!!  The filesystem is mounted.   If you continue you ***WILL***
cause
***SEVERE*** filesystem damage.
Do you really want to
continue (y/n)? yes
/dev/xvda1 contains a file system with errors, check forced.
/dev/xvda1: Inode 273382, i_blocks is 3104, should be 3096.  FIXED.
/dev/xvda1: Inode 273383 has illegal block(s).  
/dev/xvda1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without
-a or -p options)

  fsck –r 交互式修复错误

[root@VM_168_102_centos ~]# fsck -r /dev/xvda1
fsck from util
-linux-ng 2.17.2
e2fsck
1.41.12 (17-May-2010)
/dev/xvda1 is mounted.  
WARNING
!!!  The filesystem is mounted.   If you continue you ***WILL***
cause
***SEVERE*** filesystem damage.
Do you really want to
continue (y/n)? yes
/dev/xvda1 contains a file system with errors, check forced.
Pass
1: Checking inodes, blocks, and sizes
Inode
273382, i_blocks is 3104, should be 3096.  Fix<y>? yes
Inode
273383 has illegal block(s).  Clear<y>? yes
Illegal block #
12 (2553887680) in inode 273383.  CLEARED.
Illegal block #
13 (16777216) in inode 273383.  CLEARED.
Illegal block #
14 (1601307648) in inode 273383.  CLEARED.
Illegal block #
15 (1887441664) in inode 273383.  CLEARED.
Illegal block #
21 (41950464) in inode 273383.  CLEARED.
Illegal block #
22 (167772160) in inode 273383.  CLEARED.
Inode
273383, i_blocks is 8192, should be 104.  Fix<y>? yes
Inode
273350 has illegal block(s).  Clear<y>? yes
#后面省略
  e2fsck –f 强制检测
  e2fsck –y 对问题自动回答为YES
  #mount命令:挂载命令
  mount [options] [-t fstype] [–o options] 设备 挂在点
  [options]:命令选项
  [-o options]:挂在时启用分区特性
  显示当前系统所有已挂载设备信息:

[root@VM_168_102_centos ~]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)

  挂载分区:

[root@VM_168_102_centos tmp]# mount /dev/xvdb1 /tmp/wanghan
[root@VM_168_102_centos tmp]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb1 on /tmp/wanghan type ext4 (rw)

  mount –a 自动挂载所有支持自动挂载的设备(/etc/fstab文件中)

[root@VM_168_102_centos ~]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@VM_168_102_centos
~]# cat /etc/fstab
/dev/xvda1            /                    ext3       noatime,acl,user_xattr 1 1
LABEL
=lswap            swap                 swap       defaults 0 0
proc                 
/proc                proc       defaults              0 0
sysfs               
/sys                 sysfs      noauto                0 0
debugfs              
/sys/kernel/debug    debugfs    noauto                0 0
devpts               
/dev/pts             devpts     mode=0620,gid=5       0 0
/dev/xvdb1           /tmp/wanghan          ext4       defaults              0 0
[root@VM_168_102_centos
~]# mount -a
[root@VM_168_102_centos
~]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb1 on /tmp/wanghan type ext4 (rw)

  umount命令:卸载文件系统

[root@VM_168_102_centos ~]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb1 on /tmp/wanghan type ext4 (rw)
[root@VM_168_102_centos
~]# umount /dev/xvdb1 #也可以输入挂载点进行指定卸载
[root@VM_168_102_centos
~]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)

  开机自动挂载:
  将需要挂载文件系统写入/etc/fstab文件系统挂载表中

[root@VM_168_102_centos tmp]# vim /etc/fstab
/dev/xvda1            /                    ext3       noatime,acl,user_xattr 1 1
LABEL
=lswap            swap                 swap       defaults 0 0
proc                 
/proc                proc       defaults              0 0
sysfs               
/sys                 sysfs      noauto                0 0
debugfs              
/sys/kernel/debug    debugfs    noauto                0 0
devpts               
/dev/pts             devpts     mode=0620,gid=5       0 0
/dev/xvdb1           /tmp/wanghan           ext4       defaults            0                                  0
#要挂载的设备                #挂载点,swap挂载点为swap    #文件系统类型      #挂载选项                      #是否备份(0:从不备份;1每日备份)        #自检次序(0:不自检
                                                                                                                                                                                                                                         1或者2为要自检,如果是根分区要设为1,
                                                                                                                                                                                                                                          其他分区只能是2)
  
#fuser命令:查询给定文件或目录的用户或进程信息

[root@VM_168_102_centos ~]# fuser /tmp/wanghan
/tmp/wanghan:        26452c

  fuser –v 显示更详细信息

[root@VM_168_102_centos ~]# fuser -v /tmp/wanghan
USER        PID ACCESS COMMAND
/tmp/wanghan:        wanghan   26452 ..c.. bash

  fuser –km 关闭占用进程

[root@VM_168_102_centos ~]# fuser -v /tmp/wanghan
USER        PID ACCESS COMMAND
/tmp/wanghan:        wanghan   26452 ..c.. bash
[root@VM_168_102_centos
~]# fuser -km /tmp/wanghan
/tmp/wanghan:        26452c
[root@VM_168_102_centos
~]# fuser -v /tmp/wanghan

  #df命令:显示磁盘空间的使用信息

[root@VM_168_102_centos ~]# df
Filesystem           1K
-blocks      Used Available Use% Mounted on
/dev/xvda1             8254240   1216828   6618120  16% /
[root@VM_168_102_centos
~]# mount /dev/xvdb1 /tmp/wanghan
[root@VM_168_102_centos
~]# df
Filesystem           1K
-blocks      Used Available Use% Mounted on
/dev/xvda1             8254240   1216832   6618116  16% /
/dev/xvdb1             2071384     68632   1897528   4% /tmp/wanghan

  df –h 方便阅读方式显示

[root@VM_168_102_centos ~]# df -h /dev/xvdb1
Filesystem            Size  Used Avail Use
% Mounted on
/dev/xvdb1            2.0G   68M  1.9G   4% /tmp/wanghan

  df –i 显示inode信息

Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/xvda1              512K     33K    480K    7% /
/dev/xvdb1              129K      11    129K    1% /tmp/wanghan

  #du命令:显示每个文件和目录的磁盘使用空间

[root@VM_168_102_centos tmp]# du #显示当前所在目录的每个文件的磁盘使用空间
16    ./wanghan/lost+found
20    ./wanghan
4    ./.ICE-unix
32    .  #总计


[root@VM_168_102_centos tmp]# du /tmp #指定查看
16    /tmp/wanghan/lost+found
20    /tmp/wanghan
4    /tmp/.ICE-unix
32    /tmp

  du –h:方便阅读方式显示

[root@VM_168_102_centos tmp]# du -h
16K    .
/wanghan/lost+found
20K    .
/wanghan
4.0K    ./.ICE-unix
32K    .


  du -s:显示总计,仅列出最后相加的总值

[root@VM_168_102_centos tmp]# du -s -h
32K    .


  #查看内存空间使用状态
  查看 /proc/meminfo文件

[root@VM_168_102_centos tmp]# cat /proc/meminfo
MemTotal:        
1018532 kB
MemFree:         
785884 kB
Buffers:           
43724 kB
Cached:           
116488 kB
SwapCached:            
0 kB
Active:            
67776 kB
Inactive:         
107592 kB
Active(anon):      
15268 kB
Inactive(anon):     
2604 kB
Active(file):      
52508 kB
Inactive(file):   
104988 kB
Unevictable:           
0 kB
Mlocked:               
0 kB
SwapTotal:            
0 kB
SwapFree:              
0 kB
Dirty:               
120 kB
Writeback:            
0 kB
AnonPages:         
15160 kB
Mapped:            
12424 kB
Shmem:              
2728 kB
Slab:              
41732 kB
SReclaimable:      
21500 kB
SUnreclaim:        
20232 kB
KernelStack:         
656 kB
PageTables:         
1664 kB
NFS_Unstable:         
0 kB
Bounce:               
0 kB
WritebackTmp:         
0 kB
CommitLimit:      
509264 kB
Committed_AS:      
86312 kB
VmallocTotal:   
34359738367 kB
VmallocUsed:        
7212 kB
VmallocChunk:   
34359729020 kB
HardwareCorrupted:     
0 kB
AnonHugePages:         
0 kB
HugePages_Total:      
0
HugePages_Free:        
0
HugePages_Rsvd:        
0
HugePages_Surp:        
0
Hugepagesize:      
2048 kB
DirectMap4k:        
6144 kB
DirectMap2M:     
1042432 kB

  #free命令:监控 Linux 内存使用状况

[root@VM_168_102_centos tmp]# free
total       used       free     shared    buffers     cached
Mem:      
1018532     235012     783520          0      44368     116564
-/+ buffers/cache:      74080     944452
Swap:      
2097144          0    2097144

  free –m 显示结果以MB为单位
  free –g 显示结果以GB为单位
  #dd命令:把指定的输入文件拷贝到指定的输出文件中,并且在拷贝的过程中可以进行格式转换
  dd if=input_file of=output_file bs=#[b|k|m|g] count=#

[root@VM_168_102_centos tmp]# dd if=/tmp/test.sh of=/tmp/ceshi.sh
0+1 records in
0+1 records out
153 bytes (153 B) copied, 3.3824e-05 s, 4.5 MB/s
[root@VM_168_102_centos tmp]# cat ceshi.sh
sssssssssssssssssssssssssssssssssssssssssssssssssdsdsdsdsdsdddddddddddddddddddddddddddddddddddbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccbbbbbbb

[root@VM_168_102_centos tmp]# cat test.sh
sssssssssssssssssssssssssssssssssssssssssssssssssdsdsdsdsdsdddddddddddddddddddddddddddddddddddbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccbbbbbbb


  备份MBR并进行恢复

[root@VM_168_102_centos tmp]# fdisk -l /dev/xvdb
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xd30f2acf
Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         262     2104483+  83  Linux
/dev/xvdb2             263         916     5253255    5
  Extended
/dev/xvdb5             263         655     3156741   83
  Linux
/dev/xvdb6             656         787     1060258+  83
  Linux
[root@VM_168_102_centos tmp]# dd
if=/dev/xvdb of=/tmp/xvdb bs=512 count=1 #将512Byte大小的MBR备份到/tmp/xvdb
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00227598 s, 225 kB/s
[root@VM_168_102_centos tmp]# dd if=/dev/zero of=/dev/xvdb bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000697809 s, 734 kB/s
[root@VM_168_102_centos tmp]# fdisk
-l /dev/xvdb
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x00000000
[root@VM_168_102_centos tmp]# dd
if=/tmp/xvdb of=/dev/xvdb #将备份到/tmp/xvdb的MBR信息重新写入
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000623246 s, 822 kB/s
[root@VM_168_102_centos tmp]# fdisk
-l /dev/xvdb
Disk
/dev/xvdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0xd30f2acf
    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         262     2104483+  83  Linux
/dev/xvdb2             263         916     5253255    5  Extended
/dev/xvdb5             263         655     3156741   83
  Linux
/dev/xvdb6             656         787     1060258+  83  Linux

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480452-1-1.html 上篇帖子: linux下的swap分区 下篇帖子: Linux的文件类型和Linux文件的时间戳 ⑧
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表