Skip to content

Commit 128db22

Browse files
committed
fix(os): restore empty /dev/vdb data-disk auto-initialization
1 parent 46fc3cf commit 128db22

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

os/common/rootfs/dstack-prepare.sh

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ has_luks_header() {
149149
return 1
150150
}
151151

152+
create_data_partition() {
153+
local disk="$1"
154+
log "Creating GPT partition table on ${disk}..."
155+
if ! command -v sgdisk >/dev/null 2>&1; then
156+
log "Error: sgdisk not available, cannot create partition table"
157+
return 1
158+
fi
159+
# Create GPT with single partition filling entire disk
160+
sgdisk -Z "$disk" >/dev/null || true # Zap any existing data
161+
sgdisk -n 1:1MiB:0 -c 1:dstack-data -t 1:8300 "$disk" >/dev/null || return 1
162+
# Trigger kernel to re-read partition table
163+
blockdev --rereadpt "$disk" >/dev/null || true
164+
udevadm settle >/dev/null || sleep 1
165+
part_device=$(
166+
lsblk -nr -o PATH "$disk" 2>/dev/null | sed -n '2p'
167+
)
168+
if [ -n "$part_device" ] && [ -b "$part_device" ]; then
169+
log "Created partition: $part_device"
170+
echo "$part_device"
171+
return 0
172+
fi
173+
log "Failed to create partition"
174+
return 1
175+
}
176+
152177
choose_data_device() {
153178
local override="$1"
154179
local dev=""
@@ -191,11 +216,16 @@ choose_data_device() {
191216
return 1
192217
fi
193218

194-
# Do not guess which blank disk is persistent storage or destructively
195-
# initialize it. Cloud deployment tooling must provision PARTLABEL=dstack-data.
196-
log "Error: Empty /dev/vdb has no 'dstack-data' partition"
197-
log "Provision a labeled data-disk image or specify dstack.data_device"
198-
return 1
219+
# 3.3. /dev/vdb is empty, create partition table
220+
log "Empty disk detected at /dev/vdb, creating dstack-data partition..."
221+
local new_partition
222+
new_partition=$(create_data_partition /dev/vdb)
223+
if [ -z "$new_partition" ]; then
224+
log "Error: Failed to create partition on /dev/vdb"
225+
return 1
226+
fi
227+
echo "$new_partition"
228+
return 0
199229
}
200230

201231
DATA_DEVICE_OVERRIDE=$(get_cmdline_value "dstack.data_device" || true)

0 commit comments

Comments
 (0)