109
# Grow the image container and the filesystem within to the specified # of MB
111
# The image container must be raw format.
112
# The image container has no partitioning.
113
# The filesystem in the container must be ext2/3/4.
115
local img="$1" size_MB="$2"
117
# Check that this is a raw image
118
local img_fmt=$(qemu-img info --output=json ${img} | \
119
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["format"];')
120
if [ "${img_fmt}" != "raw" ] ; then
121
error "Expected 'raw' image format, found '${img_fmt}'. Can not resize"
125
# Get current size of image
126
local img_bytes=$(qemu-img info --output=json ${img} | \
127
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["virtual-size"];')
129
size_bytes=$(($size_MB * 1024 * 1024))
130
if [ ${size_bytes} -lt ${img_bytes} ] ; then
131
info "Will not shrink image ${img} from ${img_bytes} to ${size_bytes}"
135
info "Resizing image container to ${size_MB}MB"
136
qemu-img resize ${img} ${size_MB}M
138
info "Attaching loop device to image"
139
LODEV=$(losetup --find --show ${img}) ||
140
{ error "failed to expand image to ${size_MB}M"; return 1; }
141
[ -z "${LODEV}" ] && { error "could not setup loop device"; return 1; }
143
info "Checking image filesystem"
144
e2fsck -f -y ${LODEV} || { error "fsck failed for image"; return 1; }
145
info "Resizing image filesystem to fill container"
146
resize2fs ${LODEV} || { error "resize2fs failed on image"; return 1; }
148
info "Detaching loop device for image"
149
losetup --detach ${LODEV} || { error "loop detach failure"; return 1; }
109
153
local short_opts="a:hk:p:v"
110
154
local long_opts="arch:,help,kernel:,krd-pack:,no-gzip,verbose"
180
224
ensure_file_d "$output" ||
181
225
{ error "failed to create dir for $output"; return 1; }
228
grow_img ${imgfile} 2048
183
230
# now imgfile has the root filesystem image to adjust
184
231
local pkout="${TEMP_D}/$kpkg-kernel" piout="${TEMP_D}/$kpkg-initrd"
185
232
local manif="${TEMP_D}/manifest"