歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> Linux系統下生成一個指定大小的文件

Linux系統下生成一個指定大小的文件

日期:2017/3/2 16:52:46   编辑:Linux服務器
在裝系統,因此在這裡隨便記點東西。
 
  從前與經理討論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

Copyright © Linux教程網 All Rights Reserved