0
1

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.

macOS上でRaspbianのイメージを編集する 出来なかったので別の方法で

Last updated at Posted at 2019-02-11

概要

前回でRaspbian.imgを編集するためにmacOS上でマウントする方法を紹介した。
しかし、目的である編集する権限は得られずread onlyのままであった。ext4fuseの仕様だと思われる。
*軽くググっただけで、深く調べていないので単なる思い込みかもしれない。

そのためmacOS上でマウントすることを諦めて別の方法で編集することにした

別の方法

macOS上に仮想OSのubuntuをインストールしてloop deviceを使ってイメージをマウントする方法があるのでその方法をメモする

Raspbianイメージのパーティション構成を調べる

image_partition
# fdisk -u -l raspbian-stretch-lite.img
Disk raspbian-stretch-lite.img: 1.8 GiB, 1866465280 bytes, 3645440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7ee80803

デバイス                   起動 Start 最後から セクタ  Size Id タイプ
raspbian-stretch-lite.img1       8192    98045   89854 43.9M  c W95 FAT32 (LBA)
raspbian-stretch-lite.img2      98304  3645439 3547136  1.7G 83 Linux  

bootイメージはFAT32で8192セクターから、root file sytem領域は98304セクターから。パーティション構成がこのコマンドで分かる。

イメージをマウントする

./raspberry_bootと./raspberry_kernelにbootイメージ、root file systemイメージをマウントする
loop deviceとしてデバイスを割り当てる

loop_device.sh
# losetup -f raspbian-stretch-lite.img  
# losetup -l  
/dev/loop0         0        0         0  0 raspbian-stretch-lite.img  
/dev/loop1         0  4194304         1  0 /dev/loop0  
/dev/loop2         0 50331648         1  0 /dev/loop0  
     

  
loop0にイメージがマウントされていることを確認。合わせてパーティションそれぞれにloop1とloop2がマウントされている。

mount_image
# mount -o loop,offset=4194304 /dev/loop0 ./raspbian_boot
# mount -o loop,offset=50331648 /dev/loop0 ./raspbian_kernel
試してないけど多分以下でもいける
# mount -o loop /dev/loop1 ./raspbian_boot
# mount -o loop /dev/loop2 ./raspbian_kernel

あとはraspbian_bootやraspbian_kernelの中身を好きに書き換えればよろし

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?