linux不分区直接在文件系统根上开swap

root下,直接创swapfile

dd if=/dev/zero of=/swapfile bs=1M count=8192

然后

mkswap swapfile
swapon swapfile

修改fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
#                
# / was on /dev/sda1 during installation
UUID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee /               ext4    errors=remount-ro 0       1
/swapfile                               none            swap    defaults

然后

systemctl daemon-reload

如果fstab写错了这里就会报错
没报错就可以rebootl了

如果想看是否成功

free -h

你可能感兴趣的:(linux,服务器,运维)