mount一個lvm格式的磁碟映像檔案
如果是非lvm格式的,則非常方便,給mount命令傳遞offset引數即可,例如:
[[email protected] xen-images]# fdisk -lu centos_vm1
last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.
Disk centos_vm1: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot
Start
End Blocks Id System
centos_vm1p1
*
63 208844
104391 83 Linux
centos_vm1p2
208845 4192964
1992060 8e Linux LVM
看到第一個磁碟分割槽是Linux分割槽,起始於63扇區,直接mount:
[
[[email protected] xen-images]# mount -o loop,offset=$[63*512] centos_vm1 /mnt/disk/
[[email protected] xen-images]# ls /mnt/disk/
config-2.6.18-92.el5xen
lost+found
System.map-2.6.18-92.el5xen xen-syms-2.6.18-92.el5
grub
message
vmlinuz-2.6.18-92.el5xen
initrd-2.6.18-92.el5xen.img symvers-2.6.18-92.el5xen.gz xen.gz-2.6.18-92.el5
顯示,這個linux分割槽是/boot,root檔案系統在centos_vm1p2的這塊lvm區中,要設法把它mount上來,使用以下方法:
首先找到它的起始偏移,使用fdisk的-u引數在列出磁碟分割槽的時候以扇區(sector)為單位,否則是以柱面(cylinder)為單位的:
[[email protected] xen-images]# fdisk -lu centos_vm1
last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.
Disk centos_vm1: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
centos_vm1p1 * 63 208844 104391 83 Linux
centos_vm1p2 208845 4192964 1992060 8e Linux LVM
從上看出lvm分割槽起始於208845扇區,把這個地址處的分割槽mount為loop裝置:
-f引數表示自動尋找可用的loop裝置檔案,-o指定偏移量。
[[email protected] xen-images]# losetup -f -o $[208845*512] centos_vm1
[[email protected] xen-images]# losetup -a
/dev/loop0: [0806]:1097730 (centos_vm1), offset 106928640
掃描lvm volumns:
[[email protected] xen-images]# lvm pvscan
PV /dev/loop0 VG VolGroup00 lvm2 [1.88 GB / 0 free]
Total: 1 [1.88 GB] / in use: 1 [1.88 GB] / in no VG: 0 [0 ]
啟用lvm volumn:
[[email protected] xen-images]# lvm vgchange -ay
2 logical volume(s) in volume group "VolGroup00" now active
[[email protected] xen-images]# ls /dev/mapper/
control VolGroup00-LogVol00 VolGroup00-LogVol01
[[email protected] xen-images]# lvm lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
LogVol00 VolGroup00 -wi-a- 1.50G
LogVol01 VolGroup00 -wi-a- 384.00M
使用:
[[email protected] xen-images]# mount /dev/mapper/VolGroup00-LogVol00 /mnt/usb
[[email protected] xen-images]# ls /mnt/usb
bin dev home lost+found misc opt proc sbin srv tmp var
boot etc lib media mnt poweroff root selinux sys usr
最後,在操作完以後,umount這個裝置,然後設定這個lvm volumn為非活動狀態:
[[email protected] xen-images]# umount /mnt/usb
[[email protected] xen-images]# lvm vgchange -an
0 logical volume(s) in volume group "VolGroup00" now active
[[email protected] xen-images]# losetup -a
/dev/loop0: [0806]:1097730 (centos_vm1), offset 106928640
[[email protected] xen-images]# losetup -d /dev/loop0