lost and found ( for me ? )

Showing posts with label qcow2. Show all posts
Showing posts with label qcow2. Show all posts

Fedora 19: mount cirros qcow2 image with guestfs-tools

small tips

When evaluating openstack RDO by using cirros images, I would like to change root user’s credentials from default credentials “cubswin:)” to other letters before booting instances.Because I could not enter colon “:” via VNC in my environment for some reasons.

Here’s how to mount cirros qcow2 image and edit /etc/shadow.

I changed credentials to hello.
dump credentials for shadow file
# echo "hello"| openssl passwd -1 -stdin
$1$/xfGm6Qk$zSUqaHU5nycXbK/Za.D1v0

install libguestfs-tools and mount qcow2 image.
# yum install libguestfs-tools


- mount qcow2 image

# mkdir mnt
# guestmount --rw -a cirros-0.3.1-x86_64-disk.img -i mnt

# cd mnt/

# cd etc/


- before editing shadow

# cat shadow
root:!$1$LJwQnqlv$DK6oKqcTq9Rf2ClC.kMa3/:10933:0:99999:7:::
bin:*:10933:0:99999:7:::
daemon:*:10933:0:99999:7:::
adm:*:10933:0:99999:7:::
lp:*:10933:0:99999:7:::
sync:*:10933:0:99999:7:::
shutdown:*:10933:0:99999:7:::
halt:*:10933:0:99999:7:::
uucp:*:10933:0:99999:7:::
operator:*:10933:0:99999:7:::
ftp:*:10933:0:99999:7:::
nobody:*:10933:0:99999:7:::
cirros:$1$LJwQnqlv$DK6oKqcTq9Rf2ClC.kMa3/:10933:0:99999:7:::

# cp shadow shadow.org


- after editing shadow file

# cat shadow
root:$1$/xfGm6Qk$zSUqaHU5nycXbK/Za.D1v0:10933:0:99999:7:::
bin:*:10933:0:99999:7:::
daemon:*:10933:0:99999:7:::
adm:*:10933:0:99999:7:::
lp:*:10933:0:99999:7:::
sync:*:10933:0:99999:7:::
shutdown:*:10933:0:99999:7:::
halt:*:10933:0:99999:7:::
uucp:*:10933:0:99999:7:::
operator:*:10933:0:99999:7:::
ftp:*:10933:0:99999:7:::
nobody:*:10933:0:99999:7:::
cirros:$1$/xfGm6Qk$zSUqaHU5nycXbK/Za.D1v0:10933:0:99999:7:::


# cd ../..

- unmount

# guestunmount mnt/



KVM : convert disk format to qcow2 from row image



[root@localhost ~]# uname -ri
3.7.5-201.fc18.x86_64 x86_64
[root@localhost ~]# cat /etc/fedora-release
Fedora release 18 (Spherical Cow)
[root@localhost ~]# qemu-kvm --version
QEMU emulator version 1.2.2 (qemu-kvm-devel), Copyright (c) 2003-2008 Fabrice Bellard
[root@localhost ~]# libvirtd

# qemu-img info ubuntu-1204-vm1.row
image: ubuntu-1204-vm1.row
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 10G

convert
# qemu-img convert -O qcow2 ubuntu-1204-vm1.row ubuntu-1204-vm1.qcow2

[root@localhost KVM_images]# qemu-img info ubuntu-1204-vm1.qcow2
image: ubuntu-1204-vm1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.2G
cluster_size: 65536

[root@localhost KVM_images]# qemu-img check -f qcow2 ubuntu-1204-vm1.qcow2
No errors were found on the image.

edit the VM’s xml file to use the qcow2 image instead of the row image.
# virsh edit ubuntu1204-vm1

before
      <driver name='qemu' type='raw'/>
      <source file='/var/run/media/hattori/fedora-HDD/KVM_images/ubuntu-1204-vm1.row'/>

after
      <driver name='qemu' type='qcow2'/>
      <source file='/var/run/media/hattori/fedora-HDD/KVM_images/ubuntu-1204-vm1.qcow2'/>

start the VM with qcow2.
# virsh start ubuntu1204-vm1
Domain ubuntu1204-vm1 started

virsh # qemu-monitor-command --hmp ubuntu1204-vm1 'info status'
VM status: running

virsh # qemu-monitor-command --hmp ubuntu1204-vm1 'info block'
drive-virtio-disk0: removable=0 io-status=ok file=/var/run/media/hattori/fedora-HDD/KVM_images/ubuntu-1204-vm1.qcow2 ro=0 drv=qcow2 encrypted=0 bps=0 bps_rd=0 bps_wr=0 iops=0 iops_rd=0 iops_wr=0
drive-ide0-1-0: removable=1 locked=0 tray-open=0 io-status=ok [not inserted]