pingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun; font-size: 22px; --el-button-hover-bg-color: #6d5ffd; --el-button-hover-border-color: #6d5ffd; --el-button-active-bg-color: #6d5ffd; --el-button-active-border-color: #6d5ffd; color: rgb(79, 79, 79); line-height: 32px; font-synthesis-style: auto; overflow-wrap: break-word; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);">一、在centos7.9服务器上使用LVM方式挂载磁盘
在磁盘分区挂载之前,先使用lsblk命令查看磁盘信息,未分区挂载的磁盘sdb只有disk类型没有part类型。40G的硬盘sda已经分了两个区sda1、sda2。而sdb磁盘下并没有分区信息,说明还没有分区。磁盘分区可以用fdisk,也可以用parted分区,不过超过2T的硬盘要使用Parted分区。
lvm即逻辑卷管理器(Logical Volume Manager)可以更方便的为应用与用户分配存储空间。在LVM管理下的存储卷可以按需要随时改变大小与移除。LVM也允许按用户组对存储卷进行管理,允许管理员用更直观的名称代替物理磁盘名(如dev/sda、dev/sdb)来标识存储卷。下面是使用Parted分区并进行LVM挂载磁盘的实现过程。
[root@centos]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ?..sda1 8:1 0 500M 0 part /boot sdb 8:16 0 100G 0 disk sr0 11:0 1 1024M 0 rom #查看磁盘分区信息,unrecognised disk label 说明这块磁盘上没有分区表 [root@centos]# parted -l Error: /dev/sdb: unrecognised disk label [root@centos]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt #将磁盘格式变成gpt的格式 (parted) mkpart primary 0 107GB #创建主分区 Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? i #忽略 (parted) set 1 lvm on #设置lvm (parted) print #显示磁盘信息 Model: VMware Virtual disk (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 107GB 107GB primary lvm (parted) quit [root@centos]# lsblk #现在有了sdb1了。 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ... sdb 8:16 0 100G 0 disk ?..sdb1 8:17 0 100G 0 part sr0 11:0 1 1024M 0 rom
因为parted只能针对gpt格式的磁盘进行操作,所以上面的命令中需要使用mklabel gpt将磁盘格式变成gpt的格式。创建分区的时候可以创建多分区,命令如下:
设置单位为TB:(parted) unit MB(GB,TB)
分区:(parted) mkpart primary 1 500 (分第一个主分区500MB)
分区:(parted) mkpart primary 501 1000 (分第二个主分区500MB)
分区:(parted) mkpart logical 1001 2000 (分第三个逻辑分区1000MB)
接下来开始创建PV、VG、LV。
pv:即物理卷(Physical Volume)与物理存储设备存在对应关系。即pv对应硬盘。
vg:卷组(Volume Group)由物理卷组成,承上启下,分配逻辑卷。
lv:逻辑卷(logical volume)可以使用文件系统。
[root@centos]# pvcreate -v /dev/sdb1 Wiping signatures on new PV /dev/sdb1. Set up physical volume for "/dev/sdb1" with 209715133 available sectors. Zeroing start of device /dev/sdb1. Writing physical volume data to disk "/dev/sdb1". Physical volume "/dev/sdb1" successfully created. #vgcreate [root@centos]# vgcreate -s 4M vg01 /dev/sdb1 Volume group "vg01" successfully created [root@centos]# lvcreate -l 100%FREE -n lv01 vg01 Logical volume "lv01" created.
最后是格式化文件系统并挂载。格式化文件系统类型有xfs,ext4,这里测试使用ext4格式,centos7下推荐使用xfs格式,centos6使用ext4格式
#[root@centos]# mkfs.xfs /dev/vg01/lv01 [root@centos]# mkfs.ext4 /dev/vg01/lv01 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 6553600 inodes, 26213376 blocks 1310668 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2174746624 800 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, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done #创建目录并挂载 [root@centos]# mkdir /data [root@centos]# mount /dev/vg01/lv01 /data #实现开机挂载,注意下面ext4位置到底是ext4还是xfs需要根据自己的硬盘类别来配置。 [root@localhost ~]# vi /etc/fstab /dev/vg01/lv01 /data ext4 defaults 0 0 #看到df-lh中显示为/dev/mapper/vg01-lv01。 #尝试使用这种写法 /dev/mapper/vg01-lv01 发现不行,服务器无法重启,所以下面的写法不行。 /dev/mapper/vg01-lv01 /data ext4 defaults 0 0 #lsblk -f 查看磁盘类型FSTYPE。 [root@centos]# lsblk -f
本文链接:https://blog.runxinyun.com/post/216.html 转载需授权!
留言0