Linux磁盘管理

4.5、磁盘格式化(上)

  1. Linux下查看文件系 统
1. [root@centos7 ~]# cat /etc/filesystems
	2. xfs
	3. ext4
	4. ext3
	5. ext2
	6. nodev proc
	7. nodev devpts
	8. iso9660
	9. vfat
	10. hfs
	11. hfsplus
	12. *
	13. [root@centos7 ~]#

用mount命令查看分区的文件系统

1. [root@centos7 ~]# mount
	2. sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
	3. proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
	4. devtmpfs on /dev type devtmpfs (rw,nosuid,size=1823292k,nr_inodes=455823,mode=755)
	5. securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
	6. tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
	7. devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
	8. tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
	9. tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
	10. cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
	11. pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
	12. cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
	13. cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
	14. cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
	15. cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
	16. cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
	17. cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
	18. cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
	19. cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
	20. cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
	21. cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
	22. configfs on /sys/kernel/config type configfs (rw,relatime)
	23. /dev/sda5 on / type xfs (rw,relatime,attr2,inode64,noquota)
	24. systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
	25. mqueue on /dev/mqueue type mqueue (rw,relatime)
	26. debugfs on /sys/kernel/debug type debugfs (rw,relatime)
	27. hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
	28. nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
	29. /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
	30. /dev/sda2 on /home type xfs (rw,relatime,attr2,inode64,noquota)
	31. sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
	32. tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=366744k,mode=700,uid=1000,gid=1000)

centos7默认文件系统格式为:xfs

格式化文件命令:mke2fs

参数-t为文件系统格式;

参数-b为指定块大小;

ls -lh和du -sb命令相似;

du -sh查看的文件块大小;

1. [root@centos7 ~]# du -sh 1.txt
	2. 16K    1.txt
	3. [root@centos7 ~]# ls -lh 1.txt
	4. -rw-r--r-- 1 root root 13K 10月 24 21:34 1.txt
	5. [root@centos7 ~]# du -sb 1.txt
	6. 12785    1.txt
	7. [root@centos7 ~]#

man mke2fs不支持xfs文件格式

mke2fs -t ext4 /dev/sdb1把/dev/sdb1格式化为ext4格式;

1. [root@centos7-01 ~]#
	2. [root@centos7-01 ~]# mke2fs -t ext4 /dev/sdb1
	3. mke2fs 1.42.9 (28-Dec-2013)
	4. 文件系统标签=
	5. OS type: Linux
	6. 块大小=4096 (log=2)
	7. 分块大小=4096 (log=2)
	8. Stride=0 blocks, Stripe width=0 blocks
	9. 131072 inodes, 524288 blocks
	10. 26214 blocks (5.00%) reserved for the super user
	11. 第一个数据块=0
	12. Maximum filesystem blocks=536870912
	13. 16 block groups
	14. 32768 blocks per group, 32768 fragments per group
	15. 8192 inodes per group
	16. Superblock backups stored on blocks:
	17.     32768, 98304, 163840, 229376, 294912
	18. Allocating group tables: 完成                            
	19. 正在写入inode表: 完成                            
	20. Creating journal (16384 blocks): 完成
	21. Writing superblocks and filesystem accounting information: 完成

mke2fs - create an ext2/ext3/ext4 filesystem 不支持xfs格式;

mkfs.ext4==mke2fs -t ext4

支持重复格式化

mkfs.ext4 /dev/sdb1命令;

1. [root@centos7-01 ~]# mkfs.ext4 /dev/sdb1
	2. mke2fs 1.42.9 (28-Dec-2013)
	3. 文件系统标签=
	4. OS type: Linux
	5. 块大小=4096 (log=2)
	6. 分块大小=4096 (log=2)
	7. Stride=0 blocks, Stripe width=0 blocks
	8. 131072 inodes, 524288 blocks
	9. 26214 blocks (5.00%) reserved for the super user
	10. 第一个数据块=0
	11. Maximum filesystem blocks=536870912
	12. 16 block groups
	13. 32768 blocks per group, 32768 fragments per group
	14. 8192 inodes per group
	15. Superblock backups stored on blocks:
	16.     32768, 98304, 163840, 229376, 294912
	17. Allocating group tables: 完成                            
	18. 正在写入inode表: 完成                            
	19. Creating journal (16384 blocks): 完成
	20. Writing superblocks and filesystem accounting information: 完成

