Creating a Compressed RAM Disk a) Decide on the RAM disk size that you want. Say 8 MB for this example.
dd if=/dev/zero of=ramdisk bs=1k count=8192
b) Make a filesystem on it. Say ext2fs for this example.
$mke2fs -F -vm0 ramdisk
mke2fs 1.38 (22-April-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
2048 inodes, 8192 blocks
409 blocks (4.99%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 16 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
and unmount it again.
$mount -o loop ramdisk /mnt
$ls /mnt
lost+found
$df -h /mnt
Filesystem 容量 已用 可用 已用% 掛載點
/mnt 7.8M 1.0K 7.4M 1% /mnt
$umount /mnt
d)compress
$gzip -9 ramdisk
-9使用最高級的壓縮算法,大約60%的壓縮比.得到ramdisk.gz
$mv ramdisk.gz ramdisk.image.gz
$gunzip ramdisk.image.gz
JFFS2
mkdir /jffs2_dir
這樣做就是你新做的jffs2.img里面除了你剛剛添加的hello外沒有任何目錄和文件,而這完全可以工作,啟動后自己添加即可。
mkfs.jffs2 -d /jffs2_dir -o jffs2.img
這個mkfs.jffs2工具是要額外提供的,如果您沒有,可發(fā)信索取。
mkfs.jffs2 -r rootfs/ -o jffs2.img
-r指定內(nèi)含有根文件系統(tǒng)的目錄,并使用-o來指定文件系統(tǒng)映像的輸出文件名稱.
-l or -b建立字節(jié)順序為little endian或big endian.
jffs2的壓縮比僅為10%高一點..
eraseall /dev/mtd5
Erased 8192 Kibyte @ 0 -- 100% complete.
cat jffs2.img >/dev/mtd5
mount -t jffs2 /dev/mtdblock/5 /jffs2
與磁盤文件系統(tǒng)不同,無法在loopback設(shè)備上使用mount -o loop ...命令jffs2。你必須從真正的MTD設(shè)備來安裝jffs2。
CRAMFS
對于CRAMFS:
和JFFS2完全相同的做法,你也完全可以自己
mkdir /cramfs_dir
mkcramfs /cramfs_dir cramfs.img
當(dāng)然了,和JFFS2不同的是,它是只讀的,你在PC機(jī)上添加了什么,到板子上就只能有什么,不能再動態(tài)創(chuàng)建目錄和復(fù)制進(jìn)去文件了,要添加必須重做cramfs.img燒寫到FLASH上才行。
這個mkcramfs的工具是REDHAT LINUX自帶的。
mount -t cramfs /dev/mtdblock/5 /cramfs
- 每個文件最大不超過16M;
- 不提供.和..目錄;
- 文件的uid具有16bits的width,gid有8bits的寬度.一般的文件系統(tǒng)通常會支持寬度16/32的uid和gid,CRAMFS, GIDs are truncated to the lower 8 bits.In other words, the maximum GID usable in a root filesystem built on CRAMFS is 255.
- 所有文件的時間戳?xí)辉O(shè)成Unix epoch(00:00:00 GMT, January 1, 1970).The timestamps may be
updated at runtime, but the updated values will last only as long as the inode is cached in memory;Once the file is reloaded, its timestamp will revert to epoch.
- CRAMFS images can be read only by kernels using 4096-byte page sizes (The value of
PAGE_CACHE_SIZE must be 4096).
- All files, whether they are linked or not, have a link count of 1. Even when multiple filesystem entries point to the same file, that file has a link count of only 1. This is fine for most operations,however, since no files can actually be deleted from CRAMFS.
NFTL
mke2fs /dev/nftla1
mount -t ext2 /dev/nftla1 /mnt
NFTL上的ext2并不提供"斷電可靠性"。如有這方面需要,可使用日志型文件系統(tǒng),如ext3,XFS,jfs或reiserfs.
Filesystem characteristics
Filesystem Write Persistent Power down reliability Compression Lives in RAM
CRAMFS No N/A N/A Yes No
JFFS2 Yes Yes Yes Yes No
JFFS Yes Yes Yes No No
Ext2overNFTL Yes Yes No No No
Ext3overNFTL Yes Yes Yes No No
Ext2overRAMdisk Yes No No No Yes