ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

LVM创建及管理

2020-10-14 14:31:26  阅读:242  来源: 互联网

标签:管理 创建 bytes dev template LVM 512 root size


安装lvm

```
yum install -y lvm
```

查看磁盘

```
[root@template ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000beec6

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 20971519 9436160 8e Linux LVM

Disk /dev/vdb: 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-root: 8585 MB, 8585740288 bytes, 16769024 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: 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
```

初始化

```
[root@template ~]# fdisk /dev/vdb
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 0xda419f51.

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

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 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.

```

将磁盘添加到LVM PV

```
[root@template ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
```

列出所有PV

```
[root@template ~]# pvscan
PV /dev/vda2 VG centos lvm2 [<9.00 GiB / 0 free]
PV /dev/vdb1 lvm2 [<50.00 GiB]
Total: 2 [<59.00 GiB] / in use: 1 [<9.00 GiB] / in no VG: 1 [<50.00 GiB]
```

显示pv更多信息

```
[root@template ~]# pvdisplay /dev/vdb1
"/dev/vdb1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 4kmSEn-kBZG-vMJc-T03x-aWfO-dEes-5prCUL
```

创建卷组:使用尽可能多的PV来创建VG

```
[root@template ~]# vgcreate share /dev/vdb1
Volume group "share" successfully created
```

列出所有VG

```
[root@template ~]# vgscan
Reading volume groups from cache.
Found volume group "share" using metadata type lvm2
Found volume group "centos" using metadata type lvm2
```

显示vg更多信息

```
[root@template ~]# vgdisplay share
--- Volume group ---
VG Name share
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size <50.00 GiB
PE Size 4.00 MiB
Total PE 12799
Alloc PE / Size 0 / 0
Free PE / Size 12799 / <50.00 GiB
VG UUID t9gVEp-02O6-IK40-oNxs-fdFC-nuA3-Y5NgNU
```

创建逻辑卷:使用VG创建任意数量的LV

```
[root@template ~]# lvcreate --size 49G --name vg_data share
Logical volume "vg_data" created.
```

列出所有LV

```
[root@template ~]# lvscan
ACTIVE '/dev/share/vg_data' [49.00 GiB] inherit
ACTIVE '/dev/centos/swap' [1.00 GiB] inherit
ACTIVE '/dev/centos/root' [<8.00 GiB] inherit
```

格式化

```
[root@template ~]# mkfs.ext4 /dev/share/vg_data
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
3211264 inodes, 12845056 blocks
642252 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
392 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

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

创建需要挂载到的目录

```
[root@template ~]# mkdir -p /data
```

挂载

```
[root@template ~]# mount /dev/mapper/share-vg_data /data
```

查看

```
[root@template ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 5.7G 0 5.7G 0% /dev
tmpfs 5.7G 0 5.7G 0% /dev/shm
tmpfs 5.7G 8.6M 5.7G 1% /run
tmpfs 5.7G 0 5.7G 0% /sys/fs/cgroup
/dev/mapper/centos-root 8.0G 1.8G 6.3G 22% /
/dev/vda1 1014M 231M 784M 23% /boot
tmpfs 1.2G 0 1.2G 0% /run/user/0
/dev/mapper/share-vg_data 49G 53M 46G 1% /data
```

开机自动挂载

```
[root@template ~]# vim /etc/fstab

/dev/mapper/share-vg_data /data ext4 defaults 0 0
```

增加100G到/data

```
[root@vmhost2 ~]# lvextend --size +500G --resizefs /dev/mapper/VGsdb1T-vm_main
Size of logical volume VGsdb1T/vm_main changed from 400.00 GiB (102400 extents) to 900.00 GiB (230400 extents).
Logical volume VGsdb1T/vm_main successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/VGsdb1T-vm_main is mounted on /data; on-line resizing required
old_desc_blocks = 50, new_desc_blocks = 113
The filesystem on /dev/mapper/VGsdb1T-vm_main is now 235929600 blocks long.

```

查看

```
df -h
```

 

标签:管理,创建,bytes,dev,template,LVM,512,root,size
来源: https://www.cnblogs.com/heyongboke/p/13814768.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有