Sie sind auf Seite 1von 12

Blockfilesystems

Blockfilesystems
MichaelOpdenacker ThomasPetazzoni FreeElectrons

Copyright20042011,FreeElectrons. CreativeCommonsBYSA3.0license Latestupdate:Nov25,2011, Documentsources,updatesandtranslations: http://freeelectrons.com/docs/blockfilesystems Corrections,suggestions,contributionsandtranslationsarewelcome!

FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Blockvs.flash
Storagedevicesareclassifiedintwomaintypes:blockdevices andflashdevices
Theyarehandledbydifferentsubsystemsanddifferentfilesystems

Blockdevicescanbereadandwrittentoonaperblockbasis, withouterasing,anddonotwearoutwhenbeingusedforalong time


Harddisks,floppydisks,RAMdisks USBkeys,CompactFlash,SDcard,thesearebasedonflashes, buthaveanintegratedcontrollerthatemulatesablockdevice

Flashedevicescanberead,butwritingrequireserasing,and oftenoccursonalargersizethantheblocksize
NORflash,NANDflash
2
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Traditionalblockfilesystems
Traditionalfilesystems Canbeleftinanoncoherentstateafterasystemcrash orsuddenpoweroff,whichrequiresafullfilesystem checkafterreboot. ext2:traditionalLinuxfilesystem (repairitwithfsck.ext2) vfat:traditionalWindowsfilesystem (repairitwithfsck.vfatonGNU/LinuxorScandisk onWindows)

3
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Journaledfilesystems
Designedtostayina correctstateeven aftersystemcrashes orasuddenpoweroff Allwritesarefirst describedinthe journalbeforebeing committedtofiles
Application
Userspace Kernelspace (filesystem) Writetofile

Writeanentry inthejournal Write tofile Clear journalentry

4
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Filesystemrecoveryaftercrashes
Reboot Reboot

No Discard Discard incomplete incomplete journalentries journalentries

Journal Journal empty? empty?

Thankstothejournal, thefilesystemisnever leftinacorrupted state Recentlysaveddata couldstillbelost

Yes Execute Execute journal journal FilesystemOK FilesystemOK

5
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Journaledblockfilesystems
Journaledfilesystems ext3:ext2withjournalextension ext4:thenewgenerationwithmanyimprovements. Readyforproduction.Theyarethedefaultfilesystemsforall Linuxsystemsintheworld. TheLinuxkernelsupportsmanyotherfilesystems:reiserFS, JFS,XFS,etc.Eachofthemhavetheirowncharacteristics,but aremoreorientedtowardsserverorscientificworkloads btrfs(ButterFS) Thenextgeneration.Inmainlinebutstillexperimental.

6
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Creatingext2/ext3volumes
Tocreateanemptyext2/ext3filesystemonablockdeviceor insideanalreadyexistingimagefile
mkfs.ext2/dev/hda3 mkfs.ext3/dev/sda2 mkfs.ext2disk.img

Tocreateafilesystemimagefromadirectorycontainingallyour filesanddirections
Usethegenext2fstool,fromthepackageofthesamename genext2fsdrootfs/rootfs.img Yourimageisthenreadytobetransferredtoyourblockdevice

7
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Squashfs
Squashfs:http://squashfs.sourceforge.net Readonly,compressedfilesystemforblockdevices> Fineforpartsofafilesystemwhichcanbereadonly(kernel,binaries...) Greatcompressionrateandreadaccessperformance UsedinmostliveCDsandliveUSBdistributions SupportsLZOcompressionforbetterperformance onembeddedsystemswithslowCPUs (attheexpenseofaslightlydegradedcompressionrate) AvailableinmainstreamLinuxsinceversion2.6.29. Patchesavailableforallearlierversions. Benchmarks:(roughly3timessmallerthanext3,and24timesfaster) http://elinux.org/Squash_Fs_Comparisons
8
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

SquashfsHowtouse
Needtoinstallthesquashfstoolspackage Creationoftheimage Onyourworkstation,createyourfilesystemimage: mksquashfsrootfs/rootfs.sqfs
Caution:iftheimagealreadyexistsremoveitfirst, orusethenoappendoption.

Installationoftheimage Let'sassumeyourpartitiononthetargetisin/dev/sdc1 Onyourtarget,copythefilesystemimageonthedevice (CAUTION:don'trunthisonyourworkstation! Youcoulddestroycriticalsystempartitions.) ddif=rootfs.sqfsof=/dev/sdc1 Mountyourfilesystem: mounttsquashfs/dev/sdc1/mnt/root

FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

tmpfs
UsefultostoretemporarydatainRAM: systemlogfiles,connectiondata,temporaryfiles... Don'tuseramdisks!Theyhavemanydrawbacks:fixedinsize, RemainingspacenotusableasRAM,filesduplicatedinRAM(inthe blockdeviceandfilecache)! tmpfsconfiguration:Filesystems>Pseudofilesystems LivesintheLinuxfilecache.Doesn'twasteRAM:growsandshrinksto accommodatestoredfiles.SavesRAM:noduplication;canswapout pagestodiskwhenneeded. Howtouse:chooseanametodistinguishthevarioustmpfsinstances youcouldhave.Examples: mountttmpfsvarrun/var/run mountttmpfsudev/dev SeeDocumentation/filesystems/tmpfs.txtinkernelsources.
10
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Mixingreadonlyandreadwritefilesystems
Goodideatosplityourblockstorageinto

Areadwritepartitionwithajournaledfilesystem(likeext3) Usedtostoreuserorconfigurationdata. Guaranteesfilesystemintegrityafterpowerofforcrashes. Ramstoragefortemporaryfiles(tmpfs)

readwrite userand configuration data

ext3

readwrite volatiledata

FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

RAM
11

tmpfs

BlockStorage

readonly Acompressedreadonlypartition(Squashfs) compressed Typicallyusedfortherootfilesystem(binaries,kernel...). root Compressionsavesspace.Readonlyaccessprotectsyour filesystem systemfrommistakesanddatacorruption.

Squashfs

PracticallabBlockfilesystems
Creatingpartitionsonyourblock storage Bootingyoursystemwithamixof filesystems:SquashFSfor applications,ext3forconfiguration anduserdata,andtmpfsfor temporarysystemfiles.

12
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Das könnte Ihnen auch gefallen