mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
feat: Print available diskspace
* feat: Print available diskspace
This commit is contained in:
parent
a768fecfde
commit
c3c4d966b4
23
src/disk.sh
23
src/disk.sh
@ -24,6 +24,7 @@ DISK_OPTS="\
|
||||
|
||||
addDisk () {
|
||||
|
||||
local FS
|
||||
local GB
|
||||
local DIR
|
||||
local REQ
|
||||
@ -40,6 +41,12 @@ addDisk () {
|
||||
DIR=$(dirname "${DISK_FILE}")
|
||||
[ ! -d "${DIR}" ] && return 0
|
||||
|
||||
FS=$(stat -f -c %T "$DIR")
|
||||
|
||||
if [[ "$FS" == "overlay"* ]]; then
|
||||
info "Warning: the filesystem of ${DIR} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||
fi
|
||||
|
||||
[ -z "$DISK_SPACE" ] && DISK_SPACE="16G"
|
||||
DISK_SPACE=$(echo "${DISK_SPACE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
|
||||
DATA_SIZE=$(numfmt --from=iec "${DISK_SPACE}")
|
||||
@ -70,16 +77,17 @@ addDisk () {
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
|
||||
if (( REQ > SPACE )); then
|
||||
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} .."
|
||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84
|
||||
error "Not enough free space to resize ${DISK_DESC} to ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 84
|
||||
fi
|
||||
|
||||
# Resize file by allocating more space
|
||||
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE} .." && exit 85
|
||||
error "Could not resize ${DISK_DESC} file (${DISK_FILE}) to ${DISK_SPACE}" && exit 85
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -94,24 +102,25 @@ addDisk () {
|
||||
# Create an empty file
|
||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
rm -f "${DISK_FILE}"
|
||||
error "Could not create a file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${DIR}" | tail -n 1)
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
|
||||
if (( DATA_SIZE > SPACE )); then
|
||||
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} .."
|
||||
error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86
|
||||
error "Not enough free space to create ${DISK_DESC} of ${DISK_SPACE} in ${DIR}, it has only ${SPACE_GB} GB available.."
|
||||
error "Specify a smaller ${DISK_DESC^^}_SIZE or disable preallocation with ALLOCATE=N." && exit 86
|
||||
fi
|
||||
|
||||
# Create an empty file
|
||||
if ! fallocate -l "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
if ! truncate -s "${DISK_SPACE}" "${DISK_FILE}"; then
|
||||
rm -f "${DISK_FILE}"
|
||||
error "Could not create a file for ${DISK_DESC} (${DISK_FILE}) of ${DISK_SPACE} .." && exit 87
|
||||
error "Could not create a ${DISK_SPACE} file for ${DISK_DESC} (${DISK_FILE})" && exit 87
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -48,27 +48,40 @@ rm -f "$STORAGE"/"$BASE".agent
|
||||
rm -f "$STORAGE"/"$BASE".boot.img
|
||||
rm -f "$STORAGE"/"$BASE".system.img
|
||||
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
|
||||
# Check filesystem
|
||||
MIN_SPACE=6442450944
|
||||
FS=$(stat -f -c %T "$STORAGE")
|
||||
|
||||
if [[ "$FS" == "overlay"* ]]; then
|
||||
info "Warning: the filesystem of ${STORAGE} is OverlayFS, this usually means it was binded to an invalid path!"
|
||||
fi
|
||||
|
||||
if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \
|
||||
"$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then
|
||||
TMP="$STORAGE/tmp"
|
||||
else
|
||||
TMP="/tmp/dsm"
|
||||
SPACE=$(df --output=avail -B 1 /tmp | tail -n 1)
|
||||
(( MIN_SPACE > SPACE )) && TMP="$STORAGE/tmp"
|
||||
if (( MIN_SPACE > SPACE )); then
|
||||
TMP="$STORAGE/tmp"
|
||||
info "Warning: the ${FS} filesystem of ${STORAGE} does not support UNIX permissions.."
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -rf /tmp/dsm
|
||||
rm -rf "$STORAGE/tmp"
|
||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation, need at least 6 GB." && exit 95
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 95
|
||||
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space for installation in ${STORAGE}, have ${SPACE_GB} GB available but need at least 6 GB." && exit 94
|
||||
fi
|
||||
|
||||
RDC="$STORAGE/dsm.rd"
|
||||
|
||||
@ -213,7 +226,8 @@ SYSTEM_SIZE=4954537983
|
||||
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
||||
(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk." && exit 87
|
||||
SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
||||
(( SYSTEM_SIZE > SPACE )) && error "Not enough free space to create a 4 GB system disk, have only ${SPACE_GB} GB available." && exit 87
|
||||
|
||||
if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||
if ! truncate -s "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||
@ -274,12 +288,6 @@ rm -rf "$MOUNT"
|
||||
|
||||
echo "$BASE" > "$STORAGE"/dsm.ver
|
||||
|
||||
if [[ "$TMP" != "$STORAGE/tmp" ]]; then
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "$STORAGE" | tail -n 1)
|
||||
(( MIN_SPACE > SPACE )) && error "Not enough free space in storage folder, need at least 6 GB." && exit 94
|
||||
fi
|
||||
|
||||
mv -f "$PAT" "$STORAGE"/"$BASE".pat
|
||||
mv -f "$BOOT" "$STORAGE"/"$BASE".boot.img
|
||||
mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
||||
|
Loading…
x
Reference in New Issue
Block a user