博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何挂载另一个lvm硬盘
阅读量:5898 次
发布时间:2019-06-19

本文共 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 -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes

255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000c4715

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 121602 976248832 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 8338 MB, 8338276352 bytes

255 heads, 63 sectors/track, 1013 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_home: 937.6 GB, 937649242112 bytes

255 heads, 63 sectors/track, 113996 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/sdb: 120.0 GB, 120034123776 bytes

255 heads, 63 sectors/track, 14593 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: 0x000ec679

Device Boot Start End Blocks Id System

/dev/sdb1 * 1 64 512000 83 Linux
Partition 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-BpjwHX
WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX
Found volume group "VolGroup" using metadata type lvm2
Found 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-BpjwHX
WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX
WARNING: 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 VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 111.30 GiB
PE Size 4.00 MiB
Total PE 28492
Alloc PE / Size 28492 / 111.30 GiB
Free PE / Size 0 / 0
VG UUID JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX

WARNING: 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 VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 931.02 GiB
PE Size 4.00 MiB
Total PE 238341
Alloc PE / Size 238341 / 931.02 GiB
Free 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-BpjwHX
WARNING: Duplicate VG name VolGroup: Existing FKsJuO-7348-hHqs-MKVq-WLMl-2Sbh-0oh8NZ (created here) takes precedence over JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX
WARNING: 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 "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 vg01
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 111.30 GiB
PE Size 4.00 MiB
Total PE 28492
Alloc PE / Size 28492 / 111.30 GiB
Free PE / Size 0 / 0
VG UUID JTFVF9-ULu5-cHKu-T1p3-4HnB-Tk2p-BpjwHX

--- Volume group ---

VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 931.02 GiB
PE Size 4.00 MiB
Total PE 238341
Alloc PE / Size 238341 / 931.02 GiB
Free 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] inherit
inactive '/dev/vg01/lv_home' [53.45 GiB] inherit
inactive '/dev/vg01/lv_swap' [7.85 GiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [50.00 GiB] inherit
ACTIVE '/dev/VolGroup/lv_home' [873.25 GiB] inherit
ACTIVE '/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] inherit
ACTIVE '/dev/vg01/lv_home' [53.45 GiB] inherit
ACTIVE '/dev/vg01/lv_swap' [7.85 GiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [50.00 GiB] inherit
ACTIVE '/dev/VolGroup/lv_home' [873.25 GiB] inherit
ACTIVE '/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

你可能感兴趣的文章
我的友情链接
查看>>
挖矿程序中毒分析(有这篇够不)
查看>>
对Microsoft DirectAccess产品工作原理的个人理解
查看>>
linux基础篇-14,sed命令详解
查看>>
我的友情链接
查看>>
有一个 try/catch 代码块,finally代码块总会被执行么?
查看>>
剑指offer-面试题4
查看>>
****DISPLAY environment variable not set! Oracle Net Configuration Assistan
查看>>
作业六:猜猜看,检验朋友熟悉度——Winform程序
查看>>
关于linux下socket的连接队列backlog的分析
查看>>
服务器启动报错:UNEXPECED INCONSISTENCY; RUN fsck MANUALLY
查看>>
Linux 设置全局环境变量的三种方法
查看>>
Centos 上面用Shell脚本一键安装LAMP环境
查看>>
Linux - cat
查看>>
Windows Linux配置MD3200 的iSCSI的一些笔记
查看>>
列式数据库
查看>>
linux系统调优
查看>>
sqoop db2 java.io.CharConversionException
查看>>
逻辑卷详解
查看>>
IOC的简单实现
查看>>