课堂练习1
创建raid6,并在创建的raid6中创建一个test文件,文件中写上自己的学号、姓名
操作步骤
- 1】添加硬盘—-根据raid的级别选择大小规格品牌一样的若干块硬盘
- 2】发现硬盘—-记住硬盘的位置及名称
- fdisk -l
- 3】分区并转换硬盘的类型:fd
- fdisk 硬盘的位置及名称
- n 创建分区
- p 主分区
- 1 分区序号
- 开始:回车
- 结束:回车
- t 转换
- fd—raid
- p 显示
- w 保存推出
- 4】创建raid
- mdadm -C /dev/md级别 -l 级别 -n 组建raid所需要的硬盘数量 -x 给raid准备的备份硬盘数量 硬盘的位置及名称1 硬盘的位置及名称n
- 注意:
- 级别:0、1、{2、3、4、}5、6、01、10、50、60
- 组建raid所需要的硬盘数量:》2、》2n、》3、》4、》4、》4、》6、》8
- 给raid准备的备份硬盘数量:《2
- 硬盘的位置及名称n:=组建raid所需要的硬盘数量+给raid准备的备份硬盘数量
- 5】格式化raid
- mkfs raid
- 6】创建挂载点
- 7】挂载
- 8】使用
- {1}增加文件、查文件、修改文件、删除文件
- {2}模拟坏盘,检查效果
- mdadm -D raid—查细节
- mdadm raid -f 硬盘的位置及名称n —-坏盘
- mdadm raid -r 硬盘的位置及名称n —-把坏盘移除
- mdadm raid -a 硬盘的位置及名称new —-添加一块新盘
假设您已经有足够的硬盘(至少4块用于数据存储加上2块用于奇偶校验,共6块),且这些硬盘已正确连接到系统中。
1. 发现硬盘
# 列出所有硬盘信息
[root@localhost ~]# fdisk -l
Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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/sdb: 4294 MB, 4294967296 bytes, 8388608 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/sda: 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 label type: dos
Disk identifier: 0x000c9894
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 99608575 49291264 8e Linux LVM
Disk /dev/sde: 4294 MB, 4294967296 bytes, 8388608 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/sdf: 4294 MB, 4294967296 bytes, 8388608 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/sdd: 4294 MB, 4294967296 bytes, 8388608 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/sdg: 4294 MB, 4294967296 bytes, 8388608 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/rhel-root: 48.3 GB, 48318382080 bytes, 94371840 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/rhel-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
2. 分区硬盘
操作过程
fdisk /dev/sdc
n
p
1
<Enter>
<Enter>
t
fd
p
w
fdisk /dev/sdb
n
p
1
<Enter>
<Enter>
t
fd
p
w
fdisk /dev/sde
n
p
1
<Enter>
<Enter>
t
fd
p
w
fdisk /dev/sdf
n
p
1
<Enter>
<Enter>
t
fd
p
w
fdisk /dev/sdd
n
p
1
<Enter>
<Enter>
t
fd
p
w
fdisk /dev/sdg
n
p
1
<Enter>
<Enter>
t
fd
p
w
示例
[root@localhost ~]# fdisk /dev/sdc
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 0xbc8ac6b9.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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: 0xbc8ac6b9
Device Boot Start End Blocks Id System
/dev/sdc1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# 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 0x87a76fdf.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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: 0x87a76fdf
Device Boot Start End Blocks Id System
/dev/sdb1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sde
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 0x8f1631e8.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sde: 4294 MB, 4294967296 bytes, 8388608 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: 0x8f1631e8
Device Boot Start End Blocks Id System
/dev/sde1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdf
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 0x9dc03a7f.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdf: 4294 MB, 4294967296 bytes, 8388608 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: 0x9dc03a7f
Device Boot Start End Blocks Id System
/dev/sdf1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdd
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 0x0257a13c.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdd: 4294 MB, 4294967296 bytes, 8388608 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: 0x0257a13c
Device Boot Start End Blocks Id System
/dev/sdd1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdg
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 0x278505d3.
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): 1
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607):
Using default value 8388607
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdg: 4294 MB, 4294967296 bytes, 8388608 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: 0x278505d3
Device Boot Start End Blocks Id System
/dev/sdg1 2048 8388607 4193280 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
3. 创建RAID6 格式化RAID6
# 假设我们有6块硬盘(/dev/sdc1 /dev/sdb1 /dev/sde1 /dev/sdf1 /dev/sdd1 /dev/sdg1),现在创建RAID6。
[root@localhost ~]# mdadm -C /dev/md0 -l 6 -n 4 -x 2 /dev/sdc1 /dev/sdb1 /dev/sde1 /dev/sdf1 /dev/sdd1 /dev/sdg1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# 格式化RAID设备
[root@localhost ~]# mkfs /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
524288 inodes, 2095616 blocks
104780 blocks (5.00%) reserved for the super user
First data block=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: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
4. 创建挂载点并挂载RAID
# 创建挂载目录
[root@localhost ~]# mkdir /mnt/guazai
# 挂载
[root@localhost ~]# mount /dev/md0 /mnt/guazai
# 查看文件夹内容
[root@localhost ~]# ll /mnt/guazai
total 16
drwx------. 2 root root 16384 May 23 20:49 lost+found
5. 使用RAID
# 写入文件内容
[root@localhost ~]# echo '230303000张三' >> /mnt/guazai/test
# 查看文件内容
[root@localhost ~]# cat /mnt/guazai/test
230303000张三
# 修改文件内容
[root@localhost ~]# echo 'dcyy' > /mnt/guazai/test
# 查看文件内容
[root@localhost ~]# cat /mnt/guazai/test
dcyy
# 删除文件内容
[root@localhost ~]# rm /mnt/guazai/test
rm: remove regular file ‘/mnt/guazai/test’? y
# 估计题目要求再次创建
[root@localhost ~]# echo '230303000张三' >> /mnt/guazai/test
6. 模拟坏盘与恢复
检查当前RAID状态
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu May 23 20:48:41 2024
Raid Level : raid6
Array Size : 8382464 (7.99 GiB 8.58 GB)
Used Dev Size : 4191232 (4.00 GiB 4.29 GB)
Raid Devices : 4
Total Devices : 6
Persistence : Superblock is persistent
Update Time : Thu May 23 20:54:14 2024
State : clean
Active Devices : 4
Working Devices : 6
Failed Devices : 0
Spare Devices : 2
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 95c46c7b:54d9db8f:3df9f346:99c1b557
Events : 17
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 17 1 active sync /dev/sdb1
2 8 65 2 active sync /dev/sde1
3 8 81 3 active sync /dev/sdf1
4 8 49 - spare /dev/sdd1
5 8 97 - spare /dev/sdg1
模拟坏盘
# 假设sdb1为要模拟故障的硬盘
[root@localhost ~]# mdadm /dev/md0 -f /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0
# 再次检查状态,确认故障标记
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu May 23 20:48:41 2024
Raid Level : raid6
Array Size : 8382464 (7.99 GiB 8.58 GB)
Used Dev Size : 4191232 (4.00 GiB 4.29 GB)
Raid Devices : 4
Total Devices : 6
Persistence : Superblock is persistent
Update Time : Thu May 23 20:55:59 2024
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 5
Failed Devices : 1
Spare Devices : 2
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 13% complete
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 95c46c7b:54d9db8f:3df9f346:99c1b557
Events : 21
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
5 8 97 1 spare rebuilding /dev/sdg1
2 8 65 2 active sync /dev/sde1
3 8 81 3 active sync /dev/sdf1
1 8 17 - faulty /dev/sdb1 # 显示faulty,ok
4 8 49 - spare /dev/sdd1
移除坏盘
# 移除坏盘
[root@localhost ~]# mdadm /dev/md0 -r /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md0
# 验证是否删除
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu May 23 20:48:41 2024
Raid Level : raid6
Array Size : 8382464 (7.99 GiB 8.58 GB)
Used Dev Size : 4191232 (4.00 GiB 4.29 GB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Thu May 23 20:56:46 2024
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 95c46c7b:54d9db8f:3df9f346:99c1b557
Events : 37
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
5 8 97 1 active sync /dev/sdg1
2 8 65 2 active sync /dev/sde1
3 8 81 3 active sync /dev/sdf1
4 8 49 - spare /dev/sdd1
添加新盘替换 假设新增硬盘为原来删除的sdb
# 添加原来删除的sdb
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdb1
mdadm: added /dev/sdb1
# 检查添加成功
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu May 23 20:48:41 2024
Raid Level : raid6
Array Size : 8382464 (7.99 GiB 8.58 GB)
Used Dev Size : 4191232 (4.00 GiB 4.29 GB)
Raid Devices : 4
Total Devices : 6
Persistence : Superblock is persistent
Update Time : Thu May 23 20:58:12 2024
State : clean
Active Devices : 4
Working Devices : 6
Failed Devices : 0
Spare Devices : 2
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 95c46c7b:54d9db8f:3df9f346:99c1b557
Events : 38
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
5 8 97 1 active sync /dev/sdg1
2 8 65 2 active sync /dev/sde1
3 8 81 3 active sync /dev/sdf1
4 8 49 - spare /dev/sdd1
6 8 17 - spare /dev/sdb1
课堂练习2
添加1块ide接口的1g硬盘、1块sata接口的2g硬盘、1块scsi接口的3g硬盘,创建一个2.5g的逻辑卷,在卷中创建一个文件test,写上自己的学号和姓名,将该逻辑卷增加到3.5g,检查文件test是否正常读写。
操作步骤
- 1】任意添加任意规格大小品牌的硬盘设备
- ide—-1g—-hda
- sata—2g—-sda
- ————————sd
- 固态–3g—–nvme0n1
- 2】发现硬盘—位置及名称
- fdisk -l
- /dev/sda 1g ?
- /dev/sdg 2g
- /dev/nvme0n1 3g
- 3】分区并转换硬盘类型:8e
- fdisk /dev/sda
- fdisk /dev/sdg
- fdisk /dev/nvme0n1
- /dev/nvme0n1p1
- 4】创建pv
- pvcreate 空格 位置及名称数字
- 创建一个物理卷{抽象硬盘【穿个马甲】}
- pvscan
- 扫描pv
- pvdisplay 位置及名称数字 {位置及名称数字===就是pv的名称}
- 显示pv的细节
- pvcreate 空格 位置及名称数字
- 5】创建vg
- vgcreate 空格 vg的名称 空格 pv的名称
- 将若干个pv组成一个vg
- vgscan
- 扫描vg
- vgdisplay vg的名称
- 显示vg的细节
- vgcreate 空格 vg的名称 空格 pv的名称
- 6】创建lv
- lvcreate 空格 -L 空格 +大小 空格 -n 空格 lv的名称 空格 vg的名称
- 在指定的vg上创建一个指定大小的lv
- lvscan
- 扫描lv
- lvdisplay 空格 lv的位置及名称
- 显示lv的细节
- lvcreate 空格 -L 空格 +大小 空格 -n 空格 lv的名称 空格 vg的名称
- 7】格式化lv
- mkfs 空格 lv的位置及名称
- 8】使用lv
- {1}创建挂载点
- {2}挂载lv
- {3}增加、删除、修改、查询
- {4}扩容:
- lvextend 空格 -L 空格 +大小 空格 lv的名称
- 给原有的lv增加指定大小
- vgextend 空格 vg的名称 空格 pv的名称
- 将pv添加到指定的vg中
- lvextend 空格 -L 空格 +大小 空格 lv的名称
- {5}缩减容量—-不要操作此类动作!———-数据为王!
- lvreduce 空格 -L 空格 -大小 空格 lv的名称
- 给原有的lv按指定大小缩减
- vgreduce 空格 vg的名称 空格 pv的名称
- 将原有的vg中的pv剔除出来,实现vg的缩减
- lvreduce 空格 -L 空格 -大小 空格 lv的名称
1. 发现硬盘
# 列出所有硬盘信息
[root@localhost ~]# fdisk -l
Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 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/sdb: 3221 MB, 3221225472 bytes, 6291456 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/sda: 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 label type: dos
Disk identifier: 0x000c9894
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 99608575 49291264 8e Linux LVM
Disk /dev/sdd: 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/rhel-root: 48.3 GB, 48318382080 bytes, 94371840 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/rhel-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
2. 分区硬盘
操作过程
fdisk /dev/sdc
n
p
<Enter>
<Enter>
<Enter>
t
8e
w
fdisk /dev/sdb
n
p
<Enter>
<Enter>
<Enter>
t
8e
w
fdisk /dev/sdd
n
p
<Enter>
<Enter>
<Enter>
t
8e
w
示例
[root@localhost ~]# fdisk /dev/sdc
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 0x997146fd.
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 (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# 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 0x9a1caec1.
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 (2048-6291455, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-6291455, default 6291455):
Using default value 6291455
Partition 1 of type Linux and of size 3 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdd
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 0x75086310.
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 (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3. 创建PV(Physical Volume)
# 创建pv
[root@localhost ~]# pvcreate /dev/sdd1 /dev/sdc1 /dev/sdb1
Physical volume "/dev/sdd1" successfully created.
Physical volume "/dev/sdc1" successfully created.
Physical volume "/dev/sdb1" successfully created.
# 扫描pv
[root@localhost ~]# pvscan
PV /dev/sda2 VG rhel lvm2 [47.00 GiB / 4.00 MiB free]
PV /dev/sdb1 lvm2 [3.00 GiB]
PV /dev/sdd1 lvm2 [2.00 GiB]
PV /dev/sdc1 lvm2 [1023.00 MiB]
Total: 4 [53.00 GiB] / in use: 1 [47.00 GiB] / in no VG: 3 [6.00 GiB]
# 显示pv的细节
[root@localhost ~]# pvdisplay /dev/sdd1 /dev/sdc1 /dev/sdb1
"/dev/sdb1" is a new physical volume of "3.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 3.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID gwyCMk-sYZR-WFjD-G1gq-uKWn-ur4c-hHviRX
"/dev/sdd1" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdd1
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID E1UnUU-xvGV-zwRL-wfy0-YieA-DJGR-8diubw
"/dev/sdc1" is a new physical volume of "1023.00 MiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 1023.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kFOjVB-NeL6-IRgd-2CoE-juCq-A39x-UVhGnc
4. 创建VG(Volume Group)
# 创建vg
[root@localhost ~]# vgcreate myvg /dev/sdd1 /dev/sdc1 /dev/sdb1
Volume group "myvg" successfully created
# 扫描vg
[root@localhost ~]# vgscan
Reading volume groups from cache.
Found volume group "myvg" using metadata type lvm2
Found volume group "rhel" using metadata type lvm2
# 显示vg的细节
[root@localhost ~]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE / Size 0 / 0
Free PE / Size 1533 / 5.99 GiB
VG UUID 1SOTCm-SROF-ED8T-0kCs-fJ2d-4WK3-NdENJI
5. 创建LV(Logical Volume)
# 创建lv
[root@localhost ~]# lvcreate -L +2.5G -n mylv myvg
Logical volume "mylv" created.
# 扫描lv
[root@localhost ~]# lvscan
ACTIVE '/dev/myvg/mylv' [2.50 GiB] inherit
ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit
ACTIVE '/dev/rhel/root' [45.00 GiB] inherit
# 显示lv的细节
[root@localhost ~]# lvdisplay /dev/myvg/mylv
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID Elzrht-qBnd-WFCt-RO2d-yyVm-FC4N-dIJtNJ
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-05-23 23:05:59 -0400
LV Status available
# open 0
LV Size 2.50 GiB
Current LE 640
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
6. 格式化LV并挂载使用
# 格式化lv
[root@localhost ~]# mkfs /dev/myvg/mylv
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
163840 inodes, 655360 blocks
32768 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=671088640
20 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
# 创建挂载文件夹
[root@localhost ~]# mkdir /mnt/mylv
#挂载lv
[root@localhost ~]# mount /dev/myvg/mylv /mnt/mylv
# 创建文件并写入内容
[root@localhost ~]# echo "230303000张三" > /mnt/mylv/test
# 查看创建的文件
[root@localhost ~]# cat /mnt/mylv/test
230303000张三
# 修改文件内容
[root@localhost ~]# echo "dcyy" >> /mnt/mylv/test
# 验证
[root@localhost ~]# cat /mnt/mylv/test
230303000张三
230dcyy
# 删除文件
[root@localhost ~]# rm /mnt/mylv/test
rm: remove regular file ‘/mnt/mylv/test’? y
7. 扩展LV到3.5GB
# 新增1G大小
[root@localhost ~]# lvextend -L +1G /dev/myvg/mylv
Size of logical volume myvg/mylv changed from 2.50 GiB (640 extents) to 3.50 GiB (896 extents).
Logical volume myvg/mylv successfully resized.
# 查看
[root@localhost ~]# lvscan
ACTIVE '/dev/myvg/mylv' [3.50 GiB] inherit
ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit
ACTIVE '/dev/rhel/root' [45.00 GiB] inherit
# 检查文件test是否正常读写
[root@localhost ~]# cat /mnt/mylv/test
230303000张三
© 版权声明
THE END
暂无评论内容