Sie sind auf Seite 1von 8

Prev

Chapter3.FilesystemandDevices(203)

Next

Chapter3.FilesystemandDevices(203)
Thistopichasaweightof10pointsandcontainsthefollowingfourobjectives:
Objective203.1OperatingtheLinuxfilesystem(4points)
CandidatesshouldbeabletoproperlyconfigureandnavigatethestandardLinux
filesystem.Thisobjectiveincludesconfiguringandmountingvariousfilesystem
types.
Objective203.2MaintainingaLinuxfilesystem(3points)
CandidatesshouldbeabletoproperlymaintainaLinuxfilesystemusingsystem
utilities.Thisobjectiveincludesmanipulatingstandardfilesystems.
Objective203.3Creatingandconfiguringfilesystemoptions(2points)
CandidatesshouldbeabletoconfigureautomountfilesystemsusingAutoFS.
Thisobjectiveincludesconfiguringautomountfornetworkanddevice
filesystems.AlsoincludediscreatingfilesystemsfordevicessuchasCD
ROMs.

OperatingTheLinuxFilesystem(203.1)
CandidatesshouldbeabletoproperlyconfigureandnavigatethestandardLinux
filesystem.Thisobjectiveincludesconfiguringandmountingvariousfilesystemtypes.
KeyKnowledgeAreas:
Theconceptofthefstabconfiguration
ToolsandutilitiesforhandlingSWAPpartitionsandfiles
UseofUUIDsforidentifyingandmountingfilesystems
Thefollowingisapartiallistofusedfiles,terms,andutilities:
/etc/fstab
/etc/mtab
/proc/mounts
mountandumount
sync
swapon
swapoff
blkid
Resources:LinuxRef07,Wirzenius98.

TheFileHierarchy
Historically,thelocationofcertainfilesandutilitieshasnotalwaysbeenstandard(or
fixed).Thishasledtoproblemswithdevelopmentandupgradingbetweendifferent
"distributions"ofLinux.TheLinuxdirectorystructure(orfilehierarchy)wasbasedon
existingflavorsofUNIX,butasitevolved,certaininconsistenciescameintobeing.

Thesewereoftensmallthingssuchasthelocation(orplacement)ofcertain
configurationfiles,butthisresultedindifficultiesportingsoftwarefromhosttohost.
Toequalizethesedifferencesafilestandardwasdeveloped.This,todate,isan
evolvingprocessresultinginafairlystaticmodelfortheLinuxfilehierarchy.This
filesystemhierarchyisstandardizedinthefilesystemhierarchystandard.Thecurrent
versionis2.3.MoreinformationanddocumentationontheFHScanbefoundat
FilesystemHierarchyStandardhomepage.SeealsothesectionontheFHSstandard.
ThetopleveloftheLinuxfilehierarchyisreferredtoastheroot(or/).Theroot
directorytypicallycontainsseveralotherdirectories.Anoverviewwasalready
presentedinthesectionthatdiscussesthecontentsoftherootfilesystem.Arecap:

Requiredboottimebinaries
boot/
BootconfigurationfilesfortheOSloaderandkernelimage
dev/
Devicefiles
etc/
Systemconfigurationfilesandscripts
home/
Userhomedirectories
lib/
MainOSsharedlibrariesandkernelmodules
lost+found/ Storagedirectoryforrecoveredfiles
Mountpoint(s)forremovablemedialikeCDROM's,flashdisks
media/
andfloppies
Temporarymountpointforfilesystemsasneededbyasystem
mnt/
administrator
Reservedfortheinstallationoflargeaddonapplicationsoftware
opt/
packages
A"virtual"filesystemusedbyLinuxsystemstostoreinformation
proc/
aboutthekernel,processesandcurrentresourceusage
Linux(nonstandard)homedirectoryfortherootuser.Alternate
root/
locationbeingthe/directoryitself
sbin/
Systemadministrationbinariesandtools
tmp/
Locationoftemporaryfiles
Shareable,readonlydata,containinge.g.usercommands,C
usr/
programsheaderfilesandnonvitalsystembinaries
Variabledata,usuallymachinespecific.Includesspooldirectories
var/
formailandnews,administrativeandloggingdata
bin/

