On Linux, how can a RAM disk be created and attached without being mounted? Moreover, how can the device name like
/dev/sdb assigned to the RAM disk be found? Finally, how can the RAM disk (which is not mounted) be detached?
I would like to create and attach a RAM disk, but I do not want to mount it. I want to leave it unmounted.
On Mac OS X, the following command creates and attaches a 100MiB RAM disk without mounting it.
hdiutil attach -nomount ram://204800 # In terms of the number of 512-byte sectors, # 100 MiB is equivalent to 204800 sectors.
Upon successful completion, the above command returns the device name such as
/dev/disk1 assigned to the RamDisk. However, later when you forget the device name, you can find it by the following OSX commands (as well as the GUI application Disk Utility).
# Displays the list of attached disks. diskutil list # Displays the details of a specific disk. diskutil info /dev/disk1
Finally, on Mac OS X, to detach the RAM disk, no matter whether it has been mounted, the following command (as well as the GUI application Disk Utility) works. This command automatically unmounts it first if it has been mounted.
hdiutil detach /dev/disk1
On Linux, how can all the above three operations be achieved? (If the operations I am asking for may depend on distros, then I am particularly interested in Debian 9.)
One of the reasons that I do not want the RAM disk to be mounted is that I want to run some experiments on the
dd command reading and writing directly on a disk (or device), bypassing the filesystem. In fact, the direct writing mode of
dd requires the volume on the device to be unmounted, but the device to be still attached and not ejected.
On Linux, the following
mount command creates, attaches and mounts a 100MiB RAM disk.
mkdir /mnt/ramdisk mount -t tmpfs -o size=100m tmpfs /mnt/ramdisk
However, I do not know how to disable the "mounting" part.
By the way, for those who want to know how to mount, in addition to creating and attaching, a RAM disk on Mac OS X, here is the command.
diskutil erasevolume HFS+ "RamD" $(hdiutil attach -nomount ram://204800) # 204800 is the number of 512-byte sectors, # resulting in 100 MiB. # # "RamD" is a volume name or label. # # "erasevolume" means to format the volume, # but it does not necessarily write zeros.