Swap issues, device always busy

Asked by Daniel Malz

Hey guys, thanks for your help at previous questions. Unfortunately I encountered further problems.
I made a swap partition using gparted and a live ubuntu version booted from a stick. Now everything seems to be fine, when I run "fdisk", it tells me that

   Device Boot Start End Blocks Id System
/dev/sda1 * 2048 113326079 56662016 83 Linux
/dev/sda2 113326080 125044735 5859328 82 Linux swap / Solaris

how it should be (I guess). Obviously, the swap is not used. When I run "free" it tells me that

             total used free shared buffers cached
Mem: 3089400 1219588 1869812 0 34096 409420
-/+ buffers/cache: 776072 2313328
Swap: 0 0 0

So no swap partition/file available. Well, what I did, refering to
https://help.ubuntu.com/community/SwapFaq#Why_is_my_swap_not_being_used.3F,
I tried to enable the swap partition using
sudo swapoff -a
sudo /sbin/mkswap /dev/sda2
sudo swapon -a

But after the second command, ubuntu tells me that
/dev/sda2: Device or resource busy

What should I do about that?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu util-linux Edit question
Assignee:
No assignee Edit question
Solved by:
Daniel Malz
Solved:
Last query:
Last reply:
Revision history for this message
delance (olivier-delance) said :
#1

delance@delance-desktop:~$ more /etc/fstab
Could you provide /etc/fstab
---------------------------------------------------------------------------------------------------
# /etc/fstab: static file system information.
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
UUID=ac9139a4-21a1-4a6d-8648-49eaedf3cf81 / ext4 errors=remount-ro 0 1
UUID=df0147bb-acbc-4811-8cb0-acce78d94824 /home ext4 defaults 0 2
...
UUID=c5a9c74c-d376-4b89-970d-06c63039c757 none swap sw 0 0

Revision history for this message
Daniel Malz (daniel-malz) said :
#2

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0

# / was on /dev/sda1 during installation
UUID=3a1e727f-0cdf-4a03-958d-48a428bdaea5 / ext4 errors=remount-ro 0 1

# swap was on /dev/sda2 during installation
/dev/sda2 none swap sw 0 0
#/dev/mapper/cryptswap1 none swap sw 0 0
#UUID=BA62FBE262FBA175
/dev/sdb5 /media/d ntfs-3g rw,auto,user,fmask=0111,dmask=0000 0 0

Revision history for this message
delance (olivier-delance) said :
#3

Could you try this:

sudo swapoff -a
sudo umount /dev/sda2
sudo /sbin/mkswap /dev/sda2
sudo swapon -a

I suspect /dev/sda2 is mounted even unusable.

Revision history for this message
Daniel Malz (daniel-malz) said :
#4

Hey delance, thank you for your answer. Unfortunately it did not work.. :( It was not mounted.
I still need an answer.

daniel:~$ sudo swapoff -a
daniel:~$ sudo umount /dev/sda2
umount: /dev/sda2: not mounted
daniel:~$ sudo /sbin/mkswap /dev/sda2
/dev/sda2: Device or resource busy
daniel:~$ sudo swapon -a
swapon: /dev/sda2: read swap header failed: Invalid argument

Revision history for this message
delance (olivier-delance) said :
#5

The following command works to unblock disk "frozen" by hibernation. Could you try it.
Disk busy after hibernation: "e2fsck -f -y -v /dev/sda2" command.

Revision history for this message
Daniel Malz (daniel-malz) said :
#6

Thanks a lot for your time. It says

daniel:~$ sudo swapoff -a
daniel:~$ sudo e2fsck -f -y -v /dev/sda2
e2fsck 1.41.14 (22-Dec-2010)
e2fsck: Device or resource busy while trying to open /dev/sda2
Filesystem mounted or opened exclusively by another program?
daniel:~$ sudo umount /dev/sda2
umount: /dev/sda2: not mounted

Revision history for this message
Daniel Malz (daniel-malz) said :
#7

I just checked again. The swap partition is definitely /dev/sda2 and definitely a swap partition.

Revision history for this message
delance (olivier-delance) said :
#8

I'm stupid! e2fsck is a command for ext# file systems§

Could you boot on Ubuntu CD, choose "Try" instead of "Install".
Run System->Administration->Gparted partition editor.
If automatically mounted, try to unmount it via Gparted.
Then delete and rebuild the swap partition. I presume there is a flag on partition file system saying swap was use for hibernation or something like this.
If it fails, I will be short of ideas.

Revision history for this message
Daniel Malz (daniel-malz) said :
#9

That solved it for a start, thanks a lot. That happens every time when I try to hibernate my computer. But that is, I guess, a different story.

Revision history for this message
delance (olivier-delance) said :
#10

Could you raise a bug. It's very annoying that hibernation fails on a disk issue.

Revision history for this message
Javad Sadeqzadeh (heavymetalica) said :
#11

That also solved my problem (the same problem) as well, though I was trying to do that on Linux mint 15. If your PC has been hibernated for the last time, then all of your partitions are used by the OS, even though they're not shown as mounted, and umount command cannot unmount them, you should reboot your system. That was weird because I formated the swap partition as swap after the hibernation (there was 1GB unused disk space, I mean it wasn't formated as any file system format), and after I formated it as "swap" using Gparted and I tried to use mkswap, I got the same error.

Revision history for this message
osirisgothra (osirisgothra) said :
#12

i'd like to note to those who dont know it, if you go using mkswap to remake your swap partitions and use UUID= in your /etc/fstab, the UUID CHANGES so you'll have to figure out which one is which in fstab, go into /dev/disk/by-uuid and figure out which the old UUID was corrosponding to. The main thing here is to MAKE SURE YOU WRITE DOWN (OR MAKE A COPY) OF THE OLD UUIDS _BEFORE_ using mkswap, if you have alot of disks it can become very annoying when you have to figure out which is what, it helps if you record it prior to that. Thankfully the installers that handle the initial setup record the ID's in the comment header part of fstab, but if you delete it OR MORE LIKELY, use mkswap and then "FORGET" to record the new ID's and have to repeat this process later, you have no idea because you just have the comments header with the _old_ UUIDs in there, which don't mean anything at that point to you. I thought I might just give people a heads up on that one, it wont affect you the first time around, but you will definitely feel the burn if you dont the Nth time around.