linux创建扩展lvm
2018-02-08 16:43
393 查看
linux下给新硬盘创建逻辑卷或扩展逻辑卷,实验环境为新添加的两块30G的硬盘,将这两块硬盘做成逻辑卷
1、查看硬盘标示(sdb、sdc)
ls /dev/ | grep ^sd
2、给硬盘分区
//给硬盘sdb分区
[root@rooo ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x32b0c715.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):
Using default value 3916
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
//给硬盘sdc分区
[root@rooo ~]# 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 0x32b0c715.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):
Using default value 3916
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.·1
3、创建pv物理卷
[root@rooo ~]# pvcreate /dev/sdb1 /dev/sdc1
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully create4、创建vg卷组
[root@rooo ~]# vgcreate testvg /dev/sdb1 /dev/sdc1 //testvg为卷组的名称,总大小为60G
Volume group "testvg" successfully created
//查看testvg的容量大小:
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 59.98g 0
vg_rooo 1 3 0 wz--n- 79.51g 0
5、创建逻辑卷
[root@rooo ~]# lvcreate -L 59G -n testlv testvg
Logical volume "testlv" created
//testlv为逻辑卷名,-L为逻辑卷的大小(逻辑卷的大小不能大于卷组),-n定义逻辑卷的名称
#查看lv的容量大小
[root@rooo ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 59.00g
lv_home vg_rooo -wi-ao---- 27.57g
lv_root vg_rooo -wi-ao---- 50.00g
lv_swap vg_rooo -wi-ao---- 1.94g
6、格式化逻辑卷
[root@rooo ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3866624 inodes, 15466496 blocks
773324 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
472 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on block
9b0d
s:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
7、挂载逻辑卷
mkdir /data
mount /dev/testvg/testlv
8、设置开机自动挂载
vi /etc/fstab
/dev/testvg/testlv /data ext4 defaults 0 0 //在文件末尾添加
[root@rooo ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_rooo-lv_root ext4 50G 7.4G 40G 16% /
tmpfs tmpfs 491M 76K 491M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/vg_rooo-lv_home ext4 28G 172M 26G 1% /home
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/cdrom
/dev/mapper/testvg-testlv ext4 59G 180M 55G 1% /data
9、扩展逻辑卷
注 * 首先查看testvg中是否有剩余空间
查看testvg的容量大小:
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 0(没有剩余空间)
vg_rooo 1 3 0 wz--n- 79.51g 0
①、如果卷组中还有空间,则直接执行如下命令进行扩展,如果没有空间,需要新添加一块硬盘,则按②执行
[root@rooo ~]# lvextend -L 20G /dev/testvg/testlv
②、没有剩余空间,需新添加硬盘进行扩展
#为新磁盘分区:
[root@rooo ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5672831a.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#为新添加的磁盘创建物理卷
[root@rooo ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
#将新创建的物理卷扩展到卷组中
[root@rooo ~]# vgextend testvg /dev/sdd1
Volume group "testvg" successfully extended
#查看testvg的使用情况
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 20.98g
vg_rooo 1 3 0 wz--n- 79.51g 0
#给testlv逻辑卷增加10G
[root@rooo ~]# lvextend -L +10G /dev/testvg/testlv
Extending logical volume testlv to 69.00 GiB
Logical volume testlv successfully resized
#查看lv的容量大小
[root@rooo ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 69.00g
lv_home vg_rooo -wi-ao---- 27.57g
lv_root vg_rooo -wi-ao---- 50.00g
lv_swap vg_rooo -wi-ao---- 1.94g
#再次查看卷组的剩余容量:
[root@rooo ~]# vgsan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 10.98g(剩余10.98G如果有需要还可以扩展给testlv,或创建其他lv)
vg_rooo 1 3 0 wz--n- 79.51g 0
1、查看硬盘标示(sdb、sdc)
ls /dev/ | grep ^sd
2、给硬盘分区
//给硬盘sdb分区
[root@rooo ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x32b0c715.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):
Using default value 3916
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
//给硬盘sdc分区
[root@rooo ~]# 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 0x32b0c715.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):
Using default value 3916
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.·1
3、创建pv物理卷
[root@rooo ~]# pvcreate /dev/sdb1 /dev/sdc1
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully create4、创建vg卷组
[root@rooo ~]# vgcreate testvg /dev/sdb1 /dev/sdc1 //testvg为卷组的名称,总大小为60G
Volume group "testvg" successfully created
//查看testvg的容量大小:
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 59.98g 0
vg_rooo 1 3 0 wz--n- 79.51g 0
5、创建逻辑卷
[root@rooo ~]# lvcreate -L 59G -n testlv testvg
Logical volume "testlv" created
//testlv为逻辑卷名,-L为逻辑卷的大小(逻辑卷的大小不能大于卷组),-n定义逻辑卷的名称
#查看lv的容量大小
[root@rooo ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 59.00g
lv_home vg_rooo -wi-ao---- 27.57g
lv_root vg_rooo -wi-ao---- 50.00g
lv_swap vg_rooo -wi-ao---- 1.94g
6、格式化逻辑卷
[root@rooo ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3866624 inodes, 15466496 blocks
773324 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
472 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on block
9b0d
s:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
7、挂载逻辑卷
mkdir /data
mount /dev/testvg/testlv
8、设置开机自动挂载
vi /etc/fstab
/dev/testvg/testlv /data ext4 defaults 0 0 //在文件末尾添加
[root@rooo ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_rooo-lv_root ext4 50G 7.4G 40G 16% /
tmpfs tmpfs 491M 76K 491M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/vg_rooo-lv_home ext4 28G 172M 26G 1% /home
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/cdrom
/dev/mapper/testvg-testlv ext4 59G 180M 55G 1% /data
9、扩展逻辑卷
注 * 首先查看testvg中是否有剩余空间
查看testvg的容量大小:
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 0(没有剩余空间)
vg_rooo 1 3 0 wz--n- 79.51g 0
①、如果卷组中还有空间,则直接执行如下命令进行扩展,如果没有空间,需要新添加一块硬盘,则按②执行
[root@rooo ~]# lvextend -L 20G /dev/testvg/testlv
②、没有剩余空间,需新添加硬盘进行扩展
#为新磁盘分区:
[root@rooo ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5672831a.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#为新添加的磁盘创建物理卷
[root@rooo ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
#将新创建的物理卷扩展到卷组中
[root@rooo ~]# vgextend testvg /dev/sdd1
Volume group "testvg" successfully extended
#查看testvg的使用情况
[root@rooo ~]# vgscan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 20.98g
vg_rooo 1 3 0 wz--n- 79.51g 0
#给testlv逻辑卷增加10G
[root@rooo ~]# lvextend -L +10G /dev/testvg/testlv
Extending logical volume testlv to 69.00 GiB
Logical volume testlv successfully resized
#查看lv的容量大小
[root@rooo ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 69.00g
lv_home vg_rooo -wi-ao---- 27.57g
lv_root vg_rooo -wi-ao---- 50.00g
lv_swap vg_rooo -wi-ao---- 1.94g
#再次查看卷组的剩余容量:
[root@rooo ~]# vgsan
VG #PV #LV #SN Attr VSize VFree
testvg 3 1 0 wz--n- 79.98g 10.98g(剩余10.98G如果有需要还可以扩展给testlv,或创建其他lv)
vg_rooo 1 3 0 wz--n- 79.51g 0
相关文章推荐
- Linux 创建LVM及扩展文件系统
- Linux LVM 创建、删除、扩展
- Linux LVM 创建、删除、扩展
- Linux环境下创建、扩展以及缩减LVM
- (转)Linux LVM逻辑卷配置过程详解(创建、扩展、缩减、删除、卸载、快照创建)
- Linux下创建、扩展、移除、管理LVM
- Linux 逻辑卷LVM创建扩展删除实例
- linux——添加3块5G硬盘做lvm,2块新建,1块做扩展
- Linux创建LVM
- LVM的创建扩展缩减与删除
- Linux系统基础之创建lvm
- 创建和扩展lvm
- Linux 上创建或扩展交换分区的方法!
- Linux使用图形LVM(Logical Volume Manager)工具进行分区的动态扩展
- LVM 的创建,扩展,缩减及建立快照
- LINUX 下创建RAID5以及LVM磁盘配额
- 【Linux】创建逻辑卷管理(LVM)
- lvm创建及扩展和磁盘配额
- ESXi中Linux虚拟机LVM扩展实例
- LVM的创建、扩展、收缩及快照功能的介绍