可以使用mkfs.xfs /dev/sdb1,如果格式为ext4时,使用mkfs.xfs命令需要加 -f参数(force);

1. [root@centos7-01 ~]# mkfs.xfs /dev/sdb1
	2. mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
	3. mkfs.xfs: Use the -f option to force overwrite.
	4. [root@centos7-01 ~]# mkfs.xfs -f /dev/sdb1
	5. meta-data=/dev/sdb1              isize=512    agcount=4, agsize=131072 blks
	6.          =                       sectsz=512   attr=2, projid32bit=1
	7.          =                       crc=1        finobt=0, sparse=0
	8. data     =                       bsize=4096   blocks=524288, imaxpct=25
	9.          =                       sunit=0      swidth=0 blks
	10. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
	11. log      =internal log           bsize=4096   blocks=2560, version=2
	12.          =                       sectsz=512   sunit=0 blks, lazy-count=1
	13. realtime =none                   extsz=4096   blocks=0, rtextents=0

格式化完成后用mount命令看不到/dev/sdb1的文件格式,因为sdb磁盘还没有任何挂载点;

查看/dev/sdb1文件格式需使用blkid命令查看blkid /dev/sdb1;

1. [root@centos7-01 ~]# blkid /dev/sdb1
2. /dev/sdb1: UUID="b2c8d1c9-7c0e-4aff-bdfe-39cd11fed43a" TYPE="xfs"

4.6、磁盘格式化(下)

mkfs.ext4==mke2fs -t ext4 mke2fs -b 8192 /dev/sdb1,指定文件块为8192(4的倍数),如果存放的是大文件(视频、语言)可以指定大的文件块,这样存储速率高;

1. [root@centos7-01 ~]# mke2fs -b 8192 /dev/sdb1
	2. Warning: blocksize 8192 not usable on most systems.
	3. mke2fs 1.42.9 (28-Dec-2013)
	4. mke2fs: 8192-byte blocks too big for system (max 4096)
	5. 无论如何也要继续? (y,n) n  
	6. [root@centos7-01 ~]# mke2fs -b 2048 /dev/sdb1
	7. mke2fs 1.42.9 (28-Dec-2013)
	8. 文件系统标签=
	9. OS type: Linux
	10. 块大小=2048 (log=1)
	11. 分块大小=2048 (log=1)
	12. Stride=0 blocks, Stripe width=0 blocks
	13. 131072 inodes, 1048576 blocks
	14. 52428 blocks (5.00%) reserved for the super user
	15. 第一个数据块=0
	16. Maximum filesystem blocks=537919488
	17. 64 block groups
	18. 16384 blocks per group, 16384 fragments per group
	19. 2048 inodes per group
	20. Superblock backups stored on blocks:
	21.     16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
	22. Allocating group tables: 完成                            
	23. 正在写入inode表: 完成                            
	24. Writing superblocks and filesystem accounting information: 完成

参数-m指定root用户预留空间

mke2fs -m 0.1 /dev/sdb1

1. [root@centos7-01 ~]# mke2fs -m 0.1 /dev/sdb1
	2. mke2fs 1.42.9 (28-Dec-2013)
	3. 文件系统标签=
	4. OS type: Linux
	5. 块大小=4096 (log=2)
	6. 分块大小=4096 (log=2)
	7. Stride=0 blocks, Stripe width=0 blocks
	8. 131072 inodes, 524288 blocks
	9. 524 blocks (0.10%) reserved for the super user
	10. 第一个数据块=0
	11. Maximum filesystem blocks=536870912
	12. 16 block groups
	13. 32768 blocks per group, 32768 fragments per group
	14. 8192 inodes per group
	15. Superblock backups stored on blocks:
	16.     32768, 98304, 163840, 229376, 294912
	17. Allocating group tables: 完成                            
	18. 正在写入inode表: 完成                            
	19. Writing superblocks and filesystem accounting information: 完成

mkfs.ext4和mke2fs -t ext4支持的格式是一样的;

