Wednesday, March 27, 2013

在MacOS和Linux上使用Ramdisk

在Linux上使用Ramdisk


我使用如下脚本来生成一个大小可设定的tmpfs作为ramdisk
#!/bin/bash

TMPFS_SIZE=12G

mkdir -p ./ramdisk
sudo umount ./ramdisk >& /dev/null
sudo mount -t tmpfs -o size=$TMPFS_SIZE,mode=0775,gid=binfan tmpfs ./ramdisk

在MacOS上使用Ramdisk


创建一个Ramdisk
$ hdiutil attach -nomount ram://1165430
/dev/disk2                                           
$ diskutil erasevolume HFS+ "ramdisk" /dev/disk2
Started erase on disk2
Unmounting disk
Erasing
Initialized /dev/rdisk2 as a 569 MB HFS Plus volume
Mounting disk
Finished erase on disk2 ramdisk
然后使用df就可以看见这个device了
$ df
Filesystem                        512-blocks      Used Available Capacity  iused    ifree %iused  Mounted on
/dev/disk0s2                       818359360 273993824 543853536    34% 34313226 67981692   34%   /
devfs                                    381       381         0   100%      660        0  100%   /dev
map -hosts                                 0         0         0   100%        0        0  100%   /net
map auto_home                              0         0         0   100%        0        0  100%   /home
/dev/disk0s4                       156733432  41530424 115203008    27%   108561 57608399    0%   /Volumes/BOOTCAMP
localhost:/AI1XeO7VNLFdFPonF9OexW  818359360 818359360         0   100%        0        0  100%   /Volumes/MobileBackups
/dev/disk1s1s2                         35040     35040         0   100%     8758        0  100%   /Volumes/HTC Sync Manager
/dev/disk2                           1165424     27376   1138048     3%     3420   142256    2%   /Volumes/ramdisk
不用的时候在Finder里面弹出这个设备就可以了.

No comments: