| View previous topic :: View next topic |
| Author |
Message |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Thu May 03, 2012 6:24 am Post subject: Scripting - remove oldest kernel cruft |
|
|
The Idea is to purge the system of the files belonging to the oldest (i.e. lowest version) kernel on the system.
This is independent of whether the package has been "unmerged" in Portage; the point is to remove the files left behind by Portage which are associated with a kernel no longer being used and no longer needed as a fall-back.
How can I improve this? I have a list below of "nice to have" improvement ideas, but I am more interested in fundamentals. Is there already a tool for this I don't know about? What I have screwed up, done stupidly, done inefficiently, etc. | Code: | #!/bin/sh
## configurable
src="/usr/src"
## testing
cmd="echo"
#cmd="rm -rf"
## kernel name: e.g., "linux-3.3.4-hardened"
krn=$(ls -1 --hide linux $src | sort -V | head -n 1)
$cmd ${src}/${krn}
## kernel version: e.g., "3.3.4-hardened"
ver=${krn#linux-}
$cmd /lib/modules/${ver}
$cmd /boot/*-${ver} |
"Nice to have" (not the more basic "what did I do wrong" input I am mainly looking for):
- Take as a command line argument the version (release number) to be purged or the keyword "list", which would allow the user to select one from a list (in something like 'eselect' fashion). If no argument is given, invoke the current default of purging the oldest kernel.
- Protect the current kernel. Abort if version matches running kernel (via 'uname -r'). Erase self and emit surly message from energyman76b; user is too stupid to have such tools.
- If system has separate /boot device, mount it if necessary and then unmount it when done.
- Preserve versions likely be referenced by bootloader config files. I.e., exit with error if version is same as target of any links in /boot (softlinks should be easy; haven't thought through most efficient way to versions for hardlinks, which I do happen to use).
- Maybe: Protect any slotted kernels. Abort if version matches any kernel packages reported by Portage as being installed (via 'equery list'?).
- Maybe: "About to have unprotected sex -- are you sure? (y/n)" type of validation, unless -q option given.
I have no idea what if anything an initrd user would add, because I don't use one. _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
grooveharder n00b

Joined: 18 Feb 2007 Posts: 43
|
Posted: Thu May 03, 2012 8:16 am Post subject: |
|
|
Have you looked at app-portage/eclean-kernel?  |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Thu May 03, 2012 8:59 am Post subject: |
|
|
| grooveharder wrote: | Have you looked at app-portage/eclean-kernel?  |
No. So I wasn't aware of it.
Excellent. I'd rather not reinvent the wheel if this does all the same things.
Thanks.
Edit: after a quick look, it looks like it very much does.  _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four.
Last edited by BoneKracker on Thu May 03, 2012 9:53 am; edited 1 time in total |
|
| Back to top |
|
 |
notageek Tux's lil' helper


Joined: 05 Jun 2008 Posts: 81 Location: Bangalore, India
|
Posted: Thu May 03, 2012 9:13 am Post subject: |
|
|
/facepalm _________________ What looks like a cat, flies like a bat, brays like a donkey, and plays like a monkey? |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Thu May 03, 2012 9:53 am Post subject: |
|
|
| notageek wrote: | | /facepalm |
Eat me. I suppose you knew about this tool. At least I was smart enough to ask.  _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four.
Last edited by BoneKracker on Thu May 03, 2012 9:54 am; edited 1 time in total |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Thu May 03, 2012 10:03 am Post subject: |
|
|
So, you deleted your "of course" reply. Does that mean you realized this is not part of eclean? Doh!? Or did you actually know about this? _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
notageek Tux's lil' helper


Joined: 05 Jun 2008 Posts: 81 Location: Bangalore, India
|
Posted: Thu May 03, 2012 10:09 am Post subject: |
|
|
I removed my reply because you had edited your post and my reply made it look like I agreed with you that you're smart. _________________ What looks like a cat, flies like a bat, brays like a donkey, and plays like a monkey? |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Thu May 03, 2012 10:20 am Post subject: |
|
|
Oh, I see.
Hmm... it's quite lacking in documentation and code comments. Git entries prior to the current version we have indicate capability was added to automatically mount /boot (and unmount it), but it doesn't seem to work. It kind of shits the bed if /boot isn't mounted.
| Code: | ~ # eclean-kernel
No outdated kernels found.
~ # umount /boot
~ # eclean-kernel
Traceback (most recent call last):
File "/usr/bin/eclean-kernel-2.7", line 26, in <module>
sys.exit(main(sys.argv))
File "/usr/lib/python2.7/site-packages/ecleankernel/cli.py", line 118, in main
debug = debug)
File "/usr/lib/python2.7/site-packages/ecleankernel/process.py", line 33, in get_removal_list
raise SystemError('No vmlinuz found. This seems ridiculous, aborting.')
SystemError: No vmlinuz found. This seems ridiculous, aborting. |
_________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Wed May 09, 2012 9:22 pm Post subject: |
|
|
Decided to use my own script. It's faster, its interpreter (BASH) is always loaded, it takes care of mounting if needed, and it's only 341 bytes in size. It meets my needs, and it's one less package. Here it is with the mount / unmount logic added.
| Code: | #!/bin/bash
krn=$(ls -1 --hide linux /usr/src |sort -V |head -n 1)
ver=${krn#linux-}
if ! mountpoint -q /boot; then
mount /boot
mnt=true
fi
if ! find /boot -lname "vmlinu*" -execdir readlink {} \; |grep -q $ver; then
rm -rf /usr/src/${krn}
rm -rf /lib/modules/${ver}
rm -f /boot/*-${ver}
fi
[ $mnt ] && umount /boot |
_________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
Prenj n00b


Joined: 20 Nov 2011 Posts: 8 Location: Mostar, BiH
|
Posted: Wed May 09, 2012 10:01 pm Post subject: |
|
|
My grandad used to say that those who ask for directions don't get lost.  |
|
| Back to top |
|
 |
Akkara Administrator


Joined: 28 Mar 2006 Posts: 4366 Location: &akkara
|
Posted: Wed May 09, 2012 10:35 pm Post subject: |
|
|
| notageek wrote: | | /facepalm |
This isn't necessary. It was a legitimate question and BK was wise to ask and save time instead of quietly re-inventing a wheel. Not to mention, this is directly on-topic with what these forums exist for. Unlike 99.9999% of the posts here. And while BK certainly doesn't need anyone to help defend him, I felt this needed to be said, if only to encourage (or not discourage) others who aren't sure about something, to ask. |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Wed May 09, 2012 11:41 pm Post subject: |
|
|
Yeah. So there, haterz. _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
pjp Administrator


Joined: 16 Apr 2002 Posts: 16033 Location: Colorado
|
Posted: Fri May 11, 2012 3:45 am Post subject: |
|
|
I started writing the equivalent of the eselect tool to manage which kernel was selected. Mostly done too, then found the eselect version, which I don't have to maintain.
I was going to bring that system up to see if I was using the portage tool mentioned in the thread, but I think it has an overheating / dead fan problem, so don't have the time to correct that. Oh well. I'll probably forget by the time I get around to fixing it. _________________ lolgov. 'cause where we're going, you don't have civil liberties.
In Loving Memory
1787 - 2008 |
|
| Back to top |
|
 |
notageek Tux's lil' helper


Joined: 05 Jun 2008 Posts: 81 Location: Bangalore, India
|
Posted: Fri May 11, 2012 4:44 am Post subject: |
|
|
| Akkara wrote: | | notageek wrote: | | /facepalm |
This isn't necessary. It was a legitimate question and BK was wise to ask and save time instead of quietly re-inventing a wheel. Not to mention, this is directly on-topic with what these forums exist for. Unlike 99.9999% of the posts here. And while BK certainly doesn't need anyone to help defend him, I felt this needed to be said, if only to encourage (or not discourage) others who aren't sure about something, to ask. | Wow, I must be the first person in the history of OTW to have been lectured on being unhelpful. On OTW.
...and all I got was this lousy T-shirt. _________________ What looks like a cat, flies like a bat, brays like a donkey, and plays like a monkey? |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Fri May 11, 2012 2:47 pm Post subject: |
|
|
| notageek wrote: | | Akkara wrote: | | notageek wrote: | | /facepalm |
This isn't necessary. It was a legitimate question and BK was wise to ask and save time instead of quietly re-inventing a wheel. Not to mention, this is directly on-topic with what these forums exist for. Unlike 99.9999% of the posts here. And while BK certainly doesn't need anyone to help defend him, I felt this needed to be said, if only to encourage (or not discourage) others who aren't sure about something, to ask. | Wow, I must be the first person in the history of OTW to have been lectured on being unhelpful. On OTW.
...and all I got was this lousy T-shirt. |
Look at your lame ass with 77 posts. Don't you ever help anybody? Go answer some unanswered questions.  _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
notageek Tux's lil' helper


Joined: 05 Jun 2008 Posts: 81 Location: Bangalore, India
|
Posted: Fri May 11, 2012 3:02 pm Post subject: |
|
|
Will not. By principle. People who use Gentoo shouldn't need help. You need help? Use Ubuntu, Fedora. _________________ What looks like a cat, flies like a bat, brays like a donkey, and plays like a monkey? |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1499 Location: U.S.A.
|
Posted: Fri May 11, 2012 8:16 pm Post subject: |
|
|
| notageek wrote: | | Will not. By principle. People who use Gentoo shouldn't need help. You need help? Use Ubuntu, Fedora. |
Says the guy who rides a motorcycle into cows. _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
Dr.Willy Apprentice

Joined: 15 Jul 2007 Posts: 296 Location: NRW, Germany
|
Posted: Fri May 11, 2012 8:23 pm Post subject: |
|
|
| BoneKracker wrote: | | Says the guy who rides a motorcycle into cows. |
Are you sure it's not the other way around? |
|
| Back to top |
|
 |
pjp Administrator


Joined: 16 Apr 2002 Posts: 16033 Location: Colorado
|
Posted: Fri May 11, 2012 11:32 pm Post subject: |
|
|
| notageek wrote: | | Will not. By principle. People who use Gentoo shouldn't need help. You need help? Use Ubuntu, Fedora. | Hopefully that happens to you the next time you need help (with anything). _________________ lolgov. 'cause where we're going, you don't have civil liberties.
In Loving Memory
1787 - 2008 |
|
| Back to top |
|
 |
|