TechBuzzPro

How to Create Swap on Chromebook: Step-by-Step Guide

· 5 min read · Windows & PC

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can create a swap file on a Chromebook, but only if you have enabled Developer Mode and have access to the Linux terminal (Crostini). ChromeOS itself does not provide a user-facing swap setting; the system manages memory automatically. The steps below use the Linux container to add a swap file, which can help if you run memory-heavy Linux apps. Be aware that this does not affect ChromeOS itself—only the Linux environment.

What You'll Need

  • A Chromebook with Linux (Crostini) enabled. Most modern Chromebooks support this; check Settings > About ChromeOS > Additional details > Linux development environment.
  • At least 2 GB of free storage in your Linux container (check with df -h).
  • Basic familiarity with the Linux terminal. You'll use commands like dd, mkswap, and swapon.
  • Note: You do not need Developer Mode for Crostini; it's a supported feature. But you do need to open the Terminal app.

Step-by-Step

  1. Open the Linux terminal. Launch the Terminal app from your launcher (it's called "Terminal" and has a dark icon). If you haven't set up Linux yet, go to Settings > About ChromeOS > Developers > Linux development environment and follow the prompts.
  2. Check available disk space. Type df -h and press Enter. Look at the line mounted on / or /home. You need free space equal to the swap file size you plan to create (e.g., 2 GB). If space is low, free up files first.
  3. Create a swap file. Decide on size—2 GB is a reasonable start. Run: sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress. This creates a 2 GB file named swapfile at the root. Replace 2048 with your desired size in MB (e.g., 4096 for 4 GB). The status=progress shows progress; it may take a minute.
  4. Set secure permissions. Only root should read/write the swap file: sudo chmod 600 /swapfile.
  5. Format the file as swap. Run: sudo mkswap /swapfile. You'll see output like "Setting up swapspace version 1, size = 2 GiB".
  6. Enable the swap file. Run: sudo swapon /swapfile. If you get an error about invalid argument, ensure the file is not on a filesystem that doesn't support swap (unlikely in Crostini).
  7. Verify it's active. Run: free -h or swapon --show. You should see the swap file listed with its size and used amount.
  8. Make it persistent across reboots (optional but recommended). Edit /etc/fstab with a text editor like nano: sudo nano /etc/fstab. Add this line at the end: /swapfile none swap sw 0 0. Save (Ctrl+O, Enter) and exit (Ctrl+X). Now the swap file will activate automatically when the Linux container starts.

Common Mistakes

  • Creating the swap file in a folder that gets wiped. Use /swapfile at the root, not in your home directory, to avoid permission issues and accidental deletion.
  • Forgetting to set permissions. Without chmod 600, other users or processes could read sensitive memory data.
  • Using a swap file larger than free space. Always check df -h first; a full disk can break the Linux container.
  • Expecting ChromeOS to use the swap. This swap only applies to the Linux container. ChromeOS manages its own memory and does not expose swap settings to users.
  • Not adding to fstab. If you skip the fstab step, the swap file won't be active after a reboot or after the Linux container restarts.

Tips

  • Start with a 2 GB swap file; increase only if you see out-of-memory errors in Linux apps.
  • Use swapon --show to confirm the swap is active and its priority.
  • If you need to resize later, turn off swap (sudo swapoff /swapfile), delete the file, and repeat the steps with a new size.
  • Keep an eye on disk usage with df -h; swap files consume real storage.
  • For most users, ChromeOS's built-in memory management is sufficient; only add swap if you regularly run heavy Linux applications.

Troubleshooting

  • "swapon: /swapfile: read swap header failed" – You likely skipped mkswap. Run sudo mkswap /swapfile again, then sudo swapon /swapfile.
  • "swapon: /swapfile: insecure permissions 0644, 0600 suggested" – Fix with sudo chmod 600 /swapfile and try again.
  • "swapon: /swapfile: swapon failed: Invalid argument" – This can happen if the file is on a filesystem that doesn't support swap (e.g., some network mounts). Ensure you created it in the Linux container's ext4 filesystem.
  • Swap not active after reboot – Check that you added the correct line to /etc/fstab and that there are no typos. Run sudo swapon -a to test.
  • Linux container won't start after adding swap – You may have run out of disk space. Boot into ChromeOS, open the Terminal, and remove the swap file: sudo swapoff /swapfile, then sudo rm /swapfile, and remove the fstab line.

Frequently Asked Questions

Can I create swap on a Chromebook without Linux?

No. ChromeOS does not provide a user-accessible swap setting. The only way to add swap is through the Linux container (Crostini).

Does adding swap improve ChromeOS performance?

No. The swap file only affects the Linux container. ChromeOS manages its own memory separately and does not use this swap file.

How do I remove the swap file?

First disable it: sudo swapoff /swapfile. Then delete the file: sudo rm /swapfile. Finally, remove the line you added to /etc/fstab.

What size swap file should I use?

A common rule is 2 GB for light use, or equal to your RAM if you hibernate (not applicable here). Start with 2 GB and increase if needed.

Will this void my warranty or break ChromeOS?

No. Using the Linux container is officially supported. However, incorrect commands could affect your Linux environment, so follow steps carefully.

Can I use a swap partition instead of a file?

In Crostini, you cannot create a swap partition because the container uses a disk image. A swap file is the only method.