由于測試導(dǎo)致系統(tǒng)啟動不了,需要將系統(tǒng)中的數(shù)據(jù)拷貝出來,所以想到將磁盤掛載到另一個能用的系統(tǒng)中進(jìn)行拷貝,但是由于創(chuàng)建的系統(tǒng)都是用默認(rèn)的方式創(chuàng)建的,所以一般的系統(tǒng)盤都是由兩個分區(qū)組成,例如/dev/sda,/dev/sda1用來存放啟動項,而/dev/sda2是一個邏輯卷,都是由/dev/VolGroup/lv_root、/dev/VolGroup/lv_home、/dev/VolGroup/lv_swap三部分組成的,由于邏輯卷的名字是一樣的,所以這樣導(dǎo)致將系統(tǒng)盤/dev/sdb掛載后,其中的邏輯卷部分不能掛載。
下面介紹分區(qū)格式為為Linux LVM的虛擬機(jī)掛載另一塊的Linux LVM硬盤的方法:
在Hyper-V上添加要掛載的硬盤,開啟虛擬機(jī),啟動好以后
#fdisk -l //下面會看到所有硬盤的情況,sda是虛擬機(jī)自己的硬盤,sdb則是掛載上去的硬盤
[root@localhost ~]# fdisk -lDisk /dev/sda: 1000.2 GB, 1000204886016 bytes255 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: 0x000c4715 Device Boot Start End Blocks Id System/dev/sda1 * 16451200083 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64121602976248832 8e Linux LVMDisk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes255 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 bytes255 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 bytes255 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 bytes255 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: 0x000ec679 Device Boot Start End Blocks Id System/dev/sdb1 * 16451200083 LinuxPartition 1 does not end on cylinder boundary./dev/sdb2 6414594116707328 8e Linux LVM
[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
[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'
//重新命名掛載盤的卷組名,因為和虛擬機(jī)本身的卷組名是一樣的所以LVM分區(qū)無法掛載,必須改名(要修改掛載盤的卷組名,這里要分編號哪個是掛載上去的),這里的類似于序列號的就是VG UUID,卷組名是一樣的,只能靠VG UUID來修改卷組名
看到最下面Volume group 'VolGroup00' successfully renamed to 'vg01'則說明改名成功
#vgdisplay //可以看到已經(jīng)有一個改名為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是正在使用的系統(tǒng)盤,而上面是需要拷貝出來的系統(tǒng)盤
#vgchange -ay /dev/vg01 //激此卷組
[root@localhost ~]# vgchange -ay /dev/vg01 3 logical volume(s) in volume group 'vg01' now active
[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 //新建一個文件夾用來作為掛載點(diǎn)
#mount /dev/vg01/邏輯卷名(比如LogVol00) /mnt/hdb //掛載vg01/LogVol00
#vgchange -an /dev/vg01 去除激活的LVM分區(qū)
修改過卷組名的這個硬盤是不能再啟動了,應(yīng)為默認(rèn)啟動引導(dǎo)是引導(dǎo)到VolGroup00卷組的,所以修改過卷組名的硬盤要想仍能重新啟動的話,必須把卷組名修改會默認(rèn)的VolGroup00
但是在已經(jīng)有VolGroup00卷組的虛擬機(jī)上是不能修改的!這里我們單獨(dú)建立一個分區(qū)格式不是Linux LVM格式的虛擬機(jī)來掛載硬盤,其格式為ext3的(顯示為Linux)
#lvscan //查看要改名的卷組是否被激活,要是被激活的話則不能修改卷組名,如果直接修改的話會提示報錯
#vgchange -an /dev/VolGroup00 //如果上一步驟是激活狀態(tài),則需用此命令修改為不激 活狀態(tài)
#lvscan //查看是否修改為不激活狀態(tài)
#vgrename vg01 VolGroup00 //修改為不激活狀態(tài)則可以修改卷組名
在ext3格式分區(qū)的虛擬機(jī)上直接掛載Linux LVM分區(qū)的硬盤的方法如下:
#lvscan //查看掛載的磁盤的卷組是否處于激活的狀態(tài)
#vgchange -ay /dev/VolGroup00 //如上步看到?jīng)]有激活,則執(zhí)行此命令
#mkdir /mnt/hdb //創(chuàng)建掛載點(diǎn)的文件夾
#mount /dev/VolGroup00/LogVol00 /mnt/hdb // 掛載,掛載后則可以訪問/mnt/hdb
#vgchange -an /dev/VolGroup00 //去除掛載磁盤卷組的激活狀態(tài)
補(bǔ)充如果要設(shè)置開機(jī)自動加載LVM分區(qū):
/dev/vg110/LogVol01 /wwwroot/ ext4 defaults 0 0