How to add swap space in Linux

本文详细介绍了在Linux系统中手动创建并配置Swap分区的具体步骤,包括确定Swap大小、使用dd命令创建Swap文件、进行格式化及激活Swap分区等。同时提供了确保系统重启后Swap仍能正常工作的设置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何在Linux下面添加swap file,记录之。

1) 首先确定你要添加的swap的大小,比如是2G,那么就是2048000k

2)以root用户登录到终端,dd一个文件,大小就是你期望的swap文件大小,比如:
dd if=/dev/zero of=/swapfile bs=1024000k count=2
这样就创建了一个大小是2G的文件

3)创建这个swap file
mkswap /swapfile

4)激活当前的swap file,这样在swapon -s就可以看到当前swap已经生效了
swapon /swapfile

5)为了在系统重启后依然生效,还需要一个步骤,在/etc/fstab中添加:
/swapfile swap swap defaults 0 0

为了验证swap已经生效,有下面的几种方法,/proc/swaps or use free command or swapon -s command:

### Ubuntu EFI Partition Configuration and Management In modern computing environments, the transition from BIOS to UEFI has introduced changes in how operating systems like Ubuntu handle boot processes. Despite common terminology referring to "entering BIOS," this actually pertains to accessing UEFI firmware settings interfaces[^1]. For systems utilizing UEFI with an EFI System Partition (ESP), specific configurations are necessary for proper operation of Ubuntu. #### Creating and Configuring an EFI Partition During Installation When installing Ubuntu on a system that uses UEFI, ensuring there is an ESP formatted as FAT32 is crucial. This partition typically resides at the beginning of the disk and should be around 100 MB or larger depending on requirements. The installer will automatically detect if the machine boots via UEFI mode and prompt creation of such partitions unless they already exist. To manually create during installation: 1. Choose `Something else` when asked about disk setup. 2. Select unallocated space where you wish to place your ESP. 3. Click Add and configure: - Size: At least 100 MiB but can go up based on needs. - Type for the new partition: Primary. - Location for the new partition: Beginning of this space. - Use as: EFI System Partition. After setting these options, continue through the rest of the installation process normally. #### Managing Existing EFI Partitions Post-Installation Once installed, managing existing EFI entries involves editing files within `/boot/efi`. Here’s how one might add custom bootloader entries using efibootmgr utility which comes pre-installed with most Linux distributions including Ubuntu. ```bash sudo efibootmgr -c -d /dev/sda -p 1 -L "Custom Boot Entry" -l "\EFI\custom\bootx64.efi" ``` This command creates (`-c`) a new entry pointing towards specified device (`-p`). Labels (`-L`) provide human-readable names while `-l` specifies path relative to ESP mount point leading to desired .efi file. For secure boot scenarios, additional steps may involve signing binaries appropriately before deployment into production environments; however, detailed procedures vary widely between hardware vendors and intended use cases. --related questions-- 1. How does Secure Boot impact EFI partition management? 2. What tools besides efibootmgr support manipulation of EFI variables under Ubuntu? 3. Can multiple OS installations share a single EFI System Partition effectively? 4. Are there any performance benefits associated with placing swap areas inside versus outside the main volume group containing root filesystem?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值