Skip to content

Instantly share code, notes, and snippets.

@deoren
Created January 18, 2018 03:47
Show Gist options
  • Save deoren/8b9c4ac22cf852e60798cc81df872b86 to your computer and use it in GitHub Desktop.
Save deoren/8b9c4ac22cf852e60798cc81df872b86 to your computer and use it in GitHub Desktop.
Create image file, format it and then mount it
#!/bin/bash
# Untested shell script to create and mount an image file. Pretty much a copy/paste
# from this site:
#
# http://ubuntuhak.blogspot.com/2012/10/how-to-create-format-and-mount-img-files.html
img_file="/tmp/bucket.img"
img_size_in_mb="1024"
mount_point="/tmp/bucket"
# Create 1 GB "bucket"
sudo dd if=/dev/zero of=${img_file} bs=1M count=${img_size_in_mb}
# Format new image file
sudo mkfs ext4 -m0 -F ${img_file}
sudo mkdir -p ${mount_point}
sudo mount -o loop,rw,sync ${img_file} ${mount_point}
@sam2332
Copy link

sam2332 commented Mar 21, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment