iT邦幫忙

1

如何在Linux 環境中檢視 DD Image的內容並在掛載後做修改

JC 2018-11-27 10:10:083095 瀏覽
  • 分享至 

  • xImage
  •  

通常筆者會使用dd 做映像檔, 那該如何檢查跟直接修改映像檔的內容呢?

[作法如下]

  1. 檢查映像檔中的sector 從哪個開始
# fdisk -lu [your dd image]
Disk h1123.img: 1.7 GiB, 1858806272 bytes, 3630481 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: 0x8211c070

Device                   Boot Start      End Sectors   Size Id Type
h1123.img1                     8192    98045   89854  43.9M  c W95
h1123.img2                    98304  3630480 3532177   1.7G 83 Linux
root@ctt:/release# 

[秘訣] 可以看到第一個分割區是從sector 8192 開始
2. 計算offset

offset:
  8192 x 512 = 4194305

[秘訣] 每一個sector 是512 byte, 所以在計算offset的時候需要把sector 開始值乘以512 byte, 除非有特別設定成4096 byte, 不然傳統的sector 都是512 byte為主

  1. 使用mount 將映像檔掛載到loop device
# mount -o ro,loop,offset=4194304 h1123.img /mnt
* 筆者的範例是使用h123.img 

[秘訣] 如果需要修改的話, 只要將ro 改成rw 就可以了
4. 使用df 及ls確認是否有掛載成功

df: /dev/loop9         44220     22541     21679  51% /mnt
ls: 
root@tt:/mnt# ls
sample
  1. 掛載成功也可以正常使用

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言