知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

在线添加磁盘,扩展LVM卷案例

发布时间:2014-09-05 14:08:15作者:知识屋

在线添加磁盘,扩展LVM卷案例
 
一、添加硬盘,在线扫描出来
首先到虚拟机那里添加一块硬盘,注意必须是SCSI类型的硬盘。
 
扫描硬盘,不用重启操作系统的。
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
echo "- - -" > /sys/class/scsi_host/host3/scan
.......
echo "- - -" > /sys/class/scsi_host/hostn/scan
 
有几个host就扫描几次就可以了!记得修改host的编号。我经过测试发现,无论是虚拟机还是物理机,从远端存储分配一些物理卷给主机,主机上都可以直接用这个命令把新添加的硬盘识别出来。
然后再运行fdisk -l就能发现新添加的硬盘已经被系统识别了,查看系统日志/var/log/messages,发现对SCSI设备进行了一次重新扫描
注意:三个- – -号之间有空隔。
以下是我添加完硬盘以后执行的过程:
[root@con4test ~]# fdisk -l
 
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sda1   *           1          13      104391  83  Linux
/dev/sda2              14       13054  104751832+  8e  Linux LVM
 
[root@con4test ~]# echo "- - -" >/sys/class/scsi_host/host0/scan
[root@con4test ~]#
 
[root@con4test ~]# fdisk -l
 
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sda1   *           1          13      104391  83  Linux
/dev/sda2              14       13054  104751832+  8e  Linux LVM
 
Disk /dev/sdb: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Disk /dev/sdb doesn't contain a valid partition table
 
二、添加硬盘到原有分区
在RedHat 使用中,我们经常会碰到硬盘空间用完的问题。今天也是因为服务器硬盘空间用完,才用到这个增加硬盘,并加入LVM现有空间的操作。
 
详细内容见内文。
 
1.收集相关数据
执行如下命令:
 
 
[root@con4test ~]#vgs
 /dev/hdc: open failed: No medium found
 VG         #PV #LV #SN Attr   VSize VFree
 VolGroup00   1   2   0wz--n- 99.88G    0
 
 
[root@con4test ~]# lvs-a -o +devices
 /dev/hdc: open failed: No medium found
 LV       VG         Attr  LSize   Origin Snap%  Move Log Copy%  Convert Devices
 LogVol00 VolGroup00 -wi-ao 99.12G                                      /dev/sda2(0)
 LogVol01 VolGroup00 -wi-ao 768.00M                                      /dev/sda2(3172)
 
2.新加硬盘初始化配置
执行如下命令:
 
[root@con4test ~]# fdisk-l
 
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14      13054   104751832+  8e Linux LVM
 
Disk/dev/sdb: 53.6 GB, 53687091200 bytes
255heads, 63 sectors/track, 6527 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes
 
Disk/dev/sdb doesn't contain a valid partition table
 
 
fdisk /dev/sdb
 
将硬盘分为一个分区。结果如下:
 
 [root@con4test~]# fdisk -l
 
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14       13054  104751832+  8e  Linux LVM
 
