天天看點

實作swap分區實驗:實作swap分區

實驗:實作swap分區

swap 相當于虛拟記憶體,交換分區

本實驗為增加swap分區大小

#建立一個分區
[[email protected] ~]#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
           

繼續閱讀