Four scripts to create, fill, check and back-up /mnt/ram1

Filemanagers, partitioning tools, etc.
Post Reply
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

Four scripts to create, fill, check and back-up /mnt/ram1

#1 Post by musher0 »

On trouvera la version française de ce fil ici.
~~~~~~~~~~~~~~
Hello all.

Nothing beats a ramdisk for speedy copy and save operations, even in this
age of fast hard disks and USB drives.

As the name of the archive suggests, the creation script takes 2/3 of your
free RAM and creates a ramdisk out of it. "2/3 of free RAM" means that
your apps should still have lots of room to run after /mnt/ram1 is created.

Edit 11 Dec. 2018 --
Actually this has been reduced to 11/20ths, to avoid any snafus. Please
use the main script below. Do download this package, but please replace
the RAMdisk creating script with the one below.
Thanks.
-- End of edit


It is strongly recommended that YOU DO NOT USE THESE SCRIPTS
if you have less than 3 Gb's of RAM on your machine.
Use
Pizza'sGood original script instead (URL below). Are we clear about this?

The attached pet archive includes 4 ramdisk bash scripts to
create,
fill,
check and
back-up /mnt/ram1.

The creation and filling at boot-up, and the back-up at shutdown are
automatic. The checking is up to you (but you don't normally need to).

The back-up script is located in /etc/init.d. It uses a shut-down technique
developed by BarryK, as I understand it. It copies (aka back-up) the
contents of an active ramdisk at /mnt/ram1 to /mnt/home/ramdisk.

Conversely, at boot-up, if there is some content in /mnt/home/ramdisk,
the zzz-ramdisk script in /root/Startup creates /mnt/ram1 and copies that
content there.

The Start-up filler script checks the size of the contents vs the capacity of
the ramdisk. If the contents' overall size is too big to fit on the ramdisk,
nothing is copied. In such a case you will have to choose what to copy to
your ramdisk manually. But normally you don't have to do this.

Reserve directory /mnt/home/ramdisk only to the shuttle with /mnt/ram1.
Don't put anything else in it.


Basically, I made it to run so that you, the user, don't have to worry
about it. The ramdisk's content is saved at boot-down and re-copied at
boot-up.

If for some reason, you need to recycle X or your window manager, it
just displays a 5-seconds message that the ramdisk is there; it doesn't
reformat or destroy anything in an existing ramdisk during your session.

Please note that hard shut-downs are not protected, meaning: if you
ever need to do an emergency shut-down with your computer's reset
button, your ramdisk contents will be lost.


But with regular power-offs and re-boots, you should find the contents of
your ramdisk in /mnt/ram1 from one session to the next.

Inspired by Pizza's Good original script and a discussion with Smithy
on that thread. Thanks to both of them.

I tested it extensively, and I decided to make it a permanent feature of
my current and future Pups -- because it's so handy. But please test it too
and get back to me if it needs improvements. I'll try to accommodate.

Enjoy.
~~~~~~~~~~
PS. The tree of the pet archive is as follows:
[4.0K] ./etc
[4.0K] ./etc/init.d
[ 431] ./etc/init.d/stop_ramdisk-0.1
[4.0K] ./opt
[4.0K] ./opt/local
[4.0K] ./opt/local/bin
[1.6K] ./opt/local/bin/ramdisk_2thirds.sh
[ 834] ./opt/local/bin/ramdisk_check.sh
[ 610] ./opt/local/bin/ramdisk_cp.sh
[ 158] ./pet.specs
[4.0K] ./root
[4.0K] ./root/Startup
[ 33] ./root/Startup/zzz_ramdisk.sh -> /opt/local/bin/ramdisk_2thirds.sh
7 directories, 6 files
Attachments
RamDisk_2thirds-0.1.pet
(2.9 KiB) Downloaded 459 times
Last edited by musher0 on Tue 11 Dec 2018, 21:56, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Hi, all.

No replies, but 109 downloads! Many thanks.

I'm here this afternoon to present a variation of the above:
this script you put in /root/my-applications/bin, /opt/local/bin or
/usr/local/bin. Then make a symlink of it in /root/Startup.

This script creates, on startup, a ramdisk 55% the size of the RAM that's
left after the pup has loaded. Only kicks in if you have more than 2G of
RAM.

Please do not play with that 55%, aka < int(($4/20)*11) >, in the awk
command on line 15. I tested and re-tested various percentages, and I
believe this 55% to be optimal. If you don't believe me, expect a freeze,
or the zram utility occupying all the pupsave, making it kaput (that's
really no fun and a tough one to get out of). In short, fiddle with this
figure and you're on your own.

A RAMdisk is very handy to speed up downloads, store temporary files,
even compile source code. RAM is reputedly 120 x faster than a solid
state HD, so... if you're looking for speed, this is it.

Remember to make periodical back-ups on a thumb-drive or a HD.
Otherwise, upon shutdown, bye-bye forever to that hard-won compilation
or that beautiful collection of family pictures.

However, no worries on soft reboot, the ramdisk stays put on soft reboot,
i.e. on reboot of X, or change of WM. It will tell you, too.

~~~~~~~~

As I said, I have tested and retested it, and this is revision 3a. But still
feel free to report any bug you encounter below. I'll try to provide an
answer.

TWYL.

Code: Select all

#!/bin/bash
# start_dv-zram-3a.sh # Copie de /opt/local/bin/DV-zram-3a.sh
# Créer un disque virtuel de type zram, par "Mute Ant".
# Source : https://forums.linuxmint.com/viewtopic.php?t=203420
# Relevé le 2017/10/24 à 04:30 par musher0
# (c) musher0 for original lines. Rév. : 26 oct. et 1er nov. 2017; 10 déc. 2018.
####
MEVTotal="`free -m | awk '$1 ~ /Mem/ { print $2 }'`"
if [ "$MEVTotal" -gt "1999" ];then
# To avoid headaches, if the computer has less than 2Gb of RAM, we pass. /
# Pour éviter les maux de tête, si l'ordi a moins de 2 Go de MEV, on passe.
     ChecK="`df | awk '$NF ~ /ram1/'`" # musher0, 17-10-14
     if [ "$ChecK" = "" ];then # musher0, 17-10-14
          MOUNTPOINT="/mnt/ram1"
          SIZE="`free -m | awk '/Mem/ {print int(($4/20)*11) }'`" # musher0, 18-12-10
          mkdir -p "$MOUNTPOINT" # s'assurer que le point de montage existe
          sleep 0.1s
          modprobe zram  # Tell the kernel to create device zram0
          sleep 0.1s
          echo 1 > /sys/block/zram0/reset # Réinitialiser # Playing it safe.
          sleep 0.1s
          echo "${SIZE}"m > /sys/block/zram0/disksize  # Set the size of zram0 ...
          sleep 0.1s
          mkfs.ext2 /dev/zram0  # Format the new device as ext2
#    mkudffs --media-type=hd --blocksize=512 /dev/zram # non
          sleep 0.1s
          mount /dev/zram0 /mnt/ram1 # Ramdisk  # Mount the new device on Ramdisk
#    mount -t udf -o bs=512 /dev/zram0 /mnt/ram1 # mount-point
          sleep 0.1s
          chmod 1777 /mnt/ram1 # Ramdisk  # Change Ramdisk flags to be like a /tmp/ folder
          sleep 0.1s
          mkdir -p /mnt/ram1/Downloads # Make a Downloads folder in Ramdisk
          sleep 0.1s

          cd /mnt/home/ramdisk
          rsync -qavz . "/mnt/ram1" # --delete # optionnel

          sleep 0.5s # Cette section par musher0, 17-10-14, 17-10-26
          case "${LANG:0:2}" in fr) MsG="

