对Linux而言,虚拟内存必须是独立的文件系统,因此只能用分区来提供虚拟内存。
root@ubuntu:~# fdisk-l
Disk /dev/sda: 21.5GB, 21474836480 bytes
255 heads, 63sectors/track, 2610 cylinders, total 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 identifier:0x0007ef80
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 39847934 41940991 1046529 5 Extended
/dev/sda3 39845888 39847933 1023 83 Linux
/dev/sda5 39849982 41940991 1045505 83 Linux
Partition tableentries are not in disk order
#每种分区的ID字段是不一样的,要想修改分区类型就要修改分区的ID
修改分区类别:
root@ubuntu:~# fdisk/dev/sda
Command (m for help):m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verifythe partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):t
Partition number(1-5): 5
Hex code (type L to listcodes): 82 #修改/dev/sda5为swap分区(swap分区的标识为82)
Changed system typeof partition 5 to 82 (Linux swap / Solaris)
Command (m for help):w
The partition tablehas been altered!
Calling ioctl() tore-read partition table.
WARNING: Re-readingthe partition table failed with error 16: Device or resource busy.
The kernel still usesthe old table. The new table will be used at
the next reboot orafter you run partprobe(8) or kpartx(8)
Syncing disks.
修改分区属性之后,我们还要将/dev/sda5创建为swap文件系统才能使用:
root@ubuntu:~# mkswap/dev/sda5 #创建为swap文件系统
Setting up swapspaceversion 1, size = 1045500 KiB
no label,UUID=f33720ed-3b0c-46e1-a898-c7f4cb9adfb8