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

Commit ac30b1f

Browse files
author
Julio Montes
committed
scripts: align image size to PAGE_SECTION_MASK
In order to support memory hot plug, image size 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 fixes #49 Signed-off-by: Julio Montes <[email protected]>
1 parent 1aff7fc commit ac30b1f

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
@@ -206,8 +206,10 @@ Environment Variables:
206206
"a b c". By default this values is empty.
207207

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

212214
- PKG_MANAGER
213215
Specify the path to dnf or yum.

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)