but, I would like to make it automatic by creating an udev rule, so when I plug in that device the swap space is automatically activated and the priority is changed. I've tried to google for a solution like this, but I did not find. Maybe you already have some script at hand can you please share this with me?
Thanks
Laszlo
07-01-2010, 02:05 PM
Nils Larsson
activating swap by udev event
tor 2010-07-01 klockan 15:49 +0200 skrev SpaceCake:
> Hi,
>
>
> I would like to increase the speed of my machine by putting some swap
> on a fast pendrive. It is working manually by starting a script
>
> swapon -s
> swapon -p -1 /dev/sdb1
> swapoff /dev/sda6
> swapon -p -2 /dev/sda6
> swapon -s
>
> but, I would like to make it automatic by creating an udev rule, so
> when I plug in that device the swap space is automatically activated
> and the priority is changed. I've tried to google for a solution like
> this, but I did not find. Maybe you already have some script at
> hand can you please share this with me?
>
> Thanks
> Laszlo
>
I tried doing something like this awhile ago. The problem I encountered
was that I couldn't disable the swap once the the device was removed,
swapoff couldn't find the device path(as it wasn't there anymore) but
the system thought the swap was still there. So plugging and unplugging
the swap stick got my system thinking it had loads of swap.
But I didn't experiment all that much, maybe there's a way. Tricking
udev to hold on to the device node until swap is disabled might be
possible.
07-01-2010, 02:16 PM
Neil Bothwick
activating swap by udev event
On Thu, 1 Jul 2010 15:49:08 +0200, SpaceCake wrote:
> I would like to increase the speed of my machine by putting some swap
> on a fast pendrive. It is working manually by starting a script
>
> swapon -s
> swapon -p -1 /dev/sdb1
> swapoff /dev/sda6
> swapon -p -2 /dev/sda6
> swapon -s
>
> but, I would like to make it automatic by creating an udev rule, so
> when I plug in that device the swap space is automatically activated
> and the priority is changed.
Create the udev rule in the usual way and add
RUN="/path/to/your/script"
You must use a full path when running a program from a udev rule and the
program should exit quickly as udev blocks while it is running.
--
Neil Bothwick
What colour is a chameleon on a mirror?
07-01-2010, 03:17 PM
SpaceCake
activating swap by udev event
I've never created udev rule so the usal way does not tell me too much I've checked the net for examples but it looks like very complicated for me
My usb stick looks like this
Bus 007 Device 015: ID 058f:6387 Alcor Micro Corp. Transcend JetFlash Flash Drive
Can you share with me some example how can I use this info on udev rules?
Thanks
Laszlo
2010/7/1 Neil Bothwick <neil@digimed.co.uk>
On Thu, 1 Jul 2010 15:49:08 +0200, SpaceCake wrote:
> I would like to increase the speed of my machine by putting some swap
> on a fast pendrive. It is working manually by starting a script
>
> swapon -s
> swapon -p -1 /dev/sdb1
> swapoff /dev/sda6
> swapon -p -2 /dev/sda6
> swapon -s
>
> but, I would like to make it automatic by creating an udev rule, so
> when I plug in that device the swap space is automatically activated
> and the priority is changed.
Create the udev rule in the usual way and add
RUN="/path/to/your/script"
You must use a full path when running a program from a udev rule and the
program should exit quickly as udev blocks while it is running.
--
Neil Bothwick
What colour is a chameleon on a mirror?
07-01-2010, 03:26 PM
Neil Bothwick
activating swap by udev event
On Thu, 1 Jul 2010 17:17:15 +0200, SpaceCake wrote:
> I've never created udev rule so the usal way does not tell me too
> much I've checked the net for examples but it looks like very
> complicated for me
> My usb stick looks like this
>
> Bus 007 Device 015: ID 058f:6387 Alcor Micro Corp. Transcend JetFlash
> Flash Drive
>
> Can you share with me some example how can I use this info on udev
> rules?
Like an atheist in a grave: all dressed up and no place to go.
07-01-2010, 03:44 PM
SpaceCake
activating swap by udev event
So, it solves the first problem, identifiying the device, but how can I tell to udev to use always /dev/sds (for example) for this device? Also I'm thinking how can I instruct udev to turn off swap when the device is removed, but this is another story
Thanks
L:
2010/7/1 Neil Bothwick <neil@digimed.co.uk>
On Thu, 1 Jul 2010 17:17:15 +0200, SpaceCake wrote:
> I've never created udev rule so the usal way does not tell me too
> much I've checked the net for examples but it looks like very
Like an atheist in a grave: all dressed up and no place to go.
07-01-2010, 03:49 PM
Bill Longman
activating swap by udev event
On 07/01/2010 08:44 AM, SpaceCake wrote:
> So, it solves the first problem, identifiying the device, but how can I
> tell to udev to use always /dev/sds (for example) for this device? Also
> I'm thinking how can I instruct udev to turn off swap when the device is
> removed, but this is another story
Here's what I have in my /etc/fstab file for one of my USB keys. I
assume you could just change it to say swap instead.
that's good if I want to mount at a specific location, but for swap I need the device name, but this is changes depending on how many other usb drives are connected. Looks lik this is a tricky question*
L:
2010/7/1 Bill Longman <bill.longman@gmail.com>
On 07/01/2010 08:44 AM, SpaceCake wrote:
> So, it solves the first problem, identifiying the device, but how can I
> tell to udev to use always /dev/sds (for example) for this device? Also
> I'm thinking how can I instruct udev to turn off swap when the device is
> removed, but this is another story
Here's what I have in my /etc/fstab file for one of my USB keys. I
assume you could just change it to say swap instead.
UUID=BA62-89BD /mnt/key auto noauto,user,exec,nosuid 0 0
07-01-2010, 04:05 PM
Alex Schuster
activating swap by udev event
SpaceCake writes:
> So, it solves the first problem, identifiying the device, but how can I
> tell to udev to use always /dev/sds (for example) for this device?
I think, you can's. But you can add SYMLINK="swap" to make the device
appear as /dev/swap, too.
> Also I'm thinking how can I instruct udev to turn off swap when the
> device is removed, but this is another story
I doubt this is possible at all. If you unplug it, the memory that has
been swapped there is lost.
Wonko
07-01-2010, 04:06 PM
Nils Larsson
activating swap by udev event
tor 2010-07-01 klockan 08:49 -0700 skrev Bill Longman:
> On 07/01/2010 08:44 AM, SpaceCake wrote:
> > So, it solves the first problem, identifiying the device, but how can I
> > tell to udev to use always /dev/sds (for example) for this device?
You need to have the udev rule or the script that it runs look at
something specific(the swaplabel for instance).
> > I'm thinking how can I instruct udev to turn off swap when the device is
> > removed, but this is another story
I tried doing exactly what you're doing now awhile ago and this is where
I got stuck, swapoff needs the deivce node(path) to still exist, it
can't disable swap without it. I could never get swapoff to run before
udev removed the device node, so I ended up with the system thinking(or
at least reporting) that it had loads more swap than it actually did.