+++++++swap创建、挂载、激活和文件系统空间查看工具小结

简介:

命令

mkswap,swapon,swapoff

free,du,df


swapon命令

1
2
3
4
5
swapon [OPTIONS...] PARTITIONS ...
-a             ## 激活所有swap分区
-P PRIORITY    ## 指定激活swap分区的优先级
##激活时指定激活分区的优先级(性能好的,优先级调高。 性能差的在"不同磁盘"之上,以相同的优先级同时启用,实现负载均衡。同一个硬盘之上,实现不同盘swap,伪负载均衡)
##但凡有物理内存使用,不建议用swapon partition

swapoff命令

1
2
swapoff [OPTIONS...] PARTITION
-a            ##  禁用所有swap分区


free命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
free  [OPTIONS...] 
-k 以K为单位显示
-m 以M为单位显示
-g 以g为单位显示
*小于1时,为0
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
             总大小     已用空间          free          shared    缓冲     缓存
物理内存:   248620      69224            179396          272      11868    15412
-/+ buffers /cache :     正常使用的空间    真正的空闲空间
Swap:      2047996      0                 2047996
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
已用空间=正常使用的空间 + 分配给buffer + 分配给cached
真正的空闲空间=  free (空闲空间) + 分配给buffer + 分配给cached
share 共享内存空间


使用示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1、查看swap大小
[root@localhost ~] # free -h
              total       used        free      shared    buffers     cached
Mem:          242M        84M       158M       284K        11M        20M
-/+ buffers /cache :        52M       190M
Swap:          11G         0B        11G
 
2、禁用所有swap分区
[root@localhost ~] # swapoff -a
 
3、以易读方式显示单位
[root@localhost ~] # free -h
              total       used        free      shared    buffers     cached
Mem:          242M        76M       166M       284K        11M        21M
-/+ buffers /cache :        43M       199M
Swap:           0B         0B         0B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1、以k显示
[root@localhost ~] # free -k
              total       used        free      shared    buffers     cached
Mem:        248620      78208     170412        284      12052      21784
-/+ buffers /cache :      44372     204248
Swap:            0          0          0
2、以m显示
[root@localhost ~] # free -m
              total       used        free      shared    buffers     cached
Mem:           242         76        166          0         11         21
-/+ buffers /cache :         43        199
Swap:            0          0          0
3、以G显示
[root@localhost ~] # free -g
              total       used        free      shared    buffers     cached
Mem:             0          0          0          0          0          0
-/+ buffers /cache :          0          0
Swap:            0          0          0
#不到1为0


du命令

1
2
3
du  [options..] DIR
-h 易读
-s 目录及目录下的所有文件总体大小之和

df命令

1
2
3
4
df  [OPTIONS...]
-h 易读
-P 兼容POSIX格式显示
-i inode数量


使用示例

1
2
3
4
5
6
1、显示目录4K大小
[root@localhost ~] # ls -ldh /etc
drwxr-xr-x. 76 root root 4.0K 8月   9 06:09  /etc
2、显示目录和目录下的文件总和
[root@localhost ~] # du -sh /etc
30M  /etc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1、以POSIX格式兼容输出,只在一行显示
1)、默认显示
[root@localhost ~] # df 
Filesystem           1K-blocks   Used Available Use% Mounted on
/dev/mapper/myvg-lv_root
                       50264772 532072  47172700   2% /
tmpfs                   124308      0    124308   0%  /dev/shm
/dev/sda1                487652  33127    428925   8%  /boot
/dev/mapper/myvg-lv_home
                        4908544  10060   4642484   1%  /home
/dev/mapper/myvg-lv_usr
                       14987656 726992  13492664   6%  /usr
/dev/mapper/myvg-lv_var
                        9948012  88256   9347756   1%  /var
/dev/sda3              10194072  23068   9646516   1%  /mnt
 
