7

I want to make a swap on mounted external EBS, /workspace

And I got Device or resource busy

swapon: /workspace/swap.1: swapon failed: Device or resource busy

sudo /bin/dd if=/dev/zero of=/workspace/swap.1 bs=1M count=10240
sudo /sbin/mkswap /workspace/swap.1
sudo /sbin/swapon /workspace/swap.1


Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  5.1G  2.3G  70% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            2.0G   12K  2.0G   1% /dev
tmpfs           396M  336K  395M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G     0  2.0G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/xvdb       6.0T  1.7T  4.1T  29% /workspace

Still not working after running sync command

➜  ~  sync
➜  ~  sudo /sbin/swapon /workspace/swap.1
swapon: /workspace/swap.1: swapon failed: Device or resource busy

Here's the swap information

➜  ~   cat /proc/swaps
Filename                Type        Size    Used    Priority
/workspace/swap.1                       file        10485756    0   -1
poc
  • 191
  • 2
    It may already have been added. Could you cut-and-paste the output of cat /proc/swaps into your question? – MadHatter May 05 '15 at 06:08
  • @MadHatter Hi I updated the info. – poc May 05 '15 at 06:15
  • 1
    @poc Swapping was on it already turned on... it probably remained from a previous try. Before your next try, turn off swap with a swapoff /workspace/swap.1. Glory belongs to MadHatter. – peterh May 05 '15 at 06:16
  • "Swap on, swap off, Daniel-San", like Mr. Miyagi taught the young kid still in his early steps to mastering server-fu. – Janne Pikkarainen May 05 '15 at 09:00

4 Answers4

10

I had a similar issue trying to make a swap partition on sda2. My solution was to type

#: swapoff /dev/sda2
#: mkswap /dev/sda2
#: swapon /dev/sda2

This seemed to reset whatever issue I was having. To make sure this worked, use "lsblk" to check the mountpoint.

3

The problem is not adding the swap; the problem is your assumption that all swap space shows up in the output of df.

Only partition-type data shows up in that, and as you're using in-system swapping, aka a swapfile, it doesn't show up. The swap space was activated by the first swapon you did; you were just looking in the wrong place to confirm that. The second swapon failed, quite rightly, because you can't add the same file a second time. When you looked in /proc/swaps, which is the definitive system summary of all swap space, you saw that your new space was up and running.

MadHatter
  • 80,590
1

You need to sync out the block cache after the mkswap command.

Its explanation is the following.

If you write data, but they aren't written out into the disk physically, they will be dirty pages. It means, that their content was created here, on your system, and wasn't read in from the hard disk. Thus you can't swap on dirty pages.

peterh
  • 4,971
0

try this command

echo 1 > /sys/block/zram0/reset

replace "zram0" with your swap partition. example:

    # Zram disk - 512MB size
#zram_enable=`getprop ro.config.zram`
#if [ "$zram_enable" == "true" ]; then
#    swapoff /dev/block/zram0
#    echo 1 > /sys/block/zram0/reset
#    echo 536870912 > /sys/block/zram0/disksize
#    mkswap /dev/block/zram0
#    sync
#    swapon /dev/block/zram0 -p 32758