LVM image mount/umount

本文介绍了两种在Linux下挂载LVM(Logical Volume Manager)映像文件的方法。首先通过`losetup`分配loopback设备,然后使用`kpartx`创建映射分区,接着扫描卷组并挂载逻辑卷。另一种方法是通过`fdisk`确定分区起始位置,使用`losetup`指定偏移量挂载。最后,展示了如何卸载挂载的LVM映像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error

It can not mount.

#mount system.img /mnt/

mount: system.img is not a block device (maybe try `-o loop'?)

#mount -o loop system.img /mnt/

mount: you must specify the filesystem type

#file system.img

system.img: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 63, 208782 sectors; partition

0x8e, starthead 0, startsector 208845, 12370050 sectors, code offset 0x48

Solution_1

Mount

1).Survey which is open to the loopback device to mount

#losetup -f/dev/loop0

#losetup /dev/loop0 system.img


2).To check the status of DEBAISUMAPPA add a partition

#ls /dev/mapper/control


Add partition mappings from partition tables

#kpartx -a /dev/loop0

#ls /dev/mapper/

control loop0p1 loop0p2

3).Check out the partition

#fdisk -l -u /dev/loop0Disk /dev/loop0: 6442 MB, 6442450944 bytes Disk

255 heads, 63 sectors/track, 783 cylinders, total 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System Device Boot
/dev/loop0p1 * 63 208844 104391 83 Linux
/dev/loop0p2 208845 12578894 6185025 8e Linux LVM

4).To Check status

Scan the volume group

#vgscanReading all physical volumes. This may take a while…

Found volume group " VolGroup00" using metadata type lvm2
Scan the logic volume


#lvscaninactive '/dev/VolGroup00/LogVol00' [3.94 GB]

inactive '/dev/ VolGroup00/ LogVol01' [1.94 GB]
Scan the physical volume


#pvscan

PV /dev/mapper/loop0p2 VG VolGroup00? lvm2 [5.88 GB / 0 free]

Total:1 [5.88 GB] / in use: 1 [5.88 GB] / in no VG: 0 [0 ]

Check VG Enabled

#vgchange -ay

2 logical volume(s) in volume group "VolGroup00" now active

#lvscanACTIVE '/dev/VolGroup00/LogVol00' [3.94 GB] inherit

ACTIVE '/dev/ VolGroup00/ LogVol01' [1.94 GB] inherit


#mount /dev/VolGroup00/LogVol00 /mnt


7) If you try to mount a swap will failed
  1. mount /dev/VolGroup00/LogVol01 /mnt2
/dev/ VolGroup00/ LogVol01 looks like swapspace – not mounted
mount: you must specify the filesystem type

UMount

#umount /mnt

#vgchange -an

logical volume(s) in volume group "VolGroup00" now active

lvscaninactive '/dev/VolGroup00/LogVol00' [3.94 GB] inherit
inactive '/dev/VolGroup00/LogVol01' [1.94 GB] inherit

#kpartx -d /dev/loop0

#ls /dev/mapper/control

#losetup -d /dev/loop0

#losetup -f /dev/loop0


Solution_2

Mount

# fdisk -l -u system.img
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 system.img: 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
ovs_el5_x86_64.img1   *          63      208844      104391   83  Linux
ovs_el5_x86_64.img2          208845    12578894     6185025   8e  Linux LVM



  Calculate the byte offset to the desired partition by multiplying the Start location times the Unit size (e.g. 63 * 512 bytes = 32256 bytes). Using 'losetup', mount a loop device to the calculated partition of the image file.

# losetup -f system.img -o 32256
# losetup -a

/dev/loop0: [0821]:49057 (/OVS/EL5/system.img)
/dev/loop1: [0821]:49057 (system.img), offset 32256
# mkdir /mnt/img
# mount /dev/loop1 /mnt/img
# ls /mnt/img
config-2.6.18-8.1.14.0.2.el5      symvers-2.6.18-8.el5xen.gz
config-2.6.18-8.el5xen            System.map-2.6.18-8.1.14.0.2.el5
grub                              System.map-2.6.18-8.el5xen
initrd-2.6.18-8.1.14.0.2.el5.img  vmlinuz-2.6.18-8.1.14.0.2.el5
initrd-2.6.18-8.el5xen.img        vmlinuz-2.6.18-8.el5xen
lost+found                        xen.gz-2.6.18-8.el5
symvers-2.6.18-8.1.14.0.2.el5.gz  xen-syms-2.6.18-8.el5

 UMount


#umount /mnt   

#losetup -d /dev/loop0

#losetup -f /dev/loop0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值