- df 命令
查看磁盘的挂载情况以及使用情况
[root@localhost.localdomain ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda3 38G 1.5G 37G 4% /
/dev/sda1 1014M 131M 884M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
- lsblk 命令
查看磁盘的分区以及挂载情况
[root@localhost.localdomain ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 1G 0 part [SWAP]
└─sda3 8:3 0 38G 0 part /
sr0 11:0 1 10.3G 0 rom
- blkid 命令
查看磁盘分区的uuid和文件系统
[root@localhost.localdomain ~]$ blkid
/dev/sda1: UUID="f742f124-2e1d-46fb-94cf-3401d4d8628d" TYPE="xfs"
/dev/sda2: UUID="5989f2c7-8cb4-4f14-91f8-1c995637948d" TYPE="swap"
/dev/sda3: UUID="97f3a80e-57d4-4504-b83f-7967bbbde1f1" TYPE="xfs"
/dev/sr0: UUID="2019-09-09-19-08-41-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
- fdisk 命令
磁盘分区命令,(只能分区小于2T的硬盘,最多只能分4个主分区,可以分3个主分区,一个拓展分区,拓展分区中再分逻辑分区,有MBR分区表决定) 选项: -l 查看磁盘的分区情况
[root@localhost.localdomain ~]$ fdisk -l /dev/sda #查看/dev/sda磁盘的情况
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c242e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 4196351 1048576 82 Linux swap / Solaris
/dev/sda3 4196352 83879935 39841792 83 Linux
[root@localhost.localdomain ~]$ fdisk /dev/sdb
Command (m for help): m #输入m列出常用的命令
Command action
a toggle a bootable flag #切换分区启动标记
b edit bsd disklabel #编辑sdb磁盘标签
c toggle the dos compatibility flag #切换dos兼容模式
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 #创建新的Sun磁盘标签
t change a partitions system id #修改分区ID,可以通过l查看id
u change display/entry units #修改容量单位,磁柱或扇区
v verify the partition table #检验分区表
w write table to disk and exit #保存退出
x extra functionality (experts only) #拓展功能
- mkfs 命令
对磁盘或者分区进行格式化文件系统。
[root@localhost /]$ mkfs.xfs /dev/sdb1 # 对/dev/sdb1分区进行格式化xfs
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost /]$ blkid
/dev/sda1: UUID="f742f124-2e1d-46fb-94cf-3401d4d8628d" TYPE="xfs"
/dev/sda2: UUID="5989f2c7-8cb4-4f14-91f8-1c995637948d" TYPE="swap"
/dev/sda3: UUID="97f3a80e-57d4-4504-b83f-7967bbbde1f1" TYPE="xfs"
/dev/sr0: UUID="2019-09-09-19-08-41-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb1: UUID="a475dfc6-4440-4a6a-959c-4838f261ad49" TYPE="xfs"
[root@localhost /]$ mkfs.xfs -f /dev/sdb # 对/dev/sdb磁盘进行格式化xfs
meta-data=/dev/sdb isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
- mount 命令
磁盘挂载和卸载
[root@localhost /]$ mount /dev/sdb /test # 将/dev/sdb挂载到/test目录下
[root@localhost /]$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.5M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda3 38G 1.5G 37G 4% /
/dev/sda1 1014M 131M 884M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb 20G 33M 20G 1% /test
- umount 命令
磁盘取消挂载,选项: -l 处在挂载目录中不能直接取消挂载,可以使用-l参数进行强制取消挂载,或者退出挂载目录进行取消挂载
[root@localhost.localdomain /]$ umount /dev/sdb
- 如何永久挂载
在/etc/fstab配置文件中进行配置,然后使用mount -a 进行校验并重新加载配置文件
[root@localhost.localdomain /]$ blkid 使用blkid来查看设备的uuid
/dev/sda1: UUID="f742f124-2e1d-46fb-94cf-3401d4d8628d" TYPE="xfs"
/dev/sda2: UUID="5989f2c7-8cb4-4f14-91f8-1c995637948d" TYPE="swap"
/dev/sda3: UUID="97f3a80e-57d4-4504-b83f-7967bbbde1f1" TYPE="xfs"
/dev/sr0: UUID="2019-09-09-19-08-41-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb: UUID="341da041-1ad9-45bf-a83e-564d9d6dc8eb" TYPE="xfs"
[root@localhost.localdomain /]$ vim /etc/fstab
1
2 #
3 # /etc/fstab
4 # Created by anaconda on Mon Oct 19 10:20:32 2020
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 UUID=97f3a80e-57d4-4504-b83f-7967bbbde1f1 / xfs defaults 0 0
10 UUID=f742f124-2e1d-46fb-94cf-3401d4d8628d /boot xfs defaults 0 0
11 UUID=5989f2c7-8cb4-4f14-91f8-1c995637948d swap swap defaults 0 0
12 UUID=341da041-1ad9-45bf-a83e-564d9d6dc8eb /test xfs defaults 0 0
[root@localhost.localdomain /]$ mount -a 校验/etc/fstab文件并加载fstab配置文件
UUID=341da041-1ad9-45bf-a83e-564d9d6dc8eb ---> 设备uuid
/test --->挂载点
xfs --->文件系统
defaults --->挂载的配置参数(这里是默认,有很多,不作深究)
0 --->是否备份
0 --->是否检查
- swap
swap虚拟内存指的是当物理内存不够用的时候,会使用磁盘空间临时充当内存使用
# 使用文件增加swap空间
[root@localhost ~]$ dd if=/dev/zero of=/opt/swap_file bs=1M count=500 新建一个500m的文件
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 2.94767 s, 178 MB/s
[root@localhost ~]$ mkswap /opt/swap_file 将文件格式化为swap
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=38eb21aa-25c3-43e2-aa6c-299e17c8d60e
[root@localhost ~]$ swapon /opt/swap_file 启用/opt/swap_file作为swap
swapon: /opt/swap_file: insecure permissions 0644, 0600 suggested.
[root@localhost ~]$ free -h
total used free shared buff/cache available
Mem: 972M 155M 200M 7.5M 617M 668M
Swap: 1.5G 0B 1.5G
[root@localhost ~]$ swapoff /opt/swap_file 关闭/opt/swap_file作为swap
[root@localhost ~]$ free -h
total used free shared buff/cache available
Mem: 972M 154M 200M 7.5M 617M 669M
Swap: 1.0G 0B 1.0G
- 如何查看磁盘的文件系统(是否格式化)
[root@m01 ~]# file -s /dev/sdc
/dev/sdc: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)