一、LVM概述
linux管理员事先没有规划好分区或者没有采取其他的管理文件系统的策略,那么就可能会遇到某个分区随着存储的文件增多而造成空间不够用的状况。对于这种状况,一般可以采取新增一个磁盘或分区,然后使用符合链接进行重定向的方法来解决,也可以使用调整分区的工具,甚至可以先备份整个系统,再清除磁盘并重新对磁盘分区,最后回复数据到新分区。但是这些方法无法从根本上解决问题,因为分区空间可能会再次耗尽,而且有些调整需要重新引导系统才能够实现,这对于一些不可停机的服务器来说是不可接受的。另外,分区调整程序也无法解决新磁盘上的分区问题及跨越多个磁盘的文件系统问题。
为了解决以上出现的问题,linux系统管理员可以采用逻辑卷管理机制(Logical Volume manager , LVM),它是linux环境下对磁盘分区进行管理的一种机制,用来提高磁盘分区管理的灵活性。采用逻辑卷可以在不停机的前提下自由且自如地对文件系统进行大小的调整,并可以方便地实现文件系统跨越不同磁盘和分区。
通过LVM,系统管理员可以轻松管理磁盘分区 。例,将若干个磁盘分区连接为一个卷组,系统管理员可以再卷组上随意创建逻辑卷,并进一步在逻辑卷上创建文件系统。系统管理员通过LVM可以方便地调整存储卷组的大小,当系统添加了新的磁盘时,系统管理员不必将磁盘的文件移动到新磁盘上以利用新的存储空间,而只需直接扩展文件系统跨越磁盘即可。
要正确地使用和管理LVM,还需要理解几个关键概念:
1.物理存储介质(Physical Media, PM )
PM是指系统存储设备,如/dev/hda1./dev/sda等,是存储系统最底层的存储单元。
2.物理卷(Physical volume, PV)
PV是指磁盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),它是LVM的基本存储逻辑块,但与基本的物理存储介质相比却包含有与LVM相关的管理参数。
3.卷组(Vloume Group ,VG)
VG类似于非LVM系统中的物理磁盘,由物理卷组成。可以再卷组上创建一个或多个"LVM分区"(逻辑卷),LVM卷组由一个或多个物理卷组成。
4.逻辑卷(Logical Volume,LV)
LV是用从卷组中分配的一定大小的空间创建的逻辑单元,也可以是用一个完整的卷组空间大小来创建一个LV.LV类似于非LVM系统中的磁盘分区,在它上面可以建立文件系统。
5.PE(Phsical Extent)
每一个物理卷均被划分为称为PE的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。
6.LE(Logical Extent)
逻辑卷也被划分为被称为LE的可寻址的基本单位。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。
PM是整个存储结构的基础,首先需要从PM中分出一部分货将其全部转换成为PV,PV是以PE为单元进行组织的,然后由这些PV组成一个活个VG,再由VG中划分出一个或若干个LV,LV是以LE为单元进行组织的。在一个VG内, PE和LE的大小是相同的,默认为4MB,也可以在创建PV的时候指定。LV在其所属的PV内是可以自如地缩放空间的,如果VG的空间不够,则可以把新的PV加进来或者把不同的VG进行整合。如果新的PV或VG是其他磁盘上的,那么顺理成章且透明的实现了跨磁盘扩展。
二、LVM的创建和扩容
前一章节我们讨论了LVM的基本概念及其作用,本节将通过实例来帮助大家继续掌握LVM管理的使用技能。实验用机器上是安装了4个15GB的SCSI接口磁盘,其中一块上安装了linux操作系统并且没有剩余的空间,我们利用其他磁盘来进行操作。
1.创建物理卷PV
首先在这两块磁盘上分别创建分区,这些分区将会被转换为物理卷PV。
- [root@db8 ~]# fdisk /dev/sdb
- The number of cylinders for this disk is set to 1958.
- 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/sdb: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First cylinder (1-1958, default 1):
- Using default value 1
- Last cylinder or +size or +sizeM or +sizeK (1-1958, default 1958): +200M
- Command (m for help): T
- Selected partition 1
- Hex code (type L to list codes): p
- 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.
- WARNING: Re-reading the partition table failed with error 16: 璁惧鎴栬祫婧愬繖.
- The kernel still uses the old table.
- The new table will be used at the next reboot.
- Syncing disks.
- [root@db8 ~]# fdisk /dev/sdc
- The number of cylinders for this disk is set to 1958.
- 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: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First cylinder (1-1958, default 1):
- Using default value 1
- Last cylinder or +size or +sizeM or +sizeK (1-1958, default 1958): +300M
- Command (m for help): t
- Selected partition 1
- Hex code (type L to list codes): l
- 0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris 。。。。。。。。。。。。。
- 。。。。。。。。。。。。。。。。。。。。。。。。。。。。
- #其他的介绍说明略
- 8e Linux LVM
- 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.
- WARNING: Re-reading the partition table failed with error 16: 璁惧鎴栬祫婧愬繖.
- The kernel still uses the old table.
- The new table will be used at the next reboot.
- Syncing disks.
- [root@db8 ~]# fdisk -l
- Disk /dev/sda: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 25 200781 83 Linux
- /dev/sda2 26 280 2048287+ 82 Linux swap / Solaris
- /dev/sda3 281 1958 13478535 83 Linux
- Disk /dev/sdb: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 25 200781 8e Linux LVM
- Disk /dev/sdc: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdc1 1 37 297171 8e Linux LVM
将分区转换为PV,现在有了两个PV,一个味200MB,一个为300MB.
- [root@db8 ~]# pvcreate /dev/sdb1
- Physical volume "/dev/sdb1" successfully created
- [root@db8 ~]# pvcreate /dev/sdc1
- Physical volume "/dev/sdc1" successfully created
- [root@db8 ~]#
使用pvdisplay查看系统所有的或指定的pv信息。
- [root@db8 ~]# pvdisplay
- "/dev/sdb1" is a new physical volume of "196.08 MB"
- --- NEW Physical volume ---
- PV Name /dev/sdb1
- VG Name
- PV Size 196.08 MB
- Allocatable NO
- PE Size (KByte) 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID lLcHyf-Ko3x-gOzM-kdeU-7npm-xS2o-jhuNil
- "/dev/sdc1" is a new physical volume of "290.21 MB"
- --- NEW Physical volume ---
- PV Name /dev/sdc1
- VG Name
- PV Size 290.21 MB
- Allocatable NO
- PE Size (KByte) 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID 6mkvrh-OSLf-p8qW-B22G-SjGz-eEHu-dL5K7t
2.建立卷组VG
将上面的两个PV组合成一个名为myvg1的卷组VG
- [root@db8 ~]# vgcreate myvg1 /dev/sdb1 /dev/sdc1
- Volume group "myvg1" successfully created
使用vgdisplay查看系统所有的或指定VG信息。
- [root@db8 ~]# vgcreate myvg1 /dev/sdb1 /dev/sdc1
- Volume group "myvg1" successfully created
- [root@db8 ~]# vgdisplay
- --- Volume group ---
- VG Name myvg1
- 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 480.00 MB
- PE Size 4.00 MB
- Total PE 120
- Alloc PE / Size 0 / 0
- Free PE / Size 120 / 480.00 MB
- VG UUID zmkQL8-HfZI-gQ98-w66a-g5fX-zfbN-gquqQX
这个VG的PE默认大小为4MB,一共有120个PE,它们都没有被使用。
3.创建逻辑卷LV
下面使用lvcreate命令创建两个逻辑卷LV,一个名为mylv1,另一个名为mylv2.其中,选项-n后面的参数是为LV取的名称,最后的参数用于指出从哪个卷组分配LV,而选项-I后面的参数则表示LV的大小,注意使用的是数字,表示LV占用的PE数。如果使用的选项是-L,那么后面的参数应该使用容量,表示分配给LV的空间大小。但要注意,由于LE和PE在同一个VG内大小是相同的(这里使用默认值4MB),所以在分配空间大小时,如果指定的空间不是PE或LE大小的整数倍,那么系统会自动将容量往上增加至PE或LE的整数倍。
创建逻辑卷LV:
- [root@db8 ~]# lvcreate -L 50 -n mylvl myvg1
- Rounding up size to full physical extent 52.00 MB
- Logical volume "mylvl" created
- [root@db8 ~]# lvcreate -L 100 -n mylv2 myvg1
- Logical volume "mylv2" created
使用lvdisplay查看系统所有的或指定的LV的信息:
- [root@db8 ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/myvg1/mylvl
- VG Name myvg1
- LV UUID GceWCb-Q7nM-Drou-KOT2-xb7i-v3TQ-Z5yv8w
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 52.00 MB
- Current LE 13
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:0
- --- Logical volume ---
- LV Name /dev/myvg1/mylv2
- VG Name myvg1
- LV UUID l1G3SM-EJa7-15Ck-8Lix-XPuu-cgft-PDNhu9
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 100.00 MB
- Current LE 25
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:1
将两个LV格式化为EXT3文件格式,注意设备名的表示方式:
- [root@db8 ~]# mkfs.ext3 /dev/myvg1/mylvl
- mke2fs 1.39 (29-May-2006)
- Filesystem label=
- OS type: Linux
- Block size=1024 (log=0)
- Fragment size=1024 (log=0)
- 13328 inodes, 53248 blocks
- 2662 blocks (5.00%) reserved for the super user
- First data block=1
- Maximum filesystem blocks=54525952
- 7 block groups
- 8192 blocks per group, 8192 fragments per group
- 1904 inodes per group
- Superblock backups stored on blocks:
- 8193, 24577, 40961
- Writing inode tables: done
- Creating journal (4096 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 28 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- [root@db8 ~]# mkfs.ext3 /dev/myvg1/mylv2
- mke2fs 1.39 (29-May-2006)
- Filesystem label=
- OS type: Linux
- Block size=1024 (log=0)
- Fragment size=1024 (log=0)
- 25688 inodes, 102400 blocks
- 5120 blocks (5.00%) reserved for the super user
- First data block=1
- Maximum filesystem blocks=67371008
- 13 block groups
- 8192 blocks per group, 8192 fragments per group
- 1976 inodes per group
- Superblock backups stored on blocks:
- 8193, 24577, 40961, 57345, 73729
- Writing inode tables: done
- Creating journal (4096 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 33 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
新建两个目录,作为这两个LV的挂载点:
- [root@db8 ~]# mkdir /mylv1mnt /mylv2mnt
- #先将/dev/myvg1/mylvl挂载到/mylvlmnt/,然后再查看分区的使用情况:
- [root@db8 ~]# mount /dev/myvg1/mylvl /mylv1mnt/
- [root@db8 ~]# df -h
- 鏂囦欢绯荤粺 瀹归噺 宸茬敤 鍙敤 宸茬敤% 鎸傝浇鐐
- /dev/sda3 13G 5.7G 6.2G 48% /
- /dev/sda1 190M 15M 166M 9% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg1-mylvl
- 51M 4.9M 43M 11% /mylv1mnt
- [root@db8 ~]#
4.对挂载的逻辑卷进行扩容
将当前下一个大小为125MB的文件复制到mylv1上,但明显mylv1只有51MB,空1间不够用,所以需要对mylv1进行扩容:
- [root@db8 ~]# cp Asianux-30-SP4-i386-tools-rc-20120614.iso /mylv1mnt/
- cp: 写入/mylv1mnt/hell设备没有足够的空间
使用lvextend对mylv1进行扩容,将其容量逻辑上增加80MB:
- [root@db8 ~]# lvextend -L +80MB /dev/myvg1/mylvl
- Extending logical volume mylvl to 132.00 MB
- Logical volume mylvl successfully resized
查看分区的使用情况,发现mylvl的大小没有改变:
- [root@db8 mylv1mnt]# df -h
- 文件系统 容量 已用 可用 已用% 挂载点
- /dev/sda3 13G 5.8G 6.1G 49% /
- /dev/sda1 190M 15M 166M 9% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg1-mylvl
- 51M 4.9M 43M 11% /mylv1mnt
重复刚才的复制动作,系统仍然提示空间不够用:
- [root@db8 ~]# cp hello.txt /mylv1mnt/
- cp: 写入 “/mylv1mnt/hello.txt”: 设备上没有空间
使用resize2fs对mylv1进行在线扩容:
- [root@db8 ~]# resize2fs /dev/myvg1/mylvl
- resize2fs 1.39 (29-May-2006)
- Filesystem at /dev/myvg1/mylvl is mounted on /mylv1mnt; on-line resizing required
- Performing an on-line resize of /dev/myvg1/mylvl to 135168 (1k) blocks.
- The filesystem on /dev/myvg1/mylvl is now 135168 blocks long.
再查看分区的使用情况, 发现mylv1的大小扩展到了121MB:
- [root@db8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/sda3 13G 5.8G 6.1G 49% /
- /dev/sda1 190M 15M 166M 9% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg1-mylvl
- 129M 5.3M 117M 5% /mylv1mnt
文件也可以被正常复制:
- [root@db8 ~]# dd if=/dev/zero of=hello.txt bs=121MB count=1
- 1+0 records in
- 1+0 records out
- 121000000 bytes (121 MB) copied, 3.67127 seconds, 33.0 MB/s
- #利用dd建立一个121MB的文件
- [root@db8 ~]# cp hello.txt /mylv1mnt/
- cp: overwrite `/mylv1mnt/hello.txt'? y
- [root@db8 ~]# ls /mylv1mnt/ -lh
- total 116M
- -rw-r--r-- 1 root root 116M Oct 6 08:57 hello.txt
- drwx------ 2 root root 12K Oct 6 08:08 lost+found
5.对维挂载的逻辑卷进行扩容
使用lvextend 对未被挂载的mylv2扩容70MB后,将其挂载并查看效果,发现虽然从逻辑上mylv2已经扩容,但物理上其容量并没有变化,使用resize2fs按照提示对mylv2进行扩容:
- [root@db8 ~]# lvextend -L +70M /dev/myvg1/mylv2
- Rounding up size to full physical extent 72.00 MB
- Extending logical volume mylv2 to 172.00 MB
- Logical volume mylv2 successfully resized
- [root@db8 ~]# mount /dev/myvg1/mylv2 /mylv2mnt/
- [root@db8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/sda3 13G 5.9G 6.0G 50% /
- /dev/sda1 190M 15M 166M 9% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg1-mylvl
- 129M 122M 528K 100% /mylv1mnt
- /dev/mapper/myvg1-mylv2
- 97M 5.6M 87M 7% /mylv2mnt
- [root@db8 ~]# umount /mylv2mnt/
- [root@db8 ~]# resize2fs /dev/myvg1/mylv2
- resize2fs 1.39 (29-May-2006)
- Please run 'e2fsck -f /dev/myvg1/mylv2' first.
- [root@db8 ~]# e2fsck -f /dev/myvg1/mylv2
- 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/myvg1/mylv2: 11/25688 files (9.1% non-contiguous), 8914/102400 blocks
- [root@db8 ~]# resize2fs /dev/myvg1/mylv2
- resize2fs 1.39 (29-May-2006)
- Resizing the filesystem on /dev/myvg1/mylv2 to 176128 (1k) blocks.
- The filesystem on /dev/myvg1/mylv2 is now 176128 blocks long.
- [root@db8 ~]# mount /dev/myvg1/mylv2 /mylv2mnt/
- [root@db8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/sda3 13G 5.9G 6.0G 50% /
- /dev/sda1 190M 15M 166M 9% /boot
- tmpfs 252M 0 252M 0% /dev/shm
- /dev/mapper/myvg1-mylvl
- 129M 122M 528K 100% /mylv1mnt
- /dev/mapper/myvg1-mylv2
- 167M 5.6M 153M 4% /mylv2mnt
6.设置开机自动挂载逻辑卷
上面通过一组实例操作描述了如何建立PV、VG、LV以及如何对LV进行扩容。如果希望系统每次开机启动时LV都能正常挂载到挂载点的话,则需要在/etc/fstab文件中加入如下相应行:
- [root@db8 ~]# cat /etc/fstab
- LABEL=/ / ext3 defaults 1 1
- LABEL=/boot /boot ext3 defaults 1 2
- tmpfs /dev/shm tmpfs defaults 0 0
- devpts /dev/pts devpts gid=5,mode=620 0 0
- sysfs /sys sysfs defaults 0 0
- proc /proc proc defaults 0 0
- #/dev/md0 /RAIDmnt auto defaults 0 0
- /dev/myvg1/mylv1mnt /mylv1mnt ext3 defaults 0 0
- /dev/myvg1/mylv2mnt /mylv2mnt ext3 defaults 0 0
7.对VG进行扩容
当LV的空间不够用的时候,可以再VG容量允许的范文内对LV进行扩展,但是这样一来,LV的使用的总容量迟早会达到VG的容量,这时候就需要对VG进行扩容了。对VG进行扩容是可以用如下两种方法:一种是将新的PV加入到VG中,另一种则是把其他的VG合并到现有的VG或新的VG中去。
但第一种方法对VG进行扩容的步骤如下:
- [root@db8 ~]# fdisk /dev/sdb
- The number of cylinders for this disk is set to 1958.
- 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): 2
- First cylinder (26-1958, default 26):
- Using default value 26
- Last cylinder or +size or +sizeM or +sizeK (26-1958, default 1958): +600M
- 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): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
- The kernel still uses the old table.
- The new table will be used at the next reboot.
- Syncing disks.
- [root@db8 ~]# partprobe
- [root@db8 ~]# pvcreate /dev/sdb2
- Physical volume "/dev/sdb2" successfully created
- [root@db8 ~]# vgex
- vgexport vgextend
- [root@db8 ~]# vgextend myvg1 /dev/sdb2
- Volume group "myvg1" successfully extended
- [root@db8 ~]# vgdisplay
- --- Volume group ---
- VG Name myvg1
- System ID
- Format lvm2
- Metadata Areas 3
- Metadata Sequence No 6
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 2
- Open LV 2
- Max PV 0
- Cur PV 3
- Act PV 3
- VG Size 1.04 GB
- PE Size 4.00 MB
- Total PE 265
- Alloc PE / Size 76 / 304.00 MB
- Free PE / Size 189 / 756.00 MB
- VG UUID zmkQL8-HfZI-gQ98-w66a-g5fX-zfbN-gquqQX
使用第二种方法对VG进行扩容的步骤如下:
- [root@db8 ~]# fdisk /dev/sdb
- The number of cylinders for this disk is set to 1958.
- 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): 3
- First cylinder (100-1958, default 100):
- Using default value 100
- Last cylinder or +size or +sizeM or +sizeK (100-1958, default 1958): +3--^H^H^H^H
- Command (m for help): p
- Disk /dev/sdb: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 25 200781 8e Linux LVM
- /dev/sdb2 26 99 594405 8e Linux LVM
- /dev/sdb3 100 103 32130 83 Linux
- Command (m for help): d
- Partition number (1-4): 3
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 3
- First cylinder (100-1958, default 100):
- Using default value 100
- Last cylinder or +size or +sizeM or +sizeK (100-1958, default 1958): +300M
- Command (m for help): p
- Disk /dev/sdb: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 25 200781 8e Linux LVM
- /dev/sdb2 26 99 594405 8e Linux LVM
- /dev/sdb3 100 136 297202+ 83 Linux
- 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): p
- Disk /dev/sdb: 16.1 GB, 16106127360 bytes
- 255 heads, 63 sectors/track, 1958 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 25 200781 8e Linux LVM
- /dev/sdb2 26 99 594405 8e Linux LVM
- /dev/sdb3 100 136 297202+ 8e Linux LVM
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
- The kernel still uses the old table.
- The new table will be used at the next reboot.
- Syncing disks.
- [root@db8 ~]# partprobe /dev/sdb
- [root@db8 ~]# fdisk /dev/sdc
- The number of cylinders for this disk is set to 1958.
- 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): 2
- First cylinder (38-1958, default 38):
- Using default value 38
- Last cylinder or +size or +sizeM or +sizeK (38-1958, default 1958): +100M
- 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): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
- The kernel still uses the old table.
- The new table will be used at the next reboot.
- Syncing disks.
- [root@db8 ~]# partprobe /dev/sdc
- [root@db8 ~]# pvcreate /dev/sdb3
- Physical volume "/dev/sdb3" successfully created
- [root@db8 ~]# pvcreate /dev/sdc2
- Physical volume "/dev/sdc2" successfully created
- [root@db8 ~]# vgcreate myvg2 /dev/sdb3 /dev/sdc2
- Volume group "myvg2" successfully created
- [root@db8 ~]# vgdisplay
- --- Volume group ---
- VG Name myvg2
- 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 388.00 MB
- PE Size 4.00 MB
- Total PE 97
- Alloc PE / Size 0 / 0
- Free PE / Size 97 / 388.00 MB
- VG UUID 10X3pD-oxOa-mmPM-p0wv-KOW5-4KqN-Is7ov6
- --- Volume group ---
- VG Name myvg1
- System ID
- Format lvm2
- Metadata Areas 3
- Metadata Sequence No 6
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 2
- Open LV 2
- Max PV 0
- Cur PV 3
- Act PV 3
- VG Size 1.04 GB
- PE Size 4.00 MB
- Total PE 265
- Alloc PE / Size 76 / 304.00 MB
- Free PE / Size 189 / 756.00 MB
- VG UUID zmkQL8-HfZI-gQ98-w66a-g5fX-zfbN-gquqQX
- [root@db8 ~]# vgmerge myvg1 myvg2
- Volume group "myvg2" successfully merged into "myvg1"
- [root@db8 ~]# vgdisplay
- --- Volume group ---
- VG Name myvg1
- System ID
- Format lvm2
- Metadata Areas 5
- Metadata Sequence No 7
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 2
- Open LV 2
- Max PV 0
- Cur PV 5
- Act PV 5
- VG Size 1.41 GB
- PE Size 4.00 MB
- Total PE 362
- Alloc PE / Size 76 / 304.00 MB
- Free PE / Size 286 / 1.12 GB
- VG UUID zmkQL8-HfZI-gQ98-w66a-g5fX-zfbN-gquqQX