[linux-lvm] Repair thin pool

M.H. Tsai mingnus at gmail.com
Tue Feb 23 12:12:04 UTC 2016

The original post asks how to do if the superblock was broken (his superblock
was accidentally wiped). Since that I don't have time to update the program
at this moment, here's my workaround:

1. Partially rebuild the superblock

  (1) Obtain pool parameter from LVM

       ./sbin/lvm lvs vg1/tp1 -o transaction_id,chunksize,lv_size --units s

      sample output:
       Tran Chunk LSize
       3545  128S 7999381504S

      The number of data blocks is $((7999381504/128)) = 62495168

  (2) Create input.xml with pool parameters obtained from LVM:

       <superblock uuid="" time="0" transaction="3545"
data_block_size="128" nr_data_blocks="62495168">

  (3) Run thin_restore to generate a temporary metadata with correct superblock

       dd if=/dev/zero of=/tmp/test.bin bs=1M count=16
       thin_restore -i input.xml -o /tmp/test.bin

      The size of /tmp/test.bin depends on your pool size.

  (4) Copy the partially-rebuilt superblock (4KB) to your broken metadata.

      dd if=/tmp/test.bin of=<src_metadata> bs=4k count=1 conv=notrunc

2. Run thin_ll_dump and thin_ll_restore

   Example: assume that we found data-mapping-root=2303
     and device-details-root=277313

   ./pdata_tools thin_ll_dump <src_metadata> --data-mapping-root=2303 \
              --device-details-root 277313 -o thin_ll_dump.txt

   ./pdata_tools thin_ll_restore -E <src_metadata> -i thin_ll_dump.txt \
                                 -o <dst_metadata>

   Note that <dst_metadata> should be sufficient large especially when you
   have snapshots, since that the mapping trees reconstructed by thintools
   do not share blocks.

3. Fix superblock's time field

  (1) Run thin_dump on the repaired metadata

      thin_dump <dst_metadata> -o thin_dump.txt

  (2) Find the maximum time value in data mapping trees
      (the device with maximum snap_time might be remove, so find the
       maximum time in data mapping trees, not the device detail tree)

      grep "time=\"[0-9]*\"" thin_dump.txt -o | uniq | sort | uniq | tail

      (I run uniq twice to avoid sorting too much data)

      sample output:

      so the maximum time is 1787.

  (3) Edit the "time" value of the <superblock> tag in thin_dump's output

     <superblock uuid="" time="1787" ... >

  (4) Run thin_restore to get the final metadata

      thin_restore -i thin_dump.txt -o <dst_metadata>

Ming-Hung Tsai

More information about the linux-lvm mailing list