[root@localhost ~]# cat /etc/filesystems //查看centos7所支持的系统格式
xfs //系统默认的支持的格式
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
[root@localhost ~]#
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 1.2G 17G 7% /
devtmpfs 483M 0 483M 0% /dev
tmpfs 493M 0 493M 0% /dev/shm
tmpfs 493M 6.8M 486M 2% /run
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 99M 0 99M 0% /run/user/0
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c928b
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 41943039 18668544 83 Linux
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x3ca78df9
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
[root@localhost ~]# echo 1 > 2.txt
[root@localhost ~]# ls =lh 2.txt
ls: 无法访问=lh: 没有那个文件或目录
2.txt
[root@localhost ~]# ls -lh 2.txt //查看文件的大小
-rw-r--r--. 1 root root 2 11月 3 15:48 2.txt
[root@localhost ~]# du -sh 2.txt //查看块大小
4.0K 2.txt
[root@localhost ~]# du -sb 2.txt
2 2.txt
这里会看到ls -lh和du -sb查看文件的大小相同
而ls -lh查看的是文件的大小,du -sh 查看是块的大小
修改文件文件系统两种命令
[root@localhost ~]# mke2fs -t ext4 -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 4194304 blocks
209715 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=272629760
256 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, 1327104,
2048000, 3981312
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]#
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]#
[root@localhost ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=524288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2097152, 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 ~]#
[root@localhost ~]# mke2fs -t xfs -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Your mke2fs.conf file does not define the xfs filesystem type.
Aborting...
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="ebdc3a7b-d16d-4bd8-8019-275e587d359e" TYPE="xfs"
[root@hf-01 ~]# mke2fs -b 8194 /dev/sdb1
Warning: blocksize 8194 not usable on most systems.
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: 8192-byte blocks too big for system (max 4096)
无论如何也要继续? (y,n) n
[root@hf-01 ~]# mke2fs -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=540016640
160 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, 1327104,
2048000
Allocating group tables: 完成
正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
[root@hf-01 ~]# mke2fs -t ext4 -m 1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
13107 blocks (1.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@hf-01 ~]# mke2fs -i 8192 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
[root@hf-01 ~]#
[root@hf-01 ~]# mkfs.xfs -f /dev/sdb
meta-data=/dev/sdb isize=256 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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@hf-01 ~]# blkid /dev/sdb
/dev/sdb: UUID="fdf63a90-eaf9-4cd0-b82c-5afd2965da2a" TYPE="xfs"
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
[root@hf-01 ~]# mount /dev/sdb /mnt/
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
/dev/sdb 20G 33M 20G 1% /mnt
会看到最后一行,多了一个分区,也可称之为磁盘
[root@hf-01 ~]# cd /mnt/
[root@hf-01 mnt]# ls
[root@hf-01 mnt]# touch 1.txt 2.txt
[root@hf-01 mnt]# mkdir 124
[root@hf-01 mnt]# cd
[root@hf-01 ~]# umount /dev/sdb
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
[root@hf-01 ~]#
[root@hf-01 ~]# mount /dev/sdb /mnt/
[root@hf-01 ~]# ls /mnt
124 1.txt 2.txt
[root@hf-01 ~]# cd /mnt/
[root@hf-01 mnt]# umount /dev/sdb
umount: /mnt:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@hf-01 mnt]# umount -l /mnt/
[root@hf-01 mnt]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
defaults
Use default options: rw, suid, dev, exec, auto, nouser, and async.
#
UUID=ce0b257e-62c5-4355-9117-b1edc7085e58 / xfs defaults 1 1
UUID=a9ea9597-52e8-4d73-8975-0ecb3970c760 /boot xfs defaults 1 2
UUID=06c3de3e-7c95-4f75-905e-c5d4fbf4a5fa swap swap defaults 0 0
#
# /etc/fstab
# Created by anaconda on Sun Aug 20 21:03:05 2017
#
# 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=ce0b257e-62c5-4355-9117-b1edc7085e58 / xfs defaults 1 1
UUID=a9ea9597-52e8-4d73-8975-0ecb3970c760 /boot xfs defaults 1 2
UUID=06c3de3e-7c95-4f75-905e-c5d4fbf4a5fa swap swap defaults 0 0
这里自己添加的
/dev/sdb /mnt xfs defaults 0 0
若想写UUID,可以使用blkid命令去查看填写
[root@hf-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.728387 秒,144 MB/秒
[root@hf-01 ~]# du -sh /tmp/newdisk
100M /tmp/newdisk
[root@hf-01 ~]#
[root@hf-01 ~]# mkswap -f /tmp/newdisk //格式化swap空间
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=7355a547-2562-4320-8470-cff6b7bda975
[root@hf-01 ~]# free -m //查看磁盘使用情况
total used free shared buffers cached
Mem: 987 793 193 6 0 209
-/+ buffers/cache: 583 403
Swap: 2047 0 2047
[root@hf-01 ~]# swapon /tmp/newdisk //添加swap空间添加到现有的swap上去
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@hf-01 ~]# free -m
total used free shared buffers cached
Mem: 987 793 193 6 0 209
-/+ buffers/cache: 583 403
Swap: 2147 0 2147
会看到添加swap的时候,提示不安全,但free -m查看的的时候,会看到添加成功
[root@hf-01 ~]# chmod 0600 /tmp/newdisk
[root@hf-01 ~]# swapoff /tmp/newdisk
[root@hf-01 ~]# free -m
total used free shared buffers cached
Mem: 987 793 193 6 0 209
-/+ buffers/cache: 583 403
Swap: 2047 0 2047
[root@hf-01 ~]#
这时会看到swap空间恢复原有大小了
[root@hf-01 ~]# rm -f /tmp/newdisk
[root@hf-01 ~]#