Trying to understand .pacnew files

Before I respond to any of the individual points here. I want to add some perspective.

I have been running Arch based distros for at least 10 years. In that time, I have had 100’s of installs spanning both servers and and desktops. Across that whole time and all those installs, I have probably needed to merge changes from a pacnew file less than 10 times. It is that infrequent.

Usually you want to do the opposite, add the changes from the pacnew file into your existing file. The only exception to this is if there is a major structural change in file.

If you mv the file there will be nothing to rm. That being said, this isn’t the safest method. I would modify the original file rather than the pacnew file in most cases. Of course, making a copy first.

There is an extra space in the first command. Also, these will need probably need sudo to be thorough. There is no guarantee the changed files will be readable by other.

4 Likes

i saw a little pacman hook Garuda Linux uses for that:

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *

[Action]
Description = Checking .pacnew and .pacsave files...
When = PostTransaction
Exec = /usr/bin/bash -c 'pacfiles=$(pacdiff -o); if [[ -n "pacfiles" ]]; then echo -e "\e[1m.pac* files found:\e[0m\n$pacfiles\n\e[1mPlease check and merge\e[0m"; fi'
#/etc/pacman.d/hooks/pacnew-check.hook

place that in /etc/pacman.d/hooks/pacnew-check.hook

The command in the Exec line can be run manually in a terminal as well.

4 Likes

@T-Flips, @keybreak @dalto @ringo The support and help on this forum is phenomenal. Thank you all very much. I’m replying late because I really didn’t expect a response, and only noticed now you all had replied.

It’s too late for me now, so I’ll reply tomorrow properly, just wanted to say thanks guys. lol really thank you.

Good morning,

So I’m a bit gutted, because I was thinking I had a handle on this topic, not so sure now.

@T-Flips Thank you for the clarification on the mv command, I have an idea about it but obviously haven’t used it that much. I’ve seen the mention here and there about hooks but haven’t gotten around to researching what exactly a hook is yet. I’m assuming I’m meant to

add 'pacfiles=$(pacdiff -o); if [[ -n "pacfiles" ]]; then echo -e "\e[1m.pac* files found:\e[0m\n$pacfiles\n\e[1mPlease check and merge\e[0m"; fi'

to /etc/pacman.d/hooks/pacnew-check.hook but I’m not sure how to run it in the terminal. And I’m thinking it is an easy way to search for .pacnew files?

@ringo part of the difficulty for me is that this is all theoretical at the moment and I don’t even know yet how to use meld, pacmerge, pacdiff or vimdiff. I did read about the changes people had to make to the mkinitcpio pacnew file. I’m clear on the fact that it’s best to make changes to the current config file with the previously mentioned tools (lol somehow) and then rm the .pacnew.

@keybreak It was only yesterday I was looking at one of the courses I’ve purchased on Udemy and in the overview it mentioned that a script is a way to automate certain actions. I’m thinking that basically means instead of me pressing xyz I make the computer press xyz by setting in place a script which I just have to activate somehow. lol I’m sure your reply is very helpful, but again I thinks its a bit over my head at the moment. I think @T-Flips mentioned that same script before, but because I’ve never used a script and this topic is all theoretical at the moment it’s quite difficult for me to take much from it. Thank you all the same.

@dalto

That’s good and bad for me, because I probably won’t get much practice dealing with .pacnew files.

Lets take tlp for example. I’ve added


425 START_CHARGE_THRESH_BAT0=45
426 STOP_CHARGE_THRESH_BAT0=79

to /etc/tlp.conf. That config file is pretty long. If in an update there was a big software change I don’t know how I would even notice it. I’m thinking I would copy the changes from the .pacnew and paste them into /etc/tlp.conf then remove the .pacnew. Or maybe If I just sudo mv /etc/tlp.conf.pacnew /etc/tlp.conf then the .pacnew would then be called tlp.conf? And then I could add the BAT0 changes again. (only if everything which was in the current config file was in the .pacnew and more)

I didn’t understand what you meant about there being an extra space in the first command. I just copied them from the arch wiki page. Maybe I made a mistake when editing here that I didn’t realise. Thank you for mentioning that the command needs the sudo command for it to search thoroughly because again I suppose that’s something the wiki assumes I already know. The wiki really doesn’t help me much, it made it clear that I should run that command as a normal user by writing that command with the $ symbol.

Were you talking about running the command without sudo? “Readable by other”, did you mean other than the root user?

lol I understand if you think enough time has already been spent going over this topic. Thank you all for your time, patience and help.

I know this is out of place and I should have replied on the other post but I just thought about it now. Regarding the removal of firefox. You said I would have to look at the list of things which are being removed and research them to find out whether or not they are crucial elements of the system. Would I also need to use a command (don’t know which command) to see if other things are dependent upon the packages which are going to be removed? eg would I need to check if other things are dependent upon mailcap and firefox? And the other example I gave about wanting to remove gnome and gnome-extra after I had intsalled xfce4 and xfce4-goodies, would it have been correct to force-ably remove them and then reinstalled NetworkManager and any other packages which there were warnings about? That is if there is such a command to force a removal through. Maybe I should move this question to the other post?

I was just looking at my mkinitcpio.conf file and I’m assuming you all changed your mkinitcpio.conf to have COMPRESSION="xz" if it didn’t have that before.

Lol I won’t edit this post again after this. I just ran sudo find / -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null and got no output so I’m assuming that means I don’t have any .pacnew files to deal with?

I do put in as much effort as I am able to, to work things out on my own but I wanted you to know without your help and support I don’t think I wouldn’t be able to maintain and keep this OS on my computer so your help and support is invaluable to me.

4 Likes

alpm hooks are run by pacman. So you could create a hook that run everytime the system updates and it would look automatically and let you know at the bottom of the output.

This is overkill for me but if you are very worried about it certainly it is doable.

That is what the various diff/merge tools do for you. They show you what changed. So even if you have a huge config file you can quickly see what changed and decide what you want to do with those changes.

There seems to be a break between the r and the e in regextype

Linux permissions are assigned in 3 groups.

  • user - The permissions for user
  • group - The permissions for the members of the group assigned
  • other - The permissions for everything else

For instance, here are the permissions on my /etc/pacman.conf

-rw-r--r-- 1 root root     3147 Nov  2 15:31 pacman.conf

This file is owned by root and has the group of root. That means if I want to access it without sudo I would get the permissions assigned to other. For this file, “other” is allowed to read the file but not write it. That is why you can look at your pacman.conf but you need root to modify it.

For more information on permissions and how to read that string take a look at this article.

In that case, if anything was dependent on those it would either add them to the list to be removed or it would give an error when you tried to remove them. This would depend on what exact pacman options you used when you tried to remove the package.

That being said, if you ever want to see what depends on a package you can.

pacman -Qi packagename will also show you the direct dependencies or a package as well as what is required by it.

pactree -r packagename will show the reverse dependency tree which is basically everything that requires a package plus everything that requires those packages recursively.

Yes, no output means nothing was found.

2 Likes

Thank you @dalto for your lengthy reply. I don’t want to waste any more of your time on discussing hypothetical situations with .pacnew.

I don’t really understand the thing about the hook. I mean I get your explanation of what a hook is and does but doesn’t it show anyway in the output when one does an update if there are .pacnew files? I’m glad I have a bit of an understanding about the tools now such as pacmerge etc. I haven’t got around to learning permissions yet in detail anyway but I’ll get there soon, thanks for the insight.

I finally know how and what I can delete thanks to you. Basically if I want to delete anything I have to research what it is so I know the effect it will have on my system if/when I remove it. Quite rational really. I use the necessary pacman commands such as pacman -Qi [packagename] or pactree -r [packagename] to get the information I need to make the correct decision.

:ok_hand:

2 Likes

Yes, you will get warnings in the terminal output that will look something like:

warning: /etc/filename installed as /etc/filename.pacnew

If you pay attention to the output, pacman will alert you. But these messages will be in the list of packages scrolling by as they get updated. If you update a large number of packages, it might be easy for someone to miss them.

3 Likes

Well, @dalto already said some words about hooks. A (pacman/alpm) hook is a script that runs on certain pacman/package manager operations to automate some things. As always the Arch Wiki gives some more information: :grinning:
https://wiki.archlinux.org/index.php/Pacman#Hooks

Just have a look at your /etc/pacman.d/hooks folder. There are already some hook files in there, i’m sure.
Have look at those to get a feeling for them. They are quite comprehensive.

So the hook i posted is meant to be placed in a file in said folder (name it to your liking. “pacnew-check.hook” is just an example. Only important thing: .hook filename-suffix). Place the whole text in there.
You see there is a [Trigger] section and an [Action] section (like all hook files have)

The [Action] section specifies what will be done, its the Exec = line in particular, where the command is placed.

The [Trigger] section specifies on which (pacman-) operation that action will be executed. In this particular hook it will be:

Operation = Install
Operation = Upgrade
Operation = Remove

So this hook runs on every install, upgrade and remove operation and will check if there are any .pac* files to be merged/dealt with (remember the Exec line - with the pacdiff command)
So at the end of your pacman oparation (like a sudo pacman -Syu) you will then see something like:

:: start post-transaction hooks…
(3/7) Updating icon theme caches…
(5/7) Checking .pacnew and .pacsave files…
.pac files found:*
/etc/pacman.conf.pacnew
Please check and merge
(6/7) Updating the desktop file MIME type cache…
(7/7) Updating the MIME type database…

As @anon3337769 said, you always get a message if a pacnew file was created. But you have to scroll through the whole console output and may oversee the alert. So the hook isn’t really nescessary, just convenient, as you get a list of all .pac* files at the bottom of the console output :wink:

2 Likes

and stil i think you dont have to bother too much :slight_smile:

if you do something as : DIFFPROG=meld pacdiff

