Harddisk, format and then add?

Simen Musaeus

New Member
Sep 20, 2017
9
0
1
55
I'm trying to assign disposable storage, that would be a harddisk that is only used for a given session, and deleted upon vm shutdown.

Is it possible to create and format a harddisk, say to NTFS (for windows), without entering the virtual machine?

I would really like to avoid having to enter and format the disk each time I start a new session.
 
Is it possible to create and format a harddisk, say to NTFS (for windows), without entering the virtual machine?


Yes, the easiest way is to create a virtual disk in "raw" format, define it afterwards as loop device, e.g.

Code:
losetup /dev/loop1 /storage/images/vm-100-disk-1.raw

and format it then according to your needs. Before starting the VM disable the loop device

Code:
losetup -d /dev/loop1

Works in case of an currently idle VM.

In case of an already running VM which supports disk hotplug it may work too, but it's recommended to remove the disk from the VM for the process of formatting and join it afterwards again.