fdisk
p print显示磁盘分区信息
n new 创建磁盘分区
d delete 删除
w 保存并退出
创建1个使用 /dev/sdb 所有容量的分区 挂载到 /data 目录
第1个里程碑-磁盘分区
[root@oldboyedu60-lnb ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x162015cc.
Command (m for help): p
Disk /dev/sdb: 213 MB, 213909504 bytes, 417792 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: 0x162015cc
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-417791, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-417791, default 417791):
Using default value 417791
Partition 1 of type Linux and of size 203 MiB is set
Command (m for help): p
Disk /dev/sdb: 213 MB, 213909504 bytes, 417792 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: 0x162015cc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 417791 207872 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第2个里程碑-磁盘分区
mkfs.xfs /dev/sdb1
第3个里程碑-磁盘挂载
[root@oldboyedu60-lnb ~]# mkdir -p /data
[root@oldboyedu60-lnb ~]# mount /dev/sdb1 /data
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.6G 98G 2% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
[root@oldboyedu60-lnb ~]# blkid
/dev/sda1: UUID="67c85f99-9ff1-45cd-8aff-3bf1d5610651" TYPE="xfs"
/dev/sda2: UUID="ad818355-5849-4606-ad6e-a84bec3fe0e1" TYPE="swap"
/dev/sda3: UUID="1ca5b5e0-449a-4a91-915a-9d3d0c26f470" TYPE="xfs"
/dev/sdb1: UUID="73a994ec-49ad-4e98-868c-e1a9f8d07130" TYPE="xfs"
/dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
[root@oldboyedu60-lnb ~]# tail -1 /etc/fstab
/dev/sdb1 /data xfs defaults 0 0
[root@oldboyedu60-lnb ~]# umount /data
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.6G 98G 2% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
[root@oldboyedu60-lnb ~]# mount
[root@oldboyedu60-lnb ~]# mount -a
#根据/etc/fstab 内容挂载所有
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.6G 98G 2% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
[故障集合]Linux必备故障及原因50个
https://www.jianshu.com/p/99ec5bb4183f
fdisk 磁盘分区
-l 查看磁盘分区信息
mkfs make filesystem 创建文件系统(格式化 format)
mkfs -t xfs === mkfs.xfs
xfs CentOS 7默认的文件系统
ext4 CentOS 6默认
mkfs.ext4
mkfs.xfs
mount 挂载
-a 根据/etc/fstab内容挂载所有
umount 卸载
df 查询磁盘使用情况
-h
JAVA 大量占用内存 内存不足 swap
如何增加swap
查看swap
free -h
free -m
第1个里程碑-创建指定大小的文件
500MB文件
/dev/null 黑洞
/dev/zero 输出
dd if=/dev/zero of=/tmp/500M bs=1M count=500
input file output file block size 次数
输入文件 输出文件 每次复制多少
[root@oldboyedu60-lnb ~]# file /tmp/500m
/tmp/500m: data
第2个里程碑-成为swap (格式化)
mkfs
mkswap
第3个里程碑-生效 (挂载)
swapon /tmp/500m
swapoff /tmp/500m
[root@oldboyedu60-lnb ~]# swapon /tmp/500m
swapon: /tmp/500m: insecure permissions 0644, 0600 suggested.
[root@oldboyedu60-lnb ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 95M 1.2G 9.6M 644M 1.7G
Swap: 1.5G 0B 1.5G
[root@oldboyedu60-lnb ~]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 1048572 0 -1
/tmp/500m file 511996 0 -2
[root@oldboyedu60-lnb ~]# tail -2 /etc/fstab
/dev/sdb1 /data xfs defaults 0 0
/tmp/500m swap swap defaults 0 0
特殊文件系统
tmpfs 把数据写入到这个文件系统中 就相当于写入到了内存
[root@oldboyedu60-lnb ~]# mkdir /mem
[root@oldboyedu60-lnb ~]# mount -t tmpfs -o size=500m tmpfs /mem
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 2.7G 97G 3% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
tmpfs 500M 0 500M 0% /mem
[root@oldboyedu60-lnb ~]#
[root@oldboyedu60-lnb ~]# tail -3 /etc/fstab
/dev/sdb1 /data xfs defaults 0 0
/tmp/500m swap swap defaults 0 0
tmpfs /mem tmpfs size=500m 0 0
du -sh /* |sort -h
文件删除原理:
1.硬链接数 (入口)
2.没有进程调用(没人使用)
lsof list open files 显示系统中所有被打开的文件(正在使用中)
第1列 命令 文件大小(字节) inode号码 被使用中的文件
[root@oldboyedu60-lnb ~]# lsof |grep hosts
tail 2499 root 3r REG 8,3 193 67138812 /etc/hosts
[root@oldboyedu60-lnb ~]# lsof |grep hosts
vim 2541 root 4u REG 8,3 4096 67138811 /etc/.hosts.swp
模拟 inode满了 磁盘空间不足
[root@oldboyedu60-lnb ~]# dd if=/dev/zero of=/tmp/sdf bs=1k count=100
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.000595446 s, 172 MB/s
[root@oldboyedu60-lnb ~]# mkfs.ext4 /tmp/sdf
mke2fs 1.42.9 (28-Dec-2013)
/tmp/sdf is not a block special device.
Proceed anyway? (y,n) y
[root@oldboyedu60-lnb ~]# mount /tmp/sdf /mnt/
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 7.3G 92G 8% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
tmpfs 500M 500M 0 100% /mem
/dev/loop0 93K 14K 72K 17% /mnt
[root@oldboyedu60-lnb ~]#
[root@oldboyedu60-lnb ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 51801600 60003 51741597 1% /
devtmpfs 251024 419 250605 1% /dev
tmpfs 253771 1 253770 1% /dev/shm
tmpfs 253771 747 253024 1% /run
tmpfs 253771 16 253755 1% /sys/fs/cgroup
/dev/sda1 102400 326 102074 1% /boot
tmpfs 253771 1 253770 1% /run/user/0
/dev/sdb1 103936 3 103933 1% /data
tmpfs 253771 2 253769 1% /mem
/dev/loop0 16 11 5 69% /mnt
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 7.3G 92G 8% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
tmpfs 500M 500M 0 100% /mem
/dev/loop0 93K 14K 72K 17% /mnt
[root@oldboyedu60-lnb ~]# touch /mnt/{1..6}.txt
touch: cannot touch ‘/mnt/6.txt’: No space left on device
[root@oldboyedu60-lnb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 7.3G 92G 8% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.6M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 197M 102M 95M 52% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 200M 11M 190M 6% /data
tmpfs 500M 500M 0 100% /mem
/dev/loop0 93K 14K 72K 17% /mnt
[root@oldboyedu60-lnb ~]#
[root@oldboyedu60-lnb ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 51801600 60003 51741597 1% /
devtmpfs 251024 419 250605 1% /dev
tmpfs 253771 1 253770 1% /dev/shm
tmpfs 253771 747 253024 1% /run
tmpfs 253771 16 253755 1% /sys/fs/cgroup
/dev/sda1 102400 326 102074 1% /boot
tmpfs 253771 1 253770 1% /run/user/0
/dev/sdb1 103936 3 103933 1% /data
tmpfs 253771 2 253769 1% /mem
/dev/loop0 16 16 0 100% /mnt
[root@oldboyedu60-lnb ~]# mkdir test
[root@oldboyedu60-lnb ~]# touch test/{1..450000}
-bash: /usr/bin/touch: Argument list too long
参数列表过长 (文件名过多)
[root@oldboyedu60-lnb ~]# mkdir test
[root@oldboyedu60-lnb ~]# touch test/{1..450000}
-bash: /usr/bin/touch: Argument list too long
[root@oldboyedu60-lnb ~]# echo test/{1..450000}|xargs touch
wc 统计文件信息 行数 单词数 大小
wc -l 统计行数
[root@oldboyedu60-lnb ~]# ls test/* |xargs rm -f
-bash: /usr/bin/ls: Argument list too long
[root@oldboyedu60-lnb ~]# ls test/1* |xargs rm -f
[root@oldboyedu60-lnb ~]# ls test/2* |xargs rm -f
[root@oldboyedu60-lnb ~]# ls test/* |xargs rm -f
-bash: /usr/bin/ls: Argument list too long
[root@oldboyedu60-lnb ~]# ls test/3* |xargs rm -f
inode满了
df -h df -i
找出系统中 大目录(目录大小)