在線添加磁盤,擴展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 ~]#