Results 1 to 4 of 4
This is a simple guide to setting up your computer with solid state swap devices, a much faster method of memory management(i.e. your computer runs lots faster during paging operations).
...
- 09-08-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 8
How To setup a Diskless Swap System.
This is a simple guide to setting up your computer with solid state swap devices, a much faster method of memory management(i.e. your computer runs lots faster during paging operations).
Hardware Requirements
A) Minimum 4 USB2.0 memory storage devices of identical make and model of at lest 512MB in size. (I can get a 2G stick down the street for less then 10$)
B) A motherboard with USB2.0 ports properly configured in BIOS. (A hub should be alright but I have not tested for that... yet)
Procedure
1.) Open a text file with gedit for recording device information.
2.) Open a Terminal(Applications->Accessories->Terminal) and enter
3.) Now insert the usb device and you should see something like the followingCode:tail -f /var/log/messages
Here we see my device has been named sde, yours will probably be different (i.e. sda or sdc).Aug 6 11:53:37 kernel: [ 2059.400832] scsi9 : SCSI emulation for USB Mass Storage devices
Aug 6 11:53:42 kernel: [ 2064.404667] scsi 9:0:0:0: Direct-Access Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 0 CCS
Aug 6 11:53:43 kernel: [ 2064.973349] sd 9:0:0:0: [sde] 1953792 512-byte hardware sectors (1000 MB)
Aug 6 11:53:43 kernel: [ 2064.973970] sd 9:0:0:0: [sde] Write Protect is off
Aug 6 11:53:43 kernel: [ 2064.976592] sd 9:0:0:0: [sde] 1953792 512-byte hardware sectors (1000 MB)
Aug 6 11:53:43 kernel: [ 2064.977218] sd 9:0:0:0: [sde] Write Protect is off
Aug 6 11:53:43 kernel: [ 2064.977226] sde: sde1
Aug 6 11:53:43 kernel: [ 2064.978024] sd 9:0:0:0: [sde] Attached SCSI removable disk
Aug 6 11:53:43 kernel: [ 2064.978060] sd 9:0:0:0: Attached scsi generic sg5 type 0
4.) Record the device name.
5.) (If you have a brand new device, never used, then you can skip this step) An icon should have appeared on your desktop pointing to your newly inserted usb device. Open the icon, check for data files and back them up because we are going to erase all the data.
6.) Right click the desktop icon pointing to your device and choose 'unmount volume'.
7.) Open another Terminal and type
Change the xxx to the device name you recorded. The output will look something like this:Code:udevinfo -a -p `udevinfo -q path -n /dev/xxx`
Find the section that looks something like this:Code:Udevinfo starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/block/sde': KERNEL=="sde" SUBSYSTEM=="block" DRIVER=="" ATTR{dev}=="8:64" ATTR{range}=="16" ATTR{removable}=="1" ATTR{size}=="1953792" ATTR{stat}==" 147 80 2162 428 5 4 72 808 0 768 1236" ATTR{capability}=="13" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6/5-6:1.0/host9/target9:0:0/9:0:0:0': KERNELS=="9:0:0:0" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{type}=="0" ATTRS{scsi_level}=="0" ATTRS{vendor}=="Kingston" ATTRS{model}=="DataTraveler 2.0" ATTRS{rev}=="PMAP" ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{iocounterbits}=="32" ATTRS{iorequest_cnt}=="0x3d4" ATTRS{iodone_cnt}=="0x3d4" ATTRS{ioerr_cnt}=="0x2" ATTRS{modalias}=="scsi:t-0x00" ATTRS{evt_media_change}=="0" ATTRS{queue_depth}=="1" ATTRS{queue_type}=="none" ATTRS{max_sectors}=="240" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6/5-6:1.0/host9/target9:0:0': KERNELS=="target9:0:0" SUBSYSTEMS=="" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6/5-6:1.0/host9': KERNELS=="host9" SUBSYSTEMS=="" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6/5-6:1.0': KERNELS=="5-6:1.0" SUBSYSTEMS=="usb" DRIVERS=="usb-storage" ATTRS{bInterfaceNumber}=="00" ATTRS{bAlternateSetting}==" 0" ATTRS{bNumEndpoints}=="02" ATTRS{bInterfaceClass}=="08" ATTRS{bInterfaceSubClass}=="06" ATTRS{bInterfaceProtocol}=="50" ATTRS{modalias}=="usb:v0951p1608d0100dc00dsc00dp00ic08isc06ip50" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6': KERNELS=="5-6" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{dev}=="189:519" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="80" ATTRS{bMaxPower}=="200mA" ATTRS{urbnum}=="2225" ATTRS{idVendor}=="0951" ATTRS{idProduct}=="1608" ATTRS{bcdDevice}=="0100" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="5" ATTRS{devnum}=="8" ATTRS{version}==" 2.00" ATTRS{maxchild}=="0" ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Kingston" ATTRS{product}=="DataTraveler 2.0" ATTRS{serial}=="5B790F860008" looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5': KERNELS=="usb5" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{dev}=="189:512" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bMaxPower}==" 0mA" ATTRS{urbnum}=="122" ATTRS{idVendor}=="0000" ATTRS{idProduct}=="0000" ATTRS{bcdDevice}=="0206" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="01" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="5" ATTRS{devnum}=="1" ATTRS{version}==" 2.00" ATTRS{maxchild}=="8" ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Linux 2.6.24-19-generic ehci_hcd" ATTRS{product}=="EHCI Host Controller" ATTRS{serial}=="0000:00:10.4" ATTRS{authorized_default}=="1" looking at parent device '/devices/pci0000:00/0000:00:10.4': KERNELS=="0000:00:10.4" SUBSYSTEMS=="pci" DRIVERS=="ehci_hcd" ATTRS{vendor}=="0x1106" ATTRS{device}=="0x3104" ATTRS{subsystem_vendor}=="0x1043" ATTRS{subsystem_device}=="0x80ed" ATTRS{class}=="0x0c0320" ATTRS{irq}=="21" ATTRS{local_cpus}=="01" ATTRS{modalias}=="pci:v00001106d00003104sv00001043sd000080EDbc0Csc03i20" ATTRS{numa_node}=="-1" ATTRS{broken_parity_status}=="0" ATTRS{msi_bus}=="" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS==""
and record the serial number (i.e. mine is 5B790F860008 ).looking at parent device '/devices/pci0000:00/0000:00:10.4/usb5/5-6':
KERNELS=="5-6"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{dev}=="189:519"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="80"
ATTRS{bMaxPower}=="200mA"
ATTRS{urbnum}=="2225"
ATTRS{idVendor}=="0951"
ATTRS{idProduct}=="1608"
ATTRS{bcdDevice}=="0100"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="5"
ATTRS{devnum}=="8"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="0"
ATTRS{quirks}=="0x0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Kingston"
ATTRS{product}=="DataTraveler 2.0"
ATTRS{serial}=="5B790F860008"
8.) Now to make the device a swap device. This step is for beginners, other users should just partition and format the device as linux-swap; then skip to the next section.
Enter the command9.) Repeat steps 3-8 for each device.To make things easier I will paste my console and you can mimic the answers replacing values where needed.Code:sudo parted /dev/xxx
notes: The End value comes from this line "Disk /dev/sde: 1000MB" and might be different for your device, depending on its size.
Watch out for hotplug, it might mount your drive while your working on the device; be sure to umount it before making a change in parted.
Code:tommy@thepark:~$ sudo parted /dev/sde GNU Parted 1.7.1 Using /dev/sde Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Disk /dev/sde: 1000MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 0.51kB 500MB 500MB primary ext2 2 500MB 1000MB 500MB extended lba (parted) rm 2 (parted) rm 1 (parted) print Disk /dev/sde: 1000MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags (parted) mkpartfs Partition type? primary/extended? primary File system type? [ext2]? linux-swap Start? 0 End? 1000MB (parted) print Disk /dev/sde: 1000MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 0.51kB 1000MB 1000MB primary linux-swap (parted) quit tommy@thepark:~$
10.) Create a persistent device node for each swap device we have using udev. This will allow kernel names to change but the swap system will stay the same. Open gedit like thisThen add the following lines but using your serial numbers:Code:sudo gedit /etc/udev/rules.d/10-local.rules
11.) save and exit.Code:SUBSYSTEM=="block", ATTRS{serial}=="46d2cef7d5a461", NAME="%k", SYMLINK+="SwpNodA", SUBSYSTEM=="block", ATTRS{serial}=="SNDKA96735075A203908", NAME="%k", SYMLINK+="SwpNodB" SUBSYSTEM=="block", ATTRS{serial}=="SNDKA940252CCCC05806", NAME="%k", SYMLINK+="SwpNodC" SUBSYSTEM=="block", ATTRS{serial}=="SNDKA96735037AA03903", NAME="%k", SYMLINK+="SwpNodD"
12.) Update fstab with gedit like this:
You should see a line something like this:Code:sudo gedit /etc/fstab
it is your current swap drive, comment it out with a '#' at the front. Underneath place the following lines:UUID=921f422a-5816-4040-97df-850e569c4687 none swap sw 0 0
13.) save and exit.Code:/dev/SwpNodA none swap sw,pri=0 0 0 /dev/SwpNodB none swap sw,pri=0 0 0 /dev/SwpNodC none swap sw,pri=0 0 0 /dev/SwpNodD none swap sw,pri=0 0 0
14.) Edit sysfs at boot for high volume data transfers.
For Ubuntu users open gedit like this:
find the lines that read:Code:sudo gedit /etc/init.d/bootmisc.sh
and add these lines where xxx is your device name (e.g. /sys/block/sdb/device/max_sectors)# Remove bootclean's flag files.
# Don't run bootclean again after this!
Warning: this depends on kernel names so if you change ports and a device is not in the list your timing will be off; resulting in an unstable system.Code:echo 1024 > /sys/block/xxx/device/max_sectors echo 1024 > /sys/block/xxx/device/max_sectors echo 1024 > /sys/block/xxx/device/max_sectors echo 1024 > /sys/block/xxx/device/max_sectors
If you are using a different distro then you will have to make a small startup script with those echo calls and place it in your startup folder (ie rc.S).
15.) Reboot and check your swap system withThis setup has been in the test phase for over a year. It has been stress tested with large video files, World of Warcraft and was also used during development of http://www.linuxforums.org/forum/lin...-lfs-bash.html. It should be noted that a number of bugs appeared during development of that script which produced some extremely abnormal operating environments and I lost a drive. The final version runs very well with this setup but I don't recommend using the script, it is linked only to document testing conditions.Code:swapon -s
Testing:
To replace the bootmisc.sh step but the max_sectors value doesn't change. If anyone knows why please let me know.Code:SUBSYSTEM=="block", ATTRS{serial}=="46d2cef7d5a461", NAME="%k", RUN+="/bin/echo 1024 > /sys/block/%k/device/max_sectors", SYMLINK+="SwpNodA", OPTIONS+="last_rule"
- 09-08-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
However:
1.- Note that flash based devices have a limited about of r/w cycles, after that, they just stop working. So, if you really need such a massive amount of swap, it's a sign that you should buy more ram. After some time, the cost of the dying flash devices will be greater than the cost of a similar amount of ram (and the performance will be much worse). A random link (first googled) that illustrates this:
What is the Life Cycle of a USB Flash Drive?
2.- USB limits the usefulness of this. The transfer rate of usb 2.0 can't compare to this of SATA drives in practice, or even the better regular ATA ones.
I don't pretend to disqualify this how-to. The method is for sure useful for you. However, I think that it's fair to warn the rest of users that this might kill their pen-drives if they use them for this purpose and there's high swap activity on their system.
- 09-09-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 8
Statistically speaking, hard drives fail far more often then USB sticks. Anyone running data, swap and root on only one device should expect a failure at some time. I have used the same 4 devices now for well over 2 years and under heavy conditions with only the one failure in a situation that most people should never encounter. But, that being said, the kernel has no fault tolerance towards a missing swap file so care should be taken none the less. The only solution that comes to mind would be a swap RAID, if practical.
The idea behind a swap file is fairly simple, memory that does not get used often gets put away somewhere close. It happens not only because of finite RAM but also because the developers expect it too, they don't use all the data, all the time and they can't predict what the users will do. Swapping is a logical process. But yes, you can go buy a board with TB capacity a few TB of RAM and go no swap, heck even go live Knoppix toram no swapSo, if you really need such a massive amount of swap, it's a sign that you should buy more ram.
. All this How-To does is move the swap from a mechanical device(i.e. a robotic arm that needs to physically move from data block to data block on a fragmented disk) to an electronic device with no moving parts, split the work across 4 devices and totally remove swapping off the hard drive bus. The difference has been noticeable.
Like I said, over 2 years of heavy use on drives that cost me $9.95. If I was spending a boat load cash to keep my system running I wouldn't post this.After some time, the cost of the dying flash devices will be greater than the cost of a similar amount of ram (and the performance will be much worse).
Google gives out random links? Do you mean the lucky button? There is only one link with that... When I first did this(a couple of years ago) I found this. Before, it said that the drives could handle millions of cycles, but it has been edited with a reference to an article with no facts, studies or data to back up the claim. Another edit has the transfer speed as false, with no reference or tests given. Your site has no factual studies either... At this point I can only recommend finding out for yourself, works best for me.A random link (first googled) that illustrates this:
The swap file is not like a regular file that gets read sequentially in an ideal situation as written on the box of hard drives. Again,2.- USB limits the usefulness of this. The transfer rate of usb 2.0 can't compare to this of SATA drives in practice, or even the better regular ATA ones.
the device is a memory chip, not a big fat disk with a big arm thrashing around looking for data. There are a number of technical aspects involved here that you are obviously not aware of.
I don't think you have never followed it or tested the setup.I don't pretend to disqualify this how-to.
I already did that... but thank you.However, I think that it's fair to warn the rest of users that this might kill their pen-drives if they use them for this purpose and there's high swap activity on their system.
- 09-09-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
"Random link" means just a random pick after googling. This is a known fact, not something I invented today. Maybe you was lucky with your flash devices, or maybe they haven't been touched at all because you had enough ram, I don't know. In any case, that's doesn't make the rule general.
NAND and NOR based flash devices divide the stuff into blocks, usually one entire block is written at once, and not just one byte, word or nibble, so, when one block reaches the end of its life period, it just dies. Most modern units can dynamically adapt themselves and recount the blocks when one of them dies, so the drive can stay alive and continue working (with less capacity usually). Some data loss is inevitable from time to time on these drives (not that you will notice that on a swap drive).
I am sure the situation has improved and the write cycles of SSD memories is much better nowadays, but:
1.- I don't know by how much
2.- People still have old devices around which might not endure that well
Also, this is internet, people all around the world read it. In your country a flash device might be damn cheap, but in some countries it's not that way. I was speaking with a man from Argentina some days ago, and flash devices around there can be worth around 50$ (or more depending on the size). Not a thing I'd like to break just to "speed up" my swap device.
Who spoke about TB's? I am sure that your 9$ device is not anywhere near that
You wrote a very complete how-to, and surely a lot of people will be grateful for it. But they have the right to know the dark side of the force as well. So, I let them know. I hope that informing people about possible risks is nothing that angers you. I didn't mean to upset anyone.


Reply With Quote

