News for hackers. Stuff that matters.
Re:Save your disk, write files directly into RAM with /dev/shm by frollogaston on Thursday June 26, 2025 @08:05PM (#44392655)
"virtually every Unix system already has it mounted as a tmpfs by default" might be true if you say Linux instead, but Mac doesn't have /dev/shm
Re:Save your disk, write files directly into RAM with /dev/shm by loeg on Thursday June 26, 2025 @08:12PM (#44392705)
I may misremember, but I think it's also common in the BSDs? (Whereas /var/tmp is persisted.)
Re:Save your disk, write files directly into RAM with /dev/shm by frollogaston on Friday June 27, 2025 @06:44PM (#44400967)
Yeah, Mac is probably the odd one out, but it's also maybe the most common Unix-based/Unix-like desktop OS. Anyway, both are POSIX, unlike Linux.
Re:Save your disk, write files directly into RAM with /dev/shm by hiAndrewQuinn on Thursday June 26, 2025 @08:30PM (#44392793)
Mea culpa, you're right. I should not have assumed that just because POSIX was mentioned in the orbit of this thing that everyone else had this too.

The article has been corrected.

Re:Save your disk, write files directly into RAM with /dev/shm by AdieuToLogic on Thursday June 26, 2025 @08:42PM (#44392859)
OS-X/macOS supports RAM drives and a script which defines one for use as /private/tmp (which /tmp is symbolically linked to) is:

  #!/bin/bash
  ramfs_size_mb=1024
  mount_point=/private/tmp
  
  counter=0
  ramfs_size_sectors=$((${ramfs_size_mb}*2048))
  ramdisk_dev=`hdiutil attach -nomount ram://${ramfs_size_sectors}`
  
  while [[ ! -d "/Volumes" ]]
  do
   sleep 1
   counter=$((counter + 1))
  
   if [[ $counter -gt 10 ]]
   then
    echo "$O: /Volumes never created"
    exit 1
   fi
  done
  
  diskutil eraseVolume HFS+ 'RAM Disk' ${ramdisk_dev} || {
   echo "$O: unable to create RAM Disk on: ${ramdisk_dev}"
   exit 2
  }
  
  umount '/Volumes/RAM Disk'
  
  mkdir -p ${mount_point} 2>/dev/null
  mount -o noatime -t hfs ${ramdisk_dev} ${mount_point} || {
   echo "$0: unable to mount ${ramdisk_dev} ${mount_point}"
   exit 3
  }
  
  chown root:wheel ${mount_point}
  chmod 1777 ${mount_point}
Adding a plist definition to /Library/LaunchDaemons can ensure the above is executed when the system starts.