Un disque virtuel de
$SIZE Mo a été créé." ;;
               en|*) MsG="

A $SIZE Mb ramdisk
has been created." ;;
          esac
          bcm -u /mnt/ram1/gnome-dev-memory.png -a 1 -g c:c -d 5 -b "#000000FF" -c "#0c0c0c8F" -t "<span font='LiberationSerif Bold Italic 18' color='#FFFFFFFF' gravity='north' gravity_hint='line'>$MsG</span>" 2>/dev/null &

     else
          case "${LANG:0:2}" in fr) MsG="

Un disque virtuel
existe déja." ;;
               en|*) MsG="

A ramdisk
already exists." ;;
          esac
          bcm -u /mnt/ram1/gnome-dev-memory.png -a 1 -g c:c -d 5 -b "#000000FF" -c "#0c0c0c8F" -t "<span font='LiberationSerif Bold Italic 18' color='#FFFFFFFF' gravity='north' gravity_hint='line'>$MsG</span>" 2>/dev/null &
     fi # Fin de la section par musher0, 17-10-14, rév. 17-10-26
fi
Final note --
If you don't have the Liberation font, it will show the message in an ugly
default font. So go get it at:
https://www.fontsquirrel.com/fonts/down ... tion-serif
:)

Besides, this Liberation font is an important landmark in Linux history: it
was the first font to free us from servitude to WhineDose fonts. Every
Linuxian should have it.

Enjoy!
Attachments
DV-zram-3a.sh.zip
Same as above, in zip form. Unzip in a &quot;bin&quot; directory in your path and
make executable before using.
(1.34 KiB) Downloaded 293 times
Last edited by musher0 on Wed 12 Dec 2018, 02:59, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
perdido
Posts: 1528
Joined: Mon 09 Dec 2013, 16:29
Location: ¿Altair IV , Just north of Eeyore Junction.?

#3 Post by perdido »

I prefer deciding what size ram disk I want, no hard coding that is necessary or over-complicating a simple ram disk like pizzasgood made
http://www.murga-linux.com/puppy/viewtopic.php?t=74663
HaHa just kidding


Pizzasgood is only 500 bytes for a GUI that lets you mount/unmount the disk and recover memory. Like it should be.

pizzasgood 1128 downloads and simple one file script, the one I use
Just my 2 cents

.
Attachments
pizza-is-good ram disk(1).jpg
Then unmount if you are done no system crash
(16.44 KiB) Downloaded 398 times
pizza-is-good ram disk.jpg
pizzasgood simple chooser for your wanted size of ram disk
(11.71 KiB) Downloaded 402 times

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Hey, perdido!

However, pizzagood's experiment does not use the zram code. He's using
tmpfs to structure his RAMdisk. Which means his RAMdisk is not elastic.

The zram technique starts zipping the contents of the ramdisk when it
starts getting full. Which means a zram-type RAMdisk can store almost
two times (or thereabouts) as much stuff as a regular RAMdisk of same
size can.

In plain text, that means that a 1.5G zram-type RAMdisk will probably be
able to store up to 2.99G of stuff, whereas the regular-type RAMdisk will
choke at 1.49G.

(I said "probably" because the z-ram zipping depends largely on the file.
If there's a zip file stored in a zram-type RAMdisk, zram won't be able to
compress it more than it is already compressed. That said, zram will
probably do wonders compressing a 1M text file -- down to 100K?)

Also, IMO, too small a RAMdisk can't help the user much: it's better to
create something consistent.

BTW, pizzasgood script unpacked is 1036 bytes, not 551!
Another thing: his script won't tell you if you're creating too big a RAMdisk
for the RAM that's available. Mine won't let you unless you fiddle with the
code -- and then: good luck!

Finally, pizzasgood has been a great contributor to puppy. But is he here
now to update his stuff? Somebody has to do it! :twisted:

So there you go. Anyway -- to each his/her own.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#5 Post by musher0 »

Hello.

Here are a few more remarks about zram-type ramdisks, grappled here
and there, that may turn off some question marks blinking overhead.
Note:
There is little point creating a zram of greater than twice the size of
memory since we expect a 2:1 compression ratio. Note that zram uses
about 0.1% of the size of the disk when not in use so a huge zram is
wasteful.
Source

~~~~~~~~~

Q. -- Someone asked me yesterday by PM why use this script since
Puppy loads entirely in RAM.

A. -- The answer is that a Puppy loaded in RAM does not use all the RAM.
Even on a PC that has 1G of RAM.

The Puppy sfs unzips in RAM to approx. 3.3 times its size. E.g. if the
Puppy sfs is 235M big, in RAM, it will occupy alittle over 775M. If you
have 4G of RAM, that leaves 3.25G of RAM unused.
(Example edited, Dec. 12 2018, 19 h 40)

My reasoning is that we might as well use that remaining RAM for a
zram-type RAMdisk, given the advantages it offers in speed and
compression of data.

Of course you have to leave some room in RAM for the various execs
that you use. Which is why my script uses 55% fo what's left after
Puppy has loaded. I.e., the number in the 4th column when you type
< free -m >, NOT the number in the 2nd column, which indicates the
total amount of RAM in your system.

Code: Select all

free -m
       total       used       free     shared    buffers     cached
Mem:    3915       2252       1663          5        193       1287
(...)
E.g., on this xenialPup-706, the ROX properties function or < df -m >
reports the RAMdisk using:

Code: Select all

df -m /mnt/ram1
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/zram0          1839   147      1599   9% /mnt/ram1
So your Puppy in RAM occupies 660M, plus the zram-type RAMdisk occupies
1,839M. Therefore

Code: Select all

echo $[3915-(775+1839)]
1301
(Example edited, Dec. 12 2018, 19 h 42)
you have 1.3G of free RAM left for the execution of your programs. That's
more than enough, even for biggies such as Open|Libre|Office or
Chromium.

~~~~~~~~~~~~~~

(More to come as I find them.)

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply