您的位置:首页 > 运维架构 > Linux

linux下,使用lvm 创建、扩充 、缩减 逻辑磁盘大小,以及相应的文件系统大小

2016-04-05 16:01 986 查看
创建LVM

1.用fdisk对硬盘进行格式化

[root@training ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): d

No partition is defined yet!

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@training ~]# fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x192b7b8f.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): d

No partition is defined yet!

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

2.将物理磁盘设备初始化为物理卷pvcreate /dev/sdb /dev/sdc

3.创建卷组,并将PV加入linuxrhel卷组中vgcreate linuxrhel /dev/sdb /dev/sdc

4.基于linuxrhel卷组创建逻辑卷lvcreate -n mylv -L 2G linuxrhel

5.为创建好的逻辑卷创建文件系统

mkfs.ext4 /dev/linuxrhel/mylv

6.将格式化好的逻辑卷挂载使用mount /dev/linuxrhel/mylv /backup

7.[root@dbcs ~]# vi /etc/fstab

添加/dev/mapper/linuxrhel-mylv /backup ext4 defaults 0 0

设置开机自动挂载

可以通过以下命令查看LVM相关信息:

査看物理卷信息:

pvdisplay(详细)

pvs

査看卷组信息:

vgdisplay(详细)

vgs

查看逻辑卷信息:

lvdisplay (洋细)

lvs

删除LVM

1.删除LVlvremove /dev/linuxrhel/mylv

2.删除VGvgremove linuxrhel

3.删除物理卷pvremove /dev/sdb

拉伸逻辑卷

逻辑卷的拉伸操作可以在线执行,不需要卸载逻辑卷

1.保证VG中有足够的空闲空间vgdisplay

2.扩充逻辑卷lvextend -L +1G /dev/linuxrhel/mylv

3.査看扩充后LV大小lvdisplay

4.更新文件系统resize2fs /dev/linuxrhel/mylv

5.査看更新后文件系统df -h

扩展卷组

1.将要添加到VG的硬盘格式化为PVpvcreate /dev/sde

2.将新的PV添加到指定卷组中vgextend linuxrhel /dev/sde

3.査看扩充后VG大小vgdisplay

缩小逻辑卷逻辑卷的缩写操作必须离线执行,要卸载逻辑卷

1.卸载已经挂载的逻辑卷umount /dev/linuxrhel/mylv

2.缩小文件系统会提示需要运行e2fsck –f(遇到错误直接修复不提示)

检查文件系统resize2fs /dev/linuxrhel/mylv 10G(缩小到10个G)

3.缩小LVlvreduce -L -9G /dev/linuxrhel/mylv(减少9G)

4.查看缩小后的LVlvdisplay

5.重新格式化创建文件系统

mkfs.ext4 /dev/linuxrhel/mylv

5.挂载mount /dev/linuxrhel/mylv /mnt

缩小卷组

1.将一个PV从指定卷组中移除vgreduce linuxrhel /dev/sde

2.査看缩小后的卷组大小Vgdisplay

3. 删除物理卷:pvremove /dev/sde
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: