### version
lake@lake-Latitude-5491:~/qemu$ qemu-system-i386 -version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.10)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
lake@lake-Latitude-5491:~/qemu$ qemu-img -V
qemu-img version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.10)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
lake@lake-Latitude-5491:~/qemu$
$qemu-img create -f raw disk.img 200M
Formatting 'disk.img', fmt=raw size=209715200
lake@lake-Latitude-5491:~/qemu$ mkfs.ext4 -F disk.img
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: c9a1e9ee-d8fe-4eb6-950b-d07dc40f518a
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
lake@lake-Latitude-5491:~/qemu$ qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 200M (209715200 bytes)
disk size: 328K
lake@lake-Latitude-5491:~/qemu$ qemu-img resize disk.img +2G
WARNING: Image format was not specified for 'disk.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
Image resized.
lake@lake-Latitude-5491:~/qemu$ qemu-system-i386 -hda disk.img -cdrom Win7PE.iso -boot d
WARNING: Image format was not specified for 'disk.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
### boot from hard disk
lake@lake-Latitude-5491:~/qemu$ qemu-system-i386 -hda disk.img -cdrom Win7PE.iso -boot c
lake@lake-Latitude-5491:~/qemu$ qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 2.2G (2357198848 bytes)
disk size: 331M
lake@lake-Latitude-5491:~/qemu$
lake@lake-Latitude-5491:~/qemu$ qemu-img convert -c -O qcow2 disk.img disk.qcow2
lake@lake-Latitude-5491:~/qemu$
lake@lake-Latitude-5491:~/qemu$
lake@lake-Latitude-5491:~/qemu$ qemu-img info disk.qcow2
image: disk.qcow2
file format: qcow2
virtual size: 2.2G (2357198848 bytes)
disk size: 253M
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
Refer to
https://gist.github.com/shamil/62935d9b456a6f9877b5
https://blahcat.github.io/2018/01/07/building-a-debian-stretch-qemu-image-for-aarch64/
nbd module is not shipped with Fedora based distributions including centos/fedora/rhel. RedHat decided against shipping nbd kernel module due to security reasons. nbd module is only available on debian distributions.
Ubuntu
$ sudo apt install nbd-client
$ sudo modprobe nbd max_part=8
$ sudo qemu-nbd --connect=/dev/nbd0 disk.qcow2
$ mkdir mnt
$ sudo mount /dev/nbd0p1 mnt
$ cp mnt/initrd.img-4.9.0-4-arm64 mnt/vmlinuz-4.9.0-4-arm64 .
$ sync
$ sudo umount /dev/nbd0p1
$ sudo nbd-client -d /dev/nbd0
guestmount
libguestfs-tools
guestmount -a path_to_image.qcow2 -i --ro /mount_point # safe, read only
guestmount -a path_to_image.qcow2 -i /mount_point # use only on not running vm image
guestmount utility can be found in libguestfs-tools package (on Debian and RHEL).
Change root password
## check partition
virt-inspector /home/lake/debian-10-openstack-arm64.qcow2