Easy Way To Strip Down CentOS?

Home » CentOS » Easy Way To Strip Down CentOS?
CentOS 17 Comments

Hi,

I wonder if there’s an easy way to strip down an installation to the bare minimum, e. g. the packages you get when you select “minimum installation”.

In Slackware, the bone-headed package manager slackpkg has a few nice options, among which ‘slackpkg clean-system’, which removes all third-party packages in one single operation, or ‘slackpkg remove ‘, which does exactly that.

I know CentOS has yum groupinstall/groupremove etc. but as far as I can tell, if I only have a handful of packages from a package group installed, yum grouplist lists the group as not installed, so there’s not an easy way to tell.

You may wonder why I want to do this. I have CentOS installed on some sandbox machines here, and I like to fiddle with different desktops and setups just for the sake of experimenting.

Cheers,

Niki

Microlinux – Solutions informatiques 100% Linux et logiciels libres
7, place de l’église – 30730 Montpezat Web : http://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

17 thoughts on - Easy Way To Strip Down CentOS?

  • It’s not automatic so maybe not what you’re looking for, but reviewing the yum log in /var/log/ will give you a chronological list of what packages were installed, so you could use that create a list of packages to remove. Be careful about updates that masquerade as installations, like kernel packages.

    You could also query by install date as outlined here:

    http://unix.stackexchange.com/questions/2291/CentOS-list-the-installed-rpms-by-date-of-installation-update

    I don’t think there’s a single yum command that lets you roll back to the packages the were installed at a given point in time. I also don’t think that this would get you back to the *exact* system as it was. Linux packages aren’t completely self contained like that, and have the potential to make other changes to the system, so it’s not a completely clean rollback. At minimum, you’d have rpmsave files laying around, probably empty directories, etc…

    ❧ Brian Mathis
    @orev

  • My approach would be to create a list of installed rpms for what you’re using as the base system:

    rpm -qa –qf “%{NAME}\n” | sort > starting.txt

    Run that command again when you have all of the extra stuff installed, using a different filename for the output, for example, ending.txt

    Now merge and compare those files, and pull out the unique entries:

    sort starting.txt ending.txt | uniq -u > newstuff.txt

    Now remove the files in newstuff.txt

    yum remove `cat newstuff.txt`

    There is probably a way to combine those last two steps into one single command.

  • Before I discovered the minimal iso I found that I could unselect everything and still get a working install with CentOS on my servers. Curiously, that didn’t work with RedHat, had to at least select the
    “base” option and then go thru the base options to deselect bits. My experience is only up thru v6, don’t know about v7 (refuse to use it for now).

  • Le 25/02/2015 20:18, Brian Mathis a écrit :

    Maybe a good idea would be to find one or a handful of packages that the whole desktop and/or graphical subsystem depends on. Removing this one package – or this handful of packages, but which? – would already result in removing everything X11-related. After that, I can always manually sort out the remaining command-line stuff.

    Niki


    Microlinux – Solutions informatiques 100% Linux et logiciels libres
    7, place de l’église – 30730 Montpezat Web : http://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32

  • I’ve not tried this to see the effect but don’t forget in el6 there is the yum history database…

    yum history list will show all yum operations that have happened on the system.

    In principle you could do yum history rollback 1 … That wouldn’t clear up config data of course.

    For testing stuff VM use and templates or snapshots are essential tools. Or create a bare minimal kick start … Doesn’t take long to do a fresh install to a clean system that way.

  • The best way to do this is a new minimal install either in the GUI
    installer or with kickstart. And build up from there.

    If you do an install to e.g. CentOS-base.qcow2, that image already has machine-id and hostname set. While not running a VM, use guestfish to mount the qcow2, and make /etc/machine-id empty. Now, only use this base.qcow2 as a backing image. That is, never use it directly in a VM. Use

    qemu-img create -b base.qcow2 -f qcow2 guest1.qcow2
    qemu-img create -b base.qcow2 -f qcow2 guest2.qcow2
    qemu-img create -b base.qcow2 -f qcow2 guest3.qcow2

    Now use the guestn.qcow2 in the VM. And at first boot, the machine-id will be populated. I’m not sure of any negative consequences of not doing this, but if you want to use remote journalling it’s necessary so that the single journal can keep machines uniquely identified (even when changing the hostname).

    http://fedoraproject.org/wiki/Changes/Remote_Journal_Logging https://kashyapc.fedorapeople.org/virt/lc-2012/snapshots-handout.html

    Extra info: Anaconda uses this on lives to do installations (quite a few of these options are consolidated with -a):
    rsync -pogAXtlHrDx

  • Am 26.02.2015 um 08:38 schrieb James Hogarth :

    or

    # rpm -qa –last

    Lists the last installed package first. That way back would be one way to strip it down.

    I have here some minimal systems with about 200 packages installed ( rpm -qa | wc ).

  • # yum history rollback 1 # return to first post-update state.
    # yum history undo 1 # undo first update; return to initial state.

  • Perhaps I have not been following closely enough, but why go backwards? Why not start with a “minimal” installation and then add only those packages that are needed for your situation?

  • Ok, I understand, now. I just leave multiple desktops in place and switch between them as I want. But perhaps you have reasons to do it as you do. That is one thing I really appreciate about Linux, the fact that there are many, many ways to accomplish almost everything and that what is right and works for me may not be what works best for you.

    Your scripting style is irrelevant so long as it gets the job done for you. And one tenet the Unix/Linux Philosophy is, “automate everything,” which is what you have done.

    CentOS mailing list CentOS@CentOS.org http://lists.CentOS.org/mailman/listinfo/CentOS

  • I find that it’s quite easy to get a minimal desktop going. I tend to use a custom compiled dwm, but this will work with most window managers.

    http://srobb.net/minimaldesktop.html


    Scott Robbins PGP keyID EB3467D6
    ( 1B48 077D 66F6 9DB0 FDC2 A409 FA54 EB34 67D6 )
    gpg –keyserver pgp.mit.edu –recv-keys EB3467D6

LEAVE A COMMENT