Linux LVM 建立、刪除、擴充__Linux

來源:互聯網
上載者:User
redhat6.2上做LVM
1
先給虛擬機器上的RH加一個硬碟。
2
啟動RH
3
在終端上輸入
[BeiGang@localhost~]$fdisk -l
Disk /dev/sdc: 1073 MB, 1073741824 bytes
……
Disk /dev/sdc doesn't contain a valid partition table
4
分區1
[BeiGang@localhost~]$fdisk /dev/sdc
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +100M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[BeiGang@localhost~]$

5
查看
[BeiGang@localhost~]$fdisk -l
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1          14      112423+  83  Linux

6
分區2
[BeiGang@localhost~]$fdisk /dev/sdc
n
p
2
15
+100M
w

7
查看
[BeiGang@localhost~]$fdisk -l
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1          14      112423+  83  Linux
/dev/sdc2              15          28      112455   83  Linux

8
添加物理卷
[BeiGang@localhost~]$pvcreate /dev/sdc1
  Writing physical volume data to disk "/dev/sdc1"
  Physical volume "/dev/sdc1" successfully created
[BeiGang@localhost~]$pvcreate /dev/sdc2
  Writing physical volume data to disk "/dev/sdc2"
  Physical volume "/dev/sdc2" successfully created
[BeiGang@localhost~]$

9
查看PV
[BeiGang@localhost~]$pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/sdc1           lvm2 a--  109.79m 109.79m
  /dev/sdc2           lvm2 a--  109.82m 109.82m
[BeiGang@localhost~]$

10
建立卷組
[BeiGang@localhost~]$vgcreate VG1 /dev/sdc1 /dev/sdc2
  Volume group "VG1" successfully created
[BeiGang@localhost~]$

11
查看卷組
[BeiGang@localhost~]$vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  VG1        2   0   0 wz--n- 216.00m 216.00m
[BeiGang@localhost~]$

12
建立邏輯卷1
[BeiGang@localhost~]$lvcreate -n lv1 -L +50M VG1
  Rounding up size to full physical extent 52.00 MiB
  Logical volume "lv1" created
[BeiGang@localhost~]$

13
建立邏輯卷2,因為是PE(4M)的整數倍,所以沒有上調
[BeiGang@localhost~]$lvcreate -n lv2 -L +60M VG1
  Logical volume "lv2" created
[BeiGang@localhost~]$

14
查看邏輯卷
[BeiGang@localhost~]$lvs
  LV      VG       Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv1     VG1      -wi-a- 52.00m                                      
  lv2     VG1      -wi-a- 60.00m                                      
[BeiGang@localhost~]$

15
格式化lv1時報找不到該檔案,
[BeiGang@localhost~]$mkfs.ext3 /dev/VG1/lv1

16
掛載lv1
[BeiGang@localhost~]$mount /dev/VG1/lv1 /seconddisk/

17
在檔案夾seconddisk上組建檔案
[BeiGang@localhost~]$touch /seconddisk/{1..9}.txt
[BeiGang@localhost~]$ll /seconddisk/
total 23
-rw-r--r--. 1 root root     0 Nov  8 14:06 1.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 2.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 3.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 4.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 5.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 6.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 7.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 8.txt
-rw-r--r--. 1 root root     0 Nov  8 14:06 9.txt
drwx------. 2 root root 12288 Nov  8 13:51 lost+found
[BeiGang@localhost~]$

18
刪除/dev/VG1/lv1,/dev/VG1/lv2
[BeiGang@localhost~]$lvremove /dev/VG1/lv1
  Can't remove open logical volume "lv1"
[BeiGang@localhost~]$umount /seconddisk/
[BeiGang@localhost~]$lvremove /dev/VG1/lv1
Do you really want to remove active logical volume lv1? [y/n]: y
  Logical volume "lv1" successfully removed
[BeiGang@localhost~]$  
[BeiGang@localhost~]$lvremove /dev/VG1/lv2
Do you really want to remove active logical volume lv2? [y/n]: y
  Logical volume "lv2" successfully removed

19
刪除/dev/VG1
[BeiGang@localhost~]$vgremove /dev/VG1
  Volume group "VG1" successfully removed
[BeiGang@localhost~]$
 
20
刪除物理卷
[BeiGang@localhost~]$pvremove /dev/sdc3
  Labels on physical volume "/dev/sdc3" successfully wiped
[BeiGang@localhost~]$pvremove /dev/sdc2
  Labels on physical volume "/dev/sdc2" successfully wiped
[BeiGang@localhost~]$pvremove /dev/sdc1
  Labels on physical volume "/dev/sdc1" successfully wiped
[BeiGang@localhost~]$


值得說的一點是在做LVM時,檔案類型不必是8e,83也可,具體見下面的Id。
[BeiGang@localhost~]$fdisk -l
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1          14      112423+  83  Linux
/dev/sdc2              15          28      112455   83  Linux


===================
===================
===================
下面再在上面第17步完成後的基礎上再對lv2做一個擴充。
1
首先fdisk搞一個/dev/sdc3
查看:
[BeiGang@localhost~]$ fdisk -l | grep /sdb
/dev/sdc1               1          14      112423+  83  Linux
/dev/sdc2              15          28      112455   83  Linux
/dev/sdc3              29          42      112455   83  Linux

2
增加pv失敗
[BeiGang@localhost~]$ pvcreate /dev/sdc3
  Device /dev/sdc3 not found (or ignored by filtering).

3
載入disc partation:
[BeiGang@localhost~]$ partx -a /dev/sdc
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
[BeiGang@localhost~]$ partx -a /dev/sdc
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3

4
增加pv:
[BeiGang@localhost~]$ pvcreate /dev/sdc3
  Writing physical volume data to disk "/dev/sdc3"
  Physical volume "/dev/sdc3" successfully created

5
擴充sdb3到vg:
[BeiGang@localhost~]$ vgextend /dev/VG1 /dev/sdc3
  Volume group "VG1" successfully extended
[BeiGang@localhost~]$

6
查看VG:
[BeiGang@localhost~]$ vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  VG1        3   1   0 wz--n- 324.00m 272.00m
  VolGroup   1   2   0 wz--n-  19.51g      0

查看LV:
[BeiGang@localhost~]$ lvs
  LV      VG       Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv2 VG1     -wi-a- 52.00m                                      

7
擴充lv
[BeiGang@localhost~]$ lvextend -L +50M /dev/VG1/lv2
  Rounding up size to full physical extent 52.00 MiB
  Extending logical volume lv2 to 104.00 MiB
  Logical volume lv2 successfully resized
[BeiGang@localhost~]$

8
查看:
[BeiGang@localhost~]$ lvs
  LV      VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv2     VG1      -wi-a- 104.00m                                      

9
掛載再查看,lv2隻有51M,剛才擴充的還沒有真正加上
[BeiGang@localhost~]$ mount /dev/VG1/lv2  /mnt
[BeiGang@localhost~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG1-lv2
                       51M  4.9M   43M  11% /mnt
[BeiGang@localhost~]$

10
再resize一下:
[BeiGang@localhost~]$ resize2fs /dev/VG1/lv2

11
再df查看:
[BeiGang@localhost~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG2-lv2   101M  5.3M   91M   6% /mnt
[BeiGang@localhost~]$


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.