LVM基本应用、扩展及缩减实现1
相关概念:
磁盘:是一种断电后保存的数据不会丢失的通过磁性进行读写功能的设备
硬盘是磁盘的一种。
LVM,Logical Volume Manager逻辑卷管理
- 定义:
通过内核中的dm(device mapper)模块实现用纯软件的方式将一个或多个底层硬件设备组织组织成一个或多个逻辑设备
- 优点:
可以弹性调整文件系统的容量,整合多个物理分区形成一个逻辑上的逻辑卷,而且可以不用像之前取名sda、sda等一样取名,可以根据其具体作用进行取名
- PV,physical Volume 物理卷
可以在上面建立卷组的块设备,可以是硬盘分区或者硬盘本身。实际的分区需要调整系统标识符(SID)为8e(LVM的标识符),然后再转换为LVM最底层的物理卷PV。调整SID的方法是fdisk,物理卷包括一个特殊的header,其余部分被切割为一块块物理区域
- VG,Volume group 卷组
将多个PV组合成一个逻辑上的大磁盘,其中,VG的实际大小=PE的数量xPE的单位大小。PE默认大小为4MB
- LV,Logical Volume逻辑卷
最终的VG会被切割成LV,LV就是最后可以被格式化使用,类似于windos上的C,D盘等
- PE,Physical Extend
LVM可以弹性更改文件系统的容量,就是通过调整空闲PE的数量来实现的,而实际数据其实也是存储在PE这个块上面的

LVM相关命令

fdisk命令,以/dev/sda为例:

其中常用的有:d、l、m、p、q、t、w、n等
大体创建一个分区的过程:
1、
[root@centos ~]# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000e5fba Device Boot Start End Blocks Id System /dev/sda1 * 1 52 409600 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 52 1581 12288000 83 Linux /dev/sda3 1581 1836 2048000 83 Linux /dev/sda4 1836 3917 16710656 5 Extended /dev/sda5 1837 2092 2048000 82 Linux swap / Solaris
查看电脑中所有硬盘设备个数及名称,如图可以看到4个分区都已经被使用完毕,3个主分区,1个扩展分区,接下来我们对/dev/sda3
硬盘做逻辑卷的处理
2、
[root@centos ~]# fdisk /dev/sda3 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x77062da5. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sda3: 2097 MB, 2097152000 bytes 255 heads, 63 sectors/track, 254 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x77062da5 Device Boot Start End Blocks Id System
可以看到当前操作硬盘/dev/sda3下面并没有分区
3、
通过fdisk的n来创建新的分区
Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l 注:在这里输入l,就进入划分逻辑分区阶段了; First cylinder (51-125, default 51): 注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费; Using default value 51 Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ; Command (m for help):
4、
通过fdisk的t命令来指定分区类型
Command (m for help): t 注:通过t来指定分区类型; Partition number (1-6): 6 注:要改变哪个分区类型呢?我指定了6,其实也就是sda6 Hex code (type L to list codes):L 注:在这里输入L,就可以查看分区类型的id了; Hex code (type L to list codes): b 注:如果我想让这个分区是 W95 FAT32 类型的,通过L查看得知 b是表示的是,所以输入了b; Changed system type of partition 6 to b (W95 FAT32) 注:系统信息,改变成功;是否是改变了,请用p查看; Command (m for help): p Disk /dev/sda: 1035 MB, 1035730944 bytes 256 heads, 63 sectors/track, 125 cylinders Units = cylinders of 16128 * 512 = 8257536 bytes Device Boot Start End Blocks Id System /dev/sda1 1 25 201568+ c W95 FAT32 (LBA) /dev/sda2 26 125 806400 5 Extended /dev/sda5 26 50 201568+ 83 Linux /dev/sda6 51 75 201568+ b W95 FAT32
5、fdisk的退出:
q:直接退出,不保存
w:保存退出
6、对分区进行格式化以及加载

7、上述操作只是对硬盘进行了分区操作,接下来才是对他们进行逻辑卷的操作,我们下一个随笔再进行讲述
引用了:
http://blog.chinaunix.net/uid-23929712-id-2650378.html

浙公网安备 33010602011771号