How to extract content of a raw image on host?
Hi,
is there a way to extract the contents of a qemu raw image on (x86 Linux) host without starting QEMU itself? If so, any hint would be quite nice.
I'm looking for anything like the reverse what
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00448.html
seems to do. Extract files/directories from an existing raw image.
qemu-img reports me
Quoted 1 line
qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 4.3M (4515328 bytes)
disk size: 4.3M
but what is in it and how to access the content?
Thanks, and sorry if this is a FAQ and I missed the correct search string,
Dirk
Quoted 18 lines · Dirk Behme
Hi,
is there a way to extract the contents of a qemu raw image on (x86 Linux) host without starting QEMU itself? If so, any hint would be quite nice.
I'm looking for anything like the reverse what
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00448.html
seems to do. Extract files/directories from an existing raw image.
qemu-img reports me
Quoted 1 line
qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 4.3M (4515328 bytes)
disk size: 4.3M
Quoted 8 lines
but what is in it and how to access the content?
Thanks, and sorry if this is a FAQ and I missed the correct search string,
Dirk
Hi,
have you tried using a loop back mount?
Quoted 22 lines · JonY
Quoted 20 lines · Dirk Behme
Hi,
is there a way to extract the contents of a qemu raw image on (x86 Linux) host without starting QEMU itself? If so, any hint would be quite nice.
I'm looking for anything like the reverse what
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00448.html
seems to do. Extract files/directories from an existing raw image.
qemu-img reports me
Quoted 1 line
qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 4.3M (4515328 bytes)
disk size: 4.3Mbut what is in it and how to access the content?
Quoted 7 lines
Quoted 4 lines
Thanks, and sorry if this is a FAQ and I missed the correct search string,
Dirk
Hi,
have you tried using a loop back mount?
# mount -o loop disk.img mnt/ mount: You have to specify a file system type # mount -t raw -o loop disk.img mnt/ mount: unknown file system type „raw“
Sorry if I miss the obvious ;)
Dirk
Quoted 31 lines · Dirk Behme
Quoted 22 lines · JonY
Quoted 20 lines · Dirk Behme
Hi,
is there a way to extract the contents of a qemu raw image on (x86 Linux) host without starting QEMU itself? If so, any hint would be quite nice.
I'm looking for anything like the reverse what
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00448.html
seems to do. Extract files/directories from an existing raw image.
qemu-img reports me
Quoted 1 line
qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 4.3M (4515328 bytes)
disk size: 4.3Mbut what is in it and how to access the content?
Quoted 7 lines
Quoted 4 lines
Thanks, and sorry if this is a FAQ and I missed the correct search string,
Dirk
Hi,
have you tried using a loop back mount?
Quoted 10 lines
# mount -o loop disk.img mnt/ mount: You have to specify a file system type # mount -t raw -o loop disk.img mnt/ mount: unknown file system type „raw“Sorry if I miss the obvious ;)
Dirk
Hi,
"raw" is not really a file system, its just a way of saying the image has a "exact copy of every bit" of what a physical disk would have.
Try, "mount -o loop disk.img mnt/", mount might be able to determine the correct file system.
If it is a hard disk image with partition tables, try opening it with fdisk to confirm so. List down the partitions. Note the offsets
Try something like "mount -o loop,offset=32256 disk.img mnt/"
see here for more details:
http://howto.wikia.com/wiki/How_to_see_the_content_of_a_Qemu_image_on_a_linux-based_OS
Quoted 4 lines · JonY
Try, "mount -o loop disk.img mnt/", mount might be able to determine the correct file system.
Oops, I didn't read your message thoroughly, sorry. I've never really need to specify the type of file system for mount, not sure what happened.
Quoted 32 lines · Dirk Behme
Quoted 31 lines · JonY
Quoted 20 lines · Dirk Behme
Hi,
is there a way to extract the contents of a qemu raw image on (x86 Linux) host without starting QEMU itself? If so, any hint would be quite nice.
I'm looking for anything like the reverse what
http://lists.gnu.org/archive/html/qemu-devel/2006-04/msg00448.html
seems to do. Extract files/directories from an existing raw image.
qemu-img reports me
Quoted 1 line
qemu-img info disk.img
image: disk.img
file format: raw
virtual size: 4.3M (4515328 bytes)
disk size: 4.3MQuoted 7 lines
but what is in it and how to access the content?
Thanks, and sorry if this is a FAQ and I missed the correct search string,
Dirk
Hi,
Quoted 8 lines
Quoted 1 line
have you tried using a loop back mount?
# mount -o loop disk.img mnt/ mount: You have to specify a file system type # mount -t raw -o loop disk.img mnt/ mount: unknown file system type „raw“Sorry if I miss the obvious ;)
Loop is not able to manage partition.
Either you use the offset option to point to the offset of the partition you want to mount in the raw image.
Either you use the attached patch to be able to manage partition table with loop (and load the module with parameter "max_part=64")
Laurent
Signature · 3 lines
----------------- [email protected] ------------------ "Programmers who subconsciously view themselves as artists will enjoy what they do and will do it better." D. Knuth
Quoted 1 line
From
12bb62c07ee5c69a170bd4e5dea5aaf9fd32c4ebMon Sep 17 00:00:00 2001
From: Laurent Vivier <[email protected]>
Date: Wed, 16 Jan 2008 14:42:21 +0100
Subject: [PATCH] Modify loop device to be able to manage partitions of the image disk
--- drivers/block/loop.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 files changed, 38 insertions(+), 6 deletions(-)
drivers/block/loop.c +38 -6
@@ -82,6 +82,9 @@static LIST_HEAD (loop_devices);static DEFINE_MUTEX (loop_devices_mutex); +static int max_part =1 ; +static int part_shift; +/* * Transfer functions */
@@ -692,6 +695,8 @@ static int loop_change_fd(struct loop_device *lo, struct file *lo_file, goto out_putf;fput (old_file); +if (max_part >1 ) +ioctl_by_bdev (bdev,BLKRRPART ,0 );return 0 ; out_putf:
@@ -819,6 +824,8 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, } lo->lo_state = Lo_bound;wake_up_process (lo->lo_thread); +if (max_part >1 ) +ioctl_by_bdev (bdev,BLKRRPART ,0 );return 0 ; out_clr:
@@ -1352,6 +1359,8 @@ static struct block_device_operations lo_fops = {static int max_loop;module_param (max_loop, int,0 );MODULE_PARM_DESC (max_loop,"Maximum number of loop devices" ); +module_param (max_part, int,0 ); +MODULE_PARM_DESC (max_part,"Maximum number of partition by loop device" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_BLOCKDEV_MAJOR (LOOP_MAJOR );
@@ -1404,7 +1413,7 @@ static struct loop_device *loop_alloc(int i)if (!lo->lo_queue) goto out_free_dev; - disk = lo->lo_disk =alloc_disk (1 ); + disk = lo->lo_disk =alloc_disk (1 << part_shift);if (!disk) goto out_free_queue;
@@ -1414,7 +1423,7 @@ static struct loop_device *loop_alloc(int i)init_waitqueue_head (&lo->lo_event);spin_lock_init (&lo->lo_lock); disk->major =LOOP_MAJOR ; - disk->first_minor = i; + disk->first_minor = i << part_shift; disk->fops = &lo_fops; disk->private_data = lo; disk->queue = lo->lo_queue;
@@ -1477,7 +1486,7 @@ static struct kobject *loop_probe(dev_t dev, int *part, void *data)static int __init loop_init (void ) {int i, nr; -unsigned long range; +unsigned long range, bitfield;struct loop_device *lo, *next;/*
@@ -1494,7 +1503,11 @@ static int __init loop_init(void)* themselves and have kernel automatically instantiate actual * device on-demand. */ -if (max_loop >1UL <<MINORBITS ) + + bitfield = max_part; + part_shift =find_first_bit (&bitfield,sizeof (bitfield)); + +if (max_loop >1UL << (MINORBITS - part_shift))return -EINVAL ;if (max_loop) {
@@ -1502,7 +1515,7 @@ static int __init loop_init(void) range = max_loop; }else { nr =8 ; - range =1UL <<MINORBITS ; + range =1UL << (MINORBITS - part_shift); }if (register_blkdev (LOOP_MAJOR ,"loop" ))
@@ -1541,7 +1554,7 @@ static void __exit loop_exit(void)unsigned long range;struct loop_device *lo, *next; - range = max_loop ? max_loop :1UL <<MINORBITS ; + range = max_loop ? max_loop :1UL << (MINORBITS - part_shift);list_for_each_entry_safe (lo, next, &loop_devices, lo_list)loop_del_one (lo);
@@ -1561,4 +1574,23 @@ static int __init max_loop_setup(char *str) }__setup ("max_loop=" , max_loop_setup); + +static int __init max_part_setup (char *str) +{ + max_part =simple_strtol (str,NULL ,0 ); +if (max_part <1 ) { +/* there is at least one partition */ +printk (KERN_ERR "loop: max_part cannot be lesser than 1\n" ); +return 0 ; + } +if (max_part >MINORBITS -1 ) { +/* we must keep at least one bit for loop device number */ +printk (KERN_ERR "loop: max_part cannot be greater than %d\n" , +MINORBITS -1 ); +return 0 ; + } +return 1 ; +} + +__setup ("max_part=" , max_part_setup);#endif
Signature · 1 line
1.5.2.4
Quoted 1 line · Laurent Vivier
Loop is not able to manage partition.
You could use kpartx (from util-linux), which will create device nodes for each partition.
Cheers,
Signature · 1 line
Stuart Brady