Generally,therootshouldnotcontainanyadditionalfilesapossibleexceptionwould
bemountpointsforvariouspurposes.

Filesystems
Afilesystemconsistsofmethodsanddatastructuresthatanoperatingsystemusesto
keeptrackoffilesonadiskorpartitionthatis,thewaythefilesareorganisedonthe
disk.Thewordisalsousedtorefertoapartitionordiskthatisusedtostorethefilesor
thetypeofthefilesystem.Thus,onemightsayIhavetwofilesystemsmeaningone
hastwopartitionsonwhichfilesarestored,oronemightsayIamusingtheXFS
filesystem,meaningthetypeofthefilesystem.

Important
Thedifferencebetweenadiskorpartitionandthefilesystemitcontains
isimportant.Afewprograms(includingthosethatcreatefilesystems)
operatedirectlyontherawsectorsofadiskorpartitionifafilesystem
isalreadythereitwillbedestroyedorseriouslycorrupted.Most
programsoperateonafilesystem,andthereforewon'tworkona
partitionthatdoesn'tcontainone(orthatcontainsafilesystemofthe
wrongtype).
Beforeapartitionordiskcanbeusedasafilesystem,itneedstobeinitialized,andthe

bookkeepingdatastructuresneedtobewrittentothedisk.Thisprocessiscalled
makingafilesystem.
MostUNIXfilesystemtypeshaveasimilargeneralstructure,althoughtheexactdetails
varyquiteabit.Thecentralconceptsaresuperblock,inode,datablock,directory
block,andindirectionblock.Thesuperblockcontainsinformationaboutthefilesystem
asawhole,suchasitssize(theexactinformationheredependsonthefilesystem).An
inodecontainsallinformationaboutafile,exceptitsname.Thenameisstoredinthe
directory,togetherwiththenumberoftheinode.Adirectoryentryconsistsofa
filenameandthenumberoftheinodewhichrepresentsthefile.Theinodecontainsthe
numbersofseveraldatablocks,whichareusedtostorethedatainthefile.Thereis
spaceonlyforafewdatablocknumbersintheinode,however,andifmoreare
needed,morespaceforpointerstothedatablocksisallocateddynamically.These
dynamicallyallocatedblocksareindirectblocksthenameindicatesthatinordertofind
thedatablock,onehastofinditsnumberintheindirectblockfirst.

CreatingFilesystems
Beforeapartitioncanbemounted(orused),afilesystemmustfirstbeinstalledonit
withext2,thisistheprocessofcreatinginodesanddatablocks.
Thisprocessistheequivalentofinitializingthepartition.UnderLinux,thecommandto
createafilesystemiscalledmkfs.
Thecommandisissuedinthefollowingway:
mkfs[c][tfstype]filesystem[blocks]

e.g.
mkfstext2/dev/fd0#Makeaext2filesystemonafloppy

where:
c
forcesacheckforbadblocks
tfstype
specifiesthefilesystemtype.Formostfilesystemtypesthereisashorthandfor
thise.g.:mkfstext2canalsobecalledasmke2fsormkfs.ext2andmkfs
tvfatormkfstmsdoscanalsobecalledasmkfs.vfat,mkfs.msdosor
mkdosfs
filesystem
iseitherthedevicefileassociatedwiththepartitionordeviceORisthedirectory
wherethefilesystemismounted(thisisusedtoerasetheoldfilesystemand
createanewone)

Note
Creatingafilesystemonadevicewithanexistingfilesystemwillcause
alldataontheoldfilesystemtobeerased.

MountingandUnmounting
Linuxpresentsallfilesystemsasonedirectorytree.Hencetoaddanewdevicewitha
filesystemonititsfilesystemneedstobemadepartofthatonedirectorytree.Theway
thisisdoneisbyattachingthenewfilesystemunderanexisting(preferablyempty)
directory,whichispartoftheexistingdirectorytreethemountpoint.
Toattachanewfilesystemtothedirectoryhierarchyyoumustmountitsassociated
devicefile.Firstyouwillneedtocreatethemountpointadirectorywherethedevice

