How to create a VFAT swap file on hd, Puppy on USB drive?

Using applications, configuring, problems
Post Reply
Message
Author
shankargopal
Posts: 295
Joined: Sat 03 Dec 2005, 11:30

How to create a VFAT swap file on hd, Puppy on USB drive?

#1 Post by shankargopal »

Hi all

I use a Transcend JetFlash USB 256MB pen drive as my Puppy. I run it on several computers, all of which have either 128 or at most 224 MB of RAM (one has only 96 MB of RAM).

Unfortunately my computers never have enough physical RAM for Puppy to load the PUP100 file fully into RAM it seems (my pup100 is 196 MB in size), as it doesn't occur even on the 224 MB RAM computer. Or at least I assume so, as the USB stick remains mounted and can't be unmounted.

On the 1.0.6 multisession CD, there is a neat gimmick in the init-ORIG script to automatically create a swap file on the first partition if it is a VFAT partition. This then increases the memory size by 400 M and allows multisession to run even on 128 M computers. Can I simply copy this chunk of code into the init script on the stick, and, if I do so, will my Puppy load into RAM and save the USB drive?

Or will this be a big risk? Just wanted to ask.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

Yeah, you could copy the code & it'd probably work, if in doubt... post the code chunk here so we can look at it for you.
To make a vfat swap file, I used:

mkswap /(path)/puppy.swp"
sync

I assume you want to make the swap file on a "local" hard drive & maybe delete it on shutdown.
To make it on a USB drive is a bad idea as it will "wear" the drive out repetedly writing to it.

shankargopal
Posts: 295
Joined: Sat 03 Dec 2005, 11:30

#3 Post by shankargopal »

Sounds good, here it is. What makes me suspicious is that barry has deliberately restricted it to work when PFILE=cd - is this as part of the general principle of not tampering with existing systems except when necessary, or is there a problem with doing it on non-live CD systems?

Code: Select all

 #v1.0.6 for multi-session live-cd, also look for a swap file on /dev/hda1...
if [ "$PFILE" = "cd" ];then
 if [ "$SWAPINFO" = "" ];then
  HDA1FSTYPE="`disktype /dev/hda1 2>/dev/null | grep "file system" | head -n 1 | cut -f 1 -d " "`"
  if [ "$HDA1FSTYPE" = "NTFS" ];then
   #mount -t ntfs /dev/hda1 /mnt/swap
   mount -r -t ntfs /dev/hda1 /mnt/swap
   if [ $? -eq 0 ];then
    #i was going to use pagefile.sys as it already exists, but backing off from that...
    if [ -f /mnt/swap/pupx.swp ];then
     #echo 'Setting up Windows c:\pagefile.sys swap file for use by Puppy...'
     #mkswap /mnt/swap/pagefile.sys
     SWAPPART="/mnt/swap/pupx.swp,ntfs"
     SWAPSIZE="`du -k /mnt/swap/pupx.swp | cut -f 1`"
     SWAPSIZ4=`expr $SWAPSIZE \/ 4`
     SWAPSIZ2=`expr $SWAPSIZE \/ 2`
     SWAPSIZE=`expr $SWAPSIZ2 + $SWAPSIZ4` #3/4 of original
     SIZEFILLK=`expr $SIZEFILLK + $SWAPSIZE`
    fi
    sync
    umount /mnt/swap
   fi
  else
   if [ ! "`echo "$HDA1FSTYPE" | grep -i "fat"`" = "" ];then
    mount -t vfat /dev/hda1 /mnt/swap
    if [ $? -eq 0 ];then
     echo 'Using c:\pupx.swp swap file...'
     if [ ! -f /mnt/swap/pupx.swp ];then
      SWAPSIZE=`df | grep "/mnt/swap" | tr -s " " | cut -f 4 -d " "` #free space
      if [ $SWAPSIZE -lt 400000 ];then
       SWAPSIZ4=`expr $SWAPSIZE \/ 4`
       SWAPSIZ2=`expr $SWAPSIZE \/ 2`
       SWAPSIZE=`expr $SWAPSIZ2 + $SWAPSIZ4`
      else
       SWAPSIZE=400000
      fi
      dd if=/dev/zero of=/mnt/swap/pupx.swp bs=1024 count=$SWAPSIZE #400000000
      sync
      mkswap /mnt/swap/pupx.swp
     fi
     SWAPPART="/mnt/swap/pupx.swp,vfat"
     SWAPSIZE="`du -k /mnt/swap/pupx.swp | cut -f 1`"
     SWAPSIZ4=`expr $SWAPSIZE \/ 4`
     SWAPSIZ2=`expr $SWAPSIZE \/ 2`
     SWAPSIZE=`expr $SWAPSIZ2 + $SWAPSIZ4` #3/4 of original
     SIZEFILLK=`expr $SIZEFILLK + $SWAPSIZE`
     sync
     umount /mnt/swap
    fi
   fi
  fi
 fi
fi
[/code]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#4 Post by sunburnt »

If you just want to use a 400MB swap file every the time,
it looks like tthe file's made with the command: dd,
and then made into a swap file with the command: mkswap.
A problem, I don't think you can just edit /sbin/init, you may have to modify the image.gz file.
But you can probably put the commands into the rc.local file by just editing it, in which case I think using /mnt/home for the swap file would be good as its already mounted anyway.

dd if=/dev/zero of=/mnt/home/pupx.swp bs=1024 count=400000
sync
mkswap /mnt/home/pupx.swp

Puppy has to be told to use the swap file with the command: swapon /mnt/home/pupx.swp
Or if you don't delete the swap file then you could mount it in the fstab file.
If you remove the swap file after each use, then you'll have to repete the above steps each bootup.

I wish MU, TedDog, or someone else would chime in here & add their say so.

shankargopal
Posts: 295
Joined: Sat 03 Dec 2005, 11:30

#5 Post by shankargopal »

The only issue with this is that I haven't done enough spelunking in the scripts yet to figure out the point where Puppy decides whether or not to load the PUP100 file into RAM. The swapping has to happen before that, if it is to achieve the purpose (which is to extend the life of my USB drive). Otherwise I have already used this code in rc.local to turn on swap, but that seems too late in the process.

As for changing init, it seems easy enough (though I've not tried it) - just gunzip image.gz, mount it as a filesystem, edit the file, unmount it and gzip it again. That's worked for me when editing rc.sysinit.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#6 Post by sunburnt »

pupxxx is mounted in: /etc/rc.d/rc.sysinit, which runs after: /sbin/init
It's searched for & the partition it's found on is mounted as: /mnt/home

OR... after you mount the swap file in: /etc/rc.d/rc.local, just put code to remount pup100 how you want it.

Post Reply