Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rm /etc/make.conf - oops [SOLVED + HOWTO]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
sobani
n00b
n00b


Joined: 12 May 2007
Posts: 5

PostPosted: Sat May 12, 2007 4:34 pm    Post subject: rm /etc/make.conf - oops [SOLVED + HOWTO] Reply with quote

Ok, I've been kinda stupid. I accidentally removed make.conf when I actually wanted to remove make.profile. And of course I also have no backup of it anywhere. (this is why)

I see two possibilities for getting my make.conf back, reverse the remove command and resurrect all settings from the current state of my installation.

I'm using ReiserFS as file system. I know it logs the transactions in case of a power outage or something. Maybe it still has that fatal remove command in its logs, ready to reverse that, but I doubt it. From what I know of removing files though, is that it only removes the reference, not the data. So unless that is already destroyed by writing to another file, it should be possible to put the reference back to that chunk of data, right? Anyone knows how to do that?

So while ago I put many hours in removing and adding the use flags in a fashion that looked nice to me. So just replacing make.conf with the default file is not going to do that trick. I also know that you can see the use flags that are different when you do a "emerge -pve world". It's just that that list is a bit long and tedious to go through. Is there any way to see all the use flags that I once used, without all the packages? Or does someone know some regular expressions to make a list of the use flags from the emerge command?

Please help this luser-with-a-root-password.

sobani


Last edited by sobani on Sun May 13, 2007 1:00 am; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 31342
Location: 56N 3W

PostPosted: Sat May 12, 2007 4:42 pm    Post subject: Reply with quote

sobani,

Welcome to Gentoo.

There is normally no undelete in the *NIX world as it would be a security issue. One user could undelete another users (even roots) deleted files. You can scan the 'empty' partition space for a file fragment that you expect to find and recover something that way.

As its your USE flags that are most of the work, it will be faster to recreate them with ufed and the output of emerge -evp world, as you have already suggested.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
sobani
n00b
n00b


Joined: 12 May 2007
Posts: 5

PostPosted: Sat May 12, 2007 5:46 pm    Post subject: Reply with quote

NeddySeagoon wrote:
sobani,

Welcome to Gentoo.


Heh, been using Gentoo for over 3 years. Until now I never had a reason to subscribe to this forum though. ;)

NeddySeagoon wrote:
There is normally no undelete in the *NIX world as it would be a security issue. One user could undelete another users (even roots) deleted files. You can scan the 'empty' partition space for a file fragment that you expect to find and recover something that way.


Well, I didn't expect a normal user could undelete files. I just hoped that there was a tool for root to recover files.

NeddySeagoon wrote:
As its your USE flags that are most of the work, it will be faster to recreate them with ufed and the output of emerge -evp world, as you have already suggested.


ufed indeed is handy. Thanks for pointing it out. At this moment I got a list of all different use flags, despite my crappy reg-exp skills.

I'll post a reply with the actions I took to recover this file once everything looks the way it was. I couldn't find a similar problem in this forums, but I doubt I'll be the only one who does things like this... right?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 31342
Location: 56N 3W

PostPosted: Sat May 12, 2007 5:57 pm    Post subject: Reply with quote

sobani,

OK, I admit I managed to do
Code:
rm -rf /etc
instead of
Code:
rm -rf ./etc
on one system I have.
I was intending to remove an outdated copy.

WARNING - Do not try this at home!
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
sobani
n00b
n00b


Joined: 12 May 2007
Posts: 5

PostPosted: Sun May 13, 2007 12:47 am    Post subject: How to recover /etc/make.conf Reply with quote

How to recover /etc/make.conf

0. Calm down ;)
Remember that it isn't all lost. emerge --pretend --verbose will tell you that you're going to install that critical package without the great gnome support and with support of that *censored* kde. - Although, if you abuse root powers, maybe you deserve the extra 10GB kde libraries download.
0.1 For kde lovers; calm down. :P

1. emerge ufed
ufed is a nice tool to tweak the use flags in your make.conf. It doesn't recognize all the flags available, but that's a concern for later.

2. cp /etc/make.conf.example /etc/make.conf
Alas, you have no make.conf, remember? So from now on you do have one. Yay!
2.1 If you like the "-*" flag, like I do, use ufed and select it now.

3. emerge --pretend --verbose --emptytree world > /tmp/world-all
Let's save a snapshot of all the packages you have installed at this moment. Now you need to screw up two more times to really lose hope of recovering your make.conf. Consider backing up this file though. :P
3.1 If it takes more than a minute or so, reassure yourself that you didn't forgot about the --pretend flag. Certainly don't wait until next morning for this command to finish.
3.2 Take a good look at the packages it can't find. Maybe you have to add some portdir overlays? Find the howto about those packages and add the parts they tell you you have to add to make.conf.

4. cat /tmp/world-all | grep USE | sed -e 's/USE=\"//;s/\".*//;s/ /\n/g' | grep "*" | sort -u
This will give you a list of all the use flags we care about at this moment. It starts with reading /tmp/world-all. Then it selects all lines that contain the word "USE". Thereafter everything before and after the use flags gets stripped and all spaces get converted to newlines. Now there is one use flag per line of text. With grep only the lines which contain a * are kept and the sort -u command will make sure that you only see every use flag once.
Now we have a list of all use flags that are different compared to the current broken state of your machine. Remember them, write them down or start another terminal session.
thanks to Think4UrS11 for showing me (parts of) how to pull this off

5. ufed
Now you can finally start to set things right in make.conf. Take your list and select every flag that says "-use*" in your list. Unselect every flag that says "use* in your list. Remember that the use flags with the star are the flags that are going to be changed to the state in which they are presented.
5.1 edit /etc/make.conf
There are flags that ufed doesn't recognize. And I haven't figured out how to let ufed disable flags, other than using "-*". Find the part where it says 'USE="..." '. The use flags are likely to be spread over multiple lines. Now you have to add all the flags that ufed didn't recognize and remove all use flags that you couldn't unselect.

6. repeat step 2 to 7.1
For some reason one of the packages was merged with USE="-X" and without a /etc/portage/packages.use line. Of course the "X" use flag is pretty obvious, but you can't be sure about all of them. Repeating everything will show up those odd use flags again.

7. cat /tmp/world-all | grep "VIDEO_CARDS"
All the changed use flags may be done now, but the VIDEO_CARDS settings probably need a change too. I couldn't find these in the default make.conf file, so you will have to add it yourself. Remember however that unlike USE, you can't use a minus. You will have to add every flag you want and leave out the ones you don't.
7.1 cat /tmp/world-all | grep "INPUT_DEVICES"
The same deal as with VIDEO_CARDS.
7.2 If those settings don't need a change, it might be a nice idea to change these later on. Or don't, this is a howto about recovering make.conf, not about breaking it. At least don't make changes at this point. Never ever combine recovering with changing settings. If something gets broken in the total process it will be a lot harder to figure out what did it.

8. emerge --pretend --verbose --update --deep --newuse world
This one should come out empty. If it doesn't, take a good look at the list it shows you. You might want to start from step 2 again if you don't like the look of it. At least don't move forward until this list is either empty, or shows only the settings the way you want them.
Oh, and all flags with a % are flags that are new for that package since its last merge. Don't worry about those.

9. read /etc/make.conf
Take your time to take a look at make.conf. Maybe you need to change CHOST? Or you don't like the default CFLAGS? I can't help you with these ones though. You'll have to figure them all out again. In case of the CFLAGS it probably wouldn't mind if you forgot a few of those 'optimizing' flags though. Although entering every possible flag you can find might break rm too. ;)

10. backup your /etc/make.conf
You're going to do it this time, right? ... Heh, me neither.
10.1 repeat step 12 until you feel comfortable to touch the rm command again.

