線上添加磁碟,擴充LVM卷案例 一、添加硬碟,線上掃描出來首先到虛擬機器那裡添加一塊硬碟,注意必須是SCSI類型的硬碟。 掃描硬碟,不用重啟作業系統的。echo "- - -" > /sys/class/scsi_host/host0/scanecho "- - -" > /sys/class/scsi_host/host1/scanecho "- - -" > /sys/class/scsi_host/host2/scanecho "- - -" > /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 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = 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 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = 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 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = 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 bytes255 heads, 63 sectors/track, 13054cylindersUnits = 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 bytes255heads, 63 sectors/track, 6527 cylindersUnits= 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 bytes255 heads, 63 sectors/track, 13054cylindersUnits = 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 bytes255heads, 63 sectors/track, 6527 cylindersUnits= 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 -ThFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 ext3 145G 97G 41G 71% //dev/sda1 ext3 99M 13M 82M 14% /boottmpfs 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 createdbi-bkdb:/ # pvcreate /dev/emcpowerl Physical volume "/dev/emcpowerl" successfully createdbi-bkdb:/ #bi-bkdb:/ #bi-bkdb:/ # pvcreate /dev/emcpowerm Physical volume "/dev/emcpowerm" successfully createdbi-bkdb:/ # pvcreate /dev/emcpowern Physical volume "/dev/emcpowern" successfully createdbi-bkdb:/ # pvcreate /dev/emcpowero Physical volume "/dev/emcpowero" successfully createdbi-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 createdbi-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.44tbi-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 -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol002.9G 2.4G 396M 86% //dev/sda1 99M 11M 83M 12% /boottmpfs 1014M 0 1014M 0% /dev/shm[root@virus_update /]# fdisk -lDisk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 652 5132767+ 8e Linux LVMDisk /dev/sdb: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk /dev/sdb doesn't contain a valid partition table[root@virus_update /]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSFdisklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent 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): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-5221, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): Using default value 5221Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@virus_update /]# fdisk -lDisk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 652 5132767+ 8e Linux LVMDisk /dev/sdb: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sdb1 1 5221 41937651 83 Linux[root@virus_update /]# pvcreate /dev/sdb1Physical volume "/dev/sdb1" successfully created[root@virus_update /]# pvdisplay /dev/sdb1--- NEW Physical volume ---PV Name /dev/sdb1VG Name PV Size 39.99 GBAllocatable NOPE Size (KByte) 0Total PE 0Free PE 0Allocated PE 0PV UUID kW7PHZ-CtMC-0SzR-PNvV-OrZW-2s2d-LFfJ6I [root@virus_update /]# vgdisplay--- Volume group ---VG Name VolGroup00System ID Format lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 4.88 GBPE Size 32.00 MBTotal PE 156Alloc PE / Size 156 / 4.88 GBFree PE / Size 0 / 0 VG UUID 4Iob4o-byje-ckbV-7dGt-49zm-J27Q-w0NtrU [root@virus_update /]# vgextend VolGroup00 /dev/sdb1Volume group "VolGroup00" successfully extended[root@virus_update /]# lvextend -L +40G /dev/VolGroup00/[root@virus_update /]# lvscanACTIVE '/dev/VolGroup00/LogVol00' [2.94 GB] inheritACTIVE '/dev/VolGroup00/LogVol01' [1.94 GB] inherit[root@virus_update /]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol002.9G 2.4G 396M 86% //dev/sda1 99M 11M 83M 12% /boottmpfs 1014M 0 1014M 0% /dev/shm[root@virus_update ~]# resize2fs /dev/VolGroup00/LogVol00resize2fs 1.39 (29-May-2006)Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizingrequiredPerforming 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 -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol0041G 2.4G 37G 6% //dev/sda1 99M 11M 83M 12% /boottmpfs 1014M 0 1014M 0% /dev/shm[root@virus_update ~]#