Virtual filesystem images: Difference between revisions

From lippmann wiki
Jump to navigation Jump to search
(Created page with "if you have a raw disk image, for example a disk drive for a hypervisor (raw file or vmdk) it may have multiple partitions. to quickly create devices for these you can use kp...")
 
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
if you have a raw disk image, for example a disk drive for a hypervisor (raw file or vmdk) it may have multiple partitions.
=kpartx=
if you have a raw disk image, for example a disk drive for a hypervisor it may have multiple partitions.


to quickly create devices for these you can use kpartx. after they are created you can mount these devices on your filesystem:
to quickly create devices for these you can use kpartx. after they are created you can mount these devices on your filesystem:
Line 5: Line 6:
e.g.:
e.g.:


  [root@rkvm1 select_fun]# kpartx -v -a DataONTAPv-kvm.raw
  [maarten@rkvm1 select_fun] sudo kpartx -v -a DataONTAPv-kvm.raw
  add map loop1p1 (253:3): 0 66464 linear 7:1 64
  add map loop1p1 (253:3): 0 66464 linear 7:1 64
  add map loop1p2 (253:4): 0 8390592 linear 7:1 66528
  add map loop1p2 (253:4): 0 8390592 linear 7:1 66528
Line 15: Line 16:


and these are now visible in /dev/mapper:  
and these are now visible in /dev/mapper:  
  [root@rkvm1 select_fun]# ls -lrt /dev/mapper/
 
total 0
  [maarten@rkvm1 select_fun] ls -lrt /dev/mapper/ |grep loop
lrwxrwxrwx. 1 root root      7 Jan 29 19:42 rl-swap -> ../dm-1
lrwxrwxrwx. 1 root root      7 Jan 29 19:42 rl-root -> ../dm-0
crw-------. 1 root root 10, 236 Jan 29 19:42 control
lrwxrwxrwx. 1 root root      7 Jan 29 19:42 rl-var_lib_libvirt_images -> ../dm-2
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p1 -> ../dm-3
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p1 -> ../dm-3
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p2 -> ../dm-4
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p2 -> ../dm-4
Line 28: Line 25:
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p6 -> ../dm-8
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p6 -> ../dm-8
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p7 -> ../dm-9
  lrwxrwxrwx. 1 root root      7 Jan 29 20:12 loop1p7 -> ../dm-9
this does not seem to work well on vmdk images. As a result.
=mount a vmdk=
for a vmdk it seems other tools work better. qemu will do the trick
first create an ndb device
[maarten@rkvm1 select_fun] sudo modprobe nbd
now have it create the devices for the different partions
[maarten@rkvm1 select_fun] sudo  qemu-nbd -r -c /dev/nbd1 DataONTAPv.vmdk
[maarten@rkvm1 select_fun] ls -al /dev/nbd1p*
brw-rw----. 1 root disk 43, 33 Jan 29 20:21 /dev/nbd1p1
brw-rw----. 1 root disk 43, 34 Jan 29 20:21 /dev/nbd1p2
brw-rw----. 1 root disk 43, 35 Jan 29 20:21 /dev/nbd1p3
brw-rw----. 1 root disk 43, 36 Jan 29 20:21 /dev/nbd1p4
brw-rw----. 1 root disk 43, 37 Jan 29 20:21 /dev/nbd1p5
brw-rw----. 1 root disk 43, 38 Jan 29 20:21 /dev/nbd1p6
brw-rw----. 1 root disk 43, 39 Jan 29 20:21 /dev/nbd1p7
(with help from https://jasonmurray.org/posts/2021/mountvmdk/, he goes into more detail)
[maarten@rkvm1 select_fun] sudo  mount  /dev/nbd1p2 /mnt/source/
mount: /mnt/source: WARNING: source write-protected, mounted read-only.
  [maarten@rkvm1 select_fun] ls -l /mnt/source/
total 96
drwxr-xr-x. 2 root root 32768 Dec 11 03:41 env
drwxr-xr-x. 2 root root 32768 Dec 11 04:06 files
drwxr-xr-x. 3 root root 32768 Dec 11 03:40 x86_64

Latest revision as of 04:27, 30 January 2024

kpartx

if you have a raw disk image, for example a disk drive for a hypervisor it may have multiple partitions.

to quickly create devices for these you can use kpartx. after they are created you can mount these devices on your filesystem:

e.g.:

[maarten@rkvm1 select_fun] sudo kpartx -v -a DataONTAPv-kvm.raw
add map loop1p1 (253:3): 0 66464 linear 7:1 64
add map loop1p2 (253:4): 0 8390592 linear 7:1 66528
add map loop1p3 (253:5): 0 42336 linear 7:1 8457120
add map loop1p4 (253:6): 0 2 linear 7:1 8499456
add map loop1p5 (253:7): 0 3146976 linear 7:1 8500464
add map loop1p6 (253:8): 0 4196304 linear 7:1 11648448
add map loop1p7 (253:9): 0 5040 linear 7:1 15845760

and these are now visible in /dev/mapper:

[maarten@rkvm1 select_fun] ls -lrt /dev/mapper/ |grep loop
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p1 -> ../dm-3
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p2 -> ../dm-4
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p3 -> ../dm-5
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p4 -> ../dm-6
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p5 -> ../dm-7
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p6 -> ../dm-8
lrwxrwxrwx. 1 root root       7 Jan 29 20:12 loop1p7 -> ../dm-9

this does not seem to work well on vmdk images. As a result.

mount a vmdk

for a vmdk it seems other tools work better. qemu will do the trick

first create an ndb device

[maarten@rkvm1 select_fun] sudo modprobe nbd

now have it create the devices for the different partions

[maarten@rkvm1 select_fun] sudo  qemu-nbd -r -c /dev/nbd1 DataONTAPv.vmdk
[maarten@rkvm1 select_fun] ls -al /dev/nbd1p*
brw-rw----. 1 root disk 43, 33 Jan 29 20:21 /dev/nbd1p1
brw-rw----. 1 root disk 43, 34 Jan 29 20:21 /dev/nbd1p2
brw-rw----. 1 root disk 43, 35 Jan 29 20:21 /dev/nbd1p3
brw-rw----. 1 root disk 43, 36 Jan 29 20:21 /dev/nbd1p4
brw-rw----. 1 root disk 43, 37 Jan 29 20:21 /dev/nbd1p5
brw-rw----. 1 root disk 43, 38 Jan 29 20:21 /dev/nbd1p6
brw-rw----. 1 root disk 43, 39 Jan 29 20:21 /dev/nbd1p7

(with help from https://jasonmurray.org/posts/2021/mountvmdk/, he goes into more detail)

[maarten@rkvm1 select_fun] sudo  mount  /dev/nbd1p2 /mnt/source/
mount: /mnt/source: WARNING: source write-protected, mounted read-only.
 [maarten@rkvm1 select_fun] ls -l /mnt/source/
total 96
drwxr-xr-x. 2 root root 32768 Dec 11 03:41 env
drwxr-xr-x. 2 root root 32768 Dec 11 04:06 files
drwxr-xr-x. 3 root root 32768 Dec 11 03:40 x86_64