0
0

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 3 years have passed since last update.

スパースファイルを圧縮したい(tar方式)

Posted at

rawディスクイメージなどスパースファイルを更に圧縮したいとき、多くの圧縮ツールはただのNUL文字列として圧縮してしまうので結構な時間がかかる。

truncate -s 1T disk.img
zstd disk.img #遅い

S(--sparse)オプション対応のtarでラップする。
しかしファイル名が保存されてしまうのでアーカイブの名前を変えると混乱する。

tar -Scf - disk.img | zstd -19 > disk.img.tar.zst
mv disk.img.tar.zst foo.img.tar.zst
tar -xf foo.img.tar.zst
# 常にdisk.imgで展開される

パイプすることもできるがスパースでなくなってしまう。

tar -Oxf foo.img.tar.zst > foo.img
# foo.imgはスパースにならない

ddでconv=sparseに置きかえると遅い。

tar -Oxf foo.img.tar.zst | dd bs=1M conv=sparse of=foo.img

仕方ないのでtarの出力ファイル名を書き換える。

tar --transform "s#.*#foo.img#" -xf foo.img.tar.zst

もっと良い方法はないだろうか?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?