Installing debian gnu/linux with custom sized partitions
Recently I changed the operating system on my home computer from Windows 7 to Debian GNU/Linux. Up until now I have had a fairly good run using Debian and I haven’t encountered any problems that I couldn’t fix with a little bit of effort and a lot of reading.
When preforming a recent “apt-get dist-upgrade” I encountered this message:
failed to write (No space left on device)
Strange, because I thought I had more than enough space on my system. I check the space left on my partitions:
$ df -h
The “-h” is to make the output human readable; I get this response:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/pc-root 314M 277M 17M 95% /
udev 10M 0 10M 0% /dev
tmpfs 800M 1.5M 798M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.6G 172K 1.6G 1% /run/shm
/dev/sda1 228M 23M 194M 11% /boot
/dev/mapper/pc-home 431G 1.6G 408G 1% /home
/dev/mapper/pc-tmp 360M 2.1M 335M 1% /tmp
/dev/mapper/pc-usr 8.2G 4.5G 3.3G 58% /usr
/dev/mapper/pc-var 2.7G 569M 2.0G 22% /var
The root partition has run out of space.
First, I attempted to free some space with the following:
# apt-get autoremove # Removes all unused packages automatically
# apt-get autoclean # Erases old downloaded archive files
This only freed another 5% space which is clearly still not enough.
During the original installation process on this system, I used the default installation partition sizes, which lead to the 314MB sized partition for the root partition. There are ways to increase the sizes of partitions without repartitioning the entire hard drive and reinstalling the operating system using a live GNU/Linux CD, but but I have been thinking of doing a fresh install so this is the excuse needed.
First thing to determine is the amount of space which should be allocated to each partition initially, so similar problems are not encountered so soon after a fresh install.
This is briefly what each partition does:
- /(root) # anything that doesn’t get a partition of it’s own will become part of the root partition.
- /boot # contains the operating system kernel and various other data needed for the system to boot.
- swap # the swap partition is used to temporarily store data when the system does not have enough RAM for it’s current tasks.
- /home # the home directories of all users. This is where all the user specific files are stored.
- /usr # installed packages.
- /var # the data here usually changes frequently.
- /tmp # used as a temporary space to store files or for programs to write temporary data.
To customise the size of each partition during the installation process I followed the following steps:
- I opted to use guided partitioning, selecting “Guided – use entire disk and set up encrypted LVM.
- Select the disk that you want to partition. Beware that selecting the option to use the entire disk will delete all data on the disk.
- Select the option for “Separate /home, /usr, /var, and /tmp partitions”.
- Write the changes to disk to create and configure the LVM volume. When prompted enter your disk encryption password that you want to use.
- You will now be shown a list of partitions (logical volumes) that have been created. Its now necessary to change the default sizes.
- Select “Configure the Logical Volume Manager” and write the changes to the disk.
- You can now delete each logical volume in turn and recreate the size that is required. Initially the entire disk is used so you cant increase the size of one volume before decreasing the size of your home partition.
- To delete a volume:
- select “Delete logical volume”; and
- select the volume to delete, starting with the /home volume.
- To create a volume:
- select “Create logical volume”;
- select the logical volume group;
- enter the name of the volume you want to create, so in order to recreate the /home volume that you deleted, enter “home”;
- enter the size of the volume you want to create.
- Once you have deleted and recreated each volume you can then select “Finish” to go back to the main partitioning menu.
- What you need to do now is configure each volume that you made and select what file system to use, and where it should be mounted:
- select each volume in turn;
- select “Use as: do not use”;
- select the option to use the partition as an “Ext4 journalling file system;
- select the “Mount point” option, and select where the partition should be mounted, depending on what partition it is.
- Once the last step has been done for each volume you are done and can select the option to “Finish partitioning and write the changes to disk”
After the re-installation my partitions now look like this:
/dev/mapper/pc-root 46G 348M 44G 1% /
udev 10M 0 10M 0% /dev
tmpfs 799M 764K 799M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.6G 92K 1.6G 1% /run/shm
/dev/sda1 228M 41M 172M 19% /boot
/dev/mapper/pc-home 92G 106M 87G 1% /home
/dev/mapper/pc-tmp 922M 1.3M 857M 1% /tmp
/dev/mapper/pc-usr 46G 3.0G 41G 7% /usr
/dev/mapper/pc-var 9.1G 1.3G 7.4G 15% /var
none 4.0K 0 4.0K 0% /sys/fs/cgroup
There seems to be a lot of debate regarding the optimal size of swap partitions and root partitions, but with storage space not being too much of a problem on my system I opted for 10GB of swap space and oversized partitions for the rest of the system. This might not be an optimal use of space though if storage space on the system is a problem.
To see a tree map of each partition and the mount points the command is: