逻辑卷管理器,当分区不够用的时候,可以新建一个更大的分区再复制进去,但是浪费时间。Lvm可以弹性调整分区大小,可以动态组合分区。分区大小固定了就无法调整, apt-get update & apt-get install pv* pt-cache search <包名> 查询已经安装的package : dpkg -S libgstreamer0.10-dev 物理卷:
/dev/sda2这个分区属于VolGroup00这个卷组,大小19G。整个操作系统有一个物理卷,这个物理卷针对的就是sda2这一个分区。物理卷对应的就是实际的硬盘分区,一个卷组可以包含一个或多个物理卷,当一个卷组容量不够用的时候,可以加进来一个分区,这样这个卷组的容量就变大了,LVM本身他的价值也是体现在这里。 一个分组可以分成几个逻辑卷,比较3个逻辑卷a,b,c,a存储数据库文件,b存储文件相关的数据,c存放临时文件。 最底层的是物理卷,物理卷直接跟硬盘分区相对应。多个物理卷组成卷组。在不同的卷组里面可以划分不同的逻辑卷使用。(这个就是LVM本身的说明) root@ubuntu:/# fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39845887 39843840 19G 83 Linux /dev/sda2 39847934 41940991 2093058 1022M 5 Extended /dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4194303 4192256 2G 83 Linux root@ubuntu:/# pvcreate /dev/sdb1 :把分区制作成物理卷 WARNING: ext3 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y Wiping ext3 signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created (物理卷创建成功) root@ubuntu:/# pvdisplay :查看物理卷 "/dev/sdb1" is a new physical volume of "500.00 MiB" --- NEW Physical volume --- PV Name /dev/sdb1 :物理卷的名称就叫做/dev/sdb1 VG Name :还不属于任何卷组 PV Size 500.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID c1bSmd-8dcv-vo9s-Wooe-Qf5m-QIEP-H1ygQz 创建卷组要指定一个物理卷,否则无法创建。 root@ubuntu:/# vgcreate sdb_volm_group /dev/sdb1 Volume group "sdb_volm_group" successfully created (卷组sdb_volm_group创建成功) root@ubuntu:/# vgdisplay :查看卷组 --- Volume group --- VG Name sdb_volm_group 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 496.00 MiB PE Size 4.00 MiB Total PE 124 Alloc PE / Size 0 / 0 Free PE / Size 124 / 496.00 MiB VG UUID PzyjKt-Nc6B-HZeK-fXeu-LayV-xWpi-Li1jCd 现在把一个分区sdb1转换成物理卷sdb1,把这个卷加入到sdb_volm_group卷组里面去了,下面在卷组里面去创建不同的分区逻辑卷。 (创建逻辑卷,-L指定大小100M,-n指定名字nuoji1,后面跟卷组名称) root@ubuntu:/# lvcreate -L 100M -n nuoji1 sdb_volm_group Logical volume "nuoji1" created. (逻辑卷创建成功) root@ubuntu:/# lvcreate -L 100M -n nuoji2 sdb_volm_group Logical volume "nuoji2" created.
root@ubuntu:/# lvdisplay :查看逻辑卷 --- Logical volume --- LV Path /dev/sdb_volm_group/nuoji1 LV Name nuoji1 VG Name sdb_volm_group LV UUID oYSIhw-Fpik-19L4-CjAj-9Hob-tgCA-1ilUkU LV Write Access read/write LV Creation host, time ubuntu, 2018-02-14 04:58:50 -0800 LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/sdb_volm_group/nuoji2 LV Name nuoji2 VG Name sdb_volm_group LV UUID UVxno2-wtUW-MP78-tVOp-76Ps-wewM-h3lbJG LV Write Access read/write LV Creation host, time ubuntu, 2018-02-14 05:24:45 -0800 LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
root@ubuntu:/dev/sdb_volm_group# ls
nuoji1 nuoji2
逻辑卷创建好了之后就可以使用了,可以直接把逻辑卷挂载在目录下: root@ubuntu:/dev/sdb_volm_group# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 7.1G 11G 41% / /dev/sr0 1.5G 1.5G 0 100% /media/yw1989/Ubuntu 16.04.3 LTS amd64 /dev/sdc1 3.2G 21M 3.2G 1% /media/upan (挂载逻辑分区) root@ubuntu:/# mount -t ext3 /dev/sdb_volm_group/nuoji1 /yw/nuiji_fenqu mount: wrong fs type, bad option, bad superblock on /dev/mapper/sdb_volm_group-nuoji1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.( /dev/sdb_volm_group/nuoji1只是一个逻辑卷的分区,没有指定文件类型没有格式化,) (为逻辑卷分区指定文件类型ext3,也就是格式化) root@ubuntu:/# mke2fs -j /dev/sdb_volm_group/nuoji1 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: cb5da3fc-3a96-4c85-b392-ce6777fb05fa Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done (挂载逻辑卷分区,不报错了) root@ubuntu:/# mount -t ext3 /dev/sdb_volm_group/nuoji1 /yw/nuiji_fenqu root@ubuntu:/# mount -a root@ubuntu:/# mount /dev/mapper/sdb_volm_group-nuoji1 on /yw/nuiji_fenqu type ext3 (rw,relatime,data=ordered) root@ubuntu:/# df -h /dev/mapper/sdb_volm_group-nuoji1 93M 1.6M 87M 2% /yw/nuiji_fenqu (nuiji_fenqu目录指向逻辑卷分区sdb_volm_group-nuoji1,这个逻辑卷分区是组里面的分的,这个组是sdb硬盘下面的sdb1分区,大小93M是逻辑卷创建时指定的大小) (逻辑卷是为了重新分配卷组的硬盘大小)
----------------------------------------移除是把刚才的过程反过来:-----------------------------------------
root@ubuntu:/# umount /yw/nuiji_fenqu (先卸载挂载) root@ubuntu:/# df -h (没有挂载信息了) Filesystem Size Used Avail Use% Mounted on udev 456M 0 456M 0% /dev /dev/sda1 19G 7.1G 11G 41% / /dev/sr0 1.5G 1.5G 0 100% /media/yw1989/Ubuntu 16.04.3 LTS amd64 /dev/sdc1 3.2G 21M 3.2G 1% /media/upan root@ubuntu:/# lvremove /dev/mapper/sdb_volm_group-nuoji1 (移除逻辑卷分区) Do you really want to remove and DISCARD active logical volume nuoji1? [y/n]: y Logical volume "nuoji1" successfully removed root@ubuntu:/# lvremove /dev/mapper/sdb_volm_group-nuoji2 Do you really want to remove and DISCARD active logical volume nuoji2? [y/n]: y Logical volume "nuoji2" successfully removed root@ubuntu:/# lvdisplay (逻辑卷1,2都没有了) root@ubuntu:/# vgremove /dev/sdb_volm_group (移除卷组) Volume group "sdb_volm_group" successfully removed root@ubuntu:/# vgdisplay (卷组没了) root@ubuntu:/# pvdisplay (查看物理卷) "/dev/sdb1" is a new physical volume of "500.00 MiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 500.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID RbdqsP-cW2q-U5bQ-ZFiU-kCbN-312j-tKAsY1 root@ubuntu:/# pvremove /dev/sdb1 (移除物理卷) Labels on physical volume "/dev/sdb1" successfully wiped root@ubuntu:/# pvdisplay (没有物理卷了) root@ubuntu:/# apt-get install pv* root@ubuntu:/# pv pv pvmd pvpgn-support-installer pvchange pvmgetarch pvremove pvck pvmgroups pvresize pvcreate pvmgs pvrg-jpeg pvdisplay pvm_gstat pvs pvm pvmove pvscan