11. Apologize to your PC
Some might find this a little late, but I prefer to set things right first, and then apologize.

12. rm /tmp/world-all /tmp/world-use
Or don't. You might end up doing "rm /var/lib/portage/world".

Well, you should have your make.conf file recovered now. Good luck and be careful with rm.


Last edited by sobani on Mon May 14, 2007 8:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3181

PostPosted: Sun May 13, 2007 6:52 am    Post subject: Reply with quote

Care to put this elaborate procedure in the Documentation Tips and Tricks forum? You could ask a mod to move this particular post to that forum.
_________________
emerge --quiet redefined | E17 vids: I, II
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 31342
Location: 56N 3W

PostPosted: Sun May 13, 2007 12:40 pm    Post subject: Reply with quote

Moved from Other Things Gentoo to Documentation, Tips & Tricks.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2160
Location: The Peanut Gallery

PostPosted: Sun May 13, 2007 1:23 pm    Post subject: Re: How to recover /etc/make.conf Reply with quote

sobani wrote:
3. emerge --pretend --verbose --emptytree world > /tmp/world-all
Let's save a snapshot of all the packages you have installed at this moment. Now you need to screw up two more times to really lose hope of recovering your make.conf. Consider backing up this file though. :P
<snip>
Or don't. You might end up doing "rm /var/lib/portage/world".

what's wrong with just having a backup of /var/lib/portage/world?
I appreciate that it won't have every single package, but portage will pull in any deps required. Also if you want a package list use the function from nanfunk's post. That would make this bit a lot quicker. (I have poth pl and pc in my /etc/bash/bashrc file.)

Thanks for an excellent doc :D
Back to top
View user's profile Send private message
think4urs11
Administrator
Administrator


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sun May 13, 2007 1:48 pm    Post subject: Re: How to recover /etc/make.conf Reply with quote

sobani wrote:
4. cat /tmp/world-all | sed s/.*USE=\"// | sed s/\".*// > /tmp/world-use
w00t, one of my best regular expressions at work here. We now have a file 99% filled with use flags. A few lines are the header and footer of the emerge command. Those will be dealt with later though.

5. replace all spaces with new-lines in /tmp/world-use
Uhm yeah, that's where my skills lacked. So I used gedit and replaced all " " with "\n" in /tmp/world-use.

6. cat /tmp/world-use | sort | uniq | grep "*"
Now we have a list of all use flags that are different compared to the current broken state of your machine. Remember them, write them down or start another terminal session.

can be replaced with
Code:
sed -e '/USE=\"/!d;s/.*\"\(.*\)\".*/\1/;s/ /\n/g' /tmp/world-all | sed '/\*/!d' | sort -u

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
sobani
n00b
n00b


Joined: 12 May 2007
Posts: 5

PostPosted: Mon May 14, 2007 8:49 pm    Post subject: Re: How to recover /etc/make.conf Reply with quote

NeddySeagoon wrote:
Moved from Other Things Gentoo to Documentation, Tips & Tricks.

I feel honored. 8)

steveL wrote:
sobani wrote:
3. emerge --pretend --verbose --emptytree world > /tmp/world-all
Let's save a snapshot of all the packages you have installed at this moment. Now you need to screw up two more times to really lose hope of recovering your make.conf. Consider backing up this file though. :P
<snip>
Or don't. You might end up doing "rm /var/lib/portage/world".

what's wrong with just having a backup of /var/lib/portage/world?
I appreciate that it won't have every single package, but portage will pull in any deps required. Also if you want a package list use the function from nanfunk's post. That would make this bit a lot quicker.

