## Linux磁盘及文件系统基础操作
1、破坏mbr表并修复
默认安装的Centos系统,查看磁盘及文件系统信息:
]# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf49418ad
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 6293503 1048576 83 Linux
/dev/sdb3 6293504 8390655 1048576 83 Linux
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000c9352
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 251658239 124779520 8e Linux LVM
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-home: 71.9 GB, 71932313600 bytes, 140492800 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
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 448976 0 448976 0% /dev
tmpfs tmpfs 460992 0 460992 0% /dev/shm
tmpfs tmpfs 460992 7412 453580 2% /run
tmpfs tmpfs 460992 0 460992 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 52403200 1282788 51120412 3% /
/dev/sda1 xfs 1038336 140080 898256 14% /boot
/dev/mapper/centos-home xfs 70212100 33004 70179096 1% /home
tmpfs tmpfs 92200 0 92200 0% /run/user/0
# hexdump -C -n 512 /dev/sda
00000000 eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 |.c..............|
00000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 |...|.........!..|
00000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 |....8.u........u|
00000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b |.........|...t..|
00000040 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00 |L.....|.........|
00000050 00 00 00 00 00 00 00 00 00 00 00 80 01 00 00 00 |................|
00000060 00 00 00 00 ff fa 90 90 f6 c2 80 74 05 f6 c2 70 |...........t...p|
00000070 74 02 b2 80 ea 79 7c 00 00 31 c0 8e d8 8e d0 bc |t....y|..1......|
00000080 00 20 fb a0 64 7c 3c ff 74 02 88 c2 52 be 05 7c |. ..d|<.t...R..||
00000090 b4 41 bb aa 55 cd 13 5a 52 72 3d 81 fb 55 aa 75 |.A..U..ZRr=..U.u|
000000a0 37 83 e1 01 74 32 31 c0 89 44 04 40 88 44 ff 89 |7...t21..D.@.D..|
000000b0 44 02 c7 04 10 00 66 8b 1e 5c 7c 66 89 5c 08 66 |D.....f..\|f.\.f|
000000c0 8b 1e 60 7c 66 89 5c 0c c7 44 06 00 70 b4 42 cd |..`|f.\..D..p.B.|
000000d0 13 72 05 bb 00 70 eb 76 b4 08 cd 13 73 0d 5a 84 |.r...p.v....s.Z.|
000000e0 d2 0f 83 de 00 be 85 7d e9 82 00 66 0f b6 c6 88 |.......}...f....|
000000f0 64 ff 40 66 89 44 04 0f b6 d1 c1 e2 02 88 e8 88 |d.@f.D..........|
00000100 f4 40 89 44 08 0f b6 c2 c0 e8 02 66 89 04 66 a1 |.@.D.......f..f.|
00000110 60 7c 66 09 c0 75 4e 66 a1 5c 7c 66 31 d2 66 f7 |`|f..uNf.\|f1.f.|
00000120 34 88 d1 31 d2 66 f7 74 04 3b 44 08 7d 37 fe c1 |4..1.f.t.;D.}7..|
00000130 88 c5 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 |..0........Z....|
00000140 70 8e c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e |p..1......r...`.|
00000150 b9 00 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f |.....1..........|
00000160 61 ff 26 5a 7c be 80 7d eb 03 be 8f 7d e8 34 00 |a.&Z|..}....}.4.|
00000170 be 94 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 |..}.......GRUB .|
00000180 47 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 |Geom.Hard Disk.R|
00000190 65 61 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 |ead. Error......|
000001a0 b4 0e cd 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 |.....<.u........|
000001b0 00 00 00 00 00 00 00 00 52 93 0c 00 00 00 80 20 |........R...... |
000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 aa |!...(....... ...|
000001d0 29 82 8e fe ff ff 00 08 20 00 00 f8 df 0e 00 00 |)....... .......|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
备份MBR信息
# dd if=/dev/sda of=/root/mbr.bk bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00280891 s, 182 kB/s
将mbr.bk保存至远程电脑
# scp mbr.bk root@172.20.200.130:/data
The authenticity of host '172.20.200.130 (172.20.200.130)' can't be established.
ECDSA key fingerprint is SHA256:ucc5uQ4jfEPKzZniGQb2KT4NzAzFYC0wIIvgmTpjzdw.
ECDSA key fingerprint is MD5:8f:3e:26:10:15:4a:55:a1:61:2b:eb:cb:de:5a:75:63.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.200.130' (ECDSA) to the list of known hosts.
root@172.20.200.130's password:
mbr.bk
破坏本地磁盘mbr信息
# dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.000808557 s, 79.2 kB/s
查看破坏后的mbr信息
# hexdump -C -n 512 /dev/sda
00000000 eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 |.c..............|
00000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 |...|.........!..|
00000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 |....8.u........u|
00000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b |.........|...t..|
00000040 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00 |L.....|.........|
00000050 00 00 00 00 00 00 00 00 00 00 00 80 01 00 00 00 |................|
00000060 00 00 00 00 ff fa 90 90 f6 c2 80 74 05 f6 c2 70 |...........t...p|
00000070 74 02 b2 80 ea 79 7c 00 00 31 c0 8e d8 8e d0 bc |t....y|..1......|
00000080 00 20 fb a0 64 7c 3c ff 74 02 88 c2 52 be 05 7c |. ..d|<.t...R..||
00000090 b4 41 bb aa 55 cd 13 5a 52 72 3d 81 fb 55 aa 75 |.A..U..ZRr=..U.u|
000000a0 37 83 e1 01 74 32 31 c0 89 44 04 40 88 44 ff 89 |7...t21..D.@.D..|
000000b0 44 02 c7 04 10 00 66 8b 1e 5c 7c 66 89 5c 08 66 |D.....f..\|f.\.f|
000000c0 8b 1e 60 7c 66 89 5c 0c c7 44 06 00 70 b4 42 cd |..`|f.\..D..p.B.|
000000d0 13 72 05 bb 00 70 eb 76 b4 08 cd 13 73 0d 5a 84 |.r...p.v....s.Z.|
000000e0 d2 0f 83 de 00 be 85 7d e9 82 00 66 0f b6 c6 88 |.......}...f....|
000000f0 64 ff 40 66 89 44 04 0f b6 d1 c1 e2 02 88 e8 88 |d.@f.D..........|
00000100 f4 40 89 44 08 0f b6 c2 c0 e8 02 66 89 04 66 a1 |.@.D.......f..f.|
00000110 60 7c 66 09 c0 75 4e 66 a1 5c 7c 66 31 d2 66 f7 |`|f..uNf.\|f1.f.|
00000120 34 88 d1 31 d2 66 f7 74 04 3b 44 08 7d 37 fe c1 |4..1.f.t.;D.}7..|
00000130 88 c5 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 |..0........Z....|
00000140 70 8e c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e |p..1......r...`.|
00000150 b9 00 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f |.....1..........|
00000160 61 ff 26 5a 7c be 80 7d eb 03 be 8f 7d e8 34 00 |a.&Z|..}....}.4.|
00000170 be 94 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 |..}.......GRUB .|
00000180 47 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 |Geom.Hard Disk.R|
00000190 65 61 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 |ead. Error......|
000001a0 b4 0e cd 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 |.....<.u........|
000001b0 00 00 00 00 00 00 00 00 52 93 0c 00 00 00 00 00 |........R.......|
000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
00000200
# reboot #由于mbr信息被破坏,进入维护模式
# ip add add 172.20.200.11/24 dev ens33
# scp root@172.20.200.130:/data/mbr.bk
# dd if=mbr.bk of=/dev/sda bs=1 count=512
# reboot #恢复完成
2、总结RAID的各个级别及其组合方式和性能的不同
★标准RAID
◇RAID 0
- 优点:使用 n 颗硬盘,即可拥有将近 n 倍的读写效能。
- 缺点:数据安全性较低,同组数组中任一硬盘发生问题就会造成数据遗失。
- 硬盘数量:最少 2 个。
◇RAID 1
- 优点:安全性依照数组里的实体硬盘数量倍数成长。
- 缺点:空间利用率是所有 RAID 中最没有效率的。
- 硬盘数量:最少 2 个。
在 RAID 0 追求效能极端的彼岸,存在着强调数据安全性的RAID 1,RAID 1 的数据储存方式恰好与 RAID 0相反,欲写入硬盘的数据被复制成与硬盘相同数量的份数,分别写入数组中的各颗硬盘。如此一来每个硬盘内都拥有着同份数据的不同拷贝,只要数组中的其中 1 颗硬盘还可使用,数据就不会遗失,可忍受 n-1 颗硬盘同时损毁(n 为数组中实体硬盘的个数)。
效能部分则分为写入和读取 2 种不同状况,写入时因为须将数据复制多份写入各颗硬盘,写入效能与单颗硬盘差不多;读取时则能够同时从各颗硬盘同时读取数据的不同部分,所以能够和 RAID 0 相提并论,约是单颗硬盘读取效能乘上数组中的硬盘个数,不过也有以单颗硬盘读取的设计。
数组可使用容量是 RAID 1 最大的缺点,由于各实体硬盘中的数据几乎是以镜像的方式储存,因此无论数组中放入了多少颗硬盘,可用容量都是以最小的那颗硬盘为主;同 RAID 0,如果数组中有着硬盘容量不一的情形,大硬盘的剩余容量能否可利用端看控制器的设计,之后的 RAID 模式也是如此,将不再赘述。
◇RAID 5
- 优点:兼顾空间利用率与安全性。
- 缺点:需要额外的运算资源,仅能忍受 1 个硬盘损毁。
- 硬盘数量:至少 3 个。
◇RAID 6
- 优点:容错硬盘数量比 RAID 5 多 1 颗。
- 缺点:运算量比 RAID 5 大、空间利用率比 RAID 5 低。
- 硬盘数量:至少 4 个。
◇RAID 2、3、4 呢?
RAID2、3、4较少实际应用,它们大多只在研究领域有实作。
★混合RAID
◇JBOD
JBOD 为 ”Just a Bunch Of Disks” 的缩写,意思就是「一堆硬盘」,指的是RAID 磁盘阵列以外的所有组态。
实作上 JBOD 有 2 种方式,第一种与我们直接将硬盘安装在计算机中相同,各颗实体各自管理自己的容量,当然也可进行磁盘区分割。第二种则是能够将不同实体硬盘的空间串在一起,例如 2 颗 1TB 硬盘串成 1 个 2TB 的空间运用,如此能够放入大于 1TB 的单一档案。
◇RAID 7
RAID 7并非公开的RAID标准,而是Storage Computer Corporation的专利硬件产品名称。
RAID 7的效能超越了许多其他RAID标准的实做产品,但也因为如此,在价格方面非常的高昂。
◇RAID N+N
在厂商支持的情况下,使用者甚至可以将 2 种以上的 RAID 组态放在同 1组磁盘阵列内,也就是有时可以看到的双位数 RAID 01、10、50、60……等。
建立的方式也很好理解,首先利用前位数字的 RAID 方式建立数组,接着再将后方数字所代表的数组建立其上。
譬如 RAID 10 就是先建立 2 组 RAID 1,接着这 2 组 RAID 1 再组合成 RAID 0;RAID50 就是先建立 2 组 RAID 5,接着再组合成 1 组 RAID 0。
当然,这种组合等级的成本一般都非常昂贵,因此只在少数特定场合应用。
3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
# mkdir /test #创建挂载点
# fdisk -l #查看磁盘信息
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000c9352
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 251658239 124779520 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf49418ad
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 6293503 1048576 83 Linux
/dev/sdb3 6293504 8390655 1048576 83 Linux
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-home: 71.9 GB, 71932313600 bytes, 140492800 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
[root@localhost ~]# fdisk /dev/sdb #将磁盘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.
Command (m for help): d
Partition number (1-3, default 3): 1
Partition 1 is deleted
Command (m for help): d
Partition number (2,3, default 3): 2
Partition 2 is deleted
Command (m for help): d
Selected partition 3
Partition 3 is deleted
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (63-41943039, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000c9352
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 251658239 124779520 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf49418ad
Device Boot Start End Blocks Id System
/dev/sdb1 63 4194367 2097152+ 83 Linux
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-home: 71.9 GB, 71932313600 bytes, 140492800 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
# mke2fs -t ext4 -L TEST -m 1 -b 2048 /dev/sdb1 #创建文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
# mount -o acl /dev/sdb1 /test #手动挂载文件系统
# dumpe2fs /dev/sdb1 #查看文件系统信息
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: TEST
Last mounted on: /test
Filesystem UUID: 22f10ffd-935e-421f-bbf6-1ee912c81b62
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131072
Block count: 1048576
Reserved block count: 10485
Free blocks: 994651
Free inodes: 131061
First block: 0
Block size: 2048
Fragment size: 2048
Group descriptor size: 64
# blkid /dev/sdb1
/dev/sdb1: LABEL="TEST" UUID="22f10ffd-935e-421f-bbf6-1ee912c81b62" TYPE="ext4"
# vim /etc/fstab
# /etc/fstab
# Created by anaconda on Tue Jan 5 01:15:38 2021
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ff1c2699-9446-44cc-84fd-76cd0ec08f11 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=22f10ffd-935e-421f-bbf6-1ee912c81b62 /test ext4 acl 0 0
4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
在/dev/sdb磁盘上增加两个分区
# fdisk -l /dev/sdb #查看磁盘当前状态
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xf49418ad
Device Boot Start End Blocks Id System
/dev/sdb1 63 4194367 2097152+ 83 Linux
# 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.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (4194368-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (4194368-41943039, default 25167872):
Using default value 25167872
Last sector, +sectors or +size{K,M,G} (25167872-41943039, default 41943039):
Using default value 41943039
Partition 3 of type Linux and of size 8 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
创建pv
]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@localhost test]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created.
]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb2
VG Name testvg
PV Size 10.00 GiB / not usable 16.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 639
Free PE 639
Allocated PE 0
PV UUID u4Kbz2-BSaN-nv2h-PWxq-hXqL-78XB-JdIta2
--- Physical volume ---
PV Name /dev/sdb3
VG Name testvg
PV Size <8.00 GiB / not usable 15.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 511
Free PE 511
Allocated PE 0
PV UUID Rw2kLK-nVTu-oSUp-b3Oa-HlTM-fisb-m9pe5t
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <119.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 30463
Free PE 1
Allocated PE 30462
PV UUID efozR1-vEot-NYF6-oBy4-HC6c-mR01-2nyuif
创建vg
]# vgcreate -s 16M testvg /dev/sdb2 /dev/sdb3
# vgdisplay testvg
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size <17.97 GiB
PE Size 16.00 MiB
Total PE 1150
Alloc PE / Size 0 / 0
Free PE / Size 1150 / <17.97 GiB
VG UUID iZCsJG-6NOm-3Hvi-lv4i-rIds-3U9I-3m38jS
创建lv
# lvcreate -L 5G -n testlv testvg
Logical volume "testlv" created.
[root@localhost test]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID TpjH6V-zh7z-06TT-VjtN-q04v-UYcz-f8mLzB
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-01-05 07:30:46 -0500
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
创建文件系统
# mke2fs -t ext4 /dev/testvg/testlv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载至/users
# mkdir /users
# mount /dev/testvg/testlv /users
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 439M 0 439M 0% /dev
tmpfs tmpfs 451M 0 451M 0% /dev/shm
tmpfs tmpfs 451M 7.3M 443M 2% /run
tmpfs tmpfs 451M 0 451M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 1.3G 49G 3% /
/dev/sdb1 ext4 2.0G 9.1M 1.9G 1% /test
/dev/sda1 xfs 1014M 137M 878M 14% /boot
/dev/mapper/centos-home xfs 67G 33M 67G 1% /home
tmpfs tmpfs 91M 0 91M 0% /run/user/0
/dev/mapper/testvg-testlv ext4 4.8G 20M 4.6G 1% /users
设置成自动挂载
# vi /etc/fstab
# /etc/fstab
# Created by anaconda on Tue Jan 5 01:15:38 2021
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ff1c2699-9446-44cc-84fd-76cd0ec08f11 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=22f10ffd-935e-421f-bbf6-1ee912c81b62 /test ext4 acl 0 0
/dev/testvg/testlv /users ext4 defaults 0 0
# mount -a
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 439M 0 439M 0% /dev
tmpfs 451M 0 451M 0% /dev/shm
tmpfs 451M 7.3M 443M 2% /run
tmpfs 451M 0 451M 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 1.3G 49G 3% /
/dev/sda1 1014M 137M 878M 14% /boot
/dev/sdb1 2.0G 9.1M 1.9G 1% /test
/dev/mapper/centos-home 67G 33M 67G 1% /home
tmpfs 91M 0 91M 0% /run/user/0
/dev/mapper/testvg-testlv 4.8G 20M 4.6G 1% /users #不能使用UUID