Skip to contentSkip to conversation

Block Memory boot devices

PATCH In review Jason Wessel 1 participant 1 message May 20, 2006 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 Block Memory boot devices

This patch adds memory block devices to QEMU. It was mainly for the purpose of booting a pentium qemu without a disk, but it is also very useful for testing and debugging different types of file systems from the OS using only memory.

Signed-off-by [email protected]

Jason.

Makefile +1 -1
Index: qemu/Makefile
===================================================================
@@ -29,7 +29,7 @@ subdir-%: dyngen$(EXESUF)
 
 recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS))
         
-qemu-img$(EXESUF): qemu-img.c block.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c
+qemu-img$(EXESUF): qemu-img.c block.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c block-mem.c
 	$(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)
 
 dyngen$(EXESUF): dyngen.c
Makefile.target +1 -1
Index: qemu/Makefile.target
===================================================================
@@ -273,7 +273,7 @@ endif
 
 # must use static linking to avoid leaving stuff in virtual address space
 VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o loader.o
-VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
+VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o block-mem.o
 ifdef CONFIG_WIN32
 VL_OBJS+=tap-win32.o
 endif
block-mem.c new file +216 -0

216 lines not on this page · raw message

block.c +1 -0
Index: qemu/block.c
===================================================================
@@ -784,6 +784,7 @@ BlockDriver bdrv_raw = {
 void bdrv_init(void)
 {
     bdrv_register(&bdrv_raw);
+    bdrv_register(&bdrv_mem);
 #ifndef _WIN32
     bdrv_register(&bdrv_cow);
 #endif
qemu-doc.texi +16 -0
Index: qemu/qemu-doc.texi
===================================================================
@@ -814,6 +814,7 @@ written), compressed and encrypted disk 
 * disk_images_snapshot_mode:: Snapshot mode
 * qemu_img_invocation::       qemu-img Invocation
 * disk_images_fat_images::    Virtual FAT disk images
+* disk_images_mem_images::    Memory only scratch disk
 @end menu
 
 @node disk_images_quickstart
@@ -878,6 +879,21 @@ What you should @emph{never} do:
 @item write to the FAT directory on the host system while accessing it with the guest system.
 @end itemize
 
+@node disk_images_mem_images
+@subsection Memory only scratch disk
+
+QEMU can create an in memory scratch disk device instead of using a disk image.  This is the default on a pentium system to satisfy the BIOS if you do not provide a disk image.  In the default case you only have a single 512byte sector which is the MBR of the scratch disk, but you can create a large scratch disk.  You can also choose to use memory scratch devices with any other target.  The syntax is as follows:
+
+@example
+qemu -kernel bzImage -hda mem:0:1
+@end example
+
+The scratch disks use the keyword "mem" followed by ":" then the memory device number "0", and finally the number of 512 byte sectors to allocate.  The above invocation is equivalent to when the -hda and its parameter are omitted for the pentium qemu.  Below is an example of creating a 1 megabyte scratch disk as the second IDE drive.
+
+@example
+qemu -kernel bzImage -hda hdisk.img -hdb mem:1:524288
+@end example
+
 @node pcsys_network
 @section Network emulation
 
vl.c +8 -0
Index: qemu/vl.c
===================================================================
@@ -5556,6 +5556,14 @@ int main(int argc, char **argv)
         bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
     }
 
+#ifdef TARGET_I386
+    /* Allow a i386 target to boot with no "-hda" argument */
+    if (!hd_filename[0]) {
+        hd_filename[0] = strdup("mem:0:1");
+        boot_device = 'c';
+    }
+#endif /* TARGET_I386 */
+
     /* open the virtual block devices */
     for(i = 0; i < MAX_DISKS; i++) {
         if (hd_filename[i]) {
vl.h +1 -0
Index: qemu/vl.h
===================================================================
@@ -468,6 +468,7 @@ int cpu_load(QEMUFile *f, void *opaque, 
 typedef struct BlockDriverState BlockDriverState;
 typedef struct BlockDriver BlockDriver;
 
+extern BlockDriver bdrv_mem;
 extern BlockDriver bdrv_raw;
 extern BlockDriver bdrv_cow;
 extern BlockDriver bdrv_qcow;