I think you missed a large part of my humor. Don't worry, I'm used to that. :( But I did hope you wouldn't take those backup and remove parts seriously.

Also, I looked at nanfunk's function and it missed a very import thing required for recovering make.conf: use flags. Further down the howto /tmp/world-all is going to be abused by sed to give a list of use flags that need to be entered into the new make.conf.

Think4UrS11 wrote:
<an earlier version of step 4> can be replaced with
Code:
sed -e '/USE=\"/!d;s/.*\"\(.*\)\".*/\1/;s/ /\n/g' /tmp/world-all | sed '/\*/!d' | sort -u


Almost! :P There were a few points that made me alter your suggested edit:
1. not only use flags were in the resulting list, but every flag, including video cards and input devices.
2. grep "*" looks easier to understand then sed '/\*/!d' imho.
3. I did it wrong first, but I believe it's important to make a selection of the lines with use flags first, in order to avoid showing input devices or video cards from a package without use flags (from x11-drm for example).

Anyway, thank you for teaching me that 'g' for sed and the fact that sort can do uniq too. :)
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2160
Location: The Peanut Gallery

PostPosted: Tue May 15, 2007 3:23 pm    Post subject: Re: How to recover /etc/make.conf Reply with quote

sobani wrote:
Quote:
what's wrong with just having a backup of /var/lib/portage/world?
I appreciate that it won't have every single package, but portage will pull in any deps required. Also if you want a package list use the function from nanfunk's post. That would make this bit a lot quicker.

Also, I looked at nanfunk's function and it missed a very import thing required for recovering make.conf: use flags. Further down the howto /tmp/world-all is going to be abused by sed to give a list of use flags that need to be entered into the new make.conf.

Ok sorry, didn't really read the whole thing properly. My point was that the world file can easily be backed up; you're right tho that this doesn't give you the use flags.
Quote:
Think4UrS11 wrote:
Code:
sed -e '/USE=\"/!d;s/.*\"\(.*\)\".*/\1/;s/ /\n/g' /tmp/world-all | sed '/\*/!d' | sort -u

Almost! :P There were a few points that made me alter your suggested edit:
1. not only use flags were in the resulting list, but every flag, including video cards and input devices.

grep USE | sed -e 's/USE=\"..' is exactly the same as sed '/USE/!d; /USE=\"/..' altho -n is cleaner (see below)
Quote:
2. grep "*" looks easier to understand then sed '/\*/!d' imho.
I agree, although there is no point using "" unless you have a $var in there, in general.
Code:
cat /tmp/world-all | grep USE | sed -e 's/USE=\"//;s/\".*//;s/ /\n/g' | grep "*" | sort -u

First of all you don't need cat here; this is called "useless use of cat" since 'grep USE /tmp/world-all' will do exactly the same thing with one less fork.
Try this:
Code:
sed -n '/USE/ s/.*USE="\([^"]*\)".*/\1/;s/ /\n/gp' /tmp/world-all|grep '*'|sort -u

I am sure nanafunk or someone can find a way of getting rid of the last grep too ;)

Edit: fixed quote
Edit 2 & 3: Another point which was wrong sorry :D
Edit 4: Try this:
Code:
sed -n '/USE="[^"]*\*[^"]*"/ { s/.*USE="\([^"]*\)".*/\1,/; s/ /,/g; s/-\?[a-z]*,//gp }' /tmp/world-all|sort -u

You could have [^"]\+ for the first bit before \* but there's no real need. (Or you could just use sed -r ;)
Edit 5: (last one I promise ;)
Code:
sed -n '/USE="[^"]*\*[^"]*"/ { s/.*USE="\([^"]*\)".*/\1,/; s/ /,/g; s/-\?[a-z]*%\?,//gp }' /tmp/world-all|sort -u

if there is a % without a * (only one package on my system triggers this, and it's because I don't upgrade OpenOffice til I want.)
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2160
Location: The Peanut Gallery

PostPosted: Tue May 15, 2007 4:47 pm    Post subject: Reply with quote

Nanafunk came up with this beauty:
Code:
sed -rn '/USE.*\*/{s/-?[^ *]*[ "]//g;p}' /tmp/world-all

Shame he forgot his forum password :lol:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum