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
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
相关文章推荐
- 红帽5和6的网卡绑定
- CentOS 6 升级MySql (5.1.x 到 5.5, 再到5.6)
- 重新学习linux运维,努力让自己走上正轨~!
- 20135337朱荟潼 Linux第七周学习总结——可执行程序的装载
- CentOS下OpenSSL的安装和使用
- Linux练习题
- Centos Netdata 安装与配置
- Linux下同步工具inotify+rsync使用详解
- 树莓派linux驱动学习之hello world
- ArchLinux mount U盘
- Linux下对MySql数据库备份与恢复
- CentOS 6 编译安装Git 2.8.1
- Linux下动态共享库加载时的搜索路径详解
- 查看Linux服务器内存使用情况
- Linux常见命令
- linux 系统安装wifidog
- 快速诊断Linux性能
- linux内核参数注释与优化
- linux内核参数注释与优化
- Rpath handling on Linux