Linux: Separate partition

This article will describe abstract of separationg partition.

1 Bootloader access

Kernel image is stored to /boot directory. Bootloader will read kernel image from /boot directory. So /boot directory must be formatted with filesystem which can read by bootloader.

Because GRUB1 does not support LVM, ext4 and software RAID, /boot is formatted with ext3 filesystem.

GRUB2 supports them. /boot directory is unneed to be separated.

1.1 Cannot update kernel because /boot does not have enought space

After updating kernel multiple times, /boot space will be reduced. And then kernel update will be failed. This is the reason why try to avoid separating /boot partition.

You need to run "apt autoremove" or "dnf autoremove" for removing old kernel. In Ubuntu 16.04, 2 newer version will not be removed.

$ sudo apt autoremove -y # or sudo dnf autoremove -y

2 Swap space

When memory is exhausted, swap space will be used for allocating free memory with moving inactive memory page to HDD. Swap space size is double the memory size by default.

Using swap space will cause system slow down because HDD access speed is slower than RAM access speed.

RAM size is going to be large like 16GB/32GB, and memory is getting less exhausted. But storage size is not large like memory (Because shifting device from HDD to SSD, and from SSD to eMMC). This means swap space size will pressure storage size.

The embedded system does not use swap area because NAND flash has limits for number of writing. Linux can be used without swap space.

Ubuntu 17.04 uses swap file without creating partition for swap space.

$ cat /etc/fstab
# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=009a4083-d35b-4492-afcb-d0d2938da0ea /               ext4
errors=remount-ro 0       1
/swapfile                                 none            swap
sw              0       0

But swap space is used for purposes other than memory allocation like hibernation and kdump. Especially kdump should be checked if works or not with swap file.

2.1 Increase swap space with swap file

The file created by dd command can be used as swap file. The sparse file cannot be used as swap file.

$ dd if=/dev/zero of=swapfile bs=1M count=4K
$ mkswap swapfile
$ sudo swapon -a swapfile
$ swapon
NAME                   TYPE   SIZE USED PRIO
/swapfile              file 947.2M   0B   -1
/home/hiroom2/swapfile file     4G   0B   -2

3 Encrypt filesystem

Encrypting /home directory for credential data needs to separate partition.

4 Save data in Linux reinstall

Separating partition for data directory like /home can save data in Linux reinstall.

But this needs to estimate size to be used. If separating /home without estimating size, it can happens that size of / is exhausted.

5 Conclusion

  • /boot is going to be not separated.
  • Separating swap space is going to be unneeded for memory allocation but there are still purposes other than memory allocation.
  • Encrypting filesystem needs separating partition.
  • Separating partition for saving data in Linux reinstall needs to estimate size to be used.