I am in a situation where i have to test mv(1) command while disk quota is exceeded.
Can anyone let me know the steps to create this.. i mean how can i make disk quota full on normal Unix test machine.
Thanks.
dd if=/dev/zero of=/home/usverg/test bs=1M count=1024
count は、入力する必要がある MB の数です:)
「ディスクがいっぱい」のテストにも興味があります。(ディスクがいっぱいのシナリオに敏感な Java コードをいくつか書きましたが、テストする必要があります。)
Noufal Ibrahim のアイデア #2 を拡張するために、いくつかの調査を行い、ループ デバイスのマウントをセットアップおよび破棄するために必要なすべてのコマンドを見つけました。これにより、小さな一時的なマウントを作成できます。それを埋めて、「ディスクがいっぱい」のテストを行うことができます。
私のコマンドは Debian Linux 用です。パスは多少異なる場合があります。
スクリプトは次のとおりです。
#!/bin/bash
_pwd=$(pwd -P)
usage() {
echo "Setup or Teardown a loop device mount"
echo
echo "Normally, mount & umount require root-level access."
echo "You may need to run this script via 'sudo'."
echo
echo "Usage 1: $0 setup FILE SIZE DEVICE MOUNT"
echo " FILE is the virtual file system in a single file"
echo " SIZE is the size of the virtual filesystem in 'dd' format"
echo " The minimum size appears to be 2M for ext3 file systems."
echo " DEVICE is the loop device"
echo " MOUNT is the mount point (directory)"
echo
echo "Usage 2: $0 teardown FILE DEVICE MOUNT"
echo
echo "Example: $0 setup ./data.ext3 2M /dev/loop0 /mnt/loop0"
echo "Example: $0 teardown ./data.ext3 /dev/loop0 /mnt/loop0"
echo
exit 1
}
execute_command() {
local command="$1"
echo ">>> $command"
eval "$command"
local exit_code=$?
if [ "0" != "$exit_code" ] ; then
echo ">>> Command failed with exit code: $exit_code"
exit 1
fi
}
execute_bad_command() {
local command="$1"
echo ">>> $command"
eval "$command"
local exit_code=$?
if [ "0" == "$exit_code" ] ; then
echo ">>> Command unexpectedly successful!"
exit 1
fi
}
if [ -z "$1" ] ; then
usage
fi
if [ "setup" = "$1" ] ; then
if [ "5" != "$#" ] ; then
usage
fi
VFS=$2
SIZE=$3
DEVICE=$4
MOUNT=$5
# Create a file
execute_command "dd if=/dev/zero of=${VFS} bs=${SIZE} count=1"
# Format the file with ext3 filesystem
# We need 'yes' here to ignore:
# ./data is not a block special device.
# Proceed anyway? (y,n)
execute_command "yes | /sbin/mkfs -t ext3 -m 1 -v ${VFS}"
if [ -d ${MOUNT} ] ; then
execute_command "rmdir ${MOUNT}"
fi
# Create the mount point and enable read/write/execute for all users
execute_command "mkdir -m 0777 ${MOUNT}"
# Mount the file
execute_command "mount ${VFS} ${MOUNT} -t ext3 -o loop=${DEVICE}"
# Check the loopback setup
# Example output: /dev/loop0: [0801]:17416195 (/home/kca/saveme/disk-full-test/data)
execute_command "/sbin/losetup ${DEVICE}"
# Test write
execute_command "echo abc > ${MOUNT}/dummy.txt"
# Clean-up test write
execute_command "rm ${MOUNT}/dummy.txt"
echo "Try to fill new mount with junk data:"
# We expect to fail and see this error message:
# dd: writing `/mnt/loop0/data': No space left on device
execute_bad_command "dd if=/dev/zero of=${MOUNT}/junk bs=${SIZE} count=2"
# Clean-up junk write
execute_command "rm ${MOUNT}/junk"
echo "Loop device mount setup and testing complete:"
echo "${MOUNT}"
elif [ "teardown" = "$1" ] ; then
if [ "4" != "$#" ] ; then
usage
fi
VFS=$2
DEVICE=$3
MOUNT=$4
# Unmount the file
execute_command "umount ${MOUNT}"
# Check loop device after mount. We expect to fail.
# loop: can't get info on device /dev/loop0: No such device or address
execute_bad_command "/sbin/losetup ${DEVICE}"
execute_command "rmdir ${MOUNT}"
execute_command "rm ${VFS}"
echo "Loop device mount teardown complete."
else
usage
fi
exit 0
OSやファイルシステムが提供するクォータツールを使用して非常に小さなクォータを設定するかdd
、クォータを超えるかそれに非常に近づくまで、大きなファイルを作成して(たとえばを使用して)ファイルシステムをいっぱいにしてください。