8
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモ:SDカードイメージをマウントするならkpartxが楽

Posted at

参考: Ubuntu Manpage: kpartx(8)

たまにSDカードのディスクイメージをマウントしたいときに、使い方を忘れるのでメモ。
kpartxはディスクイメージのパーティションテーブルを読み取って、パーティションごとにデバイスマップを作成してくれる。

マップを作成するにはaオプション。(vオプションは単なる動作確認用)

$ sudo kpartx -av sdcard_raspi.img
[sudo] password for user:
add map loop0p1 (252:0): 0 114688 linear /dev/loop0 8192
add map loop0p2 (252:1): 0 7917568 linear /dev/loop0 122880

$ ll /dev/mapper
合計 0
drwxr-xr-x  2 root root     100 11月 17 00:18 ./
drwxr-xr-x 18 root root    4380 11月 17 00:18 ../
crw-------  1 root root 10, 236 11月 16 23:57 control
lrwxrwxrwx  1 root root       7 11月 17 00:18 loop0p1 -> ../dm-0
lrwxrwxrwx  1 root root       7 11月 17 00:18 loop0p2 -> ../dm-1

$ sudo dmsetup info
Name:              loop0p2
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      252, 1
Number of targets: 1
UUID: part2-loop0

Name:              loop0p1
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      252, 0
Number of targets: 1
UUID: part1-loop0

マップされた/dev/mapper/loop0p1などをマウントするとアクセスできる。

マップを削除するにはunmountしてからdオプション。

$ sudo kpartx -dv sdcard_raspi.img
del devmap : loop0p2
del devmap : loop0p1
loop deleted : /dev/loop0
8
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?