使用qemu-nbd修改qcow2格式的虚拟机镜像(二):挂载qcow2镜像修改镜像中文件

6 篇文章 0 订阅
3 篇文章 0 订阅

1、映射qcow2镜像到nbd设备

为什么要修改qcow2镜像呢?因为这个镜像中的网口默认是不启动的,想把网口改为默认启动

# ls -l
-rw-r--r--. 1 root root 1617625088 Jun  8 23:09 centos7.7.qcow2
# qemu-nbd --connect=/dev/nbd0 centos7.7.qcow2

2、镜像分区

可以看到镜像中有两个分区,其中第一个是boot分区,第二个是lvm分区

# fdisk -l /dev/nbd0

Disk /dev/nbd0: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x00072170

     Device Boot      Start         End      Blocks   Id  System
/dev/nbd0p1   *        2048     2099199     1048576   83  Linux
/dev/nbd0p2         2099200   104857599    51379200   8e  Linux LVM

3、mount镜像分区

mount后,可以直接修改分区中的文件,可以修改grub中的配置文件

# mkdir tmp
# mount /dev/nbd0p1 tmp/
# ls tmp/
config-3.10.0-1062.el7.x86_64  initramfs-0-rescue-6f9bcc60986041238dcda79bfef462d5.img  System.map-3.10.0-1062.el7.x86_64
efi                            initramfs-3.10.0-1062.el7.x86_64.img                     vmlinuz-0-rescue-6f9bcc60986041238dcda79bfef462d5
grub                           initramfs-3.10.0-1062.el7.x86_64kdump.img                vmlinuz-3.10.0-1062.el7.x86_64
grub2                          symvers-3.10.0-1062.el7.x86_64.gz
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值