Disk/dev/sdb: 53.6 GB, 53687091200 bytes
255heads, 63 sectors/track, 6527 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks  Id  System
/dev/sdb1               1        6527   52428096   83  Linux
 
 
执行如下命令:
[root@con4test ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
 
3.LVM配置命令详解
 
pvcreate  /dev/sdb1  #将sdb1创建为pv,可以先用pvdisplay查看情况
 
vgcreatevmax_bkup /dev/emcpowerk  /dev/emcpowerl   #VG创建
 
vgrenamevmax_bkup vmax_bkupvg   #VG重命名
 
lvcreate   -L 2.43T   -i 5   -I1024  -n  vmax_bkuplv   vmax_bkupvg  
                                               #LV创建,-L指定lv大小,-i指定条带化个数,-I指定条带化尺寸,-n指定lv名称
 
mkfs-t ext3  /dev/vmax_bkupvg/vmax_bkuplv
 
vgextend  VolGroup00  /dev/sdb1 #将sdb1加入到VolGroup00
 
lvextend –l  +100%FREE  /dev/VolGroup00/LogVol00  #扩展所有空余空间
 
resize2fs  –f /dev/VolGroup00/LogVol00
 
4.配置后的核实
执行如下命令:
 
[root@con4test ~]# vgs
 VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup00   2  2   0 wz--n- 149.84G    0
 
 [root@con4test ~]#lvs -a -o +devices
 LV       VG         Attr  LSize   Origin Snap%  Move Log Copy%  Convert Devices
 LogVol00 VolGroup00 -wi-ao 149.09G                                      /dev/sda2(0)
 LogVol00 VolGroup00 -wi-ao 149.09G                                      /dev/sdb1(0)
 LogVol01 VolGroup00 -wi-ao 768.00M                                      /dev/sda2(3172)
 
[root@con4test ~]#df -Th
Filesystem    Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
              ext3    145G  97G   41G  71% /
/dev/sda1     ext3    99M   13M   82M 14% /boot
tmpfs       tmpfs    3.9G     0 3.9G   0% /dev/shm
 
本篇文章来源于 Linux公社网站(www.linuxidc.com)  原文链接:http://www.linuxidc.com/Linux/2010-04/25799.htm
 
 
常见错误:
[root@con4test ~]# vgextend volgroup00/dev/sdb1
 /dev/hdc: open failed: No medium found
 Volume group "volgroup00" not found
[root@con4test ~]# vgextend VolGroup00/dev/sdb1
  Nophysical volume label read from /dev/sdb1
  /dev/sdb1not identified as an existing physical volume
 Unable to add physical volume '/dev/sdb1' to volume group 'VolGroup00'.
 
需要先创建pv
[root@con4test ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
三.案例(EMC存储上的卷划分LVM详细过程)
pvcreate /dev/emcpowerk
 Physical volume "/dev/emcpowerk" successfully created
bi-bkdb:/ # pvcreate /dev/emcpowerl
 
 
 Physical volume "/dev/emcpowerl" successfully created
bi-bkdb:/ #
bi-bkdb:/ #
bi-bkdb:/ # pvcreate /dev/emcpowerm
 Physical volume "/dev/emcpowerm" successfully created
bi-bkdb:/ # pvcreate /dev/emcpowern
 Physical volume "/dev/emcpowern" successfully created
bi-bkdb:/ # pvcreate /dev/emcpowero
 Physical volume "/dev/emcpowero" successfully created
bi-bkdb:/ #
bi-bkdb:/ #
bi-bkdb:/ # pvscan
  PV/dev/emcpowerb   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowera   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerc   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerf   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowere   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerd   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerg   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerj   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerh   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpoweri   VG oraclevg        lvm2 [500.00 GiB / 0    free]
  PV/dev/emcpowerk                      lvm2 [500.00 GiB]
  PV/dev/emcpowerl                      lvm2[500.00 GiB]
  PV/dev/emcpowerm                      lvm2[500.00 GiB]
  PV/dev/emcpowern                      lvm2[500.00 GiB]
  PV/dev/emcpowero                      lvm2[500.00 GiB]
 Total: 15 [7.32 TiB] / in use: 10 [4.88 TiB] / in no VG: 5 [2.44 TiB]
bi-bkdb:/ # vgcreate vmax_bkup/dev/emcpowerk  /dev/emcpowerl/dev/emcpowerm /dev/emcpowern /dev/emcpowero
 Volume group "vmax_bkup" successfully created
bi-bkdb:/ #
bi-bkdb:/ #
bi-bkdb:/ # vgscan
 Reading all physical volumes. This may take a while...
 Found volume group "vmax_bkup" using metadata type lvm2
 Found volume group "oraclevg" using metadata type lvm2
 
bi-bkdb:/ # vgrename vmax_bkup vmax_bkupvg
 Volume group "vmax_bkup" successfully renamed to"vmax_bkupvg"
 
bi-bkdb:/ # vgs
 VG          #PV #LV #SN Attr   VSize VFree
 oraclevg     10   2   0wz--n- 4.88t    0
 vmax_bkupvg   5   0   0wz--n- 2.44t 2.44t
bi-bkdb:/ # lvcreate -L  2.43T -i 5 -I 1024  -n vmax_bkuplv vmax_bkupvg
 Rounding up size to full physical extent 2.43 TiB
 Logical volume "vmax_bkuplv" created
 
bi-bkdb:/ # mkfs -t ext3 -c/dev/vmax_bkupvg/vmax_bkuplv
 
 
四.案例(redhat AS5的LVM在线扩充)
redhat AS5 LVM添加磁盘空间 实例
 
[root@virus_update /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2.9G 2.4G 396M 86% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
[root@virus_update /]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 652 5132767+ 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@virus_update /]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSFdisklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
 
The number of cylinders for this disk is set to 5221.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): 
Using default value 5221
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@virus_update /]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 652 5132767+ 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 5221 41937651 83 Linux
[root@virus_update /]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@virus_update /]# pvdisplay /dev/sdb1
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name 
PV Size 39.99 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kW7PHZ-CtMC-0SzR-PNvV-OrZW-2s2d-LFfJ6I
 
[root@virus_update /]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID 
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 4.88 GB
PE Size 32.00 MB
Total PE 156
Alloc PE / Size 156 / 4.88 GB
Free PE / Size 0 / 0 
VG UUID 4Iob4o-byje-ckbV-7dGt-49zm-J27Q-w0NtrU
 
[root@virus_update /]# vgextend VolGroup00 /dev/sdb1
Volume group "VolGroup00" successfully extended
[root@virus_update /]# lvextend -L +40G /dev/VolGroup00/
[root@virus_update /]# lvscan
ACTIVE '/dev/VolGroup00/LogVol00' [2.94 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [1.94 GB] inherit
[root@virus_update /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2.9G 2.4G 396M 86% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
[root@virus_update ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizingrequired
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 10993664 (4k)blocks.
 
The filesystem on /dev/VolGroup00/LogVol00 is now 10993664 blocks long.
[root@virus_update ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
41G 2.4G 37G 6% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
[root@virus_update ~]#
 
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