willbeattached.Asdirectoriesarepartofafilesystemtoothemountpointexistsona
previouslymounteddevice.Itshouldbeempty.Ifisisnotthefilesinthedirectorywill
notbevisiblewhilethedeviceismountedtoit,butwillreappearafterthedevicehas
beendisconnected(orunmounted).Thistypeofsecuritybyobscurityissometimes
usedtohideinformationfromthecasualonlooker.
Tomountadevice,usethemountcommand:
mount[options]device_filemount_point

Withsomedevices,mountwilldetectwhattypeoffilesystemexistsonthedevice,
howeveritismoreusualtousemountintheformof:
mount[options]tfile_system_typedevice_filemount_point

Generally,onlytherootusercanusethemountcommandmainlyduetothefactthat
thedevicefilesareownedbyroot.Forexample,tomountthefirstpartitiononthe
second(IDE)harddriveoffthe/usrdirectoryandassumingitcontainedtheext2
filesystem,you'denterthecommand:
mounttext2/dev/hdb1/usr

Acommondevicethatismountedisthefloppydrive.Afloppydiskgenerallycontains
theFAT,alsoknownasmsdos,filesystem(butnotalways)andismountedwiththe
command:
mounttmsdos/dev/fd0/mnt

Notethatthefloppydiskwasmountedunderthe/mntdirectory.Thisisbecausethe
/mntdirectoryistheusualplacetotemporarilymountdevices.
Toseewhichdevicesyoucurrentlyhavemounted,simplytypethecommandmount.
Somesampleoutput:
/dev/hda3on/typeext2(rw)
/dev/hda1on/dostypemsdos(rw)
noneon/proctypeproc(rw)
/dev/cdromon/cdromtypeiso9660(ro)
/dev/fd0on/mnttypemsdos(rw)

Eachlineshowswhichdevicefileismounted,whereitismounted,whatfilesystem
typeeachpartitionisandhowitismounted(ro=readonly,rw=read/write).Notethe
strangeentryonlinethreetheprocfilesystem.Thisisaspecial"virtual"filesystem
usedbyLinuxsystemstostoreinformationaboutthekernel,processesandcurrent
resourceusage.Itisactuallypartofthesystem'smemoryinotherwords,thekernel
setsasideanareaofmemoryinwhichitstoresinformationaboutthesystem.This
sameareaismountedontothefilesystemsothatuserprogramshaveaccesstothis
information.
Theinformationintheprocfilesystemcanalsobeusedtoseewhichfilesystemsare
mountedbyissuingthecommand:
$cat/proc/mounts
/dev/root/ext2rw00
proc/procprocrw00
/dev/hda1/dosmsdosrw00
/dev/cdrom/cdromiso9660ro00
/dev/fd0/mntmsdosrw00

Thedifferencebetween/etc/mtaband/proc/mountsisthat/etc/mtabistheuser
spaceadministrationkeptbymount,and/proc/mountsistheinformationkeptby
thekernel.Thelatterreflectstheinformationinuserspace.Duetothesedifferent
implementationstheinfoin/proc/mountsisalwaysuptodate,whiletheinfoin
/etc/mtabmaybecomeinconsistent.
Toreleaseadeviceanddisconnectitfromthefilesystem,theumountcommandis
used.Itisissuedintheform:
umountdevice_file

or
umountmount_point

Forexample,toreleasethefloppydisk,you'dissuethecommand:
umount/dev/fd0

or
umount/mnt

Again,youmustbetherootuserorauserwithprivilegestodothis.Youcan'tunmount
adevice/mountpointthatisinusebyauser(e.g.theuser'scurrentworkingdirectory
iswithinthemountpoint)orisinusebyaprocess.Norcanyouunmount
devices/mountpointswhichinturnhavedevicesmountedtothem.
Thesystemneedstomountdevicesduringboot.IntrueUNIXfashion,thereisafile
whichgovernsthebehaviourofmountingdevicesatboottime.InLinux,thisfileis
/etc/fstab.Linesfromthefileusethefollowingformat:
device_filemount_pointfile_system_typemount_options[n][n]

Thefirstthreefieldsareselfexplanatorythefourthfield,mount_optionsdefineshow
thedevicewillbemounted(thisincludesinformationofaccessmodero/rw,execute
permissionsandotherinformation)informationonthiscanbefoundinthemountman
pages(notethatthisfieldusuallycontainstheworddefaults).Thefifthandsixth
fieldsareusedbythesystemutilitiesdumpandfsckrespectivelyseethenext
sectionfordetails.
There'salsoafilecalled/etc/mtab.Itliststhecurrentlymountedpartitionsinfstab
form.

Swap
SwapspaceinLinuxisapartitionorfilethatisusedtomovethecontentsofinactive
pagesofRAMtowhenRAMbecomesfull.Linuxcanuseeitheranormalfileinthe
filesystemoraseparatepartitionforswapspace.Aswappartitionisfaster,butitis
easiertochangethesizeofaswapfile(there'snoneedtorepartitionthewholehard
disk,andpossiblyinstalleverythingfromscratch).Whenyouknowhowmuchswap
spaceyouneed,youshoulduseaswappartition,butifyouareindoubt,youcoulduse
aswapfilefirst,andusethesystemforawhilesothatyoucangetafeelforhowmuch
swapyouneed,andthenmakeaswappartitionwhenyou'reconfidentaboutitssize.It
isrecommendedtouseaseparatepartition,becausethisexcludeschancesoffile
systemfragmentation,whichwouldreduceperformance.Also,byusingaseparate

swappartition,itcanbeguaranteedthattheswapregionisatthefastestlocationofthe
disk.OncurrentHDDsthisisatthebeginningoftheplatters(outsiderim,first
cylinders).Itispossibletouseseveralswappartitionsand/orswapfilesatthesame
time.Thismeansthatifyouonlyoccasionallyneedanunusualamountofswapspace,
youcansetupanextraswapfileatsuchtimes,insteadofkeepingthewholeamount
allocatedallthetime.
Thecommandmkswapisusedtoinitializeaswappartitionoraswapfile.Thepartition
orfileneedstoexistbeforeitcanbeinitialized.Aswappartitioniscreatedwithadisk
partitioningtoollikefdiskandaswapfilecanbecreatedwith:
ddif=/dev/zeroof=swapfilebs=1024count=65535

Whenthepartitionorfileiscreated,itcanbeinitializedwith:
mkswap{device|file}

Aninitializedswapspaceistakenintousewithswapon.Thiscommandtellsthe
kernelthattheswapspacemaybeused.Thepathtotheswapspaceisgivenasthe
argument,sotostartswappingonatemporaryswapfileonemightusethefollowing
command:
swapon/swapfile

or,whenusingaswappartition:
swapon/dev/hda8

Swapspacesmaybeusedautomaticallybylistingtheminthefile/etc/fstab:
/dev/hda8noneswapsw00
/swapfilenoneswapsw00

Thestartupscriptswillrunthecommandswapona,whichwillstartswappingonall
theswapspaceslistedin/etc/fstab.Therefore,theswaponcommandisusually
usedonlywhenextraswapisneeded.Youcanmonitortheuseofswapspaceswith
free.Itwillreportthetotalamountofswapspaceused:
$free
totalusedfreesharedbufferscached
Mem:12714812258845600158469352
/+buffers/cache:5165275496
Swap:1307485771673032

Thefirstlineofoutput(Mem:)showsthephysicalmemory.Thetotalcolumndoes
notshowthephysicalmemoryusedbythekernel,whichisloadedintotheRAM
memoryduringthebootprocess.Theusedcolumnshowstheamountofmemory
used(thesecondlinedoesnotcountbuffers).Thefreecolumnshowscompletely
unusedmemory.Thesharedcolumnshowstheamountofmemorysharedbyseveral
processesThebufferscolumnshowsthecurrentsizeofthediskbuffercache.
Thatlastline(Swap:)showssimilarinformationfortheswapspaces.Ifthislineisall
zeroes,swapspaceisnotactivated.
Thesameinformation,inaslightlydifferentformat,canbeshownbyusingcatonthe
file/proc/meminfo:

