Difference between revisions of "Disk mounting"
m |
m |
||
Line 9: | Line 9: | ||
fdisk -l | fdisk -l | ||
</pre> | </pre> | ||
+ | |||
+ | == losetup == | ||
+ | |||
+ | ;Convert a VMWare split image set to a raw disk image:cat linux-server-f001.vmdk linux-server-f002.vmdk linux-server-f003.vmdk > linux-server.img | ||
+ | ;Find the start of partitions:fdisk -l -u linux-server.img | ||
+ | ;First partition usually starts at block 63. Each block is usually 512 bytes. Offset is therefore:echo $((63*512)) | ||
+ | ;Find the start of each partition down to the exact offset byte (easier than `fdisk`):parted linux-server.img unit b print | ||
+ | ;List the next available loopback device:losetup -f | ||
+ | ;Attach loopback to a partition offset inside of a disk image:losetup -o $((63*512)) /dev/loop0 linux-server.img | ||
+ | ;Create a mount point: mkdir -p /media/adhoc | ||
+ | ;Mount the partition: mount /dev/loop0 /media/adhoc | ||
+ | ;Unmount the partition before cleaning up loop device: umount /media/adhoc | ||
+ | ;Cleanup the loop device:losetup -d /dev/loop0 | ||
== losetup -- mount individual partitions in a whole disk image == | == losetup -- mount individual partitions in a whole disk image == | ||
− | If you have a while disk image and you want to mount partitions inside that image then use `losetup` to create a loopback device for the image. | + | If you have a while disk image and you want to mount partitions inside that image then use `losetup` to create a loopback device for the image. For example, say you copied an entire disk using `[[Dd_-_Destroyer_of_Disks|dd]]` like this: |
− | |||
− | For example, | ||
<pre> | <pre> | ||
− | dd if=/dev/sda of=disk.img | + | dd if=/dev/sda of=disk.img |
</pre> | </pre> | ||
Revision as of 22:22, 31 May 2010
Contents
fdisk
This will list all the disks that Linux sees. This will not show loop devices. See `losetup` example for more information:
fdisk -l
losetup
- Convert a VMWare split image set to a raw disk image
- cat linux-server-f001.vmdk linux-server-f002.vmdk linux-server-f003.vmdk > linux-server.img
- Find the start of partitions
- fdisk -l -u linux-server.img
- First partition usually starts at block 63. Each block is usually 512 bytes. Offset is therefore
- echo $((63*512))
- Find the start of each partition down to the exact offset byte (easier than `fdisk`)
- parted linux-server.img unit b print
- List the next available loopback device
- losetup -f
- Attach loopback to a partition offset inside of a disk image
- losetup -o $((63*512)) /dev/loop0 linux-server.img
- Create a mount point
- mkdir -p /media/adhoc
- Mount the partition
- mount /dev/loop0 /media/adhoc
- Unmount the partition before cleaning up loop device
- umount /media/adhoc
- Cleanup the loop device
- losetup -d /dev/loop0
losetup -- mount individual partitions in a whole disk image
If you have a while disk image and you want to mount partitions inside that image then use `losetup` to create a loopback device for the image. For example, say you copied an entire disk using `dd` like this:
dd if=/dev/sda of=disk.img
You can later create a loop device for it and see its partitions with `fdisk` and mount those partitions individually with `mount`. Note that `fdisk -l` does not normally show loop devices. You must add an explicit path to the loop device that you want to list.
losetup /dev/loop0 disk.img fdisk -l /dev/loop0
The previous example assumed that /dev/loop0 was free. You can you the '-f' option to automatically find a free loop device. In this example we first use the '-f' option to associate the image file with the next available loop device; then we use the '-j' option to see what loop device was associated with the file:
losetup -f disk.img losetup -j disk.img
mounting partitions inside a disk image without loop device
It is also possible to mount partitions inside a disk image file directly with `mount` using the 'offset' option, but I have not had luck with this.
mount -o loop,ro,offset=1025 disk.img /media/adhoc
Disk recovery
Use `dd_rhelp`. This is a wrapper around `dd_rescue` that makes it easier to use.