would help enough i think… if a config fail to work you can check what is change average dont force your self to look in those also.

1 Like

Thank you all, hahaha it would be good if I could put my “thank you” reply in a hook file which gets activated whenever I click the reply button.

@T-Flips with the extra info you’ve just given me I’m motivated now to research more about hooks and as @anon3337769 stated it’s easy to miss the .pacnew files I’ll give a shot at setting up the hook you mentioned earlier.

@ringo Thank you I will try not to stress on the issue too much. Sorry I didn’t understand what you meant by DIFFPROG=meld pacdiff And to be honest I think if you answer it will make this post go on for days lol. I’m guessing I could maybe edit ~/.bash_profile with export DIFFPROG=meld pacdiff even if that is correct I don’t have a clue what it would do. lol It’s perfectly fine with me if you don’t answer, I have more than enough to learn at the moment. It would be good to know if I was correct though.

anyways I’m calling it a night.

Thank you all :smile:

1 Like

mayby i got the mine in wrong place cause of the sudo …

sudo pacdif ; but you can check the line was is gone or come by… just as things works merging blindly no good idea, if you use samba and have a specifik configuration you want to see what is changed before you deploing but generaly… having alarmsignes in hooks is bad idea :slight_smile:

1 Like

sorry @ringo there’s a bit of a language barrier, I’m finding it a bit difficult to understand your reply.

Are you saying it’s not a good idea to do the hook?

BTW I just thought I’d mention this, unrelated but anyway. Today I was editing my .bashrc file with vim. I never realised how good it would be, but seriously vim is amazing. so fast and efficient, just gets the job done with ease. And then I made some of my own alias’, lol again makes so many things easier. Linux just keeps getting better and better.

I’m going to be offline very soon, lol takeaways on its way. I’m starving, been learning Linux all day today, got to sleep early so I can continue tomorrow. It’s like the best RPG I’ve ever played lol. mess up the system and it’s game over. lol I see you replying @anon3337769, but your taking too long mate.

1 Like

You really don’t need any hooks.

As @ringo suggested, running something like sudo DIFFPROG=meld pacdiff will check for any pacnew files, and will allow you to compare them with meld. meld gives a nice, side-by-side view of the files, with changes/differences highlight.

Or, for example, if you use KDE and would prefer kompare to meld, you could run sudo DIFFPROG=kompare pacdiff.

I personally wouldn’t use a hook, but that doesn’t mean using a hook is wrong. I just think it’s unnecessary for me. YMMV.

(I was going to say more, but I cut it short to try and catch you before you signed off :grin:)

1 Like

sorry just to confirm are you saying I just run as a command in terminal sudo DIFFPROG=meld pacdiff?

If that’s correct sorry if I’m missing things totally but what does that command do? So it’s not an environment variable?

Door bell hasn’t rung yet lol

I already have this command sudo find / -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null

So is the only difference that sudo DIFFPROG=meld pacdiff will check for .pacnew files and open them with meld if any are found?

1 Like

That will use pacdiff to check for pacnew files, and then will display them side-by-side for editing.

The example given will use meld for the comparison, which a lot of people prefer.

so sorry, just apply in the affirmative (hopefully) if you don’t mind.

I have meld so if I want to find and open .pacnew files with meld the command would be sudo DIFFPROG=meld

Hope that’s right

and it searches the whole system?

1 Like

sudo DIFFPROG=meld pacdiff

I know it searches /etc: I think it searches / .

I prefer watching the pacman output, so I don’t really use the pacdiff method.

EDIT - yep -

pacdiff is a script which looks for pacorig, pacnew and pacsave files from the backup entries found in the local Pacman db

3 Likes

Okay that’s it for me, lol thank you for your patience @anon3337769!

Good evening all.

2 Likes

Yup just tried it. It will ask you what you want to do. Hit v for view and they open side by side. The changes are highlighted. Close that back to terminal and you can choose to overwrite or remove if you don’t want the changes.

You will need to install meld as it is a package.

yay meld
It should be number 1.

2 Likes

Hi @BONK hope your good.

I have meld but I can’t try it because I don’t have any .pacnew files. Thanks for the v. lol I would have gotten stuck right there.

So I can either do vimdiff /path/to/current/config /path/to/.pacnew or sudo DIFFPROG=meld pacdiff

lol and then hopefully I’ll know what to do next… Either copy to the current config file from the .pacnew and delete the .pacnew or just delete the .pacnew.

If I ever get a .pacnew I’ll probably post and ask anyways just to confirm

cheers guys.

2 Likes

When you use meld, for example, the two files will be open side by side, and differences will be highlighted; there will be arrows to move the highlighted diffs between the documnets:

image

Here’s a tutorial; I’ve only skimmed it, but it looks pretty good:

And finally, sometimes it’s easier (in my opinion) to just manually make the changes, without using a diff function; my methodology varies with how many changes have been made between the files.

As an example, with recent changes to the layout of /etc/systemd/swap.conf, it was quicker for me to just add my configuration changes manually to the new file.

4 Likes