教你如何不用新分区添加swap

  • A+
所属分类:运维教程

在之前的教程中我们提到过如何去添加一个swap分区,以及如何给你的swap进行扩容。在教程中我们使用的是新分区的方式,也就是新添加一块硬盘,或在原有硬盘空余空间的基础上新建一个分区,然后将其格式化为交换分区,最后进行挂载。

现在很多朋友使用的都是云主机,云主机一般不会设置swap(如某里云)购买之后一般使用的都是赠送的磁盘空间,且因为数据量小的原因并不会购买数据盘,导致没有可用分区转换为swap,有没有什么办法可以不用分区即可添加或扩容swap呢?今天就来教大家个方法!

首先使用dd命令生成一个固定大小的文件,文件的大小就是添加或扩容swap的大小:

  1. dd if=/dev/zero of=/opt/swap bs=1M count=2048

然后使用mkswap命令将其格式化:

  1. mkswap /opt/swap

使用swapon命令挂载其:

  1. swapon /opt/swap

看下一下,交换分区是不是变大了?

教你如何不用新分区添加swap

原理:Linux中皆是文件,swap对于linux系统来说也是一个文件,/opt/swap对于linux系统来说也是一个文件,这样概念就对等了。实际上这些文件就像一个笔记本,它是一个实体也是一个载体,我们是可以在笔记本中记录内容,如同可以在/opt/swap中写入数据的,你懂了吗?

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:20   其中:访客  20   博主  0

    • avatar grolyrto lemcs

      Hey there! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?

      • avatar cbd oil that works 2020

        You have made some decent points there. I looked on the net to learn more
        about the issue and found most individuals will go
        along with your views on this site.

        • avatar additional reading

          Once I originally commented I clicked the -Notify me when new feedback are added- checkbox and now every time a remark is added I get 4 emails with the identical comment. Is there any way you’ll be able to remove me from that service? Thanks!

          • avatar cbd oil that works 2020

            I do not even know how I ended up here, but I thought this post was good.

            I do not know who you are but certainly you are going to a famous blogger if you are not already ;) Cheers!

            • avatar http://dianews.ge/

              This paragraph will help the internet people for creating new
              webpage or even a blog from start to end.

              • avatar tinyurl.com

                Thanks a lot for sharing this with all of us you actually
                recognise what you’re speaking about! Bookmarked.
                Please additionally consult with my website
                =). We will have a link alternate agreement among us

                • avatar g rsacwgxy

                  With havin so much content do you ever run into any problems of plagorism or copyright
                  infringement? My website has a lot of exclusive content I’ve either authored
                  myself or outsourced but it looks like a lot of it is popping it up all over the internet without my permission.
                  Do you know any solutions to help prevent content from being
                  ripped off? I’d really appreciate it.

                  • avatar svolrfinotews

                    Hi! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward to new updates.

                    • avatar svolrfino tews

                      I keep listening to the news broadcast speak about receiving free online grant applications so I have been looking around for the finest site to get one. Could you advise me please, where could i find some?

                      • avatar outdoor wedding venue Virginia

                        Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your client to communicate. Excellent task..