[教程]开启2GB虚拟内存+文件系统完全扩展到sd卡


image
先改动以上文件,开启swap
然后按以下步骤走
0.cd /usr
1.vi diskresize.sh复制以下脚本
##############################################################
#!/bin/sh
#第1步:磁盘分区
#使用fdisk交互式方式创建分区,使用here document方式,解决交互式传递参数的问题
fdisk /dev/mmcblk0 <<EOF
p
n
p
3

w
EOF
echo “##########Partitioning complete###############”
fdisk -l /dev/mmcblk0
echo “##############################################”

#第2步:格式化
mkfs.ext4 /dev/mmcblk0p3
mkdir /media
#临时挂载
#mount /dev/mmcblk0p3 /media

#永久挂载:
#编辑/etc/fstab末行添加
echo “/dev/mmcblk0p3 /media ext4 defaults 0 0” | tee -a /etc/fstab

reboot
###############################################################
2.:wq保存后,chmod 777 ./diskresize.sh
3. ./diskresize.sh 等待重启

  1. 验证空间:df -h
    如果 /dev/mmcblk0p3 出现则分配成功:示例如下
    Filesystem Size Used Available Use% Mounted on
    /dev/root 245.9M 72.8M 156.3M 32% /
    devtmpfs 27.8M 0 27.8M 0% /dev
    tmpfs 27.8M 0 27.8M 0% /dev/shm
    tmpfs 27.8M 48.0K 27.8M 0% /tmp
    tmpfs 27.8M 24.0K 27.8M 0% /run
    /dev/mmcblk0p3 57.9G 24.0K 54.9G 0% /data

###虚拟内存
7. dd if=/dev/zero of=/media/swapfile bs=1M count=64
8. chmod -R 0600 /media/swapfile
9. mkswap /media/swapfile
10.echo “/media/swapfile swap swap defaults 0 0” | tee -a /etc/fstab
重启后free看看
L8C$H__%7JNRKDN~F6MWAU
成功
链接:百度网盘 请输入提取码
提取码:1pc4

4 Likes

From what I’ve read online, you only really want double the amount of system memory as swap (in the case of the Duo, 128mb). The swap might also wear down your SD card faster as I mentioned in my post about enabling and adding swap. You could feasibly use an external USB hard drive and just format some of it as swap and enable it using swapon to prevent SD card wear.

1 Like

you are right ,but because of the low speed of usb2.0 ,adding an external device by usb to swap is a bad way . the sdcard is running at sd3.0,and buy a cheap sd card in 2023 is not a hard way so as for me the sway is worth.

I did a quick Google search, and the results say that SD 3.01 has a maximum speed of only 25MB/s while USB 2.0 appears to have a much faster theoretical maximum. Feel free to correct me if I’m wrong here because I didn’t really look into it much further.