从前与经理讨论NVR项目的时候,他提到要预先将用户指定好的磁盘空间预留出来,这是比较容易实现的功能。不容易实现的是自己写一个文件系统,这种方法 我是不太敢照量啊,不过感兴趣的话可以到SourceForge找找开源的项目来学习,呵呵,说实在的,让我看都不一定能理解。在李素梅的帮助下,我做了 在磁盘预留空间的实验,本质上是这样的:
(1)首先在要预留空间的分区上使用dd命令生成一个指定大小的文件:
#创建一个10M的文件,名字是foobar:
# dd if=/dev/zero of=/home/foobar bs=1K count=10000
/dev/zero
From Wikipedia, the free encyclopedia
In Unix-like operating systems, /dev/zero is a special file that provides as many null characters (ASCII NULL, 0x00; not ASCII character "digit zero", "0", 0x30) as are read from it. One of the typical uses is to provide a character stream for overwriting information. Another might be to generate a clean file of a certain size. Using mmap to map /dev/zero to RAM is the BSD way of implementing shared memory.
(2)将这个文件格式化:
# mke2fs -vFm0 /home/foobar 100000000 //(1K * 10000)
(3)将这个文件mount,之后就可以向这个文件中写内容了,就好比向一个目录中写内容一样:
# mount -o loop home/foobar /mnt/mountpoint
(1)首先在要预留空间的分区上使用dd命令生成一个指定大小的文件:
#创建一个10M的文件,名字是foobar:
# dd if=/dev/zero of=/home/foobar bs=1K count=10000
/dev/zero
From Wikipedia, the free encyclopedia
In Unix-like operating systems, /dev/zero is a special file that provides as many null characters (ASCII NULL, 0x00; not ASCII character "digit zero", "0", 0x30) as are read from it. One of the typical uses is to provide a character stream for overwriting information. Another might be to generate a clean file of a certain size. Using mmap to map /dev/zero to RAM is the BSD way of implementing shared memory.
(2)将这个文件格式化:
# mke2fs -vFm0 /home/foobar 100000000 //(1K * 10000)
(3)将这个文件mount,之后就可以向这个文件中写内容了,就好比向一个目录中写内容一样:
# mount -o loop home/foobar /mnt/mountpoint