1. [root@centos7-01 ~]# mkfs.ext4 -m 0.1 /dev/sdb1
	2. mke2fs 1.42.9 (28-Dec-2013)
	3. 文件系统标签=
	4. OS type: Linux
	5. 块大小=4096 (log=2)
	6. 分块大小=4096 (log=2)
	7. Stride=0 blocks, Stripe width=0 blocks
	8. 131072 inodes, 524288 blocks
	9. 524 blocks (0.10%) reserved for the super user
	10. 第一个数据块=0
	11. Maximum filesystem blocks=536870912
	12. 16 block groups
	13. 32768 blocks per group, 32768 fragments per group
	14. 8192 inodes per group
	15. Superblock backups stored on blocks:
	16.     32768, 98304, 163840, 229376, 294912
	17. Allocating group tables: 完成                            
	18. 正在写入inode表: 完成                            
	19. Creating journal (16384 blocks): 完成
	20. Writing superblocks and filesystem accounting information: 完成
	21. [root@centos7-01 ~]# mke2fs -t ext4 -m 0.1 /dev/sdb1
	22. mke2fs 1.42.9 (28-Dec-2013)
	23. 文件系统标签=
	24. OS type: Linux
	25. 块大小=4096 (log=2)
	26. 分块大小=4096 (log=2)
	27. Stride=0 blocks, Stripe width=0 blocks
	28. 131072 inodes, 524288 blocks
	29. 524 blocks (0.10%) reserved for the super user
	30. 第一个数据块=0
	31. Maximum filesystem blocks=536870912
	32. 16 block groups
	33. 32768 blocks per group, 32768 fragments per group
	34. 8192 inodes per group
	35. Superblock backups stored on blocks:
	36.     32768, 98304, 163840, 229376, 294912
	37. Allocating group tables: 完成                            
	38. 正在写入inode表: 完成                            
	39. Creating journal (16384 blocks): 完成
	40. Writing superblocks and filesystem accounting information: 完成

mkefs -i参数指定多少个字节对应一个inode;

格式:mke2fs -i 8192 -t ext4 /dev/sdb1

1. [root@centos7-01 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1
	2. mke2fs 1.42.9 (28-Dec-2013)
	3. 文件系统标签=
	4. OS type: Linux
	5. 块大小=4096 (log=2)
	6. 分块大小=4096 (log=2)
	7. Stride=0 blocks, Stripe width=0 blocks
	8. 262144 inodes, 524288 blocks
	9. 26214 blocks (5.00%) reserved for the super user
	10. 第一个数据块=0
	11. Maximum filesystem blocks=536870912
	12. 16 block groups
	13. 32768 blocks per group, 32768 fragments per group
	14. 16384 inodes per group
	15. Superblock backups stored on blocks:
	16.     32768, 98304, 163840, 229376, 294912
	17. Allocating group tables: 完成                            
	18. 正在写入inode表: 完成                            
	19. Creating journal (16384 blocks): 完成
	20. Writing superblocks and filesystem accounting information: 完成

mke2fs常用参数:-b指定块大小,-m指定预留空间,-i指定多少字节对应一个inode(最低只能支持一个块对应一个inode),-t指定格式;

4.7、磁盘挂载(上)

一个磁盘不分区也可以直接格式化,只有格式化才能挂载;

1. [root@centos7-01 ~]# mkfs.xfs -f /dev/sdb
	2. meta-data=/dev/sdb               isize=512    agcount=4, agsize=655360 blks
	3.          =                       sectsz=512   attr=2, projid32bit=1
	4.          =                       crc=1        finobt=0, sparse=0
	5. data     =                       bsize=4096   blocks=2621440, imaxpct=25
	6.          =                       sunit=0      swidth=0 blks
	7. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
	8. log      =internal log           bsize=4096   blocks=2560, version=2
	9.          =                       sectsz=512   sunit=0 blks, lazy-count=1
	10. realtime =none                   extsz=4096   blocks=0, rtextents=0
	11. [root@centos7-01 ~]# blkid
	12. /dev/sda1: UUID="4c1ae631-2b19-464d-b226-1da717f58b96" TYPE="xfs"
	13. /dev/sda2: UUID="Rpf1Lw-oScG-iE7T-Y3S1-nGUD-UK17-s6kDL4" TYPE="LVM2_member"
	14. /dev/mapper/cl-root: UUID="887ddb0f-3885-480e-88e0-a6f486926a44" TYPE="xfs"
	15. /dev/mapper/cl-swap: UUID="91c60fb8-c8e0-419d-9462-5631f2883501" TYPE="swap"
	16. /dev/sdb: UUID="1c52d474-f007-4f40-be15-32f5ea3f5ab8" TYPE="xfs"

挂载命令:mount;格式:mount /dev/sdb /mnt/

1. [root@centos7-01 ~]# mount /dev/sdb /mnt/
	2. [root@centos7-01 ~]# df -h
	3. 文件系统             容量  已用  可用 已用% 挂载点
	4. /dev/mapper/cl-root   28G  1.2G   27G    5% /
	5. devtmpfs             478M     0  478M    0% /dev
	6. tmpfs                489M     0  489M    0% /dev/shm
	7. tmpfs                489M  6.7M  482M    2% /run
	8. tmpfs                489M     0  489M    0% /sys/fs/cgroup
	9. /dev/sda1            197M  117M   81M   60% /boot
	10. tmpfs                 98M     0   98M    0% /run/user/0
	11. /dev/sdb              10G   33M   10G    1% /mnt
	12. [root@centos7-01 ~]# mount
	13. sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
	14. proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
	15. devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=489000k,nr_inodes=122250,mode=755)
	16. securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
	17. tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
	18. devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
	19. tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
	20. tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
	21. cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
	22. pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
	23. cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
	24. cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
	25. cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
	26. cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
	27. cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
	28. cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
	29. cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
	30. cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
	31. cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
	32. cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
	33. configfs on /sys/kernel/config type configfs (rw,relatime)
	34. /dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
	35. selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
	36. systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
	37. debugfs on /sys/kernel/debug type debugfs (rw,relatime)
	38. mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
	39. hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
	40. /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
	41. tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=100000k,mode=700)
	42. /dev/sdb on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

