Sunday, January 7, 2018

emulate a flashdrive in qemu


1- create usbstick image

- if raw type
$ qemu-img create -f raw -o size=1G test.raw

-if qcow2 type

$ qemu-img create -f qcow2 -o size=1G test.cow2

2- create file system

if need to create partition use fdisk test.raw
-or to formate as ext4 file system
$ mkfs.ext4 test.raw



3- to test we can just to tinycore live cd, download from
https://mirrors.dotsrc.org/tinycorelinux/downloads.html

- execute
$ qemu-system-x86_64 -drive if=none,id=usbstick,file=/home/use1/test.raw -usb -device usb-ehci,id=ehci   \
        -device usb-storage,bus=ehci.0,drive=usbstick -m 2048 -hdc /home/tun/Downloads/TinyCore-current.iso



- the usb will be in /dev/sdb, so we can mount it to use
$ mount /dev/sdb /mnt

No comments:

Post a Comment