41

Is it necessary to have a /home partition in Ubuntu Desktop 20.04? I read somewhere about a home file in /root partition... Does the same go to the /swap partition?

Can someone set up a guide for New and Experienced users so that this information will be beneficial to many.

VidathD
  • 2,704
  • @user535733 I have 16GB RAM. I only use this to explore. My main OS is Windows 10. In Windows I never get above 50% RAM however many apps I open. – VidathD May 03 '20 at 16:42
  • @user535733 I would like to set up a dual boot. If I stick to defaults as you suggest, is 30GB enough for the root partition. Also, Ubuntu doesn't give me the option to install alongside windows. So will create just "/" partition with 30GB in something else option and continuing do it? – VidathD May 03 '20 at 16:53
  • @user535733 Ok, thanks. But I seem to have tried everything suggested in those questions. Can you help me? Chat? – VidathD May 03 '20 at 16:58
  • 1
    What brand/model system? What video card/chip? Some need settings. Only use Windows to shrink NTFS partitions & reboot so it runs chkdsk. Then use gparted or during install create / (root) and optionally /home. Make sure Windows fast start up is off. http://askubuntu.com/questions/843153/ubuntu-16-showing-windows-10-partitions & https://askubuntu.com/questions/145902/unable-to-mount-windows-ntfs-filesystem-due-to-hibernation UEFI install: https://help.ubuntu.com/community/UEFI & https://askubuntu.com/questions/221835/installing-ubuntu-on-a-pre-installed-windows-10-with-uefi – oldfred May 03 '20 at 17:04
  • @user535733 I have secure boot disabled and 20.04 support UEFI so everything should work even with secure boot enabled. I also have fast startup and hibernation disabled. Is it safe to just install using "Something else" option? – VidathD May 03 '20 at 17:38
  • 2
    A /home partition protects your personal data in case something goes wrong with your main installation. I've been using Linux as my primary desktop for 20 years and always keep /home separate. – chrylis -cautiouslyoptimistic- May 04 '20 at 12:07
  • zram is much much better than a swap file or partition. Chrome OS, Android and many Linux distros like Fedora or Lubuntu already turn it on by default. Windows and macOS also use similar compression technologies by default – phuclv May 04 '20 at 17:08
  • @phuclv No need. I never hit RAM limit. – VidathD May 04 '20 at 17:13
  • @SasukeUchiha in that sense you never need a swap file or partition either. You should always have some kind of swap, and zram is the best kind of it. It'll just stay their like a swap file/partition and just consumes memory when you need it. See https://unix.stackexchange.com/q/499485/44425 – phuclv May 05 '20 at 01:25
  • The "double amount of ram as swap" rule that I learned when I dabbled in system administration in the 90'es, most likely came from that this was what would be a pain point to have any larger, as only what was necessary was used. Workloads have shifted since and the amount of memory as well as disks becoming very very much faster. If your workload never, ever uses more memory than you have RAM you don't need it Note that doing it this way, the installer can play it safe and have the files needed for boot in a separate partition guaranteeing that it is accessible on all computers. – Thorbjørn Ravn Andersen May 05 '20 at 13:17

5 Answers5

55

/home partition: A separate /home partition has never been necessary. It has always been optional.

The Ubuntu installer has well-considered and quite sane defaults to create a working system for new and/or unskilled users. That default does not create a separate /home partition.

Some folks prefer a separate /home partition, others don't.

/swap partition: Since 18.04, a separate swap partition in most Desktops has been superseded by a swap file within the root (/) partition. A separate swap partition is no longer recommended for most new Desktop users. Swap in a server is a little more complex; swap is recommended for some advanced uses (like non-ext filesystems).

Advice for new users: For your first install, stick to the installer defaults as much as possible. Focus on making your first install successful rather than perfect. You can always repartition/reinstall a more complex system later -- Ubuntu makes it easy.

user535733
  • 62,253
  • So if I am not creating a separate /home partition what should be the size of the root partition? – VidathD May 03 '20 at 16:34
  • Question edited to include swap. – VidathD May 03 '20 at 16:37
  • Answer edited to include swap. – user535733 May 03 '20 at 16:46
  • Just assign all space to / @SasukeUchiha – eckes May 04 '20 at 06:02
  • 5
    Not all filesystems support swapfiles. BtrFS only recently started(kernel 5.0) and ZFS does not. If you're creating a / partitioon on ZFS, you should create a swap partition instead of a swap file. – Syfer Polski May 04 '20 at 11:16
  • 1
    @SyferPolski edited to address your comment. – user535733 May 04 '20 at 11:46
  • Does hibernate still work properly with swap files, or does that need additional magic then? – Simon Richter May 04 '20 at 19:45
  • 3
    @SasukeUchiha, If you are not having a separate /home , /usr or /var, just make the /root the entire disk. – Lenne May 05 '20 at 08:38
  • You usually don't want users to be able to fill up the system partition completely, and this is easily done with a separate /home partition. If you are the only user this might not be an issue. – Thorbjørn Ravn Andersen May 05 '20 at 13:18
  • @ThorbjørnRavnAndersen Arguments of the type "I'm an experienced user so I will never make (or install an application that makes) mistake X" always make me nervous. To err is human (and computers can screw up even worse). – Dan Is Fiddling By Firelight May 05 '20 at 14:30
  • @dan well, depends on your priorities. For hobbies your time is free. Personally I prefer doing exactly what the installer suggests and adjust the hardware if necessary. But - as always you have to learn. – Thorbjørn Ravn Andersen May 05 '20 at 15:37
  • 7
    @Lenne you mean /, not /root right? In fact, /root should never be it's own partition, the entire reason it exists is so ~root is on the root partition. – vikarjramun May 05 '20 at 18:02
  • @vikarjramun, of cause you are right. On / – Lenne May 07 '20 at 11:04
  • I use Ubuntu since 8.04 and have always made a swap. I always put Home on a separate disk for a long time. My question is, can I just delete the swap partition I made in my last install? I play games that take some ram and plan on streaming on Twitch so maybe I need it. – userDepth Nov 25 '20 at 07:53
  • @userDepth track your swap usage with free for few days or weeks. Then you will know if you need swap or not. – user535733 Nov 25 '20 at 12:52
