Linux VPS Create/Add swap partition Space example

Source: Internet
Author: User
Tags extend vps hex code

It may be that we use a smaller VPS system with less memory performance when running certain programs. Here we can focus on creating and increasing swap space for Linux Xen VPS hosts, which provide sufficient resources for the program to run. Swap is just like the virtual memory of our Windows system, which can be used for a short time when there is not enough physical memory to help run the program.

Here, regardless of whether our Xen VPS has swap analysis, the tutorial below will add 1GB swap to the space on the hard drive.

Increase memory before swap

The above diagram is my memory before I add swap, and now swap is 1023MB. Here's how to increase the swap and the final effect.

First, create the swap partition via the DD command

DD If=/dev/zero Of=/home/swap bs=1024 count=1048576
Here I create 1GB of space as swap so that the following count data is in front of the bs*1024

Second, format the swap partition

Mkswap/home/swap

Third, convert to swap partition

Swapon/home/swap

Four, create automatic mount

Edit the/etc/fstab file and add the "/home/swap swap default 0 0" script at the end of the file.

Then we reboot the system and free-m to see the resource situation.

Create swap Results

We can see the contrast between this picture and the image above, adding 1024MB of RAM. You can use the Swapoff/home/swap command if you need to turn off the swap partition.

Another LVM way to mount an extended hard disk partition

Linux partition for LVM, expansion of the hard disk is divided into three phases: New partition--New pv--expansion vg--extension LV
For a single hard drive to be divided into multiple logical partitions, create a new partition, such as using the entire hard drive to skip this step:

Fdisk-l #查看需要挂载的分区, generally for/DEV/XVDB
Fdisk/dev/xvdb
Command (M for help): N #新建分区
Command Action
E Extended #扩展分区
P primary partition (1-4) #主分区
P #输入p选择新建为主分区
Partition number (1-4): 1 #主分区编号
Cylinder (1-3263, default 1): #分区起始位置, defaults
Last cylinder, (1-3263, default 3263): #结束位置, by default
Command (M for help): T #指定分区格式
Hex code (type L to list codes): 8e #设置为LVM
Changed system type of partition 1 to 8e (Linux LVM)
Command (M for help): W #保存
#The partition table has been altered!
Quit #退出

New PV and extend to VolGroup00

Partprobe #重新读取分区表
PVCREATE/DEV/XVDB1 #新建PV
Vgscan #显示当前VG
#Reading all physical volumes. This could take a while ...
#Found Volume Group "VolGroup00" using metadata type LVM2 #VG名称为VolGroup00
Vgextend VOLGROUP00/DEV/XVDB1 #扩展PV到PG中

View the number of VolGroup00 remaining PE for extended LV preparation

Vgdisplay
#---Volume Group---
#VG Name VolGroup00 #VG名称
#Free pe/size 2553/79.78 GB #2553为剩余PE数

View the LV to extend

Lvscan #列出LV, large capacity for the LV to extend
#ACTIVE '/dev/volgroup00/logvol00 ' [10.53 GB] Inherit #要扩展的LV
#ACTIVE '/dev/volgroup00/logvol01 ' [256.00 MB] Inherit

Extend LV
 
lvresize-l +2553/dev/volgroup00/logvol00 #2553为VG内剩余PE数
Resize2fs/dev/volgroup00/ LogVol00

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.