2)、POSIX
[root@localhost ~] # df -P
Filesystem               1024-blocks   Used Available Capacity Mounted on
/dev/mapper/myvg-lv_root     50264772 532072  47172700       2% /
tmpfs                         124308      0    124308       0%  /dev/shm
/dev/sda1                      487652  33127    428925       8%  /boot
/dev/mapper/myvg-lv_home      4908544  10060   4642484       1%  /home
/dev/mapper/myvg-lv_usr      14987656 726992  13492664       6%  /usr
/dev/mapper/myvg-lv_var       9948012  88256   9347756       1%  /var
/dev/sda3                    10194072  23068   9646516       1%  /mnt
2、易读格式
[root@localhost ~] # df -Ph
Filesystem                Size  Used Avail Use% Mounted on
/dev/mapper/myvg-lv_root    48G  520M   45G   2% /
tmpfs                     122M     0  122M   0%  /dev/shm
/dev/sda1                  477M   33M  419M   8%  /boot
/dev/mapper/myvg-lv_home   4.7G  9.9M  4.5G   1%  /home
/dev/mapper/myvg-lv_usr     15G  710M   13G   6%  /usr
/dev/mapper/myvg-lv_var    9.5G   87M  9.0G   1%  /var
/dev/sda3                  9.8G   23M  9.2G   1%  /mnt
3、显示Inode数量
[root@localhost ~] # df -Phi
Filesystem               Inodes IUsed IFree IUse% Mounted on
/dev/mapper/myvg-lv_root    3.1M  8.4K  3.1M    1% /
tmpfs                       31K     1   31K    1%  /dev/shm
/dev/sda1                   126K    38  125K    1%  /boot
/dev/mapper/myvg-lv_home    313K    24  313K    1%  /home
/dev/mapper/myvg-lv_usr     939K   27K  912K    3%  /usr
/dev/mapper/myvg-lv_var     626K  1.2K  625K    1%  /var
/dev/sda3                   641K    13  641K    1%  /mnt
##Inode数量使用占比和block数量使用占比1:2
说明,大文件多,以后存储更多小多件,inode比率就会提高


创建swap分区

1、查看可用的磁盘

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~] # fdisk -l /dev/[sh]d[a-z]
cylinders 柱面总数
  Device Boot      Start         End      Blocks   Id  System
  Device   ## 设备文件路径
  Boot     ## 是否为引导加载器、kernle所在的分区,用*表示
  Start    ## 起始柱面 分区划分:按柱面,由外向内,编号依次增大
  End      ## 结束柱面 
  Blocks   ## 磁盘块数
  Id       ## id标示
  System   ## 系统标示
  **结束柱面不等于总柱面数即可分区,除了System: Extended的分区

2、修改分区表

1
2
3
4
5
6
7
8
9
[root@localhost ~] # fdisk /dev/sda
     n 创建一个新分区
     d 删除
     l 列出分区的 id 标示
     t 调整 id
     q 退出
     w 保存退出
     m manual
     p 显示分区表信息

3、创建分区,修改id为82

1
2
3
4
5
6
7
8
Command (m  for  help): n
First cylinder (14119-15665, default 14119): 
Using default value 14119
Last cylinder, +cylinders or +size{K,M,G} (14119-15665, default 15665): +10G
Command (m  for  help): t
Partition number (1-5): 5
Hex code ( type  L to list codes): 82    ##swap分区为82
Changed system  type  of partition 5 to 82 (Linux swap / Solaris)

4、让内核识别添加的新分区

1
2
3
4
5
6
1)内核是否识别添加的新分区
[root@localhost ~] # ls /dev/sda*
[root@localhost ~] # cat /proc/partitions 
2)重读分区表
[root@localhost ~] # partx -a /dev/sda
[root@localhost ~] # partx -a /dev/sda

5、创建swap分区

1
[root@localhost ~] # mkswap -L 'MYswap' -U $(uuidgen) /dev/sda5

6、查看文件系统属性信息

1
2
3
4
5
6
7
8
9
10
11
12
1)查看TYPE,LABEL,UUID
[root@localhost ~] # blkid /dev/sda5
/dev/sda5 : LABEL= "MYswap"  UUID= "f6af2ba9-4bc1-4bee-aa5c-e2bd99336edd"  TYPE= "swap" 
 
2) 查看默认挂载属性、超级块信息
[root@localhost ~] # tune2fs  -l /dev/sda5
[root@localhost ~] # dumpe2fs -h /dev/sda5
 
