Saturday, January 19, 2013

Cleanup Amazon Linux

Amazon Linux is pretty good and complete.
But sometimes it is necessary to clean and minimize the default system.
It is possible, but be especially careful when cleaning the system!

Disk usage after creation:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  932M  6.9G  12% /


and after "sudo yum update":

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  978M  6.9G  13% /


$ sudo du -sh /*
7.7M    bin
25M     boot
5.0M    etc
28K     home
58M     lib
22M     lib64
4.0K    local
16K     lost+found
4.0K    media
4.0K    mnt
56M     opt
44K     root
11M     sbin
4.0K    selinux
4.0K    srv
12K     tmp
534M    usr
115M    var


Remove previous kernels
Size of /boot/ directory depends on amount of previous versions of kernel in your system. Sometimes "yum update" upgrades the linux kernel and size of /boot directory incrementally increases.
It is possible to remove old kernels from the file system (System.map-, config-, initramfs-, vmlinuz- files) and from the "/boot/grub/menu.lst" file




Remove unnecessary packages
For  example I don't need aws-tools and java on some of my servers (java exists by default because aws-tools depends on it).

$ yum remove java


or remove only aws packages:

$ yum remove aws-apitools-common
$ yum remove aws-amitools-ec2
$ yum remove aws-cfn-bootstrap


!Don't forget to remove "/etc/profile.d/aws-apitools-common.sh" file

Remove yum cache

Just delete "/var/cache/yum/x86_64/latest"
You can then recover this cache via "sudo yum makecache" command



Remove unnecessary locales
I don't need any national languages​​, and everything except the English. Therefore I purge non-en* files in these directories:

/usr/share/locale
/usr/share/doc
/usr/share/man

/usr/share/vim/vim72/doc
/usr/share/vim/vim72/lang
/usr/share/vim/vim72/tutor


After that I have about double free space:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  643M  7.2G   9% /

1 comment: