[root@Rocky8-mini ~]# !df df -Th /dev/sdc Filesystem Type Size Used Avail Use% Mounted on /dev/sdc ext4 9.8G 37M 9.3G 1% /mnt/sdc [root@Rocky8-mini ~]# ls /mnt/sdc/ fstab lost+found passwd
[root@Rocky8-mini ~]# dd if=/dev/zero of=/dev/sdc bs=1M count=1 1+0 records in 1+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00332407 s, 315 MB/s [root@Rocky8-mini ~]# ls /mnt/sdc/ [root@Rocky8-mini ~]# tune2fs -l /dev/sdc tune2fs 1.45.6 (20-Mar-2020) tune2fs: Bad magic number in super-block while trying to open /dev/sdc [root@Rocky8-mini ~]# df -Th /dev/sdc Filesystem Type Size Used Avail Use% Mounted on /dev/sdc ext4 64Z 64Z 9.8G 100% /mnt/sdc
[root@Rocky8-mini ~]# umount /mnt/sdc [root@Rocky8-mini ~]# e2fsck -y -f /dev/sdc e2fsck 1.45.6 (20-Mar-2020) ext2fs_open2: Bad magic number in super-block e2fsck: Superblock invalid, trying backup blocks... Resize inode not valid. Recreate? yes
Padding at end of inode bitmap is not set. Fix? yes
/dev/sdc: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdc: 13/655360 files (0.0% non-contiguous), 66755/2621440 blocks [root@Rocky8-mini ~]# tune2fs -l /dev/sdc tune2fs 1.45.6 (20-Mar-2020) Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: 0a133b5e-e5f7-466e-8693-2250f0398266 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 655360 Block count: 2621440 Reserved block count: 131072 Free blocks: 2554685 Free inodes: 655347 First block: 0 Block size: 4096 Fragment size: 4096 Group descriptor size: 64 Reserved GDT blocks: 1024 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8192 Inode blocks per group: 512 Flex block group size: 16 Filesystem created: Fri Nov 25 21:52:06 2022 Last mount time: n/a Last write time: Fri Nov 25 21:56:53 2022 Mount count: 0 Maximum mount count: -1 Last checked: Fri Nov 25 21:56:53 2022 Check interval: 0 (<none>) Lifetime writes: 8 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: 7e999f31-eee7-479f-ad7f-f3d1f3f1b409 Journal backup: inode blocks Checksum type: crc32c Checksum: 0xd4f66ca7 [root@Rocky8-mini ~]# mount /dev/sdc /mnt/sdc/ [root@Rocky8-mini ~]# ls /mnt/sdc/ fstab lost+found passwd [root@Rocky8-mini ~]# cat /mnt/fstab
# # /etc/fstab # Created by anaconda on Sun Mar 13 06:11:42 2022 # # 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. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # /dev/mapper/rl-root / xfs defaults 0 0 UUID=4ec1a2f6-693f-4d0a-a605-7335893cb82b /boot xfs defaults 0 0 /dev/mapper/rl-data /data ext4 defaults 1 2 /dev/mapper/rl-swap none swap defaults 0 0 [root@Rocky8-mini ~]# df -Th /dev/sdc Filesystem Type Size Used Avail Use% Mounted on /dev/sdc ext4 9.8G 37M 9.3G 1% /mnt/sdc
2.3 挂载
挂载:将额外文件系统与根文件系统某现存目录建立连接关系,使该目录作为访问该文件系统的入口
卸载:取消该关联关系的过程
挂载点原有文件在挂载完成后会被临时隐藏,因此,挂载点目录一般为空;挂载的设备正在使用中时无法被卸载
2.3.1 挂载文件系统 mount
格式
1 2 3 4 5 6 7 8 9
mount [-fnrsvw] [-t vfstype] [-o options] device mountpoint
格式 ddif=/PATH/SRC_FILE of=/PATH/DEST_FILE bs=# count=# 常用选项 if=file read from FILE instead of stdin of=file write to FILE instead of stdout ibs=size read up to BYTES bytes at a time (default: 512) obs=size write BYTES bytes at a time (default: 512) bs=size read and write up to BYTES bytes at a time (default: 512); overrides ibs and obs cbs=size convert BYTES bytes at a time skip=N skip N ibs-sized blocks at start of input seek=N skip N obs-sized blocks at start of output count=N copy only N input blocks conv=conversion convert the file as per the comma separated symbol list conversion 转换参数: ascii from EBCDIC to ASCII ebcdic from ASCII to EBCDIC lcase change upper case to lower case ucase change lower case to upper case nocreat do not create the output file noerror continue after read errors notrunc do not truncate the output file sync pad every input block with NULs to ibs-size; when used with block or unblock, pad with spaces rather than NULs fdatasync physically write output file data before finishing
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[root@Rocky8-mini ~]# cat f1.txt f2.txt abcdefg 123456789 [root@Rocky8-mini ~]# dd if=f1.txt of=f2.txt bs=1 count=2 skip=3 seek=4 2+0 records in 2+0 records out 2 bytes copied, 0.000114454 s, 17.5 kB/s [root@Rocky8-mini ~]# cat f2.txt 1234de[root@Rocky8-mini ~]# echo 123456789 > f2.txt
[root@Rocky8-mini ~]# cat f1.txt f2.txt abcdefg 123456789 [root@Rocky8-mini ~]# dd if=f1.txt of=f2.txt bs=1 count=2 skip=3 seek=4 conv=notrunc 2+0 records in 2+0 records out 2 bytes copied, 8.7494e-05 s, 22.9 kB/s [root@Rocky8-mini ~]# cat f2.txt 1234de789
# 持久挂载 [root@Rocky8-mini ~]# mkdir /test [root@Rocky8-mini ~]# vim /etc/fstab /dev/sdb1 /test ext4 acl 0 0 [root@Rocky8-mini ~]# mount -a [root@Rocky8-mini ~]# df -Th /dev/sdb1 Filesystem Type Size Used Avail Use% Mounted on /dev/sdb1 ext4 2.0G 9.1M 2.0G 1% /test
三、RAID
3.1 什么是RAID
独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列。利用虚拟化存储技术把多个硬盘组合起来,成为一个或多个硬盘阵列组,目的为提升性能或数据冗余,或是两者同时提升。
1、创建分区并调整分区类型为8e [root@localhost ~]# fdisk /dev/sdb Command (m forhelp): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): e // 直接创建扩展分区 Partition number (1-4, default 1): First sector (2048-10485759, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): Using default value 10485759 Partition 1 of type Extended and of size 5 GiB is set
Command (m forhelp): n Partition type: p primary (0 primary, 1 extended, 3 free) l logical (numbered from 5) Select (default p): l // 在扩展分区上创建逻辑分区5,6,7,8,9 Adding logical partition 6 First sector (1030144-10485759, default 1030144): Using default value 1030144 Last sector, +sectors or +size{K,M,G} (1030144-10485759, default 10485759): +500M Partition 6 of type Linux and of size 500 MiB is set
Command (m forhelp): t // 调整分区类型 Partition number (1,5-9, default 9): 5 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
Command (m forhelp): p Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x5372fd24 Device Boot Start End Blocks Id System /dev/sdb1 2048 10485759 5241856 5 Extended /dev/sdb5 4096 1028095 512000 8e Linux LVM /dev/sdb6 1030144 2054143 512000 8e Linux LVM /dev/sdb7 2056192 3080191 512000 8e Linux LVM /dev/sdb8 3082240 5179391 1048576 8e Linux LVM /dev/sdb9 5181440 10485759 2652160 8e Linux LVM
Command (m forhelp): w // 保存退出 The partition table has been altered! 2、刷新分区 [root@localhost ~]# partprobe /dev/sdb [root@localhost ~]# lsblk /dev/sdb NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 5G 0 disk ├─sdb1 8:17 0 1K 0 part ├─sdb5 8:21 0 500M 0 part ├─sdb6 8:22 0 500M 0 part ├─sdb7 8:23 0 500M 0 part ├─sdb8 8:24 0 1G 0 part └─sdb9 8:25 0 2.5G 0 part
# 缩减文件系统大小至2G [root@Rocky8-mini mnt]# resize2fs /dev/vg0/mylv 2G resize2fs 1.45.6 (20-Mar-2020) Resizing the filesystem on /dev/vg0/mylv to 524288 (4k) blocks. The filesystem on /dev/vg0/mylv is now 524288 (4k) blocks long.
# 缩减逻辑卷空间大小 [root@Rocky8-mini mnt]# lvreduce -L 2G /dev/vg0/mylv WARNING: Reducing active logical volume to 2.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/mylv? [y/n]: y Size of logical volume vg0/mylv changed from 3.00 GiB (768 extents) to 2.00 GiB (512 extents). Logical volume vg0/mylv successfully resized.
# 重新挂载该逻辑卷 [root@Rocky8-mini mnt]# mount /dev/vg0/mylv /mnt/mylv/ [root@Rocky8-mini mnt]# df -Th /mnt/mylv/ Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg0-mylv ext4 2.0G 3.0M 1.9G 1% /mnt/mylv
# 先备份xfs文件系统数据 [root@Rocky8-mini ~]# xfsdump -f data.img /mnt/xfs_lv xfsdump: using file dump (drive_simple) strategy xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control
# 缩减逻辑卷大小 [root@Rocky8-mini ~]# lvreduce -L 1G /dev/vg1/xfs_lv WARNING: Reducing active logical volume to 1.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg1/xfs_lv? [y/n]: y Size of logical volume vg1/xfs_lv changed from 2.00 GiB (512 extents) to 1.00 GiB (256 extents). Logical volume vg1/xfs_lv successfully resized. # 重新创建文件系统 [root@Rocky8-mini ~]# mkfs.xfs -f /dev/vg1/xfs_lv
# 重新挂载 [root@Rocky8-mini ~]# mount /dev/vg1/xfs_lv /mnt/xfs_lv/