Android设备创建大Swap文件求助:三星S7 Edge(安卓7.0已Root)
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 zerosof=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:
- First, remount the system partition as writable:
mount -o remount,rw /system - Add the swap file entry to
fstab:
(Ifecho "/sdcard/swapfile none swap defaults 0 0" >> /system/etc/fstab/system/etc/fstabdoesn’t exist, check/vendor/etc/fstabinstead – Samsung devices sometimes store it there) - 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
99swapin/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
swapfilefrom internal storage, and reboot.
内容的提问来源于stack exchange,提问作者user8808015

