分类: Aws
AWS上快速创建LVM

名词解释:

PV(Physical Volume) - 物理卷
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备

VG(Volume Group) - 卷组
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组

LV(Logical Volume) - 逻辑卷
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组

929849-20180511172228368-364897317.png

创建LVM步骤

添加新硬盘;
给新硬盘创建分区;
创建PV;
创建VG;
创建LV;
格式化LV;
挂载LV到指定目录;

在AWS上创建LVM步骤如下:

1、先在控制台上添加存储;
2、查看添加的硬盘,

[root@hongsinvm ~]# fdisk -l

Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 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/nvme0n1: 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: 0x000c7ec9

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme0n1p1   *        2048     2099199     1048576   83  Linux
/dev/nvme0n1p2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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

创建lvm 8e分区:

[root@hongsinvm ~]# fdisk /dev/nvme1n1
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 0x56ce9c54.

Command (m for help): o
Building a new DOS disklabel with disk identifier 0x98e04e99.

Command (m for help): p

Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 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: 0x98e04e99

        Device Boot      Start         End      Blocks   Id  System

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-943718399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-943718399, default 943718399):
Using default value 943718399
Partition 1 of type Linux and of size 450 GiB is set

Command (m for help): p

Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 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: 0x98e04e99

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme1n1p1            2048   943718399   471858176   83  Linux

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): p

Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 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: 0x98e04e99

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme1n1p1            2048   943718399   471858176   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

重新读取分区

partprobe

创建PV

[root@hongsinvm ~]# pvcreate /dev/nvme1n1p1
  Physical volume "/dev/nvme1n1p1" successfully created.

创建VG

[root@hongsinvm ~]# vgcreate datavg /dev/nvme1n1p1
  Volume group "datavg" successfully created

创建LV

[root@hongsinvm ~]# lvcreate -l 100%free -n datalv datavg
  Logical volume "datalv" created.

格式化LV

[root@hongsinvm ~]# mkfs.ext4 /dev/datavg/datalv
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
29491200 inodes, 117963776 blocks
5898188 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2267021312
3600 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, 71663616, 78675968,
        102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

创建分区并挂载

[root@hongsinvm ~]# mkdir /data
[root@hongsinvm ~]# mount /dev/datavg/datalv /data/
[root@hongsinvm ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                    16G     0   16G   0% /dev
tmpfs                       16G     0   16G   0% /dev/shm
tmpfs                       16G   17M   16G   1% /run
  pfs                       16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root     17G  1.9G   16G  12% /
/dev/nvme0n1p1            1014M  265M  750M  27% /boot
tmpfs                      3.1G     0  3.1G   0% /run/user/0
/dev/mapper/datavg-datalv  443G   73M  421G   1% /data

加入开机启动

[root@hongsinvm ~]# blkid
/dev/mapper/centos-root: UUID="2489f74a-946e-452a-bf62-1a1890668844" TYPE="xfs"
/dev/nvme0n1p2: UUID="c6AGGx-gtd0-N6XE-5qP2-phqY-V4Hr-BurxpM" TYPE="LVM2_member"
/dev/nvme0n1p1: UUID="75eb43ef-927b-4b24-af8e-bfc46bd0c2c2" TYPE="xfs"
/dev/mapper/centos-swap: UUID="9424b55f-2eb2-4156-b6ea-8d4bacf27d02" TYPE="swap"
/dev/nvme1n1p1: UUID="D0fh8n-ezI3-2Ork-bdAY-d0mE-R8eC-DrtDSy" TYPE="LVM2_member"
/dev/mapper/datavg-datalv: UUID="35c5eb3d-a7a0-4365-9ab9-91e1069c1d65" TYPE="ext4"
/dev/nvme1n1: PTTYPE="dos"
/dev/nvme0n1: PTTYPE="dos"
[root@hongsinvm ~]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Aug 13 06:35:13 2019
#
# 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=75eb43ef-927b-4b24-af8e-bfc46bd0c2c2       /boot   xfs     defaults        0 0
UUID=35c5eb3d-a7a0-4365-9ab9-91e1069c1d65       /data   ext4    defaults        0 0
/dev/mapper/centos-swap swap    swap    defaults        0 0

"/etc/fstab" 12L, 458C written
[root@hongsinvm ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                    16G     0   16G   0% /dev
tmpfs                       16G     0   16G   0% /dev/shm
tmpfs                       16G   17M   16G   1% /run
tmpfs                       16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root     17G  1.9G   16G  12% /
/dev/nvme0n1p1            1014M  265M  750M  27% /boot
tmpfs                      3.1G     0  3.1G   0% /run/user/0
/dev/mapper/datavg-datalv  443G   73M  421G   1% /data


相关博文:

发表新评论