Increase space on linux

How to Increase Swap Space on Linux Ubuntu?

In this article, we will learn how to increase the swap space, which will solve the memory errors in applications. This will cover how to add a swap file to an Ubuntu Linux.

Anyway, this is recommended to utilize the spinning hard disk drivers for swap as SSD can cause issues with hardware degradation over time. Due to this reason, do not enable swap on Cloud where the SSD storage is provided.

What is Swap file?

The Swap is a place where the OS can store temporary data as it can no longer holds in RAM. Basically, this will increase the ability of the amount of data that a server can hold during its working memory. The swap space on the hard disk drive will be used mainly when sufficient space is available in the RAM to hold the data.

The data written on the disk will be slower than the RAM, but the OS will prefer to keep the running applications and data in memory and keep the old data in the swap.

Check the System for Swap Information

We will first check the system which already has the swap space. We can have multiple swap files or partitions.

Please note that, we can see the swap available in the system by using the below command –

Or we can use free -h command to display the swap space.

We can see the Swap row in the output of the machine. Here in this machine we have 1.0 G swap space allocated.

Checking the Available Space on the Hard Disk Partition

The most common way of allocating the swap space on the Linux is to use the separate partitions allocated for the swap. We cannot alter the partition scheme which is impossible, but we can easily create a swap file that resides on the existing partition.

Before we do this we will check the current disk space by using below command.

The device under the /dev is the hard disk drives here we have 15 G space available.

In general, the amount equal to or double the amount of RAM on the machine is recommended for a good starting.

Creating a Swap File

As we know the available hard disk space, we can go head by creating a swap file within our filesystem. Also, note that, a file of the swap size which we are calling as ‘swapfile’ is in our root partition / directory.

The best way to create a swap file is by using a file called ‘fallocate’ program, this command will creates a file of a pre-allocated size instantly.

As we have 1 GB RAM allocated to our machine we will create more 2 GB file to meet the minimum requirement of the Linux.

We can verify that using the below command.

Enabling the Swap File to Use

We have created the swap file of our requirement but it needs to be turned on in this swap space. Before we turn on the swap file, we needed to lock the permissions of the file to only root users privileges who can read the contents of the files which will prevents the normal users from being able to access the file.

Читайте также:  Lshw linux версия bios

We can do this using the below command

To verify the permissions we can see using the below command

We can turn on the »swapfile» to use as swap space by using the below command

We have to verify that the swap is available with the amount of space allocated. For this, we can use below command –

OR Use the following command –

Making the Swap File Permanent

As we have changed in swap file for the current session, we also need to reboot the server that will not retain the swap settings to this permanant setting. Also, automatically we can add this swap file settings to ‘/etc/fstab’ file.

We can use the above steps to increase the swap space using a swap file, where we can fix the issues related to the memory exceptions. If we are running out of memory on any Linux servers then the above content will be specially be useful.

Источник

Increase the Size of a Linux Root Partition Without Rebooting

Table of Contents

Introduction

A typical Linux server deployed from a ProfitBricks supplied image has a single storage volume, /dev/vda . If we take a look at that using fdisk we will see that the disk is divided into two partitions. The first one, /dev/vda1 , is the boot partition where the OS resides. The second partition, /dev/vda2 , is configured as swap space.

In the example above, the total 50 GB storage volume is split into 46 GB usable space and 4 GB for swap. What if after provisioning we find that 46 GB of disk space is not enough but we prefer not to add an additional storage volume? The goal is to increase the amount of disk space available on the root filesystem. This can be accomplished with minimal disruption. We do not need to reboot the server!

Requirements

  • A Linux Server created from a ProfitBricks supplied image.
  • SSH or console access (via the DCD) to the Linux Server.
  • The partprobe command. Can be installed from the parted package on most Linux distributions.
  • The fdisk , swapoff , mkswap , swapon , and resize2fs commands. Likely available by default.
  • A current snapshot or other backup of the system you are working on. Just to be safe!

Provision Additional Space

To increase the size of the hard drive, go into the DCD (Data Center Designer) and upscale the drive.

After you have increased the amount of drive space, click on «provisioning» to process the change. Takes around a minute and your hard drive is bigger.

We then need to switch off the swap — so make sure you can live a few minutes without swap space:

Once swap has been disabled, we need to reconfigure the partitions using fdisk :

We will delete the two existing partitions first. We run fdisk /dev/vda and then use the d command to delete partition 2, and then delete partition 1. Follow the example below:

Now we recreate our partitions. In the example we have 4 GB of swap space. So we need to keep at least that much space available for the new swap partition.

Recreate /dev/vda1 first. Press n to create a new partition. Enter p to create a primary partition. We can press Enter to accept the default value of 2048 for the first sector. Then enter a size for the partition. You can enter a value in GB, so if we are increasing the disk to 100 GB, we subtract our 4 GB for swap, and enter +96G for 96 GB.

Now we recreate the swap partition following a simalar process. Press n and then p to create a new primary partition. Press Enter to accept the default value for «First sector». We can also press Enter again to accept the default value for «Last sector».

Читайте также:  Меню пуска windows 10 не открывается

Since this second partition is going to be used for swap space, we need to change the partition type. This can be done by pressing t at the fdisk prompt. We then press 2 to select the second partition. If you want to see the list of available partition types, press L, otherwise enter 82 to select «Linux swap / Solaris».

fdisk helpfully informs us that we have changed the partition type with the message:

After that, we save using the w command and are returned to a shell prompt:

