New feature: guestfish hexedit

New in guestfish 1.5.17 will be a feature for hex editing partitions and filesystems (and plain files). This lets you do some “unconventional” modifications to partition tables and superblocks. We are using Pascal Rigaux’s hexedit program as the UI.

The new command is very simple to use. In the example below I am editing the superblock from an ext4 filesystem which is buried inside an LV inside a disk image:

$ guestfish -a disk.img
><fs> run
><fs> hexedit /dev/vg_guest/lv_root 0x400 0x400

00000000   00 A0 27 00  00 20 9E 00  57 93 01 00  01 C1 7A 00  ..'.. ..W.....z.
00000010   B9 E6 25 00  00 00 00 00  02 00 00 00  02 00 00 00  ..%.............
00000020   00 80 00 00  00 80 00 00  00 20 00 00  74 80 92 4C  ......... ..t..L
00000030   4B 4E 92 4C  05 00 FF FF  53 EF 01 00  01 00 00 00  KN.L....S.......
00000040   07 A6 92 4C  00 00 00 00  00 00 00 00  01 00 00 00  ...L............
00000050   00 00 00 00  0B 00 00 00  00 01 00 00  3C 00 00 00  ............>...
00000060   46 02 00 00  7B 00 00 00  5F C3 C4 91  FD 40 4B 04  F...{..._....@K.
00000070   81 FB DD D8  99 33 2D AB  46 65 64 6F  72 61 2D 31  .....3-.Fedora-1
00000080   33 2D 78 38  36 5F 36 34  2F 00 40 85  2A 32 01 88  3-x86_64/.@.*2..
00000090   FF FF 7D 84  1D 14 00 00  00 00 40 85  2A 32 01 88  ..}.......@.*2..
000000A0   FF FF 00 65  BB 2F 01 88  FF FF 00 33  EF 32 01 88  ...e./.....3.2..
000000B0   FF FF 21 B9  17 81 FF FF  FF FF 48 5D  CD 2F 01 88  ..!.......H]./..
000000C0   FF FF 79 C4  10 81 FF FF  00 00 00 00  00 00 BD 00  ..y.............
000000D0   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
000000E0   08 00 00 00  00 00 00 00  FB 7A 00 00  63 4D 51 56  .........z..cMQV
000000F0   8C 61 4F E6  92 99 E3 CA  63 92 94 9F  01 01 00 00  .aO.....c.......
00000100   0C 00 00 00  00 00 00 00  C9 5B EB 4B  0A F3 01 00  .........[.K....
00000110   04 00 00 00  00 00 00 00  00 00 00 00  00 40 00 00  .............@..
00000120   00 80 05 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
00000130   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
00000140   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 04  ................
00000150   00 00 00 00  00 00 00 00  00 00 00 00  1C 00 1C 00  ................
00000160   01 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
---  guestfish577CEP	   --0x7D/0x400----------------------------------------

(EF53 highlighted there is the magic number of ext2/3/4 superblocks).

Explanation:

  1. “guestfish -a disk.img” / “run” adds a disk image file to guestfish and launches the back-end.
  2. “hexedit /dev/vg_guest/lv_root” says that we want to edit /dev/vg_guest/lv_root (inside the disk image), and
  3. “0x400 0x400” says we want to edit the area of this device starting at offset 0x400, for 0x400 bytes, which is the normal location of the first ext2 superblock.

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s