如何在Linux 环境中检视 DD Image的内容并在挂载后做修改

通常笔者会使用dd 做映像档, 那该如何检查跟直接修改映像档的内容呢?

[作法如下]

检查映像档中的sector 从哪个开始
# fdisk -lu [your dd image]Disk h1123.img: 1.7 GiB, 1858806272 bytes, 3630481 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x8211c070Device                   Boot Start      End Sectors   Size Id Typeh1123.img1                     8192    98045   89854  43.9M  c W95h1123.img2                    98304  3630480 3532177   1.7G 83 Linuxroot@ctt:/release# 

[秘诀] 可以看到第一个分割区是从sector 8192 开始
2. 计算offset

offset:  8192 x 512 = 4194305

[秘诀] 每一个sector 是512 byte, 所以在计算offset的时候需要把sector 开始值乘以512 byte, 除非有特别设定成4096 byte, 不然传统的sector 都是512 byte为主

使用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% /mntls: root@tt:/mnt# lssample
挂载成功也可以正常使用

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章