12

Is it necessary to have a /home and swap partitions in 20.04

Certainly not. You may stick to the defaults, that is a single partition holding your files, and perhaps another partition for swapping. On some recent Linux distributions, swapping happen into a swap file (this is slightly less efficient but can be much more convenient, because you won't use a separate disk partition for swap). See swapon(8) and mkswap(8) and the underlying swapon(2) system call. If you are curious, read about virtual memory, file systems, the page cache, and some textbook on operating systems.

An astute reader might want to have a different /home/ partition to be able to later and easily change his/her Linux distribution (e.g. to Debian or Fedora) without losing their data. This is not necessary, but might be useful.

In all cases, don't forget to backup your important data (preferably on a different medium or on some remote server). Hardware disks do fail, and you will make mistakes. You might even automatize your backups (e.g. with crontab and rsync).

  • For the Windows people, making a separate home partition is somewhat analogous to putting your big files (like media) onto a hard disk while having your other files be on an SSD, right? – Captain Man May 04 '20 at 21:28
  • @CaptainMan Exactly. That's what's making me so confused? Where does Windows save the files when hibernating anyway? – VidathD May 05 '20 at 02:59
  • Windows has a hibernate hidden system file on the system partition (c:\hiberfil.sys). – eckes May 05 '20 at 05:10
  • 1
    @eckes And why can't Ubuntu have something similar? – VidathD May 05 '20 at 12:55
  • @SasukeUchiha As written above, swap may be a file instead of a partition – Hagen von Eitzen May 05 '20 at 13:08
  • @HagenvonEitzen But you can't hibernate with the swap file. Can you? – VidathD May 05 '20 at 13:10
  • Not so sure why having a extra file would be better, it takes double the space on the filesystem. – eckes May 05 '20 at 13:53
  • i have to say, with snaps, having a separate /home partition and a small ssd (only 100gb) is an absolute nightmare because your root partition keeps filling up with snaps every few months no matter how big you make it. Definitely not for beginners. – Rabbit May 25 '20 at 13:04
10

NOTE: I will be referring to / partition as /root to make it more clear.

For New Users (Simple Successful Install)

  1. Do you need a separate /home partition? Definitely not. The home partition is where your personal files (Documents, Downloads, Pictures, etc) are stored. If you don't make a separate /home partition, those files will be saved in /home/username folder. So if this is your first time installing Ubuntu, don't try to make it too complicated and don't make a separate partition for /home. When you are more experienced and confident, you can try this.

  2. Do you need a separate /swap partition? Well, it depends. If you want to hibernate you will need a separate /swap partition (see below). /swap is used as a virtual memory. Ubuntu uses it when you run out of RAM to prevent your system from crashing. However, new versions of Ubuntu (After 18.04) have a swap file in /root. There is a workaround way to use the swapfile to hibernate but it is not recommended for new users (See below if you want to know). So you don't need to have a separate /swap partition.

  3. So my recommendation to new users is, until you get accustomed to Ubuntu and gain confidence in using it, stick to the defaults in the installer and go with "Erase Disk and Install Ubuntu*" option (If you are dual-booting "Install Alongside YourOS" option).

For Experienced/Confident Users ("Perfect" Install)

If you are experienced and confident it is best to have a separate partition for at least /home. You won't need a separate /swap if you don't hibernate. Even if you want to hibernate, there is a workaround to use the swapfile.

Here are the recommended partitioning:

  • / root: All the software you install are stored here

    • Size: min. 10 GB (25+GB recommended. I have 40GB)
    • Type for the new partition: Primary
    • Location for the new partition: Beginning of this space
    • Use as: ext4
    • Mount point: Choose "/"
  • /home Only needed if you want to keep your personal files separate from root partition (/)

    • Size: Remainder of space on the drive or any size you want.
    • Type for the new partition: Primary
    • Location for the new partition: Beginning of this space
    • Use as: ext4
    • Mount point: Choose "/home"
  • /swap Only needed if you want to Hibernate

    • Size: Depends on your RAM. [See Swap FAQ][2].
    • Type for the new partition: Primary
    • Location for the new partition: Beginning of this space
    • Use as: swap

Workaround for hibernation using the swapfile: How to hibernate with swapfile.

Pablo Bianchi
  • 15,657
VidathD
  • 2,704
  • 4
    Incorrect. swap is nowadays a file. Not a partition. And please don't use / Root , / Swap or / Home. Use / and /swap/ and /home/ to refer to directories. – Rinzwind Jun 22 '20 at 18:56
  • @Rinzwind But you can have a separate swap partition if you prefer? Can't you? Please Edit and make the changes you suggested. My wifi is super slow at the moment and it takes ages to load – VidathD Jun 22 '20 at 19:01
  • The advice for experienced users should be to use LVM and initially allocate only what is needed, leaving most of the Physical Volume unallocated. Even the root partition works as a Logical Volume without any problems in current grub. When a filesystem tends to get full or the need for a new separate filesystem arises, one can add or online-extend LVs without the hassle of moving partitions or even reinstalling. The drawback is that installer LVM support is bad so it's only available for experienced users. – Juergen Jul 14 '20 at 10:09
4

It's optional to have a separate /home partition. It allows you to reinstall your operating system (Ubuntu) without losing your data and configuration files. There can be other uses not limited to this option.

Ubuntu by default creates a "home directory" in / partition. It's ok to go without a separate /home partition. But either way keep a backup of your important files.

While swap partition/file is needed for hibernation. The SwapFaq page shows how much space you need for a swap partition

Mido
  • 413
  • I will be saving almost no files in the "home". I will be saving all my personal files in a separate NTFS shared partition with windows. – VidathD May 03 '20 at 16:56
  • @SasukeUchiha then you won't need a /home partition. Using defaults should be fine as @user535733 mentioned. – Mido May 03 '20 at 17:02
  • @SasukeUchiha Suspend has never used swap, you're thinking of hibernate – Izkata May 04 '20 at 14:04
  • That FAQ seems not particular helpful.why would you want to have a 1TB Swap partition. (Besides it does not mention kernel crash dumps which could be the only reason to have a swap size similar to RAM size). Normally I would say have at least 1GB of Swap, use the same size as ram up to 32GB and above 32GB Ram you don't need more swap. – eckes May 06 '20 at 07:25
  • you do not have 500gb of ram or 1tb of ram (unless you are a visitor from the year 2035), why would you have a 1tb swap partition? – Rabbit May 25 '20 at 12:36
  • The SwapFaq is just a guide. I included it for educational purpose. The first few rows are sufficient to help with setting a swap partition. While I have no clue why the faq mentioned that 1TB thing, OP won't bother questioning such huge swap sizes. – Mido May 26 '20 at 00:03
4

The need for a separate /home partition and swap depends on your usage scenario.

A separate /home partition is a good idea when you have multiple users accessing it via samba or other type of file shares, to prevent them from filling up the root partition (which can cause other issues). On single-user systems with limited space, such as my work laptop, I just go with a big root disk; if it gets filled, it affects noone but me, and I'd rather have the freedom to one day download 100GB of data to my Downloads folder under /home, and the other day to fetch 100GB of docker containers which go under /var. On a server, I might put all of these (/home, /var, /var/lib/docker) on separate partitions for isolation purposes.

The swap partition is often replaced by a swap file nowadays. Apart from swapping/paging, the swap is also used for hibernation on desktop/laptop installations. A swap file has less performance than a partition, but that is hardly noticeable in most installations, and using a swap file gives you more freedom to use more or less swap when required instead of dedicating a part of your hard disk to it.

But do you actually need swap? If you have enough memory, you can do without it. Just be aware that the system to kill processes when/if it does get full. You can use the swapon/swapoff commands to turn on and off swap usage, if you want to try it out.

It should be noted that some software (for example Kubernetes) manages memory on their own and explicitly doesn't want swap space - it won't start if it is available.

rln
  • 41
  • Would the system-sharing case not be better served by some kind of quota enforcement? Otherwise, a user can still fill up the /home partition and make the system unusable for everyone else, even if it's slightly more convenient for the sysadmin. – IMSoP May 05 '20 at 11:22
  • I have a SSD. So it is pretty fast as it is. Also, my SSD is 256GB and I have about 150 used up for windows and 40GB for the shared partition. My current swap file is only 1.7GB and it NEVER seems to get used. I also never seem to get more than 15% RAM usage. – VidathD May 05 '20 at 13:00
  • wellll i recently broke half my ram by spilling coffee on it so I'm down to single channel 4gb so for me it's definitely necessary to have a swap partition.. i'm actually starting to wonder if it was broken before the coffee because the computer had started freezing a lot and at the time i had no swap partition, never thought of checking free -m – Rabbit May 25 '20 at 12:34
  • @IMSoP I would never set up quota management on the root drive. Putting the files on a separate drive comes before any quota management. But, again, it depends on the usage scenario. – rln May 26 '20 at 14:53
  • 1
    @rln I don't follow; what's the relationship between what drive/partition a directory is on and how you manage its quota? – IMSoP May 26 '20 at 16:52