AI智能
改变未来

磁盘存储管理和文件系统管理 RAID


磁盘存储管理 和文件系统管理 RAID

1、磁盘管理

1.1 磁盘分区

两种分区方式:MBR,GPT

0磁道0扇区: 512bytes

446bytes:boot loader

64bytes:分区表,其中每16bytes标识一个分区

2bytes:55AA

1.2 管理分区

列出块设备

lsblk

创建分区命令

fdisk   管理MBR分区gdisk   管理GPT分区parted  高级分区操作,

1.3 parted 命令

parted的操作是实时生效的,小心使用

格式:

parted [option]...[设备 [命令 [参数]...]...]

1.4 分区工具fdisk和gdisk

gdisk [device...]           类fdisk 的GPT分区工具fdisk -l [-u] [device...]   查看分区fdisk [device...]           管理MBR分区工具

子命令:

p       分区列表t       更改分区类型n       创建新分区d       删除分区v       校验分区u       转换单位w       保存退出q       不保存退出

查看内核是否已经识别新的分区

cat /proc/partations

非交互式创建分区

echo -e \'n\\np\\n\\n\\n+2G\\nw\\n\' | fdisk /dev/sdc

1.5 文件系统管理

1.5.1 创建文件管理工具

  • mkfs命令:

    (1) mkfs.FS_TYPE /dev/DEVICE

    ​ ext4

    ​ xfs

    ​ btfs

    ​ vfat

    (2) mkfs -t FS_TYPE /dev/DEVICE

    ​ -L \’LABEL\’ 设定卷标

    mke2fs:ext系列文件系统专用管理工具

常用选项:

-t {ext2|ext3|ext4|xfs}         指定文件系统类型-b {1024|2048|4096}             指定块大小-L \'LABEL\'                      设定卷标-i              #为数据空间中每第多少个字节创建一个inode;不小于块大小-N              #指定分区中创建多少个inode-m              #默认5%,为管理人员预留空间占总空间的百分比-o FEATURE[,...]    启用指定特性-o ^FEATURE         关闭指定特性-j                  相当于 -t ext3

2、逻辑卷管理器

相关工具来自于lvm2 包

2.1 pv管理工具

#显示pv信息pvs:简要pv信息显示pvdisplay#创建pvpvcreate /dev/DEVICE#删除pvpvremove /dev/DEVICE

2.2 vg管理工具

#显示卷组vgsvgdisplay#创建卷组vgcreate [-s #[KkmMgGtTpPeE]] volumeGroupName physicalDevicepath [PhysicalDevivePath...]#管理卷组vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevivePath...]vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevivePath...]#删除卷组先做pvmove再做 vgremove

2.3 lv管理工具

#显示逻辑卷lvslvdisplay#创建逻辑卷lvcreate -l #[mMgGtT] -n Name VolumeGrouplvcreate -l 60%VG -n mylv testvg#删除逻辑卷lvremove /dev/VG_NAME/LV_NAME

2.4 在线扩展逻辑卷

lvextend -L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME# ext格式resize2fs /dev/VG_NAME/LV_NAME# xfs格式xfs_growfs MOUNTPOINTlvresize -r -l +100%FREE /dev/VG_NAME/LV_NAME

3、RAID

3.1 总结RAID各个级别及其组合方式和性能的不同

RAID类型:RAID 0、RAID 1、RAID 4、RAID 5、RAID 6、RAID 10、RAID 01、RAID 50RAID常用性能:RAID 0:需要至少2块硬盘,读写性能提升,可用空间为n块硬盘容量之和,无容错能力。RAID 1:至少需要2块硬盘,硬盘数为2的倍数,可用空间为n/2容量的空间,读性能提升,写性能降低,有冗余能力。RAID 5:至少需要3块硬盘,硬盘数为3块以上。可用空间为(n-1),读写性能提升,有容错能力,最多允许坏1块盘。RAID 6:至少需要4块硬盘,硬盘数为4块以上,可用空间为(n-2),读写性能提升,有容错能力,最多允许坏2块盘。RAID 10:至少需要4块硬盘,硬盘数为4的偶数,可用空间为n/2,读写性能提升,有容错能力,每组镜像最多只能坏1块盘。先组RAID 1再组 RAID 0。RAID 01:至少4块盘,硬盘数为4的偶数,可用空间为n/2,读写性能提升,有容错能力。不同镜像不能坏存储相同内容的硬盘,先组RAID 0 再组 RAID 1。RAID 50:至少需要6块盘,硬盘数为3的倍数,可用空间为(n-3),读写性能提升,有容错能力,每组镜像允许坏1块盘,最多允许坏2块硬盘。

3.2 破坏mbr表并修复

# 备份MBR分区表[root@CentOS8 ~]#dd if=/dev/sda of=/data/mbr.img bs=1 count=64 skip=446[root@CentOS8 ~]#scp /data/mbr.img 10.0.0.8:# 破坏MBR分区表[root@CentOS8 ~]#dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446#重启无法进入系统[root@CentOS8 ~]#reboot#用光盘启动,进入rescue mode,选择1)Continue -->> 回车进入shell#配置网络sh-4.4#ip addr add 10.0.0.18/24 dev ens33sh-4.4#scp 10.0.0.8:/root/mbr.img .#恢复MBR分区表sh-4.4#dd if=mbr.img of=/dev/sda bs=1 seek=446sh-4.4#exit

3.3 磁盘管理实例

3.3.1 创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

#创建2G分区[root@CentOS8 ~]#fdisk -lDisk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x3bce8aa0Device     Boot     Start       End   Sectors  Size Id Type/dev/sda1  *         2048   2099199   2097152    1G 83 Linux/dev/sda2         2099200 211814399 209715200  100G 83 Linux/dev/sda3       211814400 218105855   6291456    3G 82 Linux swap / Solaris/dev/sda4       218105856 419430399 201324544   96G  5 Extended/dev/sda5       218107904 322965503 104857600   50G 83 Linux[root@CentOS8 ~]#fdisk /dev/sdaWelcome to fdisk (util-linux 2.32.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): nAll primary partitions are in use.Adding logical partition 6First sector (322967552-419430399, default 322967552):Last sector, +sectors or +size{K,M,G,T,P} (322967552-419430399, default 419430399): +2GCreated a new partition 6 of type \'Linux\' and of size 2 GiB.Command (m for help): pDisk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x3bce8aa0Device     Boot     Start       End   Sectors  Size Id Type/dev/sda1  *         2048   2099199   2097152    1G 83 Linux/dev/sda2         2099200 211814399 209715200  100G 83 Linux/dev/sda3       211814400 218105855   6291456    3G 82 Linux swap / Solaris/dev/sda4       218105856 419430399 201324544   96G  5 Extended/dev/sda5       218107904 322965503 104857600   50G 83 Linux/dev/sda6       322967552 327161855   4194304    2G 83 LinuxCommand (m for help): wThe partition table has been altered.Syncing disks.[root@CentOS8 ~]#lsblkNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda      8:0    0  200G  0 disk├─sda1   8:1    0    1G  0 part /boot├─sda2   8:2    0  100G  0 part /├─sda3   8:3    0    3G  0 part [SWAP]├─sda4   8:4    0    1K  0 part├─sda5   8:5    0   50G  0 part /data└─sda6   8:6    0    2G  0 partsr0     11:0    1  8.6G  0 rom#创建2G ext4文件系统[root@CentOS8 ~]#mkfs.ext4 -b 2048 -L \'TEST\' -m 1 /dev/sda6mke2fs 1.45.6 (20-Mar-2020)Creating filesystem with 1048576 2k blocks and 131072 inodesFilesystem UUID: 344bd85b-cf28-4ace-aa25-a962f56a554fSuperblock backups stored on blocks:16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done[root@CentOS8 ~]#blkid | grep /dev/sda6/dev/sda6: LABEL=\"TEST\" UUID=\"344bd85b-cf28-4ace-aa25-a962f56a554f\" BLOCK_SIZE=\"2048\" TYPE=\"ext4\" PARTUUID=\"3bce8aa0-06\"#创建text挂载点并添加挂载配置使开机自动挂载[root@CentOS8 ~]#mkdir /test[root@CentOS8 /]#vim /etc/fstabUUID=344bd85b-cf28-4ace-aa25-a962f56a554f /test                   ext4    defaults        0 0#设置默认挂载acl选项[root@CentOS8 ~]#tune2fs -o acl /dev/sda6[root@CentOS8 /]#reboot[root@CentOS8 ~]#dfFilesystem     1K-blocks    Used Available Use% Mounted on/dev/sda6        2031306    9236   1992908   1% /test[root@CentOS8 ~]#tune2fs -l /dev/sda6tune2fs 1.45.6 (20-Mar-2020)Filesystem volume name:   TESTLast mounted on:          <not available>Filesystem UUID:          344bd85b-cf28-4ace-aa25-a962f56a554fFilesystem magic number:  0xEF53Filesystem revision #:    1 (dynamic)Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumFilesystem flags:         signed_directory_hashDefault mount options:    user_xattr acl            #分区挂载选项支持aclFilesystem state:         cleanErrors behavior:          ContinueFilesystem OS type:       Linux

