Skip to content

Commit

Permalink
feat: create sparse images
Browse files Browse the repository at this point in the history
Instead of allocating the whole image on the disk, only allocate the parts that actually contain data. This reduces the required disk space to store or create images.

Changelog: Title
Ticket: None
Signed-off-by: Yannis Gerlach <[email protected]>
  • Loading branch information
ygerlach committed Nov 21, 2024
1 parent 94f9c1f commit add822b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ disk_get_part_nums() {
# $3 - size (in 512 blocks)
# $4 - path to output file
disk_extract_part() {
run_and_log_cmd "dd if=$1 of=$4 skip=${2}b bs=1M count=${3}b status=none iflag=count_bytes,skip_bytes"
run_and_log_cmd "dd if=$1 of=$4 skip=${2}b bs=1M count=${3}b status=none conv=sparse iflag=count_bytes,skip_bytes"
}

# Convert MiB to number of 512 sectors
Expand Down Expand Up @@ -98,7 +98,7 @@ disk_align_sectors() {
# $2 - destination file
# $3 - offset in number of 512 sectors
disk_write_at_offset() {
run_and_log_cmd "dd if=${1} of=${2} seek=${3} conv=notrunc status=none"
run_and_log_cmd "dd if=${1} of=${2} seek=${3} bs=512 conv=notrunc,sparse status=none"
}

# Create file system image from directory content
Expand Down

0 comments on commit add822b

Please sign in to comment.