[PATCH] install.sh: Preserve directory symlinks

Thierry Escande posted 1 patch 1 week, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20260313172456.871518-1-thierry.escande@vates.tech
install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] install.sh: Preserve directory symlinks
Posted by Thierry Escande 1 week, 3 days ago
In various distros (i.e. Debian) some folders like /lib or /var/run are
symlinks. Using the tar option --keep-directory-symlink preserves these
symlinks.

Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
---
 install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/install.sh b/install.sh
index 3e11c4d46f..5d0b7a4933 100644
--- a/install.sh
+++ b/install.sh
@@ -27,7 +27,7 @@ tmp="`mktemp -d`"
 echo "Installing Xen from '$src' to '$dst'..."
 (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
 
-(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
+(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
 rm -rf "$tmp"
 
 echo "All done."
-- 
2.51.0



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Jan Beulich 4 days, 8 hours ago
On 13.03.2026 18:25, Thierry Escande wrote:
> In various distros (i.e. Debian) some folders like /lib or /var/run are
> symlinks. Using the tar option --keep-directory-symlink preserves these
> symlinks.
> 
> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
> ---
>  install.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/install.sh b/install.sh
> index 3e11c4d46f..5d0b7a4933 100644
> --- a/install.sh
> +++ b/install.sh
> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>  echo "Installing Xen from '$src' to '$dst'..."
>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>  
> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -

How compatible (between flavors of tar as well as between versions of GNU
tar) is use of this option?

Jan
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Thierry Escande 4 days, 4 hours ago

On 3/19/26 10:31, Jan Beulich wrote:
> On 13.03.2026 18:25, Thierry Escande wrote:
>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>> symlinks. Using the tar option --keep-directory-symlink preserves these
>> symlinks.
>>
>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
>> ---
>>  install.sh | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/install.sh b/install.sh
>> index 3e11c4d46f..5d0b7a4933 100644
>> --- a/install.sh
>> +++ b/install.sh
>> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>>  echo "Installing Xen from '$src' to '$dst'..."
>>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>>  
>> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
>> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
> 
> How compatible (between flavors of tar as well as between versions of GNU
> tar) is use of this option?

It's supported by GNU tar since version 1.27 (from ~12 years ago) but it
seems to be the only implementation that supports it. BSD and busybox
don't support it. I didn't check for other implementations.

I can add a flavor/version check if that makes sense.

Regards,


--
 | Vates

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Jan Beulich 4 days, 4 hours ago
On 19.03.2026 14:26, Thierry Escande wrote:
> 
> 
> On 3/19/26 10:31, Jan Beulich wrote:
>> On 13.03.2026 18:25, Thierry Escande wrote:
>>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>>> symlinks. Using the tar option --keep-directory-symlink preserves these
>>> symlinks.
>>>
>>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
>>> ---
>>>  install.sh | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/install.sh b/install.sh
>>> index 3e11c4d46f..5d0b7a4933 100644
>>> --- a/install.sh
>>> +++ b/install.sh
>>> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>>>  echo "Installing Xen from '$src' to '$dst'..."
>>>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>>>  
>>> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
>>> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
>>
>> How compatible (between flavors of tar as well as between versions of GNU
>> tar) is use of this option?
> 
> It's supported by GNU tar since version 1.27 (from ~12 years ago) but it
> seems to be the only implementation that supports it. BSD and busybox
> don't support it. I didn't check for other implementations.
> 
> I can add a flavor/version check if that makes sense.

Possibly. One question then is what the behavior was prior to that option
having been introduced.

Jan
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Thierry Escande 4 days, 4 hours ago

On 3/19/26 14:48, Jan Beulich wrote:
> On 19.03.2026 14:26, Thierry Escande wrote:
>>
>>
>> On 3/19/26 10:31, Jan Beulich wrote:
>>> On 13.03.2026 18:25, Thierry Escande wrote:
>>>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>>>> symlinks. Using the tar option --keep-directory-symlink preserves these
>>>> symlinks.
>>>>
>>>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
>>>> ---
>>>>  install.sh | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/install.sh b/install.sh
>>>> index 3e11c4d46f..5d0b7a4933 100644
>>>> --- a/install.sh
>>>> +++ b/install.sh
>>>> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>>>>  echo "Installing Xen from '$src' to '$dst'..."
>>>>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>>>>  
>>>> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
>>>> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
>>>
>>> How compatible (between flavors of tar as well as between versions of GNU
>>> tar) is use of this option?
>>
>> It's supported by GNU tar since version 1.27 (from ~12 years ago) but it
>> seems to be the only implementation that supports it. BSD and busybox
>> don't support it. I didn't check for other implementations.
>>
>> I can add a flavor/version check if that makes sense.
> 
> Possibly. One question then is what the behavior was prior to that option
> having been introduced.

From the patch at [1] introducing the option, and more precisely the
test done at [2], directory symlinks were simply overwritten.

[1]
https://cgit.git.savannah.gnu.org/cgit/tar.git/commit/?id=2c06a80918019471876956eef4ef22f05c9e0571
[2]
https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?id=2c06a80918019471876956eef4ef22f05c9e0571#n934

Regards,
Thierry


--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Jan Beulich 4 days, 4 hours ago
On 19.03.2026 14:59, Thierry Escande wrote:
> On 3/19/26 14:48, Jan Beulich wrote:
>> On 19.03.2026 14:26, Thierry Escande wrote:
>>> On 3/19/26 10:31, Jan Beulich wrote:
>>>> On 13.03.2026 18:25, Thierry Escande wrote:
>>>>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>>>>> symlinks. Using the tar option --keep-directory-symlink preserves these
>>>>> symlinks.
>>>>>
>>>>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
>>>>> ---
>>>>>  install.sh | 2 +-
>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/install.sh b/install.sh
>>>>> index 3e11c4d46f..5d0b7a4933 100644
>>>>> --- a/install.sh
>>>>> +++ b/install.sh
>>>>> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>>>>>  echo "Installing Xen from '$src' to '$dst'..."
>>>>>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>>>>>  
>>>>> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
>>>>> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
>>>>
>>>> How compatible (between flavors of tar as well as between versions of GNU
>>>> tar) is use of this option?
>>>
>>> It's supported by GNU tar since version 1.27 (from ~12 years ago) but it
>>> seems to be the only implementation that supports it. BSD and busybox
>>> don't support it. I didn't check for other implementations.
>>>
>>> I can add a flavor/version check if that makes sense.
>>
>> Possibly. One question then is what the behavior was prior to that option
>> having been introduced.
> 
> From the patch at [1] introducing the option, and more precisely the
> test done at [2], directory symlinks were simply overwritten.

Which makes it hard to suggest useful behavior when the option is unavailable:
Simply refusing to install isn't nice, but corrupting the installation is
perhaps even worse.

I take it that the (presumably) more standard -h doesn't help here?

Jan

> [1]
> https://cgit.git.savannah.gnu.org/cgit/tar.git/commit/?id=2c06a80918019471876956eef4ef22f05c9e0571
> [2]
> https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?id=2c06a80918019471876956eef4ef22f05c9e0571#n934
> 
> Regards,
> Thierry
> 
> 
> --
> Thierry Escande | Vates XCP-ng Developer
> 
> XCP-ng & Xen Orchestra - Vates solutions
> 
> web: https://vates.tech
>
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Thierry Escande 4 days, 3 hours ago

On 3/19/26 15:09, Jan Beulich wrote:
> On 19.03.2026 14:59, Thierry Escande wrote:
>> On 3/19/26 14:48, Jan Beulich wrote:
>>> On 19.03.2026 14:26, Thierry Escande wrote:
>>>> On 3/19/26 10:31, Jan Beulich wrote:
>>>>> On 13.03.2026 18:25, Thierry Escande wrote:
>>>>>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>>>>>> symlinks. Using the tar option --keep-directory-symlink preserves these
>>>>>> symlinks.
>>>>>>
>>>>>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
>>>>>> ---
>>>>>>  install.sh | 2 +-
>>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/install.sh b/install.sh
>>>>>> index 3e11c4d46f..5d0b7a4933 100644
>>>>>> --- a/install.sh
>>>>>> +++ b/install.sh
>>>>>> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>>>>>>  echo "Installing Xen from '$src' to '$dst'..."
>>>>>>  (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>>>>>>  
>>>>>> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
>>>>>> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
>>>>>
>>>>> How compatible (between flavors of tar as well as between versions of GNU
>>>>> tar) is use of this option?
>>>>
>>>> It's supported by GNU tar since version 1.27 (from ~12 years ago) but it
>>>> seems to be the only implementation that supports it. BSD and busybox
>>>> don't support it. I didn't check for other implementations.
>>>>
>>>> I can add a flavor/version check if that makes sense.
>>>
>>> Possibly. One question then is what the behavior was prior to that option
>>> having been introduced.
>>
>> From the patch at [1] introducing the option, and more precisely the
>> test done at [2], directory symlinks were simply overwritten.
> 
> Which makes it hard to suggest useful behavior when the option is unavailable:
> Simply refusing to install isn't nice, but corrupting the installation is
> perhaps even worse.
> 
> I take it that the (presumably) more standard -h doesn't help here?

-h definitely helps but it has the same behavior for files and folders.
So if an already existing symlink is meant to be replaced by a file,
then it won't. I chose to use the folder specific option.

That being said there is probably no usecase where a real file replaces
a symlink in the dist archive. And anyway, that would also stand for
folders.

I'll send a v2 with -h.

Regards,



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Jason Andryuk 1 week ago
On 2026-03-13 13:25, Thierry Escande wrote:
> In various distros (i.e. Debian) some folders like /lib or /var/run are
> symlinks. Using the tar option --keep-directory-symlink preserves these
> symlinks.
> 
> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>

Coincidentally, I hit this last week.  I think the commit message should 
be expanded because it resulted in a non-functioning system.  I switched 
to make debball, but thanks for fixing this.

I saw Ubuntu's /lib -> /usr/lib symlink replaced with a directory for 
/lib/systemd/system/xen-watchdog-sleep.sh.  With /lib broken, systemd 
(/sbin/init) could not start and boot fails.

The fix was easy -  just restoring the /lib symlink.

So maybe add "Replacing the /lib symlink with a directory results in a 
non-functioning system."?

I thought /var/run was addressed by:
Fixes: 9d628ff6cc21 ("tools: Fix install.sh for systemd")
It hasn't been an issue for me since that change.

For /lib a fixes is either:
Fixes: e54a6cd6a1f3 ("systemd: Add hooks to stop/start xen-watchdog on 
suspend/resume")

or

Fixes: b34bde262c8c ("systemd: fall back to default system-sleep dir 
without systemd-devel")

It might have only been the second one that defaulted to /lib causing 
the problem.  Though the issue is more general.

I do think a fixes and backport are warranted.  With the commit message 
updated:

Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Tested-by: Jason Andryuk <jason.andryuk@amd.com>

Thanks,
Jason

> ---
>   install.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/install.sh b/install.sh
> index 3e11c4d46f..5d0b7a4933 100644
> --- a/install.sh
> +++ b/install.sh
> @@ -27,7 +27,7 @@ tmp="`mktemp -d`"
>   echo "Installing Xen from '$src' to '$dst'..."
>   (cd $src; tar -cf - * ) | tar -C "$tmp" -xf -
>   
> -(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" -xf -
> +(cd $tmp; tar -cf - *) | tar --no-same-owner -C "$dst" --keep-directory-symlink -xf -
>   rm -rf "$tmp"
>   
>   echo "All done."
Re: [PATCH] install.sh: Preserve directory symlinks
Posted by Thierry Escande 4 days, 1 hour ago
Hi,

On 3/16/26 16:37, Jason Andryuk wrote:
> On 2026-03-13 13:25, Thierry Escande wrote:
>> In various distros (i.e. Debian) some folders like /lib or /var/run are
>> symlinks. Using the tar option --keep-directory-symlink preserves these
>> symlinks.
>>
>> Signed-off-by: Thierry Escande <thierry.escande@vates.tech>
> 
> Coincidentally, I hit this last week.  I think the commit message should
> be expanded because it resulted in a non-functioning system.  I switched
> to make debball, but thanks for fixing this.
> 
> I saw Ubuntu's /lib -> /usr/lib symlink replaced with a directory for /
> lib/systemd/system/xen-watchdog-sleep.sh.  With /lib broken, systemd (/
> sbin/init) could not start and boot fails.
> 
> The fix was easy -  just restoring the /lib symlink.
> 
> So maybe add "Replacing the /lib symlink with a directory results in a
> non-functioning system."?
> 
> I thought /var/run was addressed by:
> Fixes: 9d628ff6cc21 ("tools: Fix install.sh for systemd")
> It hasn't been an issue for me since that change.

I thought it was still the case but my current config does not install
files in /var/run anymore, so I missed that fix. Thanks for pointing
this out.

> 
> For /lib a fixes is either:
> Fixes: e54a6cd6a1f3 ("systemd: Add hooks to stop/start xen-watchdog on
> suspend/resume")
> 
> or
> 
> Fixes: b34bde262c8c ("systemd: fall back to default system-sleep dir
> without systemd-devel")
> 
> It might have only been the second one that defaulted to /lib causing
> the problem.  Though the issue is more general.
> 
> I do think a fixes and backport are warranted.  With the commit message
> updated:

After discussing with Jan, I will send a v2 that uses the more standard
option -h instead of --keep-directory-symlink and updates the commit
message.

Regards,



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech