Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 19 Nov 2017, 20:34
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Problem with zram RAMdisk script [SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
musher0


Joined: 04 Jan 2009
Posts: 11158
Location: Gatineau (Qc), Canada

PostPosted: Thu 26 Oct 2017, 12:00    Post subject:  Problem with zram RAMdisk script [SOLVED]  

Hello all.

As the title says. In particular, If the LC_ALL=C and the switch back to "" worked, there
would be no need the if...elif...else...fi section, right?

I'm asking because I'm confused. This script works without fuss in my DPupStretch-7
without the language query section. It worked fine in xenial32-706 too without it until
today.

Today I had to introduce the language query section to get it to work properly in the
xenialPup version.
.
Otherwise /mnt/ram1 is just a folder. rsync fills it up anyway but it's just a folder.
But
Code:
cat /sys/block/zram0/stat
says I do have a zram ramdisk.

The LANG variable is fr_CA.UTF-8 in both. This is very mysterious.

Some comments in the script are in French, sorry. If a translation is needed, just ask.
Also, go easy on me, this is still a draft! Wink

Thanks in advance for any insight.

BFN.

Code:
#!/bin/bash
# /opt/local/bin/DV-zram.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.
####
ChecK="`df | awk '$NF ~ /ram1/'`" # musher0, 17-10-14
if [ "$ChecK" = "" ];then # musher0, 17-10-14
   MOUNTPOINT="/mnt/ram1"
   LC_ALL=C # Marche pas ?
   SIZE="`free -m | awk '/Mem/ {print $4/3*2}'`";LC_ALL=""

##############
# If the LC_ALL=C and the switch back worked, there would
# be no need the following if...elif...else...fi section, right?
#   if [ "${LANG:10}" = "8" ];then # non significatif
   if [ "${LANG:0:2}" = "fr" ];then # Laisser tomber les décimales possibles.
      SIZE="${SIZE%,*}"
   elif [ "${LANG:0:2}" = "en" ];then
      SIZE="${SIZE%.*}"
#   elif # autres langues # room for other languages
   else
      SIZE="${SIZE%.*}" # En-cas # Catch all ?
   fi
##############

   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
   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
# Source : https://unix.stackexchange.com/questions/203846/how-to-sync-two-folders-with-command-line-tools
#
# Meilleur que :
# exec /opt/local/bin/ramdisk_cp.sh & # Copier le contenu de /mnt/home/ramdisk.
#
# Inversement :
# cd /mnt/ram1
# rsync -avz . "/mnt/home/ramdisk"
#
######################
# Suite de l'explication de "Mute Ant" :
#
# The amount of memory used will fluctuate according to
# what you store in the Ramdisk folder. The disk will persist
# if you log out, but not if you reboot. 1G, 2G, 500M,
# whatever you can afford, sets the maximum data size,
# RAM use will often be less; if the data can be compressed,
# it will be.
#
# Should you ever need to switch it off without rebooting...
# sudo su -c "
# umount /dev/zram0 # &&
# echo 1 > /sys/block/zram0/reset
#
# ...will do that.
######################
   sleep 0.5s
   MsG="Un disque virtuel de $SIZE Mb a été créé."
   Xdialog --title "Créé" --ok-label "OK" --timeout 5 --msgbox "$MsG" 0 0
   rox /mnt/ram1 &

else # Cette section par musher0, 17-10-14
   Xdialog --title "Existe" --ok-label "OK" --timeout 5 --msgbox "Un DV existe déja." 0 0
fi # Fin de la section par musher0, 17-10-14

########## Référence ####
# Ajouts par musher0
#
# Divers scripts d'une ligne pour faire des vérifications sur ce DV.
#
# 1) # echo -e "Location\tUsed\tAvail.\t%\tName";df -h | awk '$NF ~ /ramdisk/ { print $1"\t\t"$3"\t"$4"\t"$5"\t"$6}'
# OU
# 2a) df | head -1;df | grep ram;echo
# 2b) df -h | head -1;df -h | grep ram;echo
#
###
# 3) df | awk '$2=="1024000" && $NF ~ /ramdisk/'
# Celle-ci vous dit seulement s'il existe un DV.
####

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)

Last edited by musher0 on Thu 26 Oct 2017, 16:13; edited 1 time in total
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 11158
Location: Gatineau (Qc), Canada

PostPosted: Thu 26 Oct 2017, 16:13    Post subject:  

Thanks to whoever read this earlier and thought of helping, but I
solved the problem by using the int capacity in awk.

I was doing complicated when I should have done simple, haha.

BFN.
Code:
#!/bin/bash
# /opt/local/bin/DV-zram-2.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. 2017.
####
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/3*2)}'`"
   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
# Source : https://unix.stackexchange.com/questions/203846/how-to-sync-two-folders-with-command-line-tools
#
# Suite de l'explication de "Mute Ant" :
#
# The amount of memory used will fluctuate according to
# what you store in the Ramdisk folder. The disk will persist
# if you log out, but not if you reboot. 1G, 2G, 500M,
# whatever you can afford, sets the maximum data size,
# RAM use will often be less; if the data can be compressed,
# it will be.
#
# Should you ever need to switch it off without rebooting...
# sudo su -c "
# umount /dev/zram0 # &&
# echo 1 > /sys/block/zram0/reset
#
# ...will do that.
######################
   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

########## Référence ####
# Ajouts par musher0
#
# Divers scripts d'une ligne pour faire des vérifications sur ce DV.
#
# 1) # echo -e "Location\tUsed\tAvail.\t%\tName";df -h | awk '$NF ~ /ramdisk/ { print $1"\t\t"$3"\t"$4"\t"$5"\t"$6}'
# OU
# 2a) df | head -1;df | grep ram;echo
# 2b) df -h | head -1;df -h | grep ram;echo
#
###
# 3) df | awk '$2=="1024000" && $NF ~ /ramdisk/'
# Celle-ci vous dit seulement s'il existe un DV.
####

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0400s ][ Queries: 12 (0.0074s) ][ GZIP on ]