1、建立Swap分區步驟:
1) 用fdisk 建立分區,一會把此分區建立為Swap分區:
fdisk /dev/sda
2) 假設新建立的分區為sda3,用fdisk 子指令 t 更改分區類型:
[root@lyg ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 32635.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82 ——82表示的分區類型就是swap分區
Changed system type of partition 3 to 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.
Syncing disks.
[root@lyg ~]# fdisk -l
3) 格式化交換分區
[root@lyg ~]# mkswap /dev/sda3
Setting up swapspace version 1, size = 4194885 kB
4)把交換分區打開:
[root@lyg ~]# swapon /dev/sda3
檢查一下:

5)確定開機時啟動swap:
檢查/etc/fstab檔案,如果沒有這一句,就添加上:
/dev/sda3 swap swap default 0 0
下面這個是不行的,沒有明确指定/dev/sda3 。。
下面是正确的設定:
6 )重新開機下機器,再次驗證:
reboot
結束。
其他參考:
剛學了這招,哈哈,用fdisk指令先建立一個partation分區,應該還記得當時的建立分區的步驟:先把原來的一個分區删除了,然後在建立兩個分區,一個小的給swap分區,具體的操作在執行fdisk /dev/sda7之後,用m列出指令清單。依次操作即可。建立好之後給分區改id,然後用mkswap /dev/sda7.來格式化這個分區,最後一步開啟這個分區:swapon /dev/sda7. 就可以用了。但是如果你不想用了的話可以用swapoff /dev/sda7 。來關閉這個swap區。
可以用free指令來檢視所有剛才做的swap分區哦。。。。哈哈。。。
好吧,做完了swap交換區,咱們再學習學習怎麼把這個交換區備份。下面來看很偉大的備份指令:dd,怎麼用呢?來幾個例子就一目了然了:dd if=/etc/passwd of=/tmp/passwd.back 恩,這樣就把etc目錄下的使用者名檔案備份到了tmp目錄下面了。這個比較簡單,再來看一個比較全面的:dd if=/dev/sda of=/tmp/mbr.temp bs=512 coumt=1. 這個bs呢,就是block
size咯,不解釋。count就是塊數。
還有一個cpio指令,這個是很有趣的指令,他是透過資料流重導向的方法來将檔案進行輸出/輸入的一個方式~
這個 cpio 還蠻神奇的呢!他最适用于備份的時候使用的一個指令了!為什麼呢?因為他并不像 cp 一樣,可以直接的将檔案給他 copy 過去,例如 cp * /tmp 就可以将所在目錄的所有檔案 copy 到 /tmp 底下,在 cpio 這個指令的用法中,由于 cpio 無法直接讀取檔案, 而是需要『每一個檔案或目錄的路徑連同檔案名一起』才可以被記錄下來!是以, cpio 最常跟 find 這個指令一起使用了! 這個 cpio 好像不怎麼好用呦!但是,嘿嘿!他可是備份的時候的一項利器呢!因為他可以備份任何的檔案,
包括 /dev 底下的任何裝置檔案!呵呵!是以他可是相當重要的呢!!您說是吧! 而由于 cpio 必需要配合其它的程式,例如 find 來建立檔名,是以, cpio 與管線指令及資料流重導向的相關性就相當的重要了!
<a target="_blank" href="http://blog.csdn.net/changyanmanman/article/details/7046633">http://blog.csdn.net/changyanmanman/article/details/7046633</a>