linux 磁盘管理
4.1 df
man df 查看df命令的详细解释 (q退出)
DF(1) User Commands DF(1)
NAME
df - report file system disk space usage
SYNOPSIS
df [OPTION]... [FILE]...
DESCRIPTION
This manual page documents the GNU version of df. df displays the amount of
disk space available on the file system containing each file name argument.
If no file name is given, the space available on all currently mounted file
systems is shown. Disk space is shown in 1K blocks by default, unless the
environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are
used.
If an argument is the absolute file name of a disk device node containing a
mounted file system, df shows the space available on that file system rather
than on the file system containing the device node. This version of df cannot
show the space available on unmounted file systems, because on most kinds of
systems doing so requires very nonportable intimate knowledge of file system
structures.
OPTIONS
Show information about the file system on which each FILE resides, or all file
systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
include dummy file systems
-B, --block-size=SIZE
scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in
units of 1,048,576 bytes; see SIZE format below
--direct
show statistics for a file instead of mount point
--total
produce a grand total
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si
likewise, but use powers of 1000 not 1024
-i, --inodes
list inode information instead of block usage
-k like --block-size=1K
-l, --local
limit listing to local file systems
--no-sync
do not invoke sync before getting usage info (default)
--output[=FIELD_LIST]
use the output format defined by FIELD_LIST, or print all fields if
FIELD_LIST is omitted.
-P, --portability
use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE
limit listing to file systems of type TYPE
-T, --print-type
print file system type
-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version
output version information and exit
Display values are in units of the first available SIZE from --block-size, and
the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise,
units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
FIELD_LIST is a comma-separated list of columns to be included. Valid field
names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size',
'used', 'avail', 'pcent', 'file' and 'target' (see info page).
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report df
translation bugs to <http://translationproject.org/team/>
AUTHOR
Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.
COPYRIGHT
Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL ver‐
sion 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is
NO WARRANTY, to the extent permitted by law.
SEE ALSO
The full documentation for df is maintained as a Texinfo manual. If the info
and df programs are properly installed at your site, the command
info coreutils 'df invocation'
should give you access to the complete manual.
GNU coreutils 8.22 June 2014 DF(1)
df 查看磁盘空间
查看已挂在磁盘的总容量、使用容量、剩余容量等,以KB单位显示
[root@dazhou ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 310021224 847508 309173716 1% /
devtmpfs 933508 0 933508 0% /dev
tmpfs 939092 0 939092 0% /dev/shm
tmpfs 939092 8692 930400 1% /run
tmpfs 939092 0 939092 0% /sys/fs/cgroup
/dev/sda1 201388 76032 125356 38% /boot
[root@dazhou ~]#
- 第一列 分区名称
- 第二列 分区总容量
- 第三列 已使用分区容量
- 第四列 剩余可用容量
- 第五列 已用容量百分比
- 第六列 挂载点
df -i 查看inodes的使用状况
[root@dazhou ~]# df -i
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
/dev/sda3 310172672 23162 310149510 1% /
devtmpfs 233377 367 233010 1% /dev
tmpfs 234773 1 234772 1% /dev/shm
tmpfs 234773 414 234359 1% /run
tmpfs 234773 13 234760 1% /sys/fs/cgroup
/dev/sda1 204800 330 204470 1% /boot
[root@dazhou ~]#
df -h 使用合适的单位显示
df -k df -m 分别表示使用kb、M为单位显示
[root@dazhou ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 296G 828M 295G 1% /
devtmpfs 912M 0 912M 0% /dev
tmpfs 918M 0 918M 0% /dev/shm
tmpfs 918M 8.5M 909M 1% /run
tmpfs 918M 0 918M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
[root@dazhou ~]# df -k
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 310021224 847508 309173716 1% /
devtmpfs 933508 0 933508 0% /dev
tmpfs 939092 0 939092 0% /dev/shm
tmpfs 939092 8692 930400 1% /run
tmpfs 939092 0 939092 0% /sys/fs/cgroup
/dev/sda1 201388 76032 125356 38% /boot
[root@dazhou ~]# df -m
文件系统 1M-块 已用 可用 已用% 挂载点
/dev/sda3 302756 828 301928 1% /
devtmpfs 912 0 912 0% /dev
tmpfs 918 0 918 0% /dev/shm
tmpfs 918 9 909 1% /run
tmpfs 918 0 918 0% /sys/fs/cgroup
/dev/sda1 197 75 123 38% /boot
扩展
/dev 、/dev/shm 为内存分区 文件存在这个分区下读写非常快,但是重启时文件就会丢失。
4.2 du 命令
du 文件或者目录名 查看某个目录或文件所占空间大小
du -a 全部文件和目录的大小列出来
[root@dazhou ~]# du -a /home
4 /home/dazhou/.bash_logout
4 /home/dazhou/.bash_profile
4 /home/dazhou/.bashrc
0 /home/dazhou/1
4 /home/dazhou/1.txt
16 /home/dazhou
4 /home/user1/.bash_logout
4 /home/user1/.bash_profile
4 /home/user1/.bashrc
12 /home/user1
4 /home/dazhou11/.bash_logout
4 /home/dazhou11/.bash_profile
4 /home/dazhou11/.bashrc
12 /home/dazhou11
4 /home/dazhou4/.bash_logout
4 /home/dazhou4/.bash_profile
4 /home/dazhou4/.bashrc
12 /home/dazhou4
52 /home
[root@dazhou ~]#
du -b 文件或目录 列出的值以B为单位输出
du -k 文件或目录 列出的值以KB为单位输出
du -M 文件或目录 列出的值以M为单位输出
du -h 文件或目录 系统会自动调节单位
[root@dazhou ~]# du -h /home/
0 /home/dazhou/1
16K /home/dazhou
12K /home/user1
12K /home/dazhou11
12K /home/dazhou4
52K /home/
[root@dazhou ~]#
du -s 列出总和
[root@dazhou ~]# du -s /home/
52 /home/
[root@dazhou ~]#
du -c 列出详细所有目录及文件大小和最后加总和
[root@dazhou ~]# du -c /home/
0 /home/dazhou/1
16 /home/dazhou
12 /home/user1
12 /home/dazhou11
12 /home/dazhou4
52 /home/
52 总用量
[root@dazhou ~]#
扩展
du后面不加任何参数和选项 只会列出目录包含子目录的大小 不指定单位默认KB
[root@dazhou ~]# du /home/
0 /home/dazhou/1
16 /home/dazhou
12 /home/user1
12 /home/dazhou11
12 /home/dazhou4
52 /home/
[root@dazhou ~]#
4.3 磁盘分区
vm虚拟机增加磁盘步骤
-
虚拟机 选项卡右击 设置
-
添加
-
默认硬盘 下一步
-
默认磁盘类型
5. 设置磁盘大小
6. 设置虚拟磁盘路径 完成
7. 要想虚拟机增加磁盘生效 必须重启虚拟机
4.4 fdisk命令
fdisk -l 会列出系统中所有磁盘设备及分区表
[root@dazhou ~]# fdisk -l
磁盘 /dev/sda:322.1 GB, 322122547200 字节,629145600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00097bb2
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 8800255 4194304 82 Linux swap / Solaris
/dev/sda3 8800256 629145599 310172672 83 Linux
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@dazhou ~]#
fdisk -l 设备名称 会列出该设备的分区表
[root@dazhou ~]# fdisk -l /dev/sda
磁盘 /dev/sda:322.1 GB, 322122547200 字节,629145600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00097bb2
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 8800255 4194304 82 Linux swap / Solaris
/dev/sda3 8800256 629145599 310172672 83 Linux
[root@dazhou ~]#
新设备分区
fdisk 设备名称 便会进入分区模式
[root@dazhou ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xd1daad64 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):
进入此模式下
p 表示打印当前磁盘的分区情况
n 表示建立一个分区
w 表示保存
q 表示退出
d 表示删除一个分区
m 表示详细命令解释
命令(输入 m 获取帮助):m
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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)
命令(输入 m 获取帮助):
- 新建分区
进入n模式下(主分区最多建立4个 扩展分区只能建立1个)
p表示建立一个主分区
e表示建立一个扩展分区
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
扩展 建立分区规则
1. 第一步要实现的操作 第二步分区类型 第三步分区号 最后一步w 是否保存 ctrl c 取消所有分区
2. 最多只能建立4个分区(1.可建立四个主分区 2.可一或者至多三个主分区 一扩展分区 3.只建立一个扩展分区(扩展分区下逻辑分区可无限增加) 或者一个主分区)
3. 逻辑分区建立在扩展分区之上 删除扩展分区会把逻辑分区直接删除的
4. 输入错误可用 ctrl u 清除
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+2G
分区 1 已设置为 Linux 类型,大小设为 2 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
分区号 (2-4,默认 2):2
起始 扇区 (4196352-20971519,默认为 4196352):
将使用默认值 4196352
Last 扇区, +扇区 or +size{K,M,G} (4196352-20971519,默认为 20971519):+2G
分区 2 已设置为 Extended 类型,大小设为 2 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p):
继续n 选择 l 建立一个逻辑分区
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
添加逻辑分区 5
起始 扇区 (4198400-8390655,默认为 4198400):
将使用默认值 4198400
Last 扇区, +扇区 or +size{K,M,G} (4198400-8390655,默认为 8390655):
将使用默认值 8390655
分区 5 已设置为 Linux 类型,大小设为 2 GiB
命令(输入 m 获取帮助):
w 后 最终磁盘保存结果
[root@dazhou ~]# fdisk -l /dev/sdb
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xd1daad64
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
/dev/sdb3 8390656 12584959 2097152 83 Linux
/dev/sdb4 12584960 20971519 4193280 5 Extended
/dev/sdb5 12587008 20971519 4192256 83 Linux
[root@dazhou ~]#
4.5-4.6 磁盘格式化
cat /etc/filesystems 查看目前系统支持的文件系统格式
[root@dazhou ~]# cat /etc/filesystems
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
[root@dazhou ~]#
centos 7默认文件系统格式是XFS
mke2fs、mkfs.ext2、mkfs.ext3、mkfs.ext4(将磁盘格式化相应文件系统格式的命令)下
-b 表示分区时设定每个数据块占用的空间大小(每个数据块支持1024 2048 4096B)
-i 设定inode的大小
-N 设定inode的数量
-c 表示 格式化前检测磁盘 运行后速度会非常慢
-L 预设该分区的标签(label)
-j 表示简历ext3的分区
-t 制定文件系统的类型 ext2、ext3或者ext4
示例:
将sdb1格式化为数据块为2048B 标签为DAZHOU 文件类型为ext4的分区
[root@dazhou ~]# mke2fs -t ext4 -b 2048 -L dazhou /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=dazhou
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@dazhou ~]#
查看未挂载分区
blkid 分区路径(如/dev/sdb1) 查看未挂载的分区
[root@dazhou ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="dazhou" UUID="09ec767a-60b5-4f41-8faa-408bd7e3e215" TYPE="ext4"
[root@dazhou ~]#
4.7-4.8 磁盘挂载
mount 挂载分区
mount 可查看已挂载分区的系统文件类型
[root@dazhou ~]# mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=933508k,nr_inodes=233377,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=32,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@dazhou ~]#
mount 分区 路径 将分区挂载在挂载点上
[root@dazhou ~]# mount /dev/sdb /mnt
[root@dazhou ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 29140072 1124124 28015948 4% /
devtmpfs 491940 0 491940 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7608 495204 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
/dev/sda1 201380 106804 94576 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
/dev/sdb 10475520 32992 10442528 1% /mnt
[root@dazhou ~]#
- mount -l 显示目前挂载的信息(并且会列出相应的Label名称 分区系统格式等信息)
- mount -a 将所有没挂载的都挂载上来
- mount -t 指定挂载的类型
- mount -n 不将实际挂载实时写入/etc/mtab中
- mount -o 添加额外的参数,如帐号、密码、读写权限等
- mount LABEL=XX 路径将标签为xx的分区挂载在挂载点上
/etc/fstab 配置文件
通过**/etc/fstab**文件来开机自动挂载(不然重启电脑后系统将不会保存之前的挂载操作)
[root@dazhou ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Mar 14 19:27:09 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=bb4466fb-50e9-408b-a83c-a1405d08da7e / xfs defaults 0 0
UUID=f9a0353d-fc5c-47f2-91ad-ce0843caf67c /boot xfs defaults 0 0
UUID=ba59457d-8285-42a3-89be-6a3fb002d32c swap swap defaults 0 0
[root@dazhou ~]#
第一字段:分区的标识;分区的LABEL;分区的UUID;分区名(/dev/sda1)
第二字段:分区挂载点
第三字段:分区的格式类型
第四字段:mount 命令的选项,和mount 中的-o 同理;defaults包括这些选项 rw, suid, dev, exec, auto, nouser, async
第五字段:表示文件系统是否需要dump 备份,1是需要,0 是不需要
第六字段: 是否在系统启动时,通过fsck磁盘检测工具来检查文件系统,1比2优先检测,0是不需要
blkid 命令
获取全部磁盘分区的UUID 分区标签 文件系统格式
[root@dazhou ~]# blkid
/dev/sda1: UUID="f9a0353d-fc5c-47f2-91ad-ce0843caf67c" TYPE="xfs"
/dev/sda2: UUID="ba59457d-8285-42a3-89be-6a3fb002d32c" TYPE="swap"
/dev/sda3: UUID="bb4466fb-50e9-408b-a83c-a1405d08da7e" TYPE="xfs"
/dev/sdb1: LABEL="DAZHOU" UUID="e817b0ff-912f-44d6-b5a3-99e16b3d4f03" TYPE="xfs"
/dev/sdb5: UUID="f5e43805-b554-49a1-a1f2-9ec3cfb1abf0" TYPE="xfs"
[root@dazhou ~]#
umount 卸载分区
umount 路径 卸载挂载点上的分区
umount -f 挂载点 强制卸载,文件系统无法读取的情况下
umount -l 挂载点 懒人卸载 当前目录还在卸载的分区上也能卸载
[root@dazhou ~]# mount /dev/sdb /mnt
[root@dazhou ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 29140072 1124124 28015948 4% /
devtmpfs 491940 0 491940 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7576 495236 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
/dev/sda1 201380 106804 94576 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
/dev/sdb 10475520 32992 10442528 1% /mnt
[root@dazhou ~]#
[root@dazhou ~]# umount -f /mnt/
[root@dazhou ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 29140072 1124124 28015948 4% /
devtmpfs 491940 0 491940 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7576 495236 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
/dev/sda1 201380 106804 94576 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
[root@dazhou ~]# mount /dev/sdb /mnt
[root@dazhou ~]# cd /mnt/
[root@dazhou mnt]# umount /mnt/
umount: /mnt:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@dazhou mnt]# umount -l /mnt/
[root@dazhou mnt]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 29140072 1124124 28015948 4% /
devtmpfs 491940 0 491940 0% /dev
tmpfs 502812 0 502812 0% /dev/shm
tmpfs 502812 7576 495236 2% /run
tmpfs 502812 0 502812 0% /sys/fs/cgroup
/dev/sda1 201380 106804 94576 54% /boot
tmpfs 100564 0 100564 0% /run/user/0
[root@dazhou mnt]#
4.9 增加swap空间(虚拟内存)
思路步骤:建立swapfile 格式化为swap格式 启用该虚拟磁盘
1. dd if=/dev/zero of=/tmp/newdisk bs=1M count=1024
if 指定源 of指定目标文件 bs定义块的大小 count定义块的数量(目标文件大小=bs*count)
建立1G的文件
2. mkswap -f /tmp/newdisk 格式化文件
3.swapon /tmp/newdisk 添加虚拟内存
[root@dazhou mnt]# free -m
total used free shared buff/cache available
Mem: 982 118 727 7 136 707
Swap: 2047 0 2047
[root@dazhou mnt]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,5.99554 秒,17.5 MB/秒
[root@dazhou mnt]# du -sh /tmp/newdisk
100M /tmp/newdisk
[root@dazhou mnt]# mkswap -f /tmp/newdisk
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=d82e5631-905d-4928-a429-8daac5f16ad8
[root@dazhou mnt]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@dazhou mnt]# chmod 0600 /tmp/newdisk
[root@dazhou mnt]# free -m
total used free shared buff/cache available
Mem: 982 118 623 7 239 689
Swap: 2147 0 2147
[root@dazhou mnt]#
free -m 查看swap状况
swap文件卸载
swapoff /文件 卸载swap文件
[root@dazhou mnt]# swapoff /tmp/newdisk
[root@dazhou mnt]# free -m
total used free shared buff/cache available
Mem: 982 118 623 7 239 690
Swap: 2047 0 2047
[root@dazhou mnt]#
4.10-4.12 LVM
1.创建分区 分别一个G
2.创建lvm文件系统 t 更改为8e
3.创建物理卷(默认没安装lvm yum install -y lvm 安装下)
pvcreate 分区(如果无法创建分区不存在 partprobe下)
4.创建卷组
vgcreate 物理卷 物理卷
vgremove xx 删除物理卷
5.创建逻辑分区
lvcreate -L(指定大小) 100M -n(指定名称) lv1 vg1(指定从哪组划分)
6.格式化
mkfs.ext4 分区
7.挂载
mount
逻辑卷扩容(ext4)
- 命令:lvresize -L XXM(指定大小不是增加) 逻辑分区
应先卸载磁盘 扩容完 再挂载磁盘
2.检查磁盘错误
3.更新逻辑卷信息
逻辑卷扩容(xfs)
1.lvresize -L 300M /路径 指定分区大小
2.xfs_growfs /路径
缩减逻辑卷(ext格式 xfs不支持)
1.umount /路径 卸载磁盘
2.e2fsck -f /路径 检查磁盘错误
3.resize /路径 100M 更新逻辑卷信息
4.lvresize -L 100M /路径 重新设置卷大小
5.mount /路径 挂载
扩展卷组
先扩容卷组 再扩容逻辑卷
扩展
安装包名字忘记了 但是知道命令 可以根据命令去搜索 yum 命令 “/*/命令”(统配搜索)
pvdispaly(pvs) 查看系统物理卷信息
vgdispaly(vgs)查看卷组信息
lvdispaly 查看逻辑卷大小
lvs 也是查看逻辑卷信息
直播笔记
1.磁盘修复工具
fsck/e2fsck -a 分区名
https://www.2cto.com/os/201204/126370.html
2.避免数据丢失的策略
做raid1 raid10 raid5 raid6
做数据备份策略 :热备drdb(实时备份) rsync+inotify
3.raid讲解
https://blog.csdn.net/caipeichao2/article/details/52661825
DELL服务器raid配置教程
https://wenku.baidu.com/view/1ba3592ca22d7375a417866fb84ae45c3b35c2cc.html
4.dd
测试磁盘读写速度
https://blog.csdn.net/daiyudong2020/article/details/53157558
/dev/zero 造零器(无限造零)
/dev/null 黑洞 (可无限写入)
备份硬盘数据
http://zuyunfei.com/2015/06/04/linux-dd/
5.LVM使用场景 (阿里云环境)
阿里 OSS
七牛
https://help.aliyun.com/document_detail/25452.html
6.pated分区gpt格式
具体步骤:
1.parted /dev/sdb
2. print
3. mklabel gpt 或者 msdos (msdos就是mbr)
4. mkfs aming1 0 2G //当使用mbr类型时,这里就不能写aming1了,得写primary/extended/logical
5. rm id
7.关于存储的常识
GB TB PB EB (千倍)
http://forum.huawei.com/enterprise/zh/thread-274145-1-1.html
https://blog.csdn.net/JesseYoung/article/details/38367217