ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux的lvm创建和管理

linux的lvm创建和管理

原创 Linux操作系统 作者:webseven 时间:2013-05-26 11:14:19 0 删除 编辑

1.检查软件包是否已安装.

[root@nc81 bin]# rpm -aq|grep lvm
system-config-lvm-1.1.5-1.0.el5
lvm2-2.02.46-8.el5

2.创建分区:

[root@nc81 bin]# fdisk /dev/cciss/c0d1

The number of cylinders for this disk is set to 35132.
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)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-35132, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-35132, default 35132): +40000m      

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (9576-35132, default 9576):
Using default value 9576
Last cylinder or +size or +sizeM or +sizeK (9576-35132, default 35132): +40000m

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (19151-35132, default 19151):
Using default value 19151
Last cylinder or +size or +sizeM or +sizeK (19151-35132, default 35132):
Using default value 35132

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): t
Hex code (type L to list codes): L

 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       bf  Solaris       
 1  FAT12           24  NEC DOS         81  Minix / old Lin c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          82  Linux swap / So c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c7  Syrinx        
 5  Extended        41  PPC PReP Boot   85  Linux extended  da  Non-FS data   
 6  FAT16           42  SFS             86  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set de  Dell Utility  
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext df  BootIt        
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access    
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e3  DOS R/O       
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor     
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs       
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT       
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor     
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor     
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f2  DOS secondary 
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     fb  VMware VMFS   
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep       
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT           
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.

[root@nc81 bin]# fdisk -l

Disk /dev/cciss/c0d0: 293.5 GB, 293563949056 bytes
255 heads, 63 sectors/track, 35690 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1         127     1020096   83  Linux
/dev/cciss/c0d0p2             128        2677    20482875   82  Linux swap / Solaris
/dev/cciss/c0d0p3            2678       35690   265176922+  83  Linux

Disk /dev/cciss/c0d1: 146.7 GB, 146778685440 bytes
255 heads, 32 sectors/track, 35132 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d1p1               1        9575    39065984   8e  Linux LVM
/dev/cciss/c0d1p2            9576       19150    39066000   8e  Linux LVM
/dev/cciss/c0d1p3           19151       35132    65206560   8e  Linux LVM

3.创建物理卷:

[root@nc81 bin]# pvcreate /dev/cciss/c0d1p1 /dev/cciss/c0d1p2
  Physical volume "/dev/cciss/c0d1p1" successfully created
  Physical volume "/dev/cciss/c0d1p2" successfully created


[root@nc81 bin]# pvcreate /dev/cciss/c0d1p3
  Physical volume "/dev/cciss/c0d1p3" successfully created

4.创建卷组:

[root@nc81 bin]# vgcreate vgdata /dev/cciss/c0d1p1 /dev/cciss/c0d1p2
  Volume group "vgdata" successfully created


[root@nc81 bin]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vgdata" using metadata type lvm2

[root@nc81 bin]# vgchange -ay vgdata
  0 logical volume(s) in volume group "vgdata" now active

5.创建逻辑卷:

[root@nc81 bin]# lvcreate -L30G -n lvdata vgdata
  Logical volume "lvdata" created


[root@nc81 bin]# lvscan
  ACTIVE            '/dev/vgdata/lvdata' [30.00 GB] inherit

[root@nc81 mnt]# mkfs.ext3 /dev/vgdata/lvdata

[root@nc81 mnt]# mount /dev/vgdata/lvdata /mnt/mylvdata

6.逻辑卷扩容:

[root@nc81 bin]# pvscan
  PV /dev/cciss/c0d1p1   VG vgdata          lvm2 [37.25 GB / 7.25 GB free]
  PV /dev/cciss/c0d1p2   VG vgdata          lvm2 [37.25 GB / 37.25 GB free]
  PV /dev/cciss/c0d1p3                      lvm2 [62.19 GB]
  Total: 3 [136.69 GB] / in use: 2 [74.51 GB] / in no VG: 1 [62.19 GB]


[root@nc81 bin]# vgextend vgdata /dev/cciss/c0d1p3
  Volume group "vgdata" successfully extended
[root@nc81 bin]# pvscan
  PV /dev/cciss/c0d1p1   VG vgdata   lvm2 [37.25 GB / 7.25 GB free]
  PV /dev/cciss/c0d1p2   VG vgdata   lvm2 [37.25 GB / 37.25 GB free]
  PV /dev/cciss/c0d1p3   VG vgdata   lvm2 [62.18 GB / 62.18 GB free]
  Total: 3 [136.69 GB] / in use: 3 [136.69 GB] / in no VG: 0 [0   ]

[root@nc81 mnt]# lvextend -L +4096M /dev/vgdata/lvdata
  Extending logical volume lvdata to 34.00 GB
  Logical volume lvdata successfully resized


[root@nc81 mnt]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/cciss/c0d0p3     245G  147G   87G  63% /
/dev/cciss/c0d0p1     965M   24M  892M   3% /boot
tmpfs                 5.9G     0  5.9G   0% /dev/shm
/dev/mapper/vgdata-lvdata
                       30G  173M   28G   1% /mnt/mylvdata

[root@nc81 mnt]# umount /mnt/mylvdata


[root@nc81 mnt]# e2fsck -f /dev/vgdata/lvdata
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgdata/lvdata: 11/3932160 files (9.1% non-contiguous), 167443/7864320 blocks

[root@nc81 mnt]# resize2fs /dev/vgdata/lvdata
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vgdata/lvdata to 8912896 (4k) blocks.
The filesystem on /dev/vgdata/lvdata is now 8912896 blocks long.

[root@nc81 mnt]# mount /dev/vgdata/lvdata /mnt/mylvdata
[root@nc81 mnt]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/cciss/c0d0p3     245G  147G   87G  63% /
/dev/cciss/c0d0p1     965M   24M  892M   3% /boot
tmpfs                 5.9G     0  5.9G   0% /dev/shm
/dev/mapper/vgdata-lvdata
                       34G  177M   32G   1% /mnt/mylvdata

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26442672/viewspace-762028/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-01-30

  • 博文量
    20
  • 访问量
    136480