设为首页 收藏本站
查看: 677|回复: 0

[经验分享] linux 挂载img文件 的方法

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-16 09:20:50 | 显示全部楼层 |阅读模式
一,有些文件可以直接挂载,不是启动文件,只是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

[iyunv@localhost 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)
[iyunv@localhost file]# echo $((1026048*512))
525336576
[iyunv@localhost file]# losetup /dev/loop3 centos.img -o 525336576
[iyunv@localhost 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   ]
[iyunv@localhost file]# vgchange -ay VolGroup
  2 logical volume(s) in volume group "VolGroup" now active
[iyunv@localhost 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
[iyunv@localhost file]# mount /dev/VolGroup/lv_root /mnt/
[iyunv@localhost 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主机。挂载使用完成后,可以通过下面的方法进行卸载和删除

[iyunv@localhost file]# umount /mnt/
[iyunv@localhost file]# vgchange -an VolGroup
  0 logical volume(s) in volume group "VolGroup" now active
[iyunv@localhost file]# losetup  -d /dev/loop3



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-258558-1-1.html 上篇帖子: centos6.5 64位ssl_version 是 NSS,不是openssl 下篇帖子: linux系统下文件查找 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表