3.3.2 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

#创建两个分区,/dev/sda7和/dev/sda8 大小均为10G 且分区格式为lvm[root@CentOS8 ~]#fdisk /dev/sdaWelcome to fdisk (util-linux 2.32.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x3bce8aa0Device     Boot     Start       End   Sectors  Size Id Type/dev/sda1  *         2048   2099199   2097152    1G 83 Linux/dev/sda2         2099200 211814399 209715200  100G 83 Linux/dev/sda3       211814400 218105855   6291456    3G 82 Linux swap / Solaris/dev/sda4       218105856 419430399 201324544   96G  5 Extended/dev/sda5       218107904 322965503 104857600   50G 83 Linux/dev/sda6       322967552 327161855   4194304    2G 83 LinuxCommand (m for help): nAll primary partitions are in use.Adding logical partition 7First sector (327163904-419430399, default 327163904):Last sector, +sectors or +size{K,M,G,T,P} (327163904-419430399, default 419430399): +10GCreated a new partition 7 of type \'Linux\' and of size 10 GiB.Command (m for help): tPartition number (1-7, default 7): 7Hex code (type L to list all codes): 8eChanged type of partition \'Linux\' to \'Linux LVM\'.Command (m for help): nAll primary partitions are in use.Adding logical partition 8First sector (348137472-419430399, default 348137472):Last sector, +sectors or +size{K,M,G,T,P} (348137472-419430399, default 419430399): +10GCreated a new partition 8 of type \'Linux\' and of size 10 GiB.Command (m for help): tPartition number (1-8, default 8): 8Hex code (type L to list all codes): 8eChanged type of partition \'Linux\' to \'Linux LVM\'.Command (m for help): pDisk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x3bce8aa0Device     Boot     Start       End   Sectors  Size Id Type/dev/sda1  *         2048   2099199   2097152    1G 83 Linux/dev/sda2         2099200 211814399 209715200  100G 83 Linux/dev/sda3       211814400 218105855   6291456    3G 82 Linux swap / Solaris/dev/sda4       218105856 419430399 201324544   96G  5 Extended/dev/sda5       218107904 322965503 104857600   50G 83 Linux/dev/sda6       322967552 327161855   4194304    2G 83 Linux/dev/sda7       327163904 348135423  20971520   10G 8e Linux LVM/dev/sda8       348137472 369108991  20971520   10G 8e Linux LVMCommand (m for help): wThe partition table has been altered.Syncing disks.#安装lvm管理工具,查看工具包安装文件[root@CentOS8 ~]#yum -y install lvm2[root@CentOS8 ~]#rpm -ql lvm2#创建物理卷PV[root@CentOS8 ~]#pvcreate /dev/sda7Physical volume \"/dev/sda7\" successfully created.[root@CentOS8 ~]#pvcreate /dev/sda8Physical volume \"/dev/sda8\" successfully created.[root@CentOS8 ~]#pvsPV         VG Fmt  Attr PSize  PFree/dev/sda7     lvm2 ---  10.00g 10.00g/dev/sda8     lvm2 ---  10.00g 10.00g#创建卷组VG,且PE大小为16MB[root@CentOS8 ~]#vgcreate -s 16M testvg /dev/sda{7,8}Volume group \"testvg\" successfully created[root@CentOS8 ~]#vgsVG     #PV #LV #SN Attr   VSize   VFreetestvg   2   0   0 wz--n- <19.97g <19.97g[root@CentOS8 ~]#vgdisplay--- Volume group ---VG Name               testvgSystem IDFormat                lvm2Metadata Areas        2Metadata Sequence No  1VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                0Open LV               0Max PV                0Cur PV                2Act PV                2VG Size               <19.97 GiBPE Size               16.00 MiBTotal PE              1278Alloc PE / Size       0 / 0Free  PE / Size       1278 / <19.97 GiBVG UUID               3peGQY-6UoH-3haX-rQCG-OeEY-jFcj-wKPFNu#创建逻辑卷LV,大小为5G的testlv[root@CentOS8 ~]#lvcreate -n testlv -L 5G testvgLogical volume \"testlv\" created.[root@CentOS8 ~]#lvsLV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Converttestlv testvg -wi-a----- 5.00g[root@CentOS8 ~]#lvdisplay--- Logical volume ---LV Path                /dev/testvg/testlvLV Name                testlvVG Name                testvgLV UUID                c2bGkH-5o3O-pM60-Kvxd-VoxM-bzoz-Nlgr0SLV Write Access        read/writeLV Creation host, time CentOS8.localdomain, 2021-03-26 06:21:59 +0800LV Status              available# open                 0LV Size                5.00 GiBCurrent LE             320Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:0[root@CentOS8 ~]#vgsVG     #PV #LV #SN Attr   VSize   VFreetestvg   2   1   0 wz--n- <19.97g <14.97g#创建ext4文件系统并自动挂载/users目录[root@CentOS8 ~]#mkfs.ext4 /dev/testvg/testlvmke2fs 1.45.6 (20-Mar-2020)Creating filesystem with 1310720 4k blocks and 327680 inodesFilesystem UUID: 2b540cd3-9f3a-4617-8940-1ae155b51474Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done[root@CentOS8 ~]#blkid/dev/sda7: UUID=\"F3GTs3-X70f-lifj-Cjbz-QCp5-tk7F-3Qz3q0\" TYPE=\"LVM2_member\" PARTUUID=\"3bce8aa0-07\"/dev/sda8: UUID=\"Qk2QT3-fUdm-w4QT-3TDO-BUbM-kZbv-PEPNC2\" TYPE=\"LVM2_member\" PARTUUID=\"3bce8aa0-08\"/dev/sr0: BLOCK_SIZE=\"2048\" UUID=\"2020-11-18-21-39-52-00\" LABEL=\"CentOS-8-3-2011-x86_64-dvd\" TYPE=\"iso9660\" PTUUID=\"6b8b4567\" PTTYPE=\"dos\"/dev/mapper/testvg-testlv: UUID=\"2b540cd3-9f3a-4617-8940-1ae155b51474\" BLOCK_SIZE=\"4096\" TYPE=\"ext4\"[root@CentOS8 ~]#mkdir /users[root@CentOS8 ~]#vim /etc/fstab#最后一行,添加UUID=2b540cd3-9f3a-4617-8940-1ae155b51474 /users                  ext4    defaults        0 0#手动挂载文件系统[root@CentOS8 ~]#mount -a[root@CentOS8 ~]#df -hFilesystem                 Size  Used Avail Use% Mounted on/dev/mapper/testvg-testlv  4.9G   20M  4.6G   1% /users
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 磁盘存储管理和文件系统管理 RAID