标签:
Creating LVM logical volumes involves creating the three layers in the LVM architecture. You first have to take care of the physical volume (PV), then you need to create the volume group (VG) and assign physical volumes to it. As the last step, the logical volume (LV) itself has to be created. In this section, you learn what is involved in creating these three layers. Different utilities exist for creating LVM. This chapter focuses on using the command-line utilities. They are relatively easy to use, and they are available in all environments (whether you are running a graphical interface or not). 顺序:PV--->VG--->LV
TIP You absolutely do not need to learn the commands discussed in this chapter by heart. All you really need to remember is pv , vg , lv . Open a command line, type pv and press the Tab key twice. This will show all commands that start with pv, which are all commands that are used for managing physical volumes. After you have found the command you need, run this command with the --help option. This shows a usage summary that lists everything that needs to be done to create the element you need.
一、Creating the Physical Volume --创建物理卷PV
In this exercise, you create a physical volume. To do this exercise, you need a hard disk that has free (unpartitioned) disk space available. The recommended method to make disk space available is by adding a new hard disk in your virtual machine environment. In this exercise, I use a clean /dev/vdb device to create the partition. You may have to change the device name to match your configuration. If you do not have a dedicated hard disk available to create this configuration, you might want to consider attaching a USB key to your machine. (我用的是Oracle VirtulBox虚拟机,添加一块虚拟磁盘用于测试)
1. Open a root shell and type fdisk /dev/sdc .
2. Type n to create a new partition. Select p to make it a primary partition, and use the partition number that is suggested as a default. If you are using a clean device, this will be partition number 1.
3. Press Enter when asked for the first sector and type +100M to accept the last sector.
4. Once you are back on the fdisk prompt, type t to change the partition type. Because there is one partition only, fdisk does not ask which partition to use this partition type on. You may have to select a partition if you are using a different configuration.
5. The partitioner asks for the partition type you want to use. Type 8e . Then, press w to write changes to disk and quit fdisk.
If you are getting a message that the partition table could not be updated while writing the changes to disk, reboot your system.
(首先,你得有一块未分区有磁盘,然后在这个磁盘上创建一个LVM类型的分区; 之后再为创建物理卷PV)
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0c16d904 Device Boot Start End Blocks Id System
[root@rhel7 ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-10485759, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +100M Partition 1 of type Linux and of size 100 MiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext‘d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ 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 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): 8e Changed type of partition ‘Linux‘ to ‘Linux LVM‘ Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@rhel7 ~]#
...略... Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0c16d904 Device Boot Start End Blocks Id System /dev/sdc1 2048 206847 102400 8e Linux LVM .....略...
6. Now that the partition has been created, you need to flag it as an LVM physical volume. To do this, type pvcreate /dev/sdc1 . You should now get this prompt: Physical volume “/dev/vbd1” successfully created.
7. Now type pvs to verify that the physical volume has been created successfully. The output may look like bellow .
[root@rhel7 ~]# pvcreate /dev/sdc1 WARNING: ext4 signature detected on /dev/sdc1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdc1. Physical volume "/dev/sdc1" successfully created [root@rhel7 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- 19.51g 40.00m /dev/sdc1 lvm2 --- 100.00m 100.00m [root@rhel7 ~]#
As an alternative to the pvs command, which shows a summary of the physical volumes and their attributes, you can also use the pvdisplay command to show some more details.
pvdisplay命令:
[root@rhel7 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 4994 Free PE 10 Allocated PE 4984 PV UUID OjqvZk-KS1b-YegW-zb4b-uaNV-zGt7-npfsjU "/dev/sdc1" is a new physical volume of "100.00 MiB" --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size 100.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mf29mQ-wx2f-L94K-AFWH-rwA1-23oj-YE4yoV
二、Creating the Volume Groups --创建卷组VG
Now that the physical volume has been created, you can assign it to a volume group. It is possible to add a physical volume to an existing volume group , but you will now learn how to create a new volume group and add the physical volume to it.This is a simple one-command procedure. Just type vgcreate followed by the name of the volume group you want to create and the name of the physical device you want to add to it. So, if the physical volume name is /dev/sdc1, the complete command is vgcreate vgdata /dev/sdc1 (语法:vgcreate 卷组名 设备名). You are completely free in your choice of name for the volume group. I like to start all volume group names with vg, which makes it easy to find the volume groups if there are many, but you are free to choose anything you like.
After creating the volume group, you can request details about the volume group using the vgs command for a short summary, or the vgdisplay command to get more information.
[root@rhel7 ~]# vgcreate vgdate /dev/sdc1 Volume group "vgdate" successfully created [root@rhel7 ~]# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- 19.51g 40.00m vgdate 1 0 0 wz--n- 96.00m 96.00m [root@rhel7 ~]# vgdisplay --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4984 / 19.47 GiB Free PE / Size 10 / 40.00 MiB VG UUID RisrnE-lJIv-XM6h-47zQ-rsiU-JVP6-9ZexZO --- Volume group --- VG Name vgdate System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size 96.00 MiB PE Size 4.00 MiB Total PE 24 Alloc PE / Size 0 / 0 Free PE / Size 24 / 96.00 MiB VG UUID hNTqaY-c0Hi-v5wk-p7lQ-TIbc-oSpm-TIOcHs [root@rhel7 ~]#
In this procedure, you learned how to create a volume group in a two-step procedure where first the physical volume is created with the pvcreate command, after which the volume group is added using the vgcreate command. You can do this in a one-step procedure as well (where using a separate pvcreate command will not be necessary). If you are adding a partition to the volume group, however, it must be marked as partition type 8e already.
The one-step procedure is particularly useful for adding a complete disk device (which does not need to be marked as anything). If you want to add the disk / dev/ sdc, for instance, just type vgcreate vgdata /dev/sdc to create a volume group vgdata that contains the /dev/sdc device. When you are doing this to add a device that has not been marked as a physical volume yet, the vgcreate utility will automatically flag it as a physical volume. When creating volume groups, a physical extent size is used. The physical extent size defines the size of the building blocks used to create logical volumes. A logical volume always has a size that is a multiple of the physical extent size. If you need to create huge logical volumes, it is more efficient to use a big physical extent size. If you do not specify anything, a default extent size of 4.00 MiB is used. The physical extent size is always specified as a multiple of 2 MiB, with a maximum size of 128 MiB. Use the vgcreate -s option to specify the physical extent size you want to use.
NOTE When working with LVM, there is the physical extent size to consider. This is the size of the basic building blocks used in the LVM configuration. When working with an ext4 file system, logical extents are used. The extent size on LVM are in no way related to the extent sizes that are used on the file systems.
三、Creating the Logical Volumes and File Systems 创建逻辑卷和文件系统
Now that the volume group has been created, you can start creating logical volumes from it. This procedure is slightly more complicated than the creation of physical volumes or volume groups because there are more choices to be made. While creating the logical volume, you must specify a volume name and a size.
The volume size can be specified as an absolute value using the -L option. Use, for instance, -L 5G to create an LVM volume with a 5GB size. Alternatively, you can use relative sizes using the -l option. For instance, use -l 50%FREE to use half of all available disk space. You’ll further need to specify the name of the volume group that the logical volume is assigned to, and optionally (but highly recommended), you can use -n to specify the name of the logical volume. For instance, use lvcreate -n lvvol1 -L 100M vgdata to create a logical volume with the name lvvol1 and add that to the vgdata volume group.
[root@rhel7 ~]# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 2 0 wz--n- 19.51g 40.00m vgdate 1 0 0 wz--n- 96.00m 96.00m [root@rhel7 ~]# lvcreate -n lvvol1 -L 100M vgdate Volume group "vgdate" has insufficient free space (24 extents): 25 required. [root@rhel7 ~]# lvcreate -n lvvol1 -L 90M vgdate Rounding up size to full physical extent 92.00 MiB Logical volume "lvvol1" created. [root@rhel7 ~]#
create file systems创建文件系统:
/dev/vgdata/lvdata /lvmFiles xfs defaults 1 2
[root@rhel7 ~]# mkfs.xfs /dev/vgdate/lvvol1 meta-data=/dev/vgdate/lvvol1 isize=256 agcount=4, agsize=5888 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=23552, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@rhel7 ~]# mkdir /lvmFiles [root@rhel7 ~]# mount /dev/vgdate/lvvol1 /lvmFiles/ -手动挂载看看 [root@rhel7 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 4.5G 13G 26% / devtmpfs 911M 0 911M 0% /dev tmpfs 921M 0 921M 0% /dev/shm tmpfs 921M 8.4M 912M 1% /run tmpfs 921M 0 921M 0% /sys/fs/cgroup /dev/sda1 497M 124M 374M 25% /boot tmpfs 185M 0 185M 0% /run/user/0 /dev/mapper/vgdate-lvvol1 89M 4.8M 84M 6% /lvmFiles [root@rhel7 ~]#
添加到/etc/fstab,加下如一行,使其开机自动挂载:
/dev/vgdate/lvvol1 /lvmFiles/ xfs defaults 1 2
===============
LVM一些常用的命令:
标签:
原文地址:http://www.cnblogs.com/rusking/p/5742125.html