Skip to content

Commit c716e3e

Browse files
authored
Better way of resizing images (#76)
1 parent acf1f5c commit c716e3e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

environment/image_recipes/bare_metal/bare_metal.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"inventory": "/mnt/bare_metal,",
1818

1919
"s3_bucket": "tailor-artifacts",
20+
"disk_size": "15",
2021

2122
"iso_image": ""
2223
},
@@ -99,6 +100,13 @@
99100
{
100101
"type": "shell-local",
101102
"inline": [
103+
"echo 'Resize image'",
104+
"qemu-nbd -c /dev/nbd0 images/{{user `image_name`}}.qcow2",
105+
"e2fsck -y -f /dev/nbd0p1",
106+
"resize2fs /dev/nbd0p1 {{user `disk_size`}}G",
107+
"qemu-nbd -d /dev/nbd0",
108+
"qemu-img resize --shrink images/{{user `image_name`}}.qcow2 {{user `disk_size`}}G",
109+
102110
"echo 'Converting image to RAW...'",
103111
"qemu-img convert images/{{user `image_name`}}.qcow2 images/{{user `image_name`}}.raw",
104112
"rm -f images/{{user `image_name`}}.qcow2",

tailor_image/create_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def create_image(name: str, distribution: str, apt_repo: str, release_track: str
116116
run_command(['modprobe', 'nbd'])
117117

118118
# Resize image
119-
run_command(['qemu-img', 'resize', base_image_local_path, f'+{disk_size}G'])
119+
run_command(['qemu-img', 'resize', base_image_local_path, '30G'])
120120

121121
# Copy image
122122
tmp_image = base_image_local_path.replace('disk1', 'disk1-resized')
@@ -133,7 +133,8 @@ def create_image(name: str, distribution: str, apt_repo: str, release_track: str
133133
'-var', f'image_name={image_name}',
134134
'-var', f's3_bucket={apt_repo}',
135135
'-var', f'iso_image={base_image_local_path}',
136-
'-var', f'distribution={distribution}'
136+
'-var', f'distribution={distribution}',
137+
'-var', f'disk_size={disk_size}'
137138
]
138139

139140
# Make sure to clean old image builds

0 commit comments

Comments
 (0)