linux扩swap ubuntu创建swap分区
这篇文章给大家聊聊关于linux扩swap,以及ubuntu创建swap分区对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。
redhat linux swap分区扩展的三种方法详解
redhat linux swap分区扩展的三种方法
swap介绍:
当物理内存占用完了后,当系统还需要更多的物理内存时,物理内存中inactive pages,就move到swap空间。swap空间是在位于硬盘上的,因此访问速度较物理内存慢。
当机器的物理内存发生变化时,swap分区也要做相应的扩展:
有三种方法可以对swap分区进行扩展:
一、扩展正在使用的swap分区的逻辑卷(推荐使用此种方式)
二、新建swap分区,
三、新建swap file,
具体步骤如下:
一、扩展正在使用的swap分区的逻辑卷
设定用作swap分区的逻辑卷为:/dev/VolGroup00/LogVol01
Disable swapping for the associated logical volume:
# swapoff-v/dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 256 MB:
# lvm lvresize/dev/VolGroup00/LogVol01-L+256M
Format the new swap space:
# mkswap/dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon-va
Test that the logical volume has been extended properly:
# cat/proc/swaps或者# free
二、新建swap分区
设定新建的swap分区的逻辑卷为:/dev/VolGroup00/LogVol02
Create the LVM2 logical volume of size 256 MB:
# lvm lvcreate VolGroup00-n LogVol02-L 256M
Format the new swap space:
# mkswap/dev/VolGroup00/LogVol02
Add the following entry to the/etc/fstab file:
/dev/VolGroup00/LogVol02 swap swap defaults 0 0
Enable the extended logical volume:
# swapon-va
Test that the logical volume has been extended properly:
# cat/proc/swaps或者# free
三、新建swapfile
通过此种方式进行swap的扩展,首先要计算出block的数目。具体为根据需要扩展的swapfile的大小,以M为单位。block=swap分区大小*1024,例如,需要扩展64M的swapfile,则:block=64*1024=65536.
然后做如下步骤:
dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:
mkswap/swapfile
To enable the swap file immediately but not automatically at boot time:
swapon/swapfile
To enable it at boot time, edit/etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat/proc/swaps或者 free.
总结:三种方法都能对swap分区进行扩展,但是推荐使用第一种方法。
Linux系统怎么调整swap分区大小
这里介绍Linux系统中调整swap大小的方法。
1、使用free命令带上m参数,查看swap文件大小,官方建议在RAM是2到4.5G时,swap是RAM的2倍;如果RAM大于等于4G则swap等于RAM即可
2、也可用cat查看etc目录下的swaps文件,如下图
3、创建一个swap文件
复制内容到剪贴板
########
dd if=/dev/zero of=/tmp/swap bs=1MB count=1024
########
以下仅供参考:不用看
Creating a swap file
First of, make sure the file system the disk you wish to swap on is properly mounted. For the purposes of this tutorial we will assume the disk is mounted as/mnt and we want to use the file/mnt/myswap.swp for swapping.
使用下面的命令创建一个1G的swap文件
复制内容到剪贴板
Use the following command to create a 1024MB file that we will use for swapping
########
dd if=/dev/zero of=/mnt/myswap.swp bs=1024MB count=1
########
4、制作一个swap文件,如果觉得繁琐,可以将mkswap文件挂载到tmp目录下,例如:
复制内容到剪贴板
########
mkswap/tmp/swap
########
以下仅供参考:不用看
Preparing the swap file
Before we enable the swap file we must first set it up. The following command accomplishes just that:
########
mkswap/mnt/myswap.swp
########
5、使用swapon启动/tmp/swap
复制内容到剪贴板
########
swapon/tmp/swap
########
使用一个swap分区,如果已经有一个swap分区,该步骤可以省略
以下仅供参考:不用看
Using a swap partition
Setting up a swap partition is a bit more difficult, as the partition must be first created then formatted using the linux-swap file system. Once that is done, assuming the swap partition is at/dev/scsi/host0/bus0/target0/lun0/part5(common for v24 USB drives with mutiple partitions), the only command that needs be issued is:
6、再次使用free查看增加后的swap大小
7、如果只想增加swap大小,请忽略以下的操作,重要!!如果不使用刚才增加的1G的swap文件,使用下面的swapoff命令,可以关闭,这样swap文件就缩小了1G
使用swapoff关闭swap文件
复制内容到剪贴板
########
swapoff/tmp/swap
########
注意事项:如果只想增加swap大小,请忽略第7步的所有操作。
Linux下如何增加swap分区大小
1、检查当前的分区情况:
[root@localhost]#free-m
2、增加交换分区文件及大小,如果要增加2G大小的交换分区,则命令写法如下,其中的 count等于想要的块大小。
[root@localhost]# dd if=/dev/zero of=/home/swap bs=1024 count=2048000
3、设置交换文件:
[root@localhost]# mkswap/home/swap
4、立即启用交换分区文件
[root@localhost]# swapon/home/swap
5、如果要在引导时自动启用,则编辑/etc/fstab文件,添加行:
/home/swap swap swap defaults 0 0
系统下次引导时,它就会启用新建的交换文件,再查看SWAP分区大小发现增加了2G。
批量删除linux下文件夹命令如下:
比如我要删除/var/www/html这个文件夹的话可以使用以下命令:rm-Rf html
然后在ls查看发现没html这个文件夹了!