Friday, March 17, 2023

Difference between ramdisk (e.g. initramfs) and loopback device filesystem

My interpretation. Both are types of virtual ramdisks. 
  • Ramdisk uses memory (non-swappable) as a virtual device, while a loopback device uses a file (IF=input_file) as the input. dd if=file_name > of=/dev/loop, then we mount -o loop /dev/loop /mnt
  • The loopback filesystem associates a file on another filesystem as a complete device. For Ramdisks, the device does not refer to any physical hardware, but to a portion of memory that is set aside for the purpose.
  • Loopback vs Ramdisks. During boot - The initial ramdisk device in Linux is another important mechanism that we need to be able to use a loopback device as a the root filesystem.
  • Using Losetup script in Linux to create a disk image.
    • Create an empty image, use losetup to associate that with a loopback device that is not in use (check losetup -a), mkfs to create a file system, mount to /mnt, copy desired files to /mnt, umount /mnt, losetup -d to detach the loopback device from the file.