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

Commit 35f2541

Browse files
authored
Merge pull request #50 from devimc/image/alignSize
scripts: align image size to PAGE_SECTION_MASK
2 parents ac7a690 + ac30b1f commit 35f2541

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ Environment Variables:
225225
"a b c". By default this values is empty.
226226

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

231233
- OS_VERSION:
232234
Clear Linux version to use as base rootfs.

scripts/image_builder.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ info()
3939
echo -e "\e[1mINFO\e[0m: $*"
4040
}
4141

42+
warning()
43+
{
44+
echo -e "\e[93mWARNING\e[0m: $*"
45+
}
46+
4247
usage()
4348
{
4449
cat <<EOT
@@ -53,15 +58,23 @@ exit 1
5358
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
5459
[ -d "${ROOTFS}" ] || die "${ROOTFS} is not a directory"
5560

61+
# In order to support memory hotplug, image must be aligned to 128M
62+
MEM_BOUNDARY=128
5663
# Image file to be created:
5764
IMAGE="container.img"
5865
# Image contents source folder
59-
IMG_SIZE=${IMG_SIZE:-80M}
66+
IMG_SIZE=${IMG_SIZE:-$MEM_BOUNDARY}
6067
BLOCK_SIZE=${BLOCK_SIZE:-4096}
6168

62-
info "Creating raw disk with size ${IMG_SIZE}"
69+
remaining=$(echo "$IMG_SIZE % $MEM_BOUNDARY" | bc)
70+
if [ "$remaining" != "0" ];then
71+
warning "image size '$IMG_SIZE' is not aligned to memory boundary '$MEM_BOUNDARY', aligning it"
72+
IMG_SIZE="$((IMG_SIZE + MEM_BOUNDARY - remaining))"
73+
fi
74+
75+
info "Creating raw disk with size ${IMG_SIZE}M"
6376
#Create image file
64-
qemu-img create -f raw "${IMAGE}" "${IMG_SIZE}"
77+
qemu-img create -f raw "${IMAGE}" "${IMG_SIZE}M"
6578

6679
# Only one partition is required for the image
6780
#Create partition table

0 commit comments

Comments
 (0)