You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android设备创建大Swap文件求助:三星S7 Edge(安卓7.0已Root)

Create a 20GB Swap File on Rooted Galaxy S7 Edge (Android 7.0)

Hey there, since you’re aware of the risks and this isn’t your primary device, let’s get straight to creating that huge 20GB swap file. We’ll use terminal commands because most third-party apps (like ROEHSOFT RAM EXPANDER) have arbitrary size limits, and terminal gives us full control.

Prerequisites

  • A rooted Galaxy S7 Edge running Android 7.0 (you already have this)
  • At least 21GB of free internal storage (to accommodate the 20GB swap file plus a little extra overhead)
  • A terminal emulator app (e.g., Termux, Terminal Emulator for Android) – install one from the Play Store if you don’t have it
  • Root access granted to the terminal app

Step-by-Step Guide

1. Gain Root Access in Terminal

Open your terminal emulator and run this command to switch to root user:

su

When prompted, tap "Allow" on the root permission request popup.

2. Navigate to Internal Storage

Most Android 7.0 devices store internal files at /storage/emulated/0 or /sdcard. Run either of these commands to move to the right directory:

cd /storage/emulated/0
# OR
cd /sdcard

3. Create the 20GB Swap File

We’ll use the dd command to create a blank file. This might take a while (depending on your storage speed), so be patient:

dd if=/dev/zero of=swapfile bs=1G count=20
  • if=/dev/zero: Reads from a null device to fill the file with zeros
  • of=swapfile: Names the output file "swapfile"
  • bs=1G: Sets the block size to 1GB (faster than smaller blocks)
  • count=20: Creates 20 blocks, totaling 20GB

If dd feels too slow, you can try fallocate (note: not all Android kernels support this, but it’s worth a shot):

fallocate -l 20G swapfile

4. Set Correct Permissions

Swap files require strict permissions to work properly. Run this command to restrict access to the root user only:

chmod 600 swapfile

5. Format the File as Swap

Now we need to format the blank file into a swap partition:

mkswap swapfile

You should see a confirmation message that the swap area has been set up.

6. Activate the Swap File

Enable the swap with this command:

swapon swapfile

To verify it’s working, run either of these commands:

free -m  # Shows total/used/free memory including swap
cat /proc/swaps  # Lists active swap devices/files

You should see your 20GB swapfile listed here.

7. Make Swap Persist After Reboot

By default, the swap will disable when you reboot your phone. To fix this, we’ll add it to the system’s fstab file:

  1. First, remount the system partition as writable:
    mount -o remount,rw /system
    
  2. Add the swap file entry to fstab:
    echo "/sdcard/swapfile none swap defaults 0 0" >> /system/etc/fstab
    
    (If /system/etc/fstab doesn’t exist, check /vendor/etc/fstab instead – Samsung devices sometimes store it there)
  3. Remount the system partition as read-only to keep it stable:
    mount -o remount,ro /system
    

Alternative: If your device supports init.d scripts (common on rooted Samsung devices), you can create a startup script instead:

  • Create a file named 99swap in /system/etc/init.d/
  • Add this line to the file: su -c swapon /sdcard/swapfile
  • Set the script’s permissions: chmod 755 /system/etc/init.d/99swap

Final Notes

  • As you already know, using such a large swap file will make your device much slower, and constant read/write cycles might shorten your storage’s lifespan. But since this isn’t your main phone, that’s up to you.
  • If your device crashes or becomes unresponsive, boot into recovery mode, use the file manager to delete the swapfile from internal storage, and reboot.

内容的提问来源于stack exchange,提问作者user8808015

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:05:21