在挂载点/mnt/下添加文件及目录;

1. [root@centos7-01 ~]# cd /mnt/
	2. [root@centos7-01 mnt]# touch 1.txt
	3. [root@centos7-01 mnt]# mkdir -pv 1/2/3/4
	4. mkdir: 已创建目录 "1"
	5. mkdir: 已创建目录 "1/2"
	6. mkdir: 已创建目录 "1/2/3"
	7. mkdir: 已创建目录 "1/2/3/4"
	8. [root@centos7-01 mnt]# ls
	9. 1  1.txt

卸载挂载点 umount /dev/sdb,提示目标忙是因为当前位置在目标目录中;

cd退出当前目录,然后在umount /dev/sdb,df -h没有任何挂载信息;

1. [root@centos7-01 mnt]# umount /dev/sdb
	2. umount: /mnt:目标忙。
	3.         (有些情况下通过 lsof(8) 或 fuser(1) 可以
	4.          找到有关使用该设备的进程的有用信息)
	5. [root@centos7-01 mnt]# cd
	6. [root@centos7-01 ~]# umount /dev/sdb
	7. [root@centos7-01 ~]# df -h
	8. 文件系统             容量  已用  可用 已用% 挂载点
	9. /dev/mapper/cl-root   28G  1.2G   27G    5% /
	10. devtmpfs             478M     0  478M    0% /dev
	11. tmpfs                489M     0  489M    0% /dev/shm
	12. tmpfs                489M  6.7M  482M    2% /run
	13. tmpfs                489M     0  489M    0% /sys/fs/cgroup
	14. /dev/sda1            197M  117M   81M   60% /boot
	15. tmpfs                 98M     0   98M    0% /run/user/0

umount -l /dev/sdb 参数-l可以直接在mnt下卸载挂载;

1. [root@centos7-01 ~]# mount /dev/sdb /mnt/
	2. [root@centos7-01 ~]# cd /mnt/
	3. [root@centos7-01 mnt]# ls
	4. 1  1.txt
	5. [root@centos7-01 mnt]# umount -l /dev/sdb
	6. [root@centos7-01 mnt]# ls
	7. 1  1.txt
	8. [root@centos7-01 mnt]# df -h
	9. 文件系统             容量  已用  可用 已用% 挂载点
	10. /dev/mapper/cl-root   28G  1.2G   27G    5% /
	11. devtmpfs             478M     0  478M    0% /dev
	12. tmpfs                489M     0  489M    0% /dev/shm
	13. tmpfs                489M  6.7M  482M    2% /run
	14. tmpfs                489M     0  489M    0% /sys/fs/cgroup
	15. /dev/sda1            197M  117M   81M   60% /boot
	16. tmpfs                 98M     0   98M    0% /run/user/0

4.8、磁盘挂载(下)

磁盘挂载的参数选项,mount -o remount 重新挂载;参数-o后面跟选项;

vi /etc/fstab