You may get a message like this before the shell prompt:

Lets forgo rebooting and instead tell the kernel about the new partitions using partprobe :

We should be returned to the shell prompt with no output from partprobe .

Now we need to resize our filesystem on /dev/vda1 :

The filesystem on /dev/vda1 is now 25165824 (4k) blocks long.

Initialize the new swap location of /dev/vda2 :

Finally we edit /etc/fstab and replace the old UUID with the new one returned in the output of the mkswap command. The line to change has no value for «mount point» and has «type» set to swap.

After editing /etc/fstab , we need to enable swap again:

Verify

We can verify the new larger disk size by utilizing df and/or fdisk .

We can also confirm that the server was not rebooted by looking at the output of uptime :

Summary

We have successfully increased the amount of disk space available on our Linux server. If you have any questions or comments, please leave them here, or in the DevOps Community section of this site.

Источник

Increase space on linux

  • VMware Technology Network
  • :
  • Cloud & SDDC
  • :
  • Guest Operating Systems
  • :
  • Virtual Machine, Guest OS and VM Tools Discussions
  • :
  • [Complete Guide] How to Increase space on Linux vm.
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

The steps below is taken from : Extending partitions on Linux VMware virtual machines | TechRepublic . To view the pictures mentioned in the step, please go to the site, i have modified the step from that site, as some steps were not clearly explained and missing:

  1. Shutdown the VM
  2. Right click the VM and select Edit Settings
  3. Select the hard disk you would like to extend
  4. On the right side, make the provisioned size as large as you need it
  5. Click OK
  6. Power on the VM
  7. Connect to the command line of the Linux VM via the console or putty session
  8. Log in as root
  9. The fdisk command provides disk partitioning functions and using it with the -l switch lists information about your disk partitions. At the command prompt type fdisk -l
  10. The response should say something like Disk /dev/sda : xxGB . (See Figure A )
  11. At the command prompt type fdisk /dev/sda. (if dev/sda is what was returned after step 10 as shown in Figure A )
  12. Type p to print the partition table and press Enter (also shown in Figure A )
  13. Type n to add a new partition
  14. Type p again to make it a primary partition
  15. Type: 3 (partition number)
  16. Type: t (type)
  17. Type the default numbers you see on the line. in other words select default first available cylinder to the default last cylinder. In Figure A the default last is 2610 so you type 2611 in that case.
  18. Type 3 (partition Number)
  19. Type: 8e (set type to LVM)
  20. Type w to save these changes
  21. reboot
  22. Log back in as root
  23. At the command prompt type fdisk -l . You’ll notice another partition is present. In Figure B it is listed as sdaX .
  24. Type: pvcreate /dev/sdaX (where X i the number you see on step 23. to initialize this new partition as a physical volume s
  25. Now you’ll add the physical volume to the existing volume group using the vgextend command. First type df -h to find the name of the volume group. In Figure C , the name of the volume group is vg_root (for me it was: . Now type vgextend [volume group] /dev/sdaX. (ex: vgextend vg_root /dev/sda4). in my case it was something like: vgextend VolGroup00 /dev/sda3
  26. Type: lvextend -l +100%FREE /dev/VolGroup00/LogVol00 to Extend the logical volume
  27. Type: resize2fs -p /dev/mapper/VolGroup00-LogVol00 to expand the ext3 file system in the logical volume
  28. You can now run the df command to verify that you have more space–df -h

Thats all

Источник

3 Ways of Increasing Swap Space on Linux

Sometimes the default physical memory is not enough to serve certain tasks or processes. It may happen that the processes are swapping more memory in and out of the swap space. This post helps to explain how to increase the swap memory on a Linux system.

There will be 3 different ways explained in this post, it depends on the availability of each case to use any of these options.

Method #1 : Use a new disk

1. Add a new disk to the Linux instance from the available storage.

2. Once the new disk is presented to the instance and the OS has detected it, run the below commands to create the new swap space/partition on this new disk. Be aware that the remaining space on the disk can be used for any other file system as required.

3. Run the following command to reload the changes on the partition table.

4. Create a new swap area on the new partition that had been just created:

5. Add the swap entry to the /etc/fstab file as indicated below on this step, the best recommendation is to use UUID of the partition instead the name.

6. Load the new swap space that had been created for the Instance to start using it when needed, the below command needs to be issued.

7. To list the swap devices run the below command.

8. Finally, run the below command to add this to the initramfs of the server.

Method # 2 : New Partition on OS disk

1. Create a new partition on the original disk, this only applies if there is some free space on it, free space can be check with the following command.

2. If there is free space, create a new partition on the original disk with the following commands.

3. Run the following command to reload the changes on the partition table.

4. Create a new swap area on the new partition that had been just created on the original disk.

5. Add the swap entry to the /etc/fstab file as indicated below on this step:

6. Load the new swap space that had been created for the Instance.

7. To list the swap devices run the below command.

Method # 3 : Create a swap file.

1. Create a swap file on the current File system for example on root, for this a new Directory can be created.

2. Create a new file into this new directory, in this example a new file for 2Gb is create.

3. Create a new swap area on the file that has been created.

4. Change the permissions on the file.

5. Add the swap partition to the /etc/fstab file as indicated below on this step:

6. Load the new swap space that had been created for the Instance.

7. To list the swap devices run the below command.

The new swap area that the instance will have available can be checked with this command below.

Источник

Читайте также:  Настройка беспроводного экрана windows 10
Оцените статью