Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from devimc/image/alignSize
Browse files Browse the repository at this point in the history
scripts: align image size to PAGE_SECTION_MASK
  • Loading branch information
jcvenegas authored Feb 1, 2018
2 parents ac7a690 + ac30b1f commit 35f2541
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ Environment Variables:
"a b c". By default this values is empty.

- IMG_SIZE
Change the image size of the image to generate (accepts any value
recognised by qemu-img(1)).
Specify the image size in megabytes. In order to support memory hot plug, this
value must be aligned to 128 (defined by PAGE_SECTION_MASK in the Linux Kernel),
otherwise memory will not be plugged by the guest Linux Kernel, If this value
is not aligned, osbuilder will align it. By default this value is 128.

- OS_VERSION:
Clear Linux version to use as base rootfs.
Expand Down
19 changes: 16 additions & 3 deletions scripts/image_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ info()
echo -e "\e[1mINFO\e[0m: $*"
}

warning()
{
echo -e "\e[93mWARNING\e[0m: $*"
}

usage()
{
cat <<EOT
Expand All @@ -53,15 +58,23 @@ exit 1
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
[ -d "${ROOTFS}" ] || die "${ROOTFS} is not a directory"

# In order to support memory hotplug, image must be aligned to 128M
MEM_BOUNDARY=128
# Image file to be created:
IMAGE="container.img"
# Image contents source folder
IMG_SIZE=${IMG_SIZE:-80M}
IMG_SIZE=${IMG_SIZE:-$MEM_BOUNDARY}
BLOCK_SIZE=${BLOCK_SIZE:-4096}

info "Creating raw disk with size ${IMG_SIZE}"
remaining=$(echo "$IMG_SIZE % $MEM_BOUNDARY" | bc)
if [ "$remaining" != "0" ];then
warning "image size '$IMG_SIZE' is not aligned to memory boundary '$MEM_BOUNDARY', aligning it"
IMG_SIZE="$((IMG_SIZE + MEM_BOUNDARY - remaining))"
fi

info "Creating raw disk with size ${IMG_SIZE}M"
#Create image file
qemu-img create -f raw "${IMAGE}" "${IMG_SIZE}"
qemu-img create -f raw "${IMAGE}" "${IMG_SIZE}M"

# Only one partition is required for the image
#Create partition table
Expand Down

0 comments on commit 35f2541

Please sign in to comment.