Ordering files inside tar created from bash
Asked Answered
Z

1

7

Any idea how to tar files in a specific order. I know it sounds weird at first, but hear me out. An OVA file is essentially a tar file but with a specific order. Tar is commonly used to create the file, but in order for the OVA to be recognised by HyperVisors like VMware, the files inside the OVA must be ordered in a very specific way. The .ovf file MUST be first in the OVA and the other files must appear in the order they are listed inside the .ovf

Here's just a quick tree to help explain:

VM.ova--
       |
       |--VM.ovf
       |--VM.mf
       |--VM.vmdk
       |--VM.iso

That is the proper order. When I try to create an ova with tar it works, but the order is wrong. Here is how I am doing it. It's actually very basic.

tar -cvf VM.ova *

I just dive into the folder containing all the contents that need to be added to the OVA and run the tar command. Please help me order these files correctly. If we can't figure this out, the VM will never work with any HyperVisor. Thank you!

* UPDATE *

Currently the order that tar does by default is: vmdk, iso, mf, ovf

Zhukov answered 14/1, 2014 at 16:14 Comment(0)
P
11

The issue is that you're just using a glob, *, to list the files. The glob expands immediately, before tar ever sees it, so what tar really sees is:

tar -cvf VM.ova VM.iso VM.mf VM.ovf VM.vmdk

Because under normal* circumstances globs expand lexically in the C collation locale. If the order is important you can list the files manually:

tar -cvf VM.ova VM.ovf VM.mf VM.vmdk VM.iso

or use brace expansion to save some typing

tar -cvf VM.ova VM.{ovf,mf,vmdk,iso}

*It's possible for a glob to expand in a different order if you mess with your LC_* vars, but I'm making some assumptions here.

Photolithography answered 14/1, 2014 at 16:19 Comment(1)
Excellent thanks! I finally realized that a minute after I asked this question, but you still get credit. Thank you very much for responding. Will select as answer as soon as it lets me. Wow I was being dumb...Zhukov

© 2022 - 2024 — McMap. All rights reserved.