码迷,mamicode.com
首页 > 其他好文 > 详细

LVM的创建扩展缩减与删除

时间:2015-02-19 18:38:09      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

LVM Logical Volume Manager 逻辑卷管理,是Linux环境下对磁盘分区进行管理的一种机制。

下面就来实现逻辑卷的 增 删 减   测试环境 Red Hat Enterprise Linux 6.5

技术分享
 1 [root@localhost ~]# fdisk /dev/sdb              #选择要操作的磁盘
 2 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 3 Building a new DOS disklabel with disk identifier 0x789aa6a8.
 4 Changes will remain in memory only, until you decide to write them.
 5 After that, of course, the previous content wont be recoverable.
 6 
 7 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 8 
 9 WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
10          switch off the mode (command c) and change display units to
11          sectors (command u).
12 
13 Command (m for help): p                                 #先查看当前磁盘的分区情况,可以看到没有分区
14 
15 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
16 255 heads, 63 sectors/track, 1305 cylinders
17 Units = cylinders of 16065 * 512 = 8225280 bytes
18 Sector size (logical/physical): 512 bytes / 512 bytes
19 I/O size (minimum/optimal): 512 bytes / 512 bytes
20 Disk identifier: 0x789aa6a8
21 
22    Device Boot      Start         End      Blocks   Id  System
23 
24 Command (m for help): n                    #n 表示创建一个分区
25 Command action
26    e   extended
27    p   primary partition (1-4)
28 p                                                       #p 表示选择主分区类型
29 Partition number (1-4): 1                   #指定分区编号为1
30 First cylinder (1-1305, default 1): 
31 Using default value 1                          #指定起始扇区 默认为1
32 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +2G                                  #指定大小为2G空间
33 
34 Command (m for help): n
35 Command action
36    e   extended
37    p   primary partition (1-4)
38 p  
39 Partition number (1-4): 2
40 First cylinder (263-1305, default 263): 
41 Using default value 263
42 Last cylinder, +cylinders or +size{K,M,G} (263-1305, default 1305): +2G
43 
44 Command (m for help): t                      #改变分区类型
45 Partition number (1-4): 1                     #选择要改变的分区
46 Hex code (type L to list codes): L           #查看系统支持的分区
47 
48  0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
49  1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
50  2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
51  3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
52  4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         
53  5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    
54  6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
55  7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
56  8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         
57  9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
58  a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
59  b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
60  c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
61  e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
62  f  W95 Extd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
63 10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
64 11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      
65 12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      
66 14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
67 16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
68 17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
69 18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
70 1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        
71 1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT            
72 1e  Hidden W95 FAT1
73 Hex code (type L to list codes): 8e              #选择对应码,这里为8e
74 Changed system type of partition 1 to 8e (Linux LVM)
75 
76 Command (m for help): t
77 Partition number (1-4): 2
78 Hex code (type L to list codes): 8e
79 Changed system type of partition 2 to 8e (Linux LVM)      #同上
80 
81 Command (m for help): p                      #再次查看分区情况
82 
83 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
84 255 heads, 63 sectors/track, 1305 cylinders
85 Units = cylinders of 16065 * 512 = 8225280 bytes
86 Sector size (logical/physical): 512 bytes / 512 bytes
87 I/O size (minimum/optimal): 512 bytes / 512 bytes
88 Disk identifier: 0x789aa6a8
89 
90    Device Boot      Start         End      Blocks   Id  System
91 /dev/sdb1               1         262     2104483+  8e  Linux LVM
92 /dev/sdb2             263         524     2104515   8e  Linux LVM
93 
94 Command (m for help): w                  #保存修改并退出
95 The partition table has been altered!
96 
97 Calling ioctl() to re-read partition table.
98 Syncing disks.
Create Partition
技术分享
 1 [root@localhost ~]# pvcreate /dev/sdb[1,2]          #创建物理卷,并指定设备
 2   Physical volume "/dev/sdb1" successfully created
 3   Physical volume "/dev/sdb2" successfully created
 4 [root@localhost ~]# pvs           #查看创建的物理卷
 5   PV         VG       Fmt  Attr PSize  PFree
 6   /dev/sda2  VolGroup lvm2 a--  19.51g    0 
 7   /dev/sdb1           lvm2 a--   2.01g 2.01g
 8   /dev/sdb2           lvm2 a--   2.01g 2.01g
 9 [root@localhost ~]# vgcreate myvg /dev/sdb[1,2]          #创建卷组,指定卷组设备为sdb1 sdb2
10   Volume group "myvg" successfully created
11 [root@localhost ~]# vgs            #查看创建成功后的卷组
12   VG       #PV #LV #SN Attr   VSize  VFree
13   VolGroup   1   2   0 wz--n- 19.51g    0 
14   myvg       2   0   0 wz--n-  4.01g 4.01g
15 [root@localhost ~]# lvcreate -n mylv -L 2G myvg           #创建逻辑卷,并指定名字为 mylv 大小为 2G
16   Logical volume "mylv" created
17 [root@localhost ~]# lvs               #查看创建后的逻辑卷
18   LV      VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
19   lv_root VolGroup -wi-ao---- 17.51g                                             
20   lv_swap VolGroup -wi-ao----  2.00g                                             
21   mylv    myvg     -wi-a-----  2.00g
Create Logical Volume

增:

顺序是从物理到逻辑卷来增加

技术分享
 1 [root@localhost ~]# vgextend myvg /dev/sdb3         #向卷组增加一个分区,它会自动创建物理卷
 2   No physical volume label read from /dev/sdb3
 3   Physical volume /dev/sdb3 not found
 4   Physical volume "/dev/sdb3" successfully created
 5   Volume group "myvg" successfully extended
 6 [root@localhost ~]# pvs                       #查看物理卷多了一个sdb3
 7   PV         VG       Fmt  Attr PSize  PFree
 8   /dev/sda2  VolGroup lvm2 a--  19.51g    0 
 9   /dev/sdb1  myvg     lvm2 a--   2.00g 4.00m
10   /dev/sdb2  myvg     lvm2 a--   2.00g 2.00g
11   /dev/sdb3  myvg     lvm2 a--   2.00g 2.00g
12 [root@localhost ~]# vgs                     #查看卷组PV为3个,大小6G
13   VG       #PV #LV #SN Attr   VSize  VFree
14   VolGroup   1   2   0 wz--n- 19.51g    0 
15   myvg       3   1   0 wz--n-  6.01g 4.01g
16 [root@localhost ~]# resize2fs -p /dev/myvg/mylv          #格式化文件系统
17 [root@localhost ~]# mount /dev/myvg/mylv /mnt/                  #挂载逻辑卷
18 [root@localhost ~]# df -lh               #查看当前空间可用大小
19 Filesystem                    Size  Used Avail Use% Mounted on
20 /dev/mapper/VolGroup-lv_root   18G  1.6G   15G  10% /
21 tmpfs                         935M     0  935M   0% /dev/shm
22 /dev/sda1                     485M   39M  421M   9% /boot
23 /dev/mapper/myvg-mylv         2.0G   67M  1.9G   4% /mnt
24 [root@localhost ~]# lvextend -L 4G /dev/myvg/mylv              #扩展逻辑卷大小为4G
25   Extending logical volume mylv to 4.00 GiB
26   Logical volume mylv successfully resized
27 [root@localhost ~]# resize2fs -p /dev/myvg/mylv        #扩展文件系统,-p 为有多大就用多大
28 resize2fs 1.41.12 (17-May-2010)
29 Filesystem at /dev/myvg/mylv is mounted on /mnt; on-line resizing required
30 old desc_blocks = 1, new_desc_blocks = 1
31 Performing an on-line resize of /dev/myvg/mylv to 1048576 (4k) blocks.
32 The filesystem on /dev/myvg/mylv is now 1048576 blocks long.
33 
34 [root@localhost ~]# df -lh                 #再次查看可用空间
35 Filesystem                    Size  Used Avail Use% Mounted on
36 /dev/mapper/VolGroup-lv_root   18G  1.6G   15G  10% /
37 tmpfs                         935M     0  935M   0% /dev/shm
38 /dev/sda1                     485M   39M  421M   9% /boot
39 /dev/mapper/myvg-mylv         4.0G   68M  3.7G   2% /mnt
Logical Volume ADD

删:

删主要是设备的移除

技术分享
 1 [root@localhost ~]# vgreduce myvg /dev/sdb3        #从卷组中移除设备
 2   Removed "/dev/sdb3" from volume group "myvg"
 3 [root@localhost ~]# vgs                      #查看当前组状态
 4   VG       #PV #LV #SN Attr   VSize  VFree
 5   VolGroup   1   2   0 wz--n- 19.51g    0 
 6   myvg       2   1   0 wz--n-  4.01g 2.01g
 7 [root@localhost ~]# pvremove /dev/sdb3        #移除物理卷
 8   Labels on physical volume "/dev/sdb3" successfully wiped
 9 [root@localhost ~]# pvs                          #查看当前物理卷状态
10   PV         VG       Fmt  Attr PSize  PFree
11   /dev/sda2  VolGroup lvm2 a--  19.51g    0 
12   /dev/sdb1  myvg     lvm2 a--   2.00g 4.00m
13   /dev/sdb2  myvg     lvm2 a--   2.00g 2.00g
Device Sub

 

减:

顺序和增是相反的

这里要注意的是,要先卸载-》强制检查-》收缩文件系统-》收缩逻辑卷-》收缩组

技术分享Logical Volume Subtract

LVM的创建扩展缩减与删除

标签:

原文地址:http://www.cnblogs.com/mmic/p/4296213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!