$cat/proc/meminfo
totalusedfreesharedbufferscached
Mem:13019955212517785650216960162201689280512
Swap:1338859525910118474784768
MemTotal:127148kB
MemFree:4904kB
MemShared:0kB
Buffers:1584kB
Cached:69120kB
SwapCached:18068kB
Active:80240kB
Inactive:31080kB
HighTotal:0kB
HighFree:0kB
LowTotal:127148kB
LowFree:4904kB
SwapTotal:130748kB
SwapFree:73032kB

Todisableadeviceorswapfile,usetheswapoffcommand:
#swapoff/dev/sda3

UUIDs
ThetermUUIDstandsforUniversalUniqueIDentifier.It'sa128bitnumberthatcanbe
usedtoidentifybasicallyanything.GeneratingsuchUUIDscanbedoneusing
appropriatesoftware.Thereare5variousversionsofUUIDs,allofthemusea
(pseudo)randomelement,currentsystemtimeandsomemostlyuniquehardwareID,
forexampleaMACaddress.Theoreticallythereisavery,veryremotechanceofan
UUIDnotbeingunique,butthisisseenasimpossibleinpractice.
OnLinux,supportforUUIDswasstartedwithinthee2fsprogspackage.With
filesystems,UUIDsareusedtorepresentaspecificfilesystem.Youcanforexample
usetheUUIDin/etc/fstabtorepresentthepartitionwhichyouwanttomount.
Usually,aUUIDisrepresentedas32hexadecimaldigits,groupedinsequencesof
8,4,4,4and12digits,separatedbyhyphens.Here'swhatanfstabentrywithaUUID
specifierlookslike:
UUID=652b786eb87f49d2af238087ced0c828/ext4errors=remountro,noatime01

YoumightbewonderingabouttheuseofUUID'sinfstab,sincedevicenameswork
fine.UUIDscomeinhandywhendisksaremovedtodifferentconnectorsor
computers,multipleoperatingsystemsareinstalledonthecomputer,orothercases
wheredevicenamescouldchangewhilekeepingthefilesystemintact.Aslongasthe
filesystemdoesnotchange,theUUIDstaysthesame.
Notethe'aslongasthefilesystemdoesnotchange'.Thismeans,whenyoureformata
partition,theUUIDwillchange.Forexample,whenyouusemke2fstoreformat
partition/dev/sda3,theUUIDwillbechanged.So,ifyouuseUUIDsin/etc/fstab,
youhavetoadjustthoseaswell.
IfyouwanttoknowtheUUIDofaspecificpartition,useblkid/path/to/partition:
#blkid/dev/sda5
/dev/sda5:UUID="24df5f2aa23f4130ae4590e1016031bc"TYPE="swap"

Note
Itispossibletocreateanewfilesystemandstillmakeithavethesame
UUIDasithadbefore,atleastfor'ext'typefilesystems.
#tune2fs/dev/sda5U24df5f2aa23f4130ae4590e1016031bc

Note
OnmostLinuxdistributionsyoucangenerateyourownUUIDsusing
thecommanduuidgen.

sync
ToimproveperformanceofLinuxfilesystems,manyoperationsaredoneinfilesystem
buffers,storedinRAM.Toactuallyflushthedatacontainedinthesebufferstodisk,the
synccommandisused.
synciscalledautomaticallyattherightmomentwhenrebootingorhaltingthesystem.
Youwillrarelyneedtousethecommandyourself.syncmightbeusedtoforcesyncing
datatoanUSBdevicebeforeremovingitfromyoursystem,forexample.
syncdoesnothaveanyoperationinfluencingoptions,sowhenyouneedto,just
execute"sync"onthecommandline.
CopyrightSnowB.V.TheNetherlands

Prev
Questionsandanswers

Home

Next
MaintainingaLinux
Filesystem(203.2)

Das könnte Ihnen auch gefallen