Re: /usr/lib/modules cleanup?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 28, 2023 at 11:29 PM Michael D. Setzer II via users
<users@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On 28 Aug 2023 at 18:37, ToddAndMargo via users wrote:
> [...]
> >
> > Fedora 38
> >
> > I got stuff all the way back to fc31.
> >
> > Can I delete all the non fc38 directories?
>
> Can't say sure, but what I have done on my machines.
> I generally use /lib/modules that is link t /usr/lib/modules.
>
> Generally found that only 3 of the directories are actually valid
> linked to the 3 latest kernels. The other ones are generally much
> smaller and just left offer stuff that somehow stopped the
> automatic removal from working.
>
> Have a script cleanmodules2
> #!/bin/bash
> x=$(du . -d 1 | sort -n|grep -v "[0-9][0-9][0-9][0-9][0-9][0-9]" | cut -s
> -f2 -d/)
> for a in $x; do
>         echo "$a";
>         rm ./"$a"/* -f -r;
>         rmdir "$a";
> done
>
> But would recommend running it without the rm and rmdir lines to
> make sure it isn't going to remove anything that is valid first.
>
> Example of results I get. Current directory is already clean so
> nothing removed.
>
> du . -d 1 | sort -n
>
> 128640  ./6.4.11-100.fc37.x86_64
> 128652  ./6.4.12-100.fc37.x86_64
> 128668  ./6.4.10-100.fc37.x86_64
> 385968  .
>
> Generally old directories would have sizes smaller that 6 digits,
> grep -v "[0-9][0-9][0-9][0-9][0-9][0-9]"  filters out all directories
> with 6 digits or more for size.
> cut -s elimanates the last line that doesn't have a second field after
> the /
>
> The loop then processes each of the resulting directories to remove
> the files and then remove directory.
>
> That has worked for me, but you setup might be different.
> Might be way to validate against kernel files in /boot or entries in
> /boot/local/entries but this works for me.
>
> getting the ones to keep
> ls -1 /boot | grep vmlinuz | grep -v rescue |cut -b9-100
> or
> ls -1 /boot/loader/entries/ | grep x86_64 | cut -f2,3 -d- | sed
> 's/.conf//g'
>
> Both give me
> 6.4.10-100.fc37.x86_64
> 6.4.11-100.fc37.x86_64
> 6.4.12-100.fc37.x86_64
>
> Would have to think about how to have it delete everything but
> thoses??

`du -sh` shows in human readable:

$ du -sh /lib/modules/*
4.0K    /lib/modules/6.2.13-300.fc38.x86_64
4.0K    /lib/modules/6.2.14-300.fc38.x86_64
4.0K    /lib/modules/6.2.15-300.fc38.x86_64
4.0K    /lib/modules/6.3.11-200.fc38.x86_64
4.0K    /lib/modules/6.3.12-200.fc38.x86_64
4.0K    /lib/modules/6.3.4-201.fc38.x86_64
4.0K    /lib/modules/6.3.5-200.fc38.x86_64
4.0K    /lib/modules/6.3.6-200.fc38.x86_64
4.0K    /lib/modules/6.3.7-200.fc38.x86_64
4.0K    /lib/modules/6.3.8-200.fc38.x86_64
126M    /lib/modules/6.4.10-200.fc38.x86_64
126M    /lib/modules/6.4.11-200.fc38.x86_64
126M    /lib/modules/6.4.12-200.fc38.x86_64

Switch to `-m`, for size in MB:

$ du -sm /lib/modules/*
1       /lib/modules/6.2.13-300.fc38.x86_64
1       /lib/modules/6.2.14-300.fc38.x86_64
1       /lib/modules/6.2.15-300.fc38.x86_64
1       /lib/modules/6.3.11-200.fc38.x86_64
1       /lib/modules/6.3.12-200.fc38.x86_64
1       /lib/modules/6.3.4-201.fc38.x86_64
1       /lib/modules/6.3.5-200.fc38.x86_64
1       /lib/modules/6.3.6-200.fc38.x86_64
1       /lib/modules/6.3.7-200.fc38.x86_64
1       /lib/modules/6.3.8-200.fc38.x86_64
126     /lib/modules/6.4.10-200.fc38.x86_64
126     /lib/modules/6.4.11-200.fc38.x86_64
126     /lib/modules/6.4.12-200.fc38.x86_64

Then, pipe to `awk` for a list of targets:

$ du -sm /lib/modules/* | awk '$1 < 10 { print $2 }'
/lib/modules/6.2.13-300.fc38.x86_64
/lib/modules/6.2.14-300.fc38.x86_64
/lib/modules/6.2.15-300.fc38.x86_64
/lib/modules/6.3.11-200.fc38.x86_64
/lib/modules/6.3.12-200.fc38.x86_64
/lib/modules/6.3.4-201.fc38.x86_64
/lib/modules/6.3.5-200.fc38.x86_64
/lib/modules/6.3.6-200.fc38.x86_64
/lib/modules/6.3.7-200.fc38.x86_64
/lib/modules/6.3.8-200.fc38.x86_64

Jeff
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux