Red Hat Linux添加一個swap分區

添加一個swap分區

要求:

swap 分區容量爲 512 MiB

當您的系統啓動時,swap 分區應該可以自動掛載

不要移除或者修改其他已經存在於您的系統中的 swap 分區

================================================ 
1、先查看一下目前系統中使用的swap分區,我的是隻有一個,現在我要再添加個,容量是512M的

[root@desktop ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/sda2             partition   2047996   0             -1

2、用分區工具重新劃分一個容量爲512M的分區,邏輯分區主分區都可以,推薦使用邏輯分區

[root@desktop ~]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p   看一下目前的分區狀態

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bffad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    20482047    10240000   83  Linux
/dev/sda2        20482048    24578047     2048000   82  Linux swap / Solaris
/dev/sda3        24578048    25602047      512000   83  Linux

Command (m for help): n    使用n新建分區
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e   選擇拓展分區
Selected partition 4
First sector (25602048-41943039, default 25602048): 
Using default value 25602048
Last sector, +sectors or +size{K,M,G} (25602048-41943039, default 41943039):  --->我這裏就把剩餘的空間全給這個擴展分區了
Using default value 41943039
Partition 4 of type Extended and of size 7.8 GiB is set

Command (m for help): n   按n繼續分區,開始分邏輯分區
All primary partitions are in use
Adding logical partition 5
First sector (25604096-41943039, default 25604096): 
Using default value 25604096
Last sector, +sectors or +size{K,M,G} (25604096-41943039, default 41943039): +512M  輸入我要分區的大小
Partition 5 of type Linux and of size 512 MiB is set

Command (m for help): t     按t修改分區類型
Partition number (1-5, default 5): 
Hex code (type L to list all codes): 82   修改爲swap類型
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): w    按w保存退出

[root@desktop ~]#partprobe    刷新磁盤信息

 

3、格式化分區爲swap格式,並且啓用

[root@desktop ~]# mkswap /dev/sda5   格式化
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=8a529678-5180-4c8c-bd2c-18677c573ba3
[root@desktop ~]# swapon /dev/sda5  啓用
[root@desktop ~]# swapon -s   查看正在使用的swap分區,已存在
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   2047996 0   -1
/dev/sda5                               partition   524284  0   -2

4、配置開機自動掛載

[root@desktop ~]# blkid     看要掛載的swap分區的UUID,然後複製
/dev/sda1: UUID="3c6e20fa-3e12-42ca-8dba-b12eee74e43e" TYPE="xfs" 
/dev/sda2: UUID="ff7d2e6d-c2d7-46a0-af09-70c85898ab46" TYPE="swap" 
/dev/sda3: UUID="4Ntfep-th0e-bCXr-Qo3b-EPJ1-SRsu-nfeOru" TYPE="LVM2_member" 
/dev/sda5: UUID="8a529678-5180-4c8c-bd2c-18677c573ba3" TYPE="swap" 
/dev/mapper/vg0-lv0: UUID="b2285e5e-de78-4392-945a-817843fd7f10" TYPE="ext3" 
[root@desktop ~]# vim /etc/fstab   編輯掛載文件,內容如下圖
[root@desktop ~]# mount -a   重新加載掛載表

[root@desktop ~]# 

 

 

 

 

 


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章