RedHat基于LVM建立逻辑卷

LVM这斯出来好些年了,而且安装linux的时候,如果你默认不选的话,它就会默认给你建成LVM分区。因此一直坚持手工分区,然后建立不同的逻辑分区用作不同的用处。LVM最主要的一个功能就是把多个逻辑分区合并在一块儿,当一个逻辑分区使。这不,有机会把两块2T的硬盘合并成一个分区使,先前没玩过,记录一下,权当学习笔记
1.查看现有分区情况

fdisk -l

Disk /dev/sda: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sda doesn't contain a valid partition table

Disk /dev/sdb: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

2.建立逻辑分区,并将分区类型设为Linux LVM

[root@ftpServer ~]#fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
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 243201.
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-243201, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-243201, default 243201):
Using default value 243201

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 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@ftpServer ~]#fdisk -l

Disk /dev/sda: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1      243201  1953512001   8e  Linux LVM

Disk /dev/sdb: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      243201  1953512032   8e  Linux LVM

3.建立物理逻辑卷

[root@ftpServer ~]#pvcreate /dev/sda1 /dev/sdb1
  Physical volume "/dev/sda1" successfully created
  Physical volume "/dev/sdb1" successfully created
[root@ftpServer ~]#pvscan
  PV /dev/sda1                      lvm2 [1.82 TB]
  PV /dev/sdb1                      lvm2 [1.82 TB]
  Total: 2 [3.64 TB] / in use: 0 [0   ] / in no VG: 2 [3.64 TB]

验证是否成功建立

[root@ftpServer ~]#pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               myVG
  PV Size               1.82 TB / not usable 2.56 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              476931
  Free PE               476931
  Allocated PE          0
  PV UUID               2eGGog-3yJc-JVXQ-HJFG-6mLR-m30R-y1k95c
   
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               myVG
  PV Size               1.82 TB / not usable 2.59 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              476931
  Free PE               476931
  Allocated PE          0
  PV UUID               iNEt1m-S4nS-VbZH-jSyM-7hyq-45cD-oE6AJF
   
[root@ftpServer ~]#pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sda1  myVG lvm2 a-   1.82T 1.82T
  /dev/sdb1  myVG lvm2 a-   1.82T 1.82T

4.建立一个叫myVG的卷组

[root@ftpServer ~]#vgcreate myVG /dev/sda1 /dev/sdb1
  Volume group "myVG" successfully created
[root@ftpServer ~]#vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "myVG" using metadata type lvm2

查看卷组

[root@ftpServer ~]#vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myVG   2   0   0 wz--n- 3.64T 3.64T
[root@ftpServer ~]#vgdisplay
  --- Volume group ---
  VG Name               myVG
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.64 TB
  PE Size               4.00 MB
  Total PE              953862
  Alloc PE / Size       0 / 0  
  Free  PE / Size       953862 / 3.64 TB
  VG UUID               pdUK9b-WSui-4oZy-vfRp-8izu-tYoH-xBYwH2

5.从卷组myVG上创建一个逻辑卷 注意-L的大小,一定要在myVG的大小范围内,不然建立不成功哟,这个地方郁闷了小一会儿

[root@ftpServer ~]#lvcreate -L 3.60TB -n mvlv myVG
  Rounding up size to full physical extent 3.60 TB
  Logical volume "mvlv" created
[root@ftpServer ~]#lvscan
  ACTIVE            '/dev/myVG/mvlv' [3.60 TB] inherit

6.给新创建的逻辑卷分区 话说3.6TB分区真挺费时间的

[root@ftpServer ~]#mkfs.ext3 /dev/myVG/mvlv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
483196928 inodes, 966368256 blocks
48318412 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
29492 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    102400000, 214990848, 512000000, 550731776, 644972544

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

7.挂载到一个目录就可以用喽~

[root@ftpServer ~]#mount /dev/myVG/mvlv /data1
[root@ftpServer data1]#df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sdc3             449G  425G  1.2G 100% /
/dev/sdc1             190M   17M  164M  10% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm
/dev/mapper/myVG-mvlv
                      3.6T  5.2G  3.4T   1% /data1

怎样开机自动加载不用多说了吧?

参考资料:
在Red Hat Linux5下建立LVM逻辑卷

转载请注明: 转自Rainbird的个人博客
   本文链接: RedHat基于LVM建立逻辑卷


相关博文

    分享到:

About rainbird

IOS攻城狮
This entry was posted in linux系统运维 and tagged , , , , , , , . Bookmark the permalink.

发表评论