如何让磁盘配额满

发布于 2024-11-01 10:10:03 字数 104 浏览 0 评论 0原文

我遇到的情况是,当超出磁盘配额时,我必须测试 mv(1) 命令。

谁能让我知道创建这个的步骤..我的意思是如何在普通的 Unix 测试机器上使磁盘配额满。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最近可好 2024-11-08 10:10:03
dd if=/dev/zero of=/home/usverg/test bs=1M count=1024 

其中 count 是您必须填写的 MB 数:)

dd if=/dev/zero of=/home/usverg/test bs=1M count=1024 

Where count is the number of MB you have to fill :)

暗恋未遂 2024-11-08 10:10:03

要么使用操作系统和文件系统提供的任何配额工具设置一个非常小的配额,要么通过创建大文件(例如使用 dd )来填充文件系统,直到超出或非常接近配额。

Either set a very small quota using whatever quota tools your OS and filesystems offer, or just fill up the filesystem by creating large files (using dd for example) until the quota is exceeded or very close to that.

心是晴朗的。 2024-11-08 10:10:03

我也有兴趣进行“磁盘已满”测试。 (我编写了一些对磁盘满场景敏感的 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

I am also interested in doing "disk full" testing. (I wrote some Java code that is sensitive to disk full scenarios, but I need to test it.)

To expand upon Noufal Ibrahim's idea #2, I did some research and found all the necessary commands to setup and teardown a mount for loop device. This will allow you to create a tiny temporary mount. You can fill it and do "disk full" testing.

My commands are for Debian Linux. Your paths may vary slightly.

Here is the script:

#!/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
我为君王 2024-11-08 10:10:03
  1. 您可以手动将配额设置为非常低的值,然后尝试您的命令。
  2. 您可以创建一个(比如说)10MB 的文件,然后将其格式化为 ext3 分区,并使用环回接口挂载它。然后,通过 cd 进入该安装点,最大大小将为 10MB。
  1. You can manually set your quota to something really low and then try your command.
  2. You can create a (say) 10MB file and then format it as a ext3 partition and mount it using a loopback interface. Then, cd into that mountpoint and you'll have a maximum size of 10MB.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文