-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdisk.sh
More file actions
25 lines (21 loc) · 847 Bytes
/
Copy pathdisk.sh
File metadata and controls
25 lines (21 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Collection of functions to work with disks on Linux
#######################################
# Create a file and binds it to a loop device
# Arguments:
# File name
# Size file (number of blocks)
# Look device
# Examples:
# linux_create_fileAndLoopDevice '/loop-file1' '10240' '/dev/loop1'
#######################################
linux_create_fileAndLoopDevice() {
local fileName=$1
local sizeFile=$2
local loopDevice=$3
echo "Creating local file ${fileName} and loop device ${fileName}..."
# prepares the file for use with loopback device (creates a file filled with zero bytes)
dd if=/dev/zero of=${fileName} bs=1M count=${sizeFile} status=progress
# binds the file to the loop device (enabling to work with the file as if it were a block device, like a physical disk)
losetup ${loopDevice} ${fileName}
}