Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
topics:disk-image-mount-partition [2017/03/26 05:37] orzfly |
topics:disk-image-mount-partition [2017/03/26 06:15] (current) orzfly [Mounting] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Mount Partitions in Disk Image ====== | ====== Mount Partitions in Disk Image ====== | ||
| - | ===== kpartx | + | * [[# |
| - | * https://nfolamp.wordpress.com/2010/ | + | * [[# |
| + | * [[# | ||
| + | * [[# | ||
| + | |||
| + | ===== losetup partscan | ||
| + | If you have util-linux v2.21 or higher, you can now do this with losetup. Use the -P (--partscan) option to read the partition table and create device nodes for each partition. | ||
| + | |||
| + | * http://stackoverflow.com/a/15200862 | ||
| ==== Mounting ==== | ==== Mounting ==== | ||
| - | |||
| - Mount image as loop device< | - Mount image as loop device< | ||
| - | # losetup /dev/loop0 rpool.img | + | # losetup |
| - | </ | + | |
| - | - List partitions in loop< | + | |
| - | # kpartx -l / | + | |
| - | loop0p1 : 0 44019712 /dev/loop0 2048 | + | |
| - | loop0p9 : 0 16384 /dev/loop0 44021760 | + | |
| - | </ | + | |
| - | - Create device mappings of partitions< | + | |
| - | # kpartx -av / | + | |
| - | add map loop0p1 (252:0): 0 44019712 linear 7:0 2048 | + | |
| - | add map loop0p9 (252:1): 0 16384 linear 7:0 44021760 | + | |
| </ | </ | ||
| - Finish< | - Finish< | ||
| - | # ls /dev/mapper/loop0* -l | + | # ls /dev/loop0* -l |
| - | lrwxrwxrwx | + | brw-rw---- |
| - | lrwxrwxrwx | + | brw-rw---- |
| + | brw-rw---- 1 root disk 259, 3 Mar 26 13:36 / | ||
| </ | </ | ||
| ==== Unmounting ==== | ==== Unmounting ==== | ||
| - | - Disconnect the device map files using kpartx< | ||
| - | # kpartx -dv /dev/loop0 | ||
| - | del devmap : loop0p9 | ||
| - | del devmap : loop0p1 | ||
| - | </ | ||
| - Unload loop device< | - Unload loop device< | ||
| # losetup -d /dev/loop0 | # losetup -d /dev/loop0 | ||
| Line 59: | Line 51: | ||
| </ | </ | ||
| - | ===== losetup partscan | + | ===== kpartx |
| - | If you have util-linux v2.21 or higher, you can now do this with losetup. Use the -P (--partscan) option to read the partition table and create device nodes for each partition. | + | * https:// |
| + | ==== Mounting ==== | ||
| - | * http:// | ||
| - | ==== Mounting ==== | ||
| - Mount image as loop device< | - Mount image as loop device< | ||
| - | # losetup | + | # losetup /dev/loop0 rpool.img |
| + | </ | ||
| + | - List partitions in loop< | ||
| + | # kpartx -l / | ||
| + | loop0p1 : 0 44019712 /dev/loop0 2048 | ||
| + | loop0p9 : 0 16384 /dev/loop0 44021760 | ||
| + | </ | ||
| + | - Create device mappings of partitions< | ||
| + | # kpartx -av / | ||
| + | add map loop0p1 (252:0): 0 44019712 linear 7:0 2048 | ||
| + | add map loop0p9 (252:1): 0 16384 linear 7:0 44021760 | ||
| </ | </ | ||
| - Finish< | - Finish< | ||
| - | # ls /dev/loop0* -l | + | # ls /dev/mapper/loop0* -l |
| - | brw-rw---- | + | lrwxrwxrwx |
| - | brw-rw---- | + | lrwxrwxrwx |
| - | brw-rw---- 1 root disk 259, 3 Mar 26 13:36 / | + | |
| </ | </ | ||
| + | ==== Unmounting ==== | ||
| + | |||
| + | - Disconnect the device map files using kpartx< | ||
| + | # kpartx -dv /dev/loop0 | ||
| + | del devmap : loop0p9 | ||
| + | del devmap : loop0p1 | ||
| + | </ | ||
| + | - Unload loop device< | ||
| + | # losetup -d /dev/loop0 | ||
| + | </ | ||
| + | |||
| + | ===== losetup offset / sizelimit ===== | ||
| + | * https:// | ||
| + | ==== Mounting ==== | ||
| + | |||
| + | - Get partition details< | ||
| + | # fdisk -l rpool.img | ||
| + | Disk rpool.img: 21 GiB, 22548578304 bytes, 44040192 sectors | ||
| + | Units: sectors of 1 * 512 = 512 bytes | ||
| + | Sector size (logical/ | ||
| + | I/O size (minimum/ | ||
| + | Disklabel type: gpt | ||
| + | Disk identifier: B37248EB-F1D7-DA47-A42D-4C42AF20D328 | ||
| + | |||
| + | Device | ||
| + | rpool.img1 | ||
| + | rpool.img9 44021760 44038143 | ||
| + | </ | ||
| + | - Setup loop device< | ||
| + | # losetup /dev/loop0 rpool.img --offset $((512 * 2048)) --sizelimit $((512 * 44019712)) | ||
| + | </ | ||
| ==== Unmounting ==== | ==== Unmounting ==== | ||