本文共 7600 字,大约阅读时间需要 25 分钟。
由于测试导致系统启动不了,需要将系统中的数据拷贝出来,所以想到将磁盘挂载到另一个能用的系统中进行拷贝,但是由于创建的系统都是用默认的方式创建的,所以一般的系统盘都是由两个分区组成,例如/dev/sda,/dev/sda1用来存放启动项,而/dev/sda2是一个逻辑卷,都是由/dev/VolGroup/lv_root、/dev/VolGroup/lv_home、/dev/VolGroup/lv_swap三部分组成的,由于逻辑卷的名字是一样的,所以这样导致将系统盘/dev/sdb挂载后,其中的逻辑卷部分不能挂载。
解决方法:
下面介绍分区格式为为Linux LVM的虚拟机挂载另一块的Linux LVM硬盘的方法:
在Hyper-V上添加要挂载的硬盘,开启虚拟机,启动好以后
#fdisk -l //下面会看到所有硬盘的情况,sda是虚拟机自己的硬盘,sdb则是挂载上去的硬盘
复制代码
[root@localhost ~]# fdisk -lDisk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk identifier: 0x000c4715Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 121602 976248832 8e Linux LVMDisk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 8338 MB, 8338276352 bytes
255 heads, 63 sectors/track, 1013 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_home: 937.6 GB, 937649242112 bytes
255 heads, 63 sectors/track, 113996 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk identifier: 0x00000000Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000ec679Device Boot Start End Blocks Id System
/dev/sdb1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sdb2 64 14594 116707328 8e Linux LVM复制代码#vgscan //扫描所有卷组[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXFound volume group "VolGroup" using metadata type lvm2Found volume group "VolGroup" using metadata type lvm2#vgdisplay //显示出多有卷组信息复制代码
[root@localhost ~]# vgdisplay WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX (created here) takes precedence over FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ--- Volume group ---VG Name VolGroupSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 111.30 GiBPE Size 4.00 MiBTotal PE 28492Alloc PE / Size 28492 / 111.30 GiBFree PE / Size 0 / 0 VG UUID JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX
--- Volume group ---VG Name VolGroupSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 931.02 GiBPE Size 4.00 MiBTotal PE 238341Alloc PE / Size 238341 / 931.02 GiBFree PE / Size 0 / 0 VG UUID FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ复制代码(主要是通过大小来区分的)[root@localhost ~]# vgrename JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX vg01
WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHXWARNING: Duplicate VG name VolGroup: Existing JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX (created here) takes precedence over FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZVolume group "VolGroup" successfully renamed to "vg01"//重新命名挂载盘的卷组名,因为和虚拟机本身的卷组名是一样的所以LVM分区无法挂载,必须改名(要修改挂载盘的卷组名,这里要分编号哪个是挂载上去的),这里的类似于序列号的就是VG UUID,卷组名是一样的,只能靠VG UUID来修改卷组名看到最下面Volume group "VolGroup00" successfully renamed to "vg01"则说明改名成功
#vgdisplay //可以看到已经有一个改名为vg01
复制代码
[root@localhost ~]# vgdisplay --- Volume group ---VG Name vg01System ID Format lvm2Metadata Areas 1Metadata Sequence No 5VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 111.30 GiBPE Size 4.00 MiBTotal PE 28492Alloc PE / Size 28492 / 111.30 GiBFree PE / Size 0 / 0 VG UUID JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX--- Volume group ---
VG Name VolGroupSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 931.02 GiBPE Size 4.00 MiBTotal PE 238341Alloc PE / Size 238341 / 931.02 GiBFree PE / Size 0 / 0 VG UUID FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ复制代码#lvscan //看到上面两个是挂在上去的磁盘,没有激活复制代码
[root@localhost ~]# lvscan inactive '/dev/vg01/lv_root' [50.00 GiB] inheritinactive '/dev/vg01/lv_home' [53.45 GiB] inheritinactive '/dev/vg01/lv_swap' [7.85 GiB] inheritACTIVE '/dev/VolGroup/lv_root' [50.00 GiB] inheritACTIVE '/dev/VolGroup/lv_home' [873.25 GiB] inheritACTIVE '/dev/VolGroup/lv_swap' [7.77 GiB] inherit可以看到下面ACTIVE是正在使用的系统盘,而上面是需要拷贝出来的系统盘复制代码#vgchange -ay /dev/vg01 //激此卷组[root@localhost ~]# vgchange -ay /dev/vg01
3 logical volume(s) in volume group "vg01" now active#lvscan //看下vg01的卷组是否被激活复制代码
[root@localhost ~]# lvscan ACTIVE '/dev/vg01/lv_root' [50.00 GiB] inheritACTIVE '/dev/vg01/lv_home' [53.45 GiB] inheritACTIVE '/dev/vg01/lv_swap' [7.85 GiB] inheritACTIVE '/dev/VolGroup/lv_root' [50.00 GiB] inheritACTIVE '/dev/VolGroup/lv_home' [873.25 GiB] inheritACTIVE '/dev/VolGroup/lv_swap' [7.77 GiB] inherit复制代码#mkdir /mnt/hdb //新建一个文件夹用来作为挂载点#mount /dev/vg01/逻辑卷名(比如LogVol00) /mnt/hdb //挂载vg01/LogVol00
使用完以后要卸载
#umount /mnt/hdb
#vgchange -an /dev/vg01 去除激活的LVM分区
修改过卷组名的这个硬盘是不能再启动了,应为默认启动引导是引导到VolGroup00卷组的,所以修改过卷组名的硬盘要想仍能重新启动的话,必须把卷组名修改会默认的VolGroup00
但是在已经有VolGroup00卷组的虚拟机上是不能修改的!这里我们单独建立一个分区格式不是Linux LVM格式的虚拟机来挂载硬盘,其格式为ext3的(显示为Linux)
#fdisk -l //查看是否识别挂上的硬盘
#vgscan //扫描卷组
#lvscan //查看要改名的卷组是否被激活,要是被激活的话则不能修改卷组名,如果直接修改的话会提示报错
#vgchange -an /dev/VolGroup00 //如果上一步骤是激活状态,则需用此命令修改为不激 活状态
#lvscan //查看是否修改为不激活状态
#vgrename vg01 VolGroup00 //修改为不激活状态则可以修改卷组名
在ext3格式分区的虚拟机上直接挂载Linux LVM分区的硬盘的方法如下:
#fdisk -l //查看是否识别挂上的硬盘
#vgscan //扫描卷组
#vgdisplay //显示所有卷组
#lvscan //查看挂载的磁盘的卷组是否处于激活的状态
#vgchange -ay /dev/VolGroup00 //如上步看到没有激活,则执行此命令
#mkdir /mnt/hdb //创建挂载点的文件夹
#mount /dev/VolGroup00/LogVol00 /mnt/hdb // 挂载,挂载后则可以访问/mnt/hdb
#umount /mnt/hdb //卸载磁盘
#vgchange -an /dev/VolGroup00 //去除挂载磁盘卷组的激活状态
补充如果要设置开机自动加载LVM分区:
vim /etc/fstab
加入
/dev/vg110/LogVol01 /wwwroot/ ext4 defaults 0 0
转载于:https://blog.51cto.com/13278927/2160428