1. [root@centos7-01 ~]# cat /etc/fstab
	2. #
	3. # /etc/fstab
	4. # Created by anaconda on Mon Oct 16 22:44:37 2017
	5. #
	6. # Accessible filesystems, by reference, are maintained under '/dev/disk'
	7. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
	8. #
	9. /dev/mapper/cl-root     /                       xfs     defaults        0 0
	10. UUID=4c1ae631-2b19-464d-b226-1da717f58b96 /boot                   xfs     defaults        0 0
	11. /dev/mapper/cl-swap     swap                    swap    defaults        0 0


从左到右,第一列可以是uuid也可以是/dev/sdb

第二列:挂载点

第三列:分区格式

第四列:挂载选项(默认是defaults)

第五列:表示是否备份(dump,1表示备份,0表示不备份)

第六列:优先级,系统启动时是否检测磁盘(0表示不检测,1和2都表示检测,1的级别高表示根分区)

1. # /etc/fstab
	2. # Created by anaconda on Mon Oct 16 22:44:37 2017
	3. #
	4. # Accessible filesystems, by reference, are maintained under '/dev/disk'
	5. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
	6. #
	7. /dev/mapper/cl-root     /                       xfs     defaults        0 0
	8. UUID=4c1ae631-2b19-464d-b226-1da717f58b96 /boot                   xfs     defaults        0 0
	9. /dev/mapper/cl-swap     swap                    swap    defaults        0 0
	10. /dev/sdb                /mnt                    xfs     defaults        0 0



也可以直接挂载uuid,用blkid查看要/dev/sdb的uuid,然后mount 挂载到/mnt/下;

1. [root@centos7-01 ~]# blkid
	2. /dev/sda1: UUID="4c1ae631-2b19-464d-b226-1da717f58b96" TYPE="xfs"
	3. /dev/sda2: UUID="Rpf1Lw-oScG-iE7T-Y3S1-nGUD-UK17-s6kDL4" TYPE="LVM2_member"
	4. /dev/mapper/cl-root: UUID="887ddb0f-3885-480e-88e0-a6f486926a44" TYPE="xfs"
	5. /dev/mapper/cl-swap: UUID="91c60fb8-c8e0-419d-9462-5631f2883501" TYPE="swap"
	6. /dev/sdb: UUID="1c52d474-f007-4f40-be15-32f5ea3f5ab8" TYPE="xfs"
	7. [root@centos7-01 ~]# mount UUID="1c52d474-f007-4f40-be15-32f5ea3f5ab8" /mnt
	8. [root@centos7-01 ~]# df -h
	9. 文件系统             容量  已用  可用 已用% 挂载点
	10. /dev/mapper/cl-root   28G  1.2G   27G    5% /
	11. devtmpfs             478M     0  478M    0% /dev
	12. tmpfs                489M     0  489M    0% /dev/shm
	13. tmpfs                489M  6.7M  482M    2% /run
	14. tmpfs                489M     0  489M    0% /sys/fs/cgroup
	15. /dev/sda1            197M  117M   81M   60% /boot
	16. tmpfs                 98M     0   98M    0% /run/user/0
	17. /dev/sdb              10G   33M   10G    1% /mnt

4.9、手动增加swap空间

dd if=/dev/zero of=/tmp/newdisk bs=1M count=100

dd命令是用来操作磁盘读写的;

if命令指定从哪里去读(指定源设备);

zero是Linux里的造零器,/dev/zero是一个特殊设备,里面有源源不断的“0”;

of指定目标设备写入到/tmp/下;

格式化swap命令:mkswap -f /tmp/newdisk;

swapon命令加载到现有的swap上;

0644权限提示不安全,chomd 0600 /tmp/newdisk

free -m命令查看swap状态

卸载swap命令:swapoff /tmp/newdisk

[root@centos7-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.327211 秒,320 MB/秒
[root@centos7-01 ~]# du -sh /tmp/newdisk
100M    /tmp/newdisk
[root@centos7-01 ~]# mkswap -f /tmp/newdisk
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=5a06de81-0c94-4ae9-9793-861667e1b340
[root@centos7-01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            976         116         571           6         288         677
Swap:          2047           0        2047
[root@centos7-01 ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@centos7-01 ~]# chmod 0600 /tmp/newdisk
[root@centos7-01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            976         117         571           6         288         677
Swap:          2147           0        2147
[root@centos7-01 ~]# swapoff /tmp/newdisk
[root@centos7-01 ~]# rm -f /tmp/newdisk

转载于:https://my.oschina.net/u/3706694/blog/1560672

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值