lvm磁盘分区以及扩展

下面本人虚拟机上操作,目的是添加一块磁盘到虚拟机上。
1 添加了一块20g的硬盘到虚拟机上
2 重启虚拟机后,fdisk -l 查看
###############################
>fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006a9dc
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 543 4046848 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 543 6528 48073728 83 Linux

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
#################################
如图所示,/dev下面两块盘,sda是当初装机的时候添加的,以分好;sdb是我刚添加的,有21.5G,不知到为什么会变大。
3 在这个磁盘里面分个区
################
>fdisk /dev/sdb
Command (m for help): -n
ommand (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): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

4 再次查看
# fdisk -l
#############################################
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xda573fa6
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
####################################################
这个时候发现 多了一个 /dev/sdb1 的分区
5 创建pv
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
######## 查看pv信息 ################################
# pvdisplay
"/dev/sdb1" is a new physical volume of "5.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 5.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Zuuyby-HczW-ocU6-pJiF-cuFl-343R-uDeVnc
###################################################
6 创建vg
# vgcreate oravg /dev/sdb1
Device /dev/sd1 not found (or ignored by filtering).
Unable to add physical volume '/dev/sd1' to volume group 'oravg'.
######### 查看vg信息 ##########################################
# vgdisplay
--- Volume group ---
VG Name oravg
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 5.01 GiB
PE Size 4.00 MiB
Total PE 1282
Alloc PE / Size 0 / 0
Free PE / Size 1282 / 5.01 GiB
VG UUID Ya0gaU-h2lj-csu2-FL3u-xTYl-SPxi-assYwA
#########################################################
7 创建lv
# lvcreate -L +5G -n oralv oravg
Logical volume "oralv" created
[root@localhost ~]# cd /dev/oravg
[root@localhost oravg]# ls
oralv
########查看lv信息#########################
# lvdisplay
--- Logical volume ---
LV Path /dev/oravg/oralv
LV Name oralv
VG Name oravg
LV UUID nIlaX0-45wz-9EXe-aveA-Zqsq-PNxs-tbbNfd
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-12-19 15:33:28 -0800
LV Status available
# open 1
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
#############################################
8 格式化lv
mkfs.ext4 /dev/oravg/oralv
9 将lv挂载到一个目录上。
mount /dev/oravg/oralv /data

######### 查看挂在前后对比 ##########
[root@localhost oravg]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 46G 2.4G 41G 6% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 291M 37M 240M 14% /boot
[root@localhost oravg]# mount /dev/oravg/oralv /data
[root@localhost oravg]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 46G 2.4G 41G 6% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 291M 37M 240M 14% /boot
/dev/mapper/oravg-oralv
5.0G 138M 4.6G 3% /data
########################################

10 需要将挂载信息放到 /etc/fstab 上面,否则每次重启都要重新挂载。
[root@localhost ~]# vi /etc/fstab

# /etc/fstab
# Created by anaconda on Sun Dec 18 02:25:10 2016
#
# 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
#
UUID=8fe86b5e-2076-42bf-a2d8-5ff60f83e92c / ext4 defaults 1 1
UUID=ec035ceb-4a4e-4a1c-9d3e-a1ebf08ef64c /boot ext4 defaults 1 2
UUID=c5d02b09-9389-43fd-966c-bea884078c0e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/oravg/oralv /data ext4 defaults 0 0

补充; 前面用了5个G还有15G可以继续用,从第三步继续开始。
#############
扩展 vg lv,这时候再添加一块新磁盘 /dev/sdc
> vgextend oravg /dev/sdc
  Volume group "oravg" successfully extended
############系统会自动将/dev/sdc识别成pv##
[root@localhost ~]# vgextend oravg /dev/sdc
No physical volume label read from /dev/sdc
Physical volume "/dev/sdc" successfully created
Volume group "oravg" successfully extended

> lvextend -L +20G /dev/oravg/oralv
> resize2fs /dev/oravg/oralv ##重新定义大小,做完这步才算完成

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31404823/viewspace-2130991/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31404823/viewspace-2130991/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值