linux 挂载img文件 的方法

一,有些文件可以直接挂载,不是启动文件,只是img文件,

losetup /dev/loop1 zenith.img

kpartx -av /dev/loop1

mount /dev/loop1 /mnt/zenith/

二,如果是虚机的系统磁盘,直接挂载可能会有问题,选择挂载对应的lv

# fdisk -ul xxx.img

Disk 3059.img: 4294 MB, 4294967296 bytes

255 heads, 63 sectors /track , 522 cylinders, total 8388608 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical /physical ): 512 bytes / 512 bytes

I /O size (minimum /optimal ): 512 bytes / 512 bytes

Disk identifier: 0x000bdbdc

Device Boot Start End Blocks Id System

3059.img1 * 63 7903979 3951958+ 83 Linux

3059.img2 7903980 8385929 240975 5 Extended

3059.img5 7904043 8385929 240943+ 82 Linux swap / Solaris

从上面的信息可以看到,从63开始,其中lvm的磁盘从7904043开始。

由这条信息可以的出,扇区大小为512

Units = sectors of 1 * 512 = 512 bytes

所以我们需要从512*63出开始挂载

最后执行:

(sudo) mount -o loop,offset=32256  xxx.img /mnt/xxx……

# ls /mnt/

config-2.6.32-279.el6.x86_64  initramfs-2.6.32-279.el6.x86_64.img  System.map-2.6.32-279.el6.x86_64

efi                           lost+found                           vmlinuz-2.6.32-279.el6.x86_64

grub                          symvers-2.6.32-279.el6.x86_64.gz

这样挂载了第一个磁盘,可能不是我们想要的系统。所以应该挂载下面的lvm

[[email protected] file]# fdisk -lu centos.img

You must set cylinders.

You can do this from the extra functions menu.

Disk centos.img: 0 MB, 0 bytes

255 heads, 63 sectors/track, 0 cylinders, total 0 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0001905c

Device Boot      Start         End      Blocks   Id  System

centos.img1   *        2048     1026047      512000   83  Linux

Partition 1 does not end on cylinder boundary.

centos.img2         1026048    62914559    30944256   8e  Linux LVM

Partition 2 has different physical/logical endings:

phys=(1023, 254, 63) logical=(3916, 63, 51)

[[email protected] file]# echo $((1026048*512))

525336576

[[email protected] file]# losetup /dev/loop3 centos.img -o 525336576

[[email protected] file]# pvscan

PV /dev/mapper/loop0p2   VG VolGroup   lvm2 [29.51 GiB / 0    free]

Total: 1 [29.51 GiB] / in use: 1 [29.51 GiB] / in no VG: 0 [0   ]

[[email protected] file]# vgchange -ay VolGroup

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

[[email protected] file]# lvs

LV      VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

lv_root VolGroup -wi-a----- 27.54g

lv_swap VolGroup -wi-a-----  1.97g

[[email protected] file]# mount /dev/VolGroup/lv_root /mnt/

[[email protected] file]# ls /mnt/

bin   dev  home  lib64       media  opt   root  selinux  sys  usr

boot  etc  lib   lost+found  mnt    proc  sbin  srv      tmp  var

这样就挂载到了对应系统的LVM 然后就可以修改系统文件了

上例中,最后几步,是通过查看配置文件区确实是否是某台KVM主机。挂载使用完成后,可以通过下面的方法进行卸载和删除

[[email protected] file]# umount /mnt/

[[email protected] file]# vgchange -an VolGroup

0 logical volume(s) in volume group "VolGroup" now active

[[email protected] file]# losetup  -d /dev/loop3

时间: 2024-08-09 19:52:00

linux 挂载img文件 的方法的相关文章

Linux挂载磁盘镜像文件

Linux挂载IMG磁盘镜像文件: 原文地址:https://blog.51cto.com/xinghaiyuan/2383244

linux访问windows文件的方法

博客转自:http://www.01happy.com/linux-access-windows-shares-folders/ 有时需要在linux下需要访问windows的共享文件夹,可以使用mount挂载或者使用samba连接. 1.mount挂载 首先创建被挂载的目录: $ mkdir windows 将共享文件夹挂载到windows文件夹: $ sudo mount -t cifs -o username=share,password=share //192.168.66.198/sh

linux下core文件调试方法(转载)

转自于:http://blog.csdn.net/fcryuuhou/article/details/8507775 在程序遇到段错误不寻常退出时,一般是访问内存出错.但是不会给出程序哪里出现的问题,这个时候就需要core文件来帮助调试. 内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件的生成开关和大小限制 1)使用ulimit -c命令可查看core文件的生成开关.若结果

linux下查找文件的方法

1. find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件. find的使用格式如下: $ find <指定目录> <指定条件> <指定动作> - <指定目录>: 所要搜索的目录及其所有子目录.默认为当前目录. - <指定条件>: 所要搜索的文件的特征. - <指定动作>: 对搜索结果进行特定的处理. 如果什么参数也不加,find默认搜索当前目录及其子目录,并且不过滤任何结果(也就是返回所有文件),将它们全都显

linux 挂载iso文件安装文件

1.首先,创建文件作为挂载点mkdir /文件名/2.mount /iso/rhel-server-7.3-x86_64-dvd.iso /dir/ 将/iso目录下的镜像挂载到 /dir/文件上 3. cd /etc/yum.repos.d/ 进入文件 4. rm -fr * 删除目录下所有文件 5.vim yum.repo 编辑文件内容 6. rhe17.3] 说明 name=rhe17.3 名称 baseurl=file:///rhe17.3 位置 gpgcheck=0 跳过来源检查 7.

linux下文件加密方法总结

为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单总结: 方法一:gzexe加密这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本中的密码等信息.它是使用系统自带的gzexe程序,它不但加密,同时压缩文件.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 3

chapter8:Linux磁盘与文件系统管理之(4)设置开机挂载

一.开机挂载/etc/fstab与/etc/mtab 前面的挂载方法每次进入系统的时候都要进行一次mount ,如果想在开机的时候自动挂载,我们应该到/etc/fstab里面进行修改. 下面我们先看看这个文件里面的内容. 第一列:设备文件名或者设备的Label 系统默认的是使用Label(对比下图),这里要说明下,使用设备名(如/dev/sda1)来挂载分区时,是被固定死的,所以硬盘不能随意插,而使用Labe name来挂载时,虽然没有上面的问题,但是你要注意label的名字,特别是在新加硬盘的

Linux系统下文件删除的恢复方法

对于rm,很多人都有惨痛的教训.我也遇到一次,一下午写的程序就被rm掉了,幸好只是一个文件,第二天很快又重新写了一遍.但是很多人可能就不像我这么幸运了.本文收集了一些在Linux下恢复rm删除的文件的方法,给大家作为参考. 首先,最好的方法是避免这个问题,以下是几点建议: 1.rm -rf误操作的后果是可怕的,rm -f也要三思而行,不能轻易使用. 2.做好数据备份. 3.用一些策略避免出错: 提倡在shell下用 TAB 补全,用脚本执行任务,减少出错的机会.或者编写一个脚本,起名rm,在脚本

linux挂载iso,u盘,分区,squashfs压缩文件

常见分区加载方法: mount挂载iso文件: #mkdir /mnt/iso1 #mount –o loop linuxsetup.iso /mnt/iso1 在linux 不需要虚拟光驱,就可以直接读取iso文件了. mount挂载squashfs压缩文件系统: #mkdir /mnt/src-squashfs #sudo mount -t squashfs -o loop src-cd/casper/filesystem.squashfs  /mnt/src-squashfs/  #挂载原