dd swap

dd swap

dd if=/dev/zero of=/swaporacle bs=1M  count=3030
mkswap /swaporacle
swapon /swaporacle
swapon -s
vi /etc/fstab

Certain software's require minimum swap space for installation. I ran into the same problem when installing oracle on my Fedora machine. Does adding more swap space mean you have to install again from scratch? Luckily, no. In this article I will show you how to add some extra space to your existing tux. You could also reshuffle and resize your partitions and make increase swap space but that is a pretty severe change to the existing machine.

Step 1: Learn to use Swap commands

Swapon and SwapOff are two command provided with Linux to enable/disable devices and files for paging and swapping.

Lets first check how much swap space is there on my machine. At the CLI, we type "swapon -s" which displays swap usage summary by device.

The sizes mentioned in above screenshot are in Kb, and my system currently has only 490MB out of which 72MB has been already used. That's the reason why oracle rpm threw errors during installation.

Step 2: Available Disk Space

Before we go ahead and create swap file, lets see how much disk space we have. At the CLI, we would now run the command "df -h". `df` command reports file system disk space usage on a Linux system. We also included the option of "-h" which print sizes in human readable format (e.g., 1K 234M 2G).

dd swap_第1张图片

Under the "Available" column I have approximately 22Gigs of free space on root partition, that’s where my new swap file will be.

Step 3: Create Swap File using DD command

In order to create an additional swap file, I am going to use the dd (data dump) command.

In the above dd command we used :

  • if=/dev/zero ; points to /dev/zero file which contains only zero's and will write those to the output file. In contrast to /dev/null, which only acts as a sink for data, /dev/zero also acts as a source. All reads on /dev/zero return as many NULL’s as characters requested.
  • of=/extraswap ; points to /extraswap file which we will use as swap
  • count=2048 ; is the file-size for /extraswap file which gets created.
  • bs=1M ; determines how many bytes should be read and written at a time

You can replace 2048 with the number of megabytes you want in your additional swap file.

Step 4: Setup Linux swap area using MKSWAP command

Once, extraswap file is generated; we will have to prepare it for use as a swap partition by using mkswap command. mkswap sets up a Linux swap area on a device or in a file. The device argument provided to mkswap is generally a disk partition (something like /dev/hda2 or /dev/sdb3) but it can also be a file (like in our case).

Step 5: SwapOn the new /extraswap file

To activate my new swap file, I run the command "swapon /extraswap" on the CLI. After that you can run "swapon -s" and view the addition made.

You can also use "free -m" command to verify addition of your new swap space.

dd swap_第2张图片

Step 6: Make swap upgrade permanent through fstab file

To make these changes permanent and load the new /extraswap everytime system reboots, we will have to modify the fstab file in /etc/ folder.

Open /etc/fstab in your VI and add another line to include information regarding new swap file.

dd swap_第3张图片

Done! Now you can reboot, do whatever and your system will have 2048Mb of more swap space (and hopefully my oracle installation wont be a PITA now).



你可能感兴趣的:(dd swap)