試試Fedora 20裡頭的File System on File

來源:互聯網
上載者:User

Create a file to host the fs.  Can also use dd here instead of truncate.
    $ truncate -s 128M bigfile
    $ du -csh bigfile
    $ stat bigfile


Create a fs on the file. There will be some warnings saying it is not a block device.

    $ mke2fs -t ext4 bigfile
    $ stat bigfile 


Find the first unused loop device, then create it.

    $ losetup -f
    $ sudo losetup /dev/loop0 bigfile


Finnally, we can mount the fs.

    $ sudo mkdir /mnt/fsof
    $ sudo mount -t ext4 /dev/loop0 /mnt/fsof
    $ mount | grep loop0
    /dev/loop0 on /mnt/fsof type ext4 (rw,relatime,seclabel,data=ordered)


Now, let us do some experiments on the fs on a file.
    $ sudo dd iflag=fullblock if=/dev/random of=largefile count=4096 bs=4096
    The performance is not so good, be patient please.
    
    $ sudo fallocate -p -o 4096 -l 8192 largefile 
    Puch a hole, and we can find the blocks used is reduced using: 
    $ du -c largefile
    Or
    $ stat largefile


Be careful to the unit of the different blocks, it may be a sector(512b), a fs block(1024b or 4096b).

===
How to Check Filesystem Block Size on Linux?
Example 1:
# tune2fs -l /dev/sda1 | grep -i ‘block size’
Block size: 4096
Example 2:
# dumpe2fs -h /dev/sda1 |grep “Block size:”
Block size: 4096
Example 3:
# blockdev –getbsz /dev/sda1
4096
Example 4:
# echo “abc” >test.txt
# du -h test.txt
4.0K test

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.