Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering files inside tar created from bash

Tags:

linux

bash

tar

ova

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

like image 381
Atomiklan Avatar asked Jan 14 '14 16:01

Atomiklan


1 Answers

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.

like image 91
kojiro Avatar answered Oct 04 '22 00:10

kojiro