3)查看块组信息
[root@localhost ~] # dumpe2fs /dev/sda5
 
##2),3)不能找到,仅记忆方便

7、调整文件系统属性信息

1
2
3
4
5
6
tune2fs [OPTIONS...] PARTITION
-t , -m  # , -L LABEL , -U UUID
-j 
-O [^]has_journal 
-o [^]acl
##仅记忆方便

8、查看swap

1
2
3
4
5
[root@localhost ~] # free -m 
              total       used        free      shared    buffers     cached
Mem:           242         77        165          0         11         20
-/+ buffers /cache :         44        198
Swap:         1999          0       1999

9、启用swap

1
2
3
4
5
6
7
[root@localhost ~] # swapon /dev/sda5
 
[root@localhost ~] # free -h
              total       used        free      shared    buffers     cached
Mem:          242M        84M       158M       284K        11M        20M
-/+ buffers /cache :        52M       190M
Swap:          11G         0B        11G

10、停止swap

1
2
3
4
5
6
7
8
[root@localhost ~] # swapoff /dev/sda5
 
[root@localhost ~] # swapoff  /dev/sda5
[root@localhost ~] # free -h
              total       used        free      shared    buffers     cached
Mem:          242M        80M       162M       284K        13M        21M
-/+ buffers /cache :        45M       197M
Swap:         2.0G         0B       2.0G

11、swap挂载

1
2
3
4
定义丰 /etc/fstab 文件中:
/dev/mapper/myvg-lv_swap  swap                    swap    defaults        0 0
 
设备文件或伪文件系统  挂载点 文件系统类型  挂载选项 备份频率 开机自检次序










本文转自 lccnx 51CTO博客,原文链接:http://blog.51cto.com/sonlich/1954781,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
存储 Shell Linux
【Shell 命令集合 磁盘维护 】Linux 创建一个用作交换空间(swap space)的特殊文件或设备 mkswap命令使用教程
【Shell 命令集合 磁盘维护 】Linux 创建一个用作交换空间(swap space)的特殊文件或设备 mkswap命令使用教程
33 0
|
6月前
|
Linux 测试技术
非LVM磁盘分区根目录扩容操作参考
在操作系统部署时,根目录使用的是非LVM分区,后期空间不足又无法扩容。 提供一个思路是新增一块硬盘,创建为逻辑卷,把根目录迁移过去,然后引导以新分区启动。 迁移完成后,旧的根目录可以再格式化为逻辑卷,合并到新磁盘分区。 本操作仅在CentOS Linux release 7.9.2009实验过,其他环境可能不支持。
537 0
|
9月前
|
Linux
Linux系统【系统管理】resize2fs命令 – 同步文件系统容量到内核
resize2fs命令来自于英文词组“resize to filesystem”的缩写,其功能是用于同步文件系统容量到内核。如对ext3、ext4、XFS等设备卷容量进行了调整,则需要使用resize2fs命令同步信息到系统内核。
276 0
|
Linux
Linux - 挂载磁盘 + 通过LVM动态实现磁盘的动态扩容
Linux - 挂载磁盘 + 通过LVM动态实现磁盘的动态扩容1 LVM是什么1.1 概念解释LVM(Logical Volume Manager), 逻辑卷管理, 是一种将一至多个硬盘的分区在逻辑上进行组合, 当成一个大硬盘来使用.
2997 0
|
Docker 容器 Linux
VM 磁盘挂载方式
SSD磁盘挂载pvcreate /dev/sdcvgcreate datavg /dev/sdclvcreate -l 100%VG -n datalv01 datavgmkfs.xfs /dev/mapper/datavg-datalv01 mkdir -p /Dockermount /dev/.
1895 0
|
Shell Linux 存储
磁盘格式化/磁盘挂载/手动增加swap空间
  4.5/4.6 磁盘格式化  4.7/4.8 磁盘挂载 4.9 手动增加swap空间     磁盘格式化  查看centos7支持的文件系统格式 cat  /etc/filesystem,centos7默认的文件系统格式xfs     ce...
1530 0

相关实验场景

更多