实现swap分区

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_43551152/article/details/83618137

实验:实现swap分区

swap 相当于虚拟内存,交换分区
本实验为增加swap分区大小

#新建一个分区
[root@CentOS6 ~]#fdisk /dev/sdb                添加硬盘sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n                    #新建分区
Command action
   e   extended
   p   primary partition (1-4)
                        p                #e为逻辑分区,p为主分区
Partition number (1-4): 2                #设定分区编号
First cylinder (6529-26108, default 6529):          #回车
Using default value 6529
Last cylinder, +cylinders or +size{K,M,G} (6529-26108, default 26108): +4G #分区大小为4G
Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7972ac2c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+  83  Linux
/dev/sdb2            6529        7051     4200997+  83  Linux

Command (m for help): t                    #修改分区信息
Partition number (1-4): 2
Hex code (type L to list codes): 82        #改为swap分区
Changed system type of partition 2 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7972ac2c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+  83  Linux
/dev/sdb2            6529        7051     4200997+  82  Linux swap / Solaris

Command (m for help): w                      #保存分区信息
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

分区已创建好
swapon /dev/sdb2   
vim /etc/fstab                                     #在其中写入以下信息
UUID=f2350b40-9169-4ef7-a4d7-c389217e192f swap   swap    pri=10          0 0  # 其中pri=10为取代原来的swap的优先级,原swap优先级为-1
swapoff        #禁用swap
swapon -a    #启用swap
cat /proc/swaps
swapon -s
free -h        #可以看到swap 又原来的2G变为了6G

猜你喜欢

转载自blog.csdn.net/weixin_43551152/article/details/83618137