Advertisement
Guest User

casper zram

a guest
May 17th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.39 KB | None | 0 0
  1. --- casper.orig 2012-05-17 12:48:23.786986671 -0400
  2. +++ casper  2012-05-17 13:19:54.204228445 -0400
  3. @@ -142,6 +142,13 @@ is_nice_device() {
  4.      return 1
  5.  }
  6.  
  7. +# Load zram if not loaded
  8. +load_zram() {
  9. +   if [ ! -b /dev/zram0 ]; then
  10. +       modprobe zram zram_num_devices=4
  11. +   fi
  12. +}
  13. +
  14.  copy_live_to() {
  15.      copyfrom="${1}"
  16.      copytodev="${2}"
  17. @@ -151,11 +158,22 @@ copy_live_to() {
  18.  
  19.      if [ "${copytodev}" = "ram" ]; then
  20.          # copying to ram:
  21. -        freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
  22. -        mount_options="-o size=${size}k"
  23. +        freespace=$(awk '/^MemTotal:/{f=$2} END{print f / 2}' /proc/meminfo)
  24. +        mount_options=""
  25.          free_string="memory"
  26. -        fstype="tmpfs"
  27. -        dev="/dev/shm"
  28. +        fstype="ext2"
  29. +   # zram0 reserved for swap, so use zram1
  30. +        dev="/dev/zram1"
  31. +   # Load if not loaded
  32. +   load_zram
  33. +   # If we didn't load enough, that's a problem
  34. +   if [ ! -b "${dev}" ]; then
  35. +       [ "$quiet" != "y" ] && log_warning_msg "${dev} is not a block device (zram loaded without zram_num_devices high enough?)."
  36. +       return 1
  37. +   fi
  38. +   # Because of file system overhead, add 10%
  39. +   echo $(( freespace * 1024 * 11 / 10 )) > /sys/block/zram1/disksize
  40. +   mkfs.ext2 "${dev}"
  41.      else
  42.          # it should be a writable block device
  43.          if [ -b "${copytodev}" ]; then
  44. @@ -425,10 +443,11 @@ setup_unionfs() {
  45.      rofsstring=${rofsstring%:}
  46.  
  47.      mkdir -p /cow
  48. -    cowdevice="tmpfs"
  49. -    cow_fstype="tmpfs"
  50. +    cowdevice="/dev/zram2"
  51. +    cow_fstype="ext2"
  52.      cow_mountopt="rw,noatime,mode=755"
  53.  
  54. +
  55.      # Looking for "${root_persistence}" device or file
  56.      if [ -n "${PERSISTENT}" ]; then
  57.          cowprobe=$(find_cow_device "${root_persistence}")
  58. @@ -439,6 +458,16 @@ setup_unionfs() {
  59.          else
  60.              [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
  61.          fi
  62. +    else
  63. +   # Load if not loaded
  64. +   load_zram
  65. +   # If we didn't load enough, that's a problem
  66. +   if [ ! -b "${cowdevice}" ]; then
  67. +       [ "$quiet" != "y" ] && log_warning_msg "${cowdevice} is not a block device (zram loaded without zram_num_devices high enough?)."
  68. +       return 1
  69. +   fi
  70. +   echo $(( freespace * 1024 )) > /sys/block/zram2/disksize
  71. +   mkfs.ext2 "${cowdevice}"
  72.      fi
  73.  
  74.      mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement