挂载qcow2/raw + guestfish + guestmount

 

1、guestfish --format=raw --rw -a focal-server-cloudimg-arm64.raw
2、 list-filesystems
libguestfs: trace: list_ldm_partitions = []
libguestfs: trace: list_filesystems = ["/dev/sda1", "ext4", "/dev/sda15", "vfat"]
/dev/sda1: ext4
/dev/sda15: vfat

 

 

[root@localhost cloud_images]# guestfish -rw -a vhuser-test1.qcow2
guestfish: cannot mix --ro and --rw options
[root@localhost cloud_images]# guestfish -rw -a vhuser-test1.qcow2
guestfish: cannot mix --ro and --rw options
[root@localhost cloud_images]# guestfish --rw -a vhuser-test1.qcow2 

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

Type: ‘help’ for help on commands
      ‘man’ to read the manual
      ‘quit’ to quit the shell

><fs>run 
><fs> list-filesystems 
/dev/sda1: vfat
/dev/sda2: xfs
><fs> ls /dev/sda2 
libguestfs: error: ls0: ls0_stub: you must call 'mount' first to mount the root filesystem
><fs> mount /dev/sda2 /
><fs> ls
error: incorrect number of arguments
usage: ls directory
type 'help ls' for more help on ls
><fs> ls /
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
><fs> 

 

 

 

[root@localhost images]# ls
centos7.qcow2
[root@localhost images]# qemu-img convert  -f  qcow2  -O raw centos7.qcow2  centos7.raw
[root@localhost images]# ls
centos7.qcow2  centos7.raw
[root@localhost images]# losetup -f 
/dev/loop0
[root@localhost images]# losetup /dev/loop0  centos7.raw
[root@localhost images]# kpartx /dev/loop0
loop0p1 : 0 4774528 /dev/loop0 2048
[root@localhost images]# ls /dev/mapper/loop0p1
ls: cannot access /dev/mapper/loop0p1: No such file or directory
[root@localhost images]# kpartx -d  /dev/loop0
[root@localhost images]# kpartx -av   /dev/loop0
add map loop0p1 (253:0): 0 4774528 linear /dev/loop0 2048
[root@localhost images]# ls /dev/mapper/loop0p1
/dev/mapper/loop0p1
[root@localhost images]# mount  /dev/mapper/loop0p1 /mnt
[root@localhost images]# ls
centos7.qcow2  centos7.raw
[root@localhost images]# mount --bind /dev /mnt/dev
[root@localhost images]# chroot /mnt /bin/bash
[root@localhost /]# PATH=$PATH:/bin:/sbin:/usr/sbin:/usr/bin
[root@localhost /]# mount -t proc none /proc
[root@localhost /]# mount -t sysfs none /sys
[root@localhost /]# ls

 

 

 

install virt-manager   libguestfs-tools

 

[root@localhost images]# guestmount -a centos7.qcow2  -i --rw /mnt
libvirt: XML-RPC error : Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
libguestfs: error: could not connect to libvirt (URI = qemu:///system): Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory [code=38 int1=2]
[root@localhost images]# systemctl restart libvirt
Failed to restart libvirt.service: Unit not found.
[root@localhost images]#  systemctl restart  libvirtd 
[root@localhost images]# yum install libguestfs-tools

 

 

kata vmlinuz

apt install libguestfs-tools -y 不要virt-manager

guestmount -a kata-containers-ubuntu-test.img   -i --rw /mnt/kata

 

posted on 2020-06-30 20:28  tycoon3  阅读(778)  评论(0编辑  收藏  举报

导航