You are not logged in.

#1 2011-12-22 13:23:33

CaptainKirk
Member
Registered: 2009-06-07
Posts: 393

Swap with USB device Problem

I am trying to setup a swap on USB as per https://wiki.archlinux.org/index.php/Sw … USB_device

I tried the UUID method in fstab but it fails. Then I tried using /dev/sdb1 and it also fails.

Take a look at this:

[kirk@arch ~]$ swapon -s
Filename				Type		Size	Used	Priority
[kirk@arch ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          3271       1297       1973          0         15        434
-/+ buffers/cache:        848       2423
Swap:            0          0          0
[kirk@arch ~]$ cat /etc/fstab
# 
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
#devpts                 /dev/pts      devpts    defaults            0      0
#shm                    /dev/shm      tmpfs     nodev,nosuid        0      0

tmpfs                   /tmp          tmpfs     nodev,nosuid        0      0


#UUID=121b8ba5-48b2-4083-ac6b-ae1386ebd600 /boot ext3 defaults 0 1
#UUID=923771e6-7ea1-4bc5-815c-a8c78bcfa1f6 /     ext3 defaults 0 1
#UUID=e0f83332-f764-400b-9052-58a3ea83aafd /home ext3 defaults 0 1
#UUID=dafb368a-0c80-40ca-aca8-208ca48a941b swap  swap defaults 0 0 
/dev/sda1 /boot ext3 defaults 0 1
/dev/sda2 / ext3 defaults 0 1
/dev/sda3 /home ext3 defaults 0 1
#/dev/sda4 swap swap defaults 0 0
#UUID=3ff533f4-a81d-4b0b-b96f-cddaaf79ecaf none swap defaults,pri=10 0 0
/dev/sdb1 none swap defaults 0 0
[kirk@arch ~]$ more /etc/mtab
rootfs / rootfs rw 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
/sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,relatime,size=10240k,nr_inodes=214749,mode=755 0 0
/run /run tmpfs rw,nosuid,nodev,relatime,size=10240k,mode=755 0 0
/dev/sda2 / ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
shm /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda1 /boot ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
/dev/sda3 /home ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
gvfs-fuse-daemon /home/hershel/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0

The USB has two partitions. If I right click on the icon that appears on my Xfce desktop and choose "mount" then I see that it mounted /dev/sdb2 OK:

[kirk@arch ~]$ more /etc/mtab
rootfs / rootfs rw 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
/sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,relatime,size=10240k,nr_inodes=214749,mode=755 0 0
/run /run tmpfs rw,nosuid,nodev,relatime,size=10240k,mode=755 0 0
/dev/sda2 / ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
shm /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda1 /boot ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
/dev/sda3 /home ext3 rw,relatime,errors=continue,commit=5,barrier=1,data=ordered 0 0
gvfs-fuse-daemon /home/hershel/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
/dev/sdb2 /media/data ext2 rw,nosuid,nodev,relatime,errors=continue 0 0
[kirk@arch ~]$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Dec 22 15:13 3ff533f4-a81d-4b0b-b96f-cddaaf79ecaf -> ../../sdb1
lrwxrwxrwx 1 root root 10 Dec 22 15:13 5e1d913b-a909-4f0d-9f8c-615b1dca4a15 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Dec 22 15:13 923771e6-7ea1-4bc5-815c-a8c78bcfa1f6 -> ../../sda2
lrwxrwxrwx 1 root root 10 Dec 22 15:13 d069e188-5c42-404a-95cc-a4e8945f0788 -> ../../sda4
lrwxrwxrwx 1 root root 10 Dec 22 15:13 e0f83332-f764-400b-9052-58a3ea83aafd -> ../../sda3
lrwxrwxrwx 1 root root 10 Dec 22 15:13 f8ff58c5-4eec-4e7d-96e1-0c04b2190578 -> ../../sda1

Here is what fdisk says:

p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d00ad

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10242047     5120000   82  Linux swap / Solaris
/dev/sdb2        10242048   976773119   483265536   83  Linux

Can anyone tell me what I am doing wrong?

Offline

#2 2011-12-22 14:44:51

scar
Member
From: Hungary
Registered: 2009-10-01
Posts: 449

Re: Swap with USB device Problem

Your /dev/sdb1 partition looks ok, but have you made:

# mkswap /dev/sdb1

?


“The future has already arrived. It's just not evenly distributed yet.”
― William Gibson

Offline

#3 2011-12-22 15:17:21

CaptainKirk
Member
Registered: 2009-06-07
Posts: 393

Re: Swap with USB device Problem

Tried that now:

$ sudo mkswap /dev/sdb1
Password: 
Setting up swapspace version 1, size = 5119996 KiB
no label, UUID=9fb37f00-125a-4fb5-acb7-4a6ae39861ce

Rebooted. Nothing. I changed fstab to use this UUID, rebooted. Nothing.

Note that it's a different UUID than "ls -l /dev/disk/by-uuid/" gave before but now "ls -l /dev/disk/by-uuid/" agrees with this new ID.

Anyhow, no swap yet. sad

Offline

#4 2011-12-23 06:15:30

TastyDr.Pepper
Member
From: Somewhere, in the US
Registered: 2011-11-23
Posts: 20

Re: Swap with USB device Problem

Have you tried using the label method instead of UUID? I always used labels instead of UUID, it seamed to make more sense to me, try

mkswap -L YOUR_LABEL /dev/sdX

and then in the /etc/fstab

YOUR_LABEL  swap  swap defaults 0 0

and see what that does
you can also try enabling swap while the system is running

swapon -L YOUR_LABEL

and check to see if it's there with

free -m

Last edited by TastyDr.Pepper (2011-12-23 06:18:47)

Offline

#5 2011-12-23 09:29:43

CaptainKirk
Member
Registered: 2009-06-07
Posts: 393

Re: Swap with USB device Problem

I tried that. Via fstab still nothing when I reboot but at least using "swapon -L myswap" works and now I see it in "free -m"

Thank you.

Offline

#6 2011-12-27 01:50:41

TastyDr.Pepper
Member
From: Somewhere, in the US
Registered: 2011-11-23
Posts: 20

Re: Swap with USB device Problem

CaptainKirk wrote:

I tried that. Via fstab still nothing when I reboot but at least using "swapon -L myswap" works and now I see it in "free -m"

Thank you.

I feel stupid for this, here's what you need to put in your fstab:

LABEL=YOUR_LABEL   swap  swap defaults 0 0

and NOT

YOUR_LABEL   swap  swap defaults 0 0

Try that and see if that works.

Offline

#7 2011-12-27 09:58:15

CaptainKirk
Member
Registered: 2009-06-07
Posts: 393

Re: Swap with USB device Problem

Thanks for the post. I did it and rebooted, but it didn't work. My guess is that it may be that the USB connect module (whatever that is) turns on after fstab runs. Or maybe has to do with permissions to the USB device?

See this:

[kirk@arch ~]$ cat /etc/fstab
# 
# /etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
#devpts                 /dev/pts      devpts    defaults            0      0
#shm                    /dev/shm      tmpfs     nodev,nosuid        0      0

tmpfs                   /tmp          tmpfs     nodev,nosuid        0      0


#UUID=121b8ba5-48b2-4083-ac6b-ae1386ebd600 /boot ext3 defaults 0 1
#UUID=923771e6-7ea1-4bc5-815c-a8c78bcfa1f6 /     ext3 defaults 0 1
#UUID=e0f83332-f764-400b-9052-58a3ea83aafd /home ext3 defaults 0 1
#UUID=dafb368a-0c80-40ca-aca8-208ca48a941b swap  swap defaults 0 0 
/dev/sda1 /boot ext3 defaults 0 1
/dev/sda2 / ext3 defaults 0 1
/dev/sda3 /home ext3 defaults 0 1
#/dev/sda4 swap swap defaults 0 0
LABEL=myswap swap swap defaults 0 0
#/dev/sdb1 none swap defaults 0 0
[kirk@arch ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          3271       1735       1535          0         27        578
-/+ buffers/cache:       1129       2141
Swap:            0          0          0
[kirk@arch ~]$ swapon -L myswap
swapon: /dev/sdb1: open failed: Permission denied
[kirk@arch ~]$ sudo swapon -L myswap
Password: 
[kirk@arch ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          3271       1726       1544          0         27        578
-/+ buffers/cache:       1120       2151
Swap:         4999          0       4999

Offline

#8 2011-12-27 16:46:31

TastyDr.Pepper
Member
From: Somewhere, in the US
Registered: 2011-11-23
Posts: 20

Re: Swap with USB device Problem

Add usb to your HOOKS line in /etc/mkinitcpio.conf

and then run:

mkinitcpio -p linux

Reboot and see if that fixes it.

EDIT:
If editing your mkinitcpio and rebuilding the ramdisk didn't do it for you, you can always add:

swapon -L mylabel

to your rc.local file, it's kind of hackish and I wouldn't recomend it, but it will probably work.

Last edited by TastyDr.Pepper (2012-01-01 17:56:14)

Offline

#9 2012-01-07 20:33:42

CaptainKirk
Member
Registered: 2009-06-07
Posts: 393

Re: Swap with USB device Problem

I think this failure to setup swap on boot has to do with error messages like

[sdb] No Caching mode page present
[sdb] Assuming drive cache: write through

Same as https://bbs.archlinux.org/viewtopic.php?id=129259 and https://bbs.archlinux.org/viewtopic.php?id=131891

Not sure though, because that second post says they're just warnings and not a true error.

Offline

#10 2012-01-07 22:05:07

thetrivialstuff
Member
Registered: 2006-05-10
Posts: 191

Re: Swap with USB device Problem

CaptainKirk wrote:

I think this failure to setup swap on boot has to do with error messages like

[sdb] No Caching mode page present
[sdb] Assuming drive cache: write through

[...]

Not sure though, because that second post says they're just warnings and not a true error.

As far as I know that's correct -- these two messages show up for every flash drive I've ever used, and I've been able to boot, swap, do all kinds of things off them without trouble. So I doubt this is your problem.

I think the order of the hooks, and having 'usb' present as one of them in mkinitcpio.conf is the most likely culprit -- make sure 'usb' comes as early as it needs to. I would recommend putting it next to whichever hook brings up your main drives; e.g.:

HOOKS="base udev autodetect pata sata usb filesystems"

and not

#probably won't work, because filesystems will attempt to mount & swapon before USB is ready
HOOKS="base udev autodetect pata sata filesystems usb"

But I'm not sure that swap even needs to come up that early, since isn't there an "Activating Swap..." message during the blue & white messages part of the boot sequence?

Anyway, failing all else, if you say that "swapon -L myswap" works when you do it manually, stick that command in /etc/rc.local -- it'll run late enough in the boot process that it should always work.

...But why exactly are you wanting to swap off a USB disk anyway? USB is pretty performance-limited, unless you've got USB 3. That wiki article's list of advantages is a little sketchy, in my opinion:

access time is lower than traditional HD

Definitely true for "real" SSD's, but usually not for USB flash drives. Most cheaper flash chips actually have slower than HD read/write performance; high-performance SSD's achieve that by being massively interleaved so that a read or write is parallel over many chips (like RAID-0 for flash). Cheap flash drives don't do that, and often their controller is so cheap that even seek time is slower than a spinning HD (try it sometime -- take a directory of many tiny files and try to randomly read them. It'll go faster on the HD.).

avoid power on HD when is in stand-by

Um, what? Hard drives are always turned off in standby. They're a persistent storage device, so they don't need power to maintain what was written to them. *RAM* needs to stay on and be refreshed, but that's going to be true no matter what you use for swap. If your laptop isn't spinning down the hard drive when you're in sleep mode, there's something wrong with your power management software/firmware and it's not actually making it into sleep mode.

USB pendrives are cheaper than HD (meaning: you can't get a $5 HDD, price per gigabyte is obviously much higher for flash drives)

True you can't get a $5 HDD, but you're much better off putting your user data (pictures, documents, music, etc.) on that $5 flash drive than your swap. If you're out of space and need to free up 2 gigs for more swap space, buy the $5 flash drive, move 2 GB of your stuff onto it, then put your swap partition on the hard drive. It'll be way faster.

~Felix.

Offline

Board footer

Powered by FluxBB