How to fix any Linux problem
Linux issues begone!
Drive filling up
I am running out of space on my hard drive – the space just seems to be disappearing. Where did it go and how can I get it back?
If you have more than one partition, the first step is to see which is affected, with the df command:
df -h
This shows the total, used and available space on each partition. If you have a separate /home, you now know whether it's your home directory or the system root that's filling up.
The steps taken are the same in each case, although you need to be root to clean up the system directories. For the system files, the usual culprits are /tmp and /var.
The first is used for temporary files, but sometimes old files get left in here, especially when processes fail without cleaning up. /var/log contains system log files and can fill up, particularly if a process is logging lots of errors. Look at the contents of any large files in here before you deal with them.
It's worth installing logrotate, which keeps your log files under control. Its default setup starts a new log file each week and compresses the last one, keeping the last four weeks of logs.
Get daily insight, inspiration and deals in your inbox
Sign up for breaking news, reviews, opinion, top tech deals, and more.
This can save a huge amount of space. In your home directory, check your downloads folder, your browser and mailer caches and also the .cache directory. You can use du to check the sizes of directories:
du -sh * | sort -h
lists everything in size order. If you want to check on hidden directories, use:
du -sh .[0-9a-z]* | sort -h
There are also graphical tools to visualise disk usage – Filelight for KDE and Disk Usage Analyser for Gnome – while Bleachbit is good for identifying and cleaning up unnecessary files, like browser caches and other temporary files.
Where has all my memory gone?
I have noticed that after running Linux for a while, I've hardly any memory left. Where is it going? How can I find the culprit and what can I do about it?
This is actually perfectly normal and the way Linux is designed to work. Free memory is memory that's doing nothing when it could be helping the performance of your computer.
The Linux kernel allocates memory that isn't in active use by processes to things, such as filesystem caches in order to improve performance. You can see this by looking at the output from free -h.
On a computer fitted with 16GB of physical memory, only 128MB is reported as free. Of the memory in use, 13GB of it is in use as buffers. These greatly speed up disk access by caching written data in memory and reading in more than you need in anticipation of your next read.
If this memory is needed for anything more important, it will be released immediately. It's not just filesystem data that remains in memory – try checking your free memory, then starting and stopping a large program like Firefox and you will see that your free memory decreases.
Now start Firefox again and see how much quicker it starts the second time. This is because the kernel keeps data in memory ready for the next use. The same applies to shared libraries, which is one reason why sticking to programs from one desktop environment can be faster than running a mixture, especially with limited memory.
Moving home
I have heard that it's better to have my home directory on a separate partition. Why is this and how do I do it?
First of all, it's not normally your individual home directory that has its own filesystem but the complete /home directory, in which your home resides. There are a number of reasons for doing this, such as simplifying backup procedures, but the main reason is to keep your data, and that of any other users, separate from the operating system.
That means you can upgrade or even replace your OS and still keep all your personal settings and data.
The simplest way to do it is with Gparted and a separate hard drive. Make sure the hard drive is formatted with a Linux filesystem, to preserve all the information saved with your files, then use rsync to copy everything over.
sudo mkdir /media/extdrive/home/
sudo rsync -a --delete /home/ /media/extdrive/
This assumes your separate drive is mounted at /media/extdrive. The trailing slashes are important. There are other tools you can use for the copy, but rsync has the advantage that it can carry on where it left off if the process is interrupted.
This means you can carry on using your PC while you do this, then boot from a live CD and repeat the process to update the files altered while you were using the system.
A live CD is needed for the next stage, where you delete the contents of /home and use Gparted to resize the root partition to a reasonable size – 20GB should be enough, but make it around 50% larger than the space currently used.
Now create a new partition after the root partition and format it, using ext4 unless you have a reason to do otherwise. Load the /etc/fstab file from the root partition into an editor and add an extra line:
/dev/sdaN /home ext4 defaults,noatime 0 0
where sdaN is the partition you just created. Finally, copy the data back from the external drive into the new /home and reboot. It is possible to do this without access to an external drive, but it is a more fiddly process.
Universally Unreadable IDs
I find the use of UUIDs in /etc/fstab annoying. What's wrong with the old method of using the device nodes, like /dev/sda1, and can I change back?
The trouble with device nodes is that they can change. If you add or remove a drive, including USB flash drives, or change the BIOS boot order, sda can become sdb. UUIDs on the other hand are (fairly) unique; it doesn't matter if the drive order changes, that unfriendly string stays the same.
And that's the problem: UUIDs are good for computers as they give a simple, reliable identification, but they are not human-friendly. A compromise is to use filesystem labels. If your root partition is on /dev/sda1 you could run
sudo e2label /dev/sda1 root
Then change the device specification in /etc/fstab from "UUID=youllneverreadorrememberthis" to "LABEL=root". Unlike many operation on the root filesystem, this one is safe to perform on a running system. It will take effect when you reboot. If you are ever likely to move drives between computers, use less generic label than 'root'.
Hard drive copying
How do I clone a complete hard drive? I am using Ubuntu but the drive also contains Windows.
Cloning a drive that the system is running on is a risky proposition. The OS could, and probably will, change files on the drive as you are trying to clone it. The simplest and safest way of doing this is with Clonezilla, a dedicated live CD distro.
Burn the ISO to a CD and boot from it. Then use the menus in Clonezilla to make a clone of your hard drive, either directly to another drive or to an image file.
Current page: Linux system issues
Prev Page Linux hardware problems Next Page Linux software glitches