Skip to content
Aasif Versi
Source

Mount file as disk linux

1 min read

Commnads

# create a file
$ WORKDIR=/var/tmp
# This will make an empty file with an apparent size of 2G
$ truncate -s +2G "$WORKDIR/disk.img"
# Make it a filesystem
$ mkfs.ext4 "$WORKDIR/disk.img"
# monut the new disk
$ sudo mkdir /mnt/disk
$ sudo mount -o loop "$WORKDIR/disk.img" /mnt/disk
$ df -h /mnt/disk
Filesystem Size Used Avail Use% Mounted on
/dev/loop20 2.0G 24K 1.8G 1% /mnt/disk
# reisze the diskA
# add 8G to the size
truncate -s +8G "$WORKDIR/disk.img"
$ sudo resize2fs /dev/loop20
$ df -ah /mnt/disk/
Filesystem Size Used Avail Use% Mounted on
/dev/loop20 9.8G 24K 9.4G 1% /mnt/disk

Reference