linux下使用逻辑卷(LVM)实现多块硬盘的整和与可持续扩充

来自:http://space.baidu.com/hl_jacky/blog/item/69c942e88d623bd8d439c952.html

操作环境:RedHat Linux AS 4 update 5;联想服务器SCSI硬盘4块

声明:本章内容只针对LVM相关操作,其中涉及到fdisk分区软件,操作系统安装等读者请自行学习

现在由于硬盘越来越大,和一些应用的特殊需要,往往需要一个巨大而又可持续扩充的存储空间。

实现这个目标一般有两种途径

1、购买新的硬盘,这样的新设备虽然价格高但是性能好而且维护方便,但是无法实现根据应用的适时扩充。

2、利用现有的多块盘通过逻辑卷功能将其整合到一起,不必增加新的投入,却获得了一个新的大容量存储设备并且该设备还可以进行适时扩展

下边我们谈一下如何配置和使用逻辑卷:

准备工作:建立逻辑卷需要空的分区或硬盘若干——大于等于1个(块)

为新建立的存储设备准备一个挂载点吧!不然建好了怎么用啊?

现在正式开始我们的LVM旅程

1、使用linux自带的分区工具fdisk对分区或硬盘进行操作,这一步一定要看好了啊,不然错杀忠良可怪不得高某人。过程如下

[root@VPNSERV ~]# fdisk -l                                                                                   ####查看当前系统中有那些可用设备

Disk /dev/sda: 36.7 GB, 36703934464 bytes                                                     ####这个看来没法用了应该是操作系统所在的盘PASS
63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sda1   *           1          13      104391   83 Linux
/dev/sda2              14        1925    15358140   83 Linux
/dev/sda3            1926        2435     4096575   82 Linux swap
/dev/sda4            2436        4462    16281877+   5 Extended
/dev/sda5            2436        4462    16281846   83 Linux

Disk /dev/sdb: 36.7 GB, 36703918080 bytes                                                      ####这个是块空盘只有一个linux分区看来可以使用啊(当然了是我新挂上的)
63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1        4462    35840983+ 83 Linux                                     ####这里可以看到该分区的ID标识为83,组建LVM需要的ID是8e,否则无法建立PV后边我们将修改该ID

Disk /dev/sdc: 36.7 GB, 36703918080 bytes                                                      ####这个也是新挂的盘也是只有一个linux分区
63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdc1               1        4462    35840983+ 83 Linux                                     

对于如何判断哪个分区/硬盘正在使用可以利用mount命令查看,新插入的磁盘一定没有被mount上,那么结合fdisk的结果和e2lable把所有正在使用的磁盘排除,剩下的大致就是可以随便搞的了


[root@VPNSERV ~]# fdisk /dev/sdb                                                                      ####使用fdisk对第一块空盘进行分区和修改分区的操作,fdisk有一个好处是在你使用w提交修改前随便怎么弄都可以。

The number of cylinders for this disk is set to 4462.
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): p                                                                                         ####分区之前使用p打印一下当前的分区表,这是个好习惯,可以再次确认这是不是你要操作的盘

Disk /dev/sdb: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1        4462    35840983+ 83 Linux                                       ####看到当前已经有一个分区了,ID是83我们直接把它修改了就行

Command (m for help): t                                                                                           ####是用t来为分区打/修改标记
Selected partition 1                                                                                                    ####对哪个分区进行操作,这里只有一个所以添1
Hex code (type L to list codes): 8e                                                                           ####输入新的标记8e
Changed system type of partition 1 to 8e (Linux LVM)                                        ####提示该分区变成LVM分区了

Command (m for help): p                                                                                         ####再次使用p查看分区情况

Disk /dev/sdb: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1        4462    35840983+ 8e Linux LVM                                 ####果然分区ID变为8e了

Command (m for help): w                                                                                          ####以上所有操作确认没有问题了下定决心使用w进行存盘操作
The partition table has been altered!

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

[[root@VPNSERV ~]# fdisk /dev/sdc                                                                           ####另一块盘也照上边的步骤操作不再多说

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

Disk /dev/sdc: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdc1               1        4462    35840983+ 83 Linux

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): p

Disk /dev/sdc: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/sdc1               1        4462    35840983+ 8e Linux LVM

Command (m for help): w                                                                                      ####好了存盘
The partition table has been altered!

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

到这里为止,分区的准备已经完成了,lvm的构成分区不知有没有个数限制,不过十几个还是可以的,相信没有谁会弄几百个分区来做这个吧?那样的人不是疯子也累疯了!

LVM是一个层次结构的系统,最底层是由许多分区构成的PV层也就是虚拟分区层,PV层之上的是VG虚拟磁盘组曾,最上边的是应用层LV层这一层可以象磁盘一样格式化和使用,当然分区也可以,不过好不容易弄了个大的你又要把它分小了,这不是有病么????


[root@VPNSERV ~]# pvcreate /dev/sdb1 /dev/sdc1                                            ####使用pvcreate把两个分区加入到新pv里,多个分区的时候也这么写只要分区间用空格格开就行
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
[root@VPNSERV ~]# vgcreate data /dev/sdb1 /dev/sdc1                                    ####使用vgcreate把两个分区放到名字叫data的VG中,执行完以后可以在/drv中看到新创建的data目录
Volume group "data" successfully created
[root@VPNSERV ~]# lvcreate -n lvdata -L 60000M data                                     ####使用lvcreate命令创建一个LVM设备名为lvdata 大小是60G 该设备属于VG data ;-n参数为LVM设备命名;-L参数为LVM设备指定空间大小,这里是60000MB即60G;最后跟VG设备名,命令执行完成后在/dev/data /下出现lvdata设备,这个就是我们可以使用的块设备了。
Logical volume "lvdata" created
[root@VPNSERV ~]# ls /dev/data/
lvdata
[root@VPNSERV ~]# mkfs.ext3 /dev/data/lvdata                                                   ####使用mkfs.ext3对LVM设备lvdata进行格式化
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
7684096 inodes, 15360000 blocks
768000 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=16777216
469 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

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

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

[root@VPNSERV ~]# mount /dev/data/lvdata /usr/local/www/                                ####格式化之后就可以把LVM设备挂载到一个目录下使用了,使用时和别的硬盘没有区别
[root@VPNSERV ~]# mount                                                                                          ####挂载后使用mount命令查看
/dev/sda2 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /boot type ext3 (rw)
/dev/sda5 on /data type ext3 (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/data-lvdata on /usr/local/www type ext3 (rw) <<<<<<<—————挂载后的lvm设备

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值