You are on page 1of 22

EmbeddedLinuxTraining

System
administration
basics
MichaelOpdenacker
ThomasPetazzoni
FreeElectrons

Copyright2009,FreeElectrons.
CreativeCommonsBYSA3.0license
Latestupdate:Dec20,2010,
Documentsources,updatesandtranslations:
http://freeelectrons.com/docs/commandline
Corrections,suggestions,contributionsandtranslationsarewelcome!

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

Systemadministrationbasics

Networking

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

Networksetup(1)
ifconfiga
Printsdetailsaboutallthenetworkinterfaces
availableonyoursystem.
ifconfigeth0
Listsdetailsabouttheeth0interface
ifconfigeth0192.168.0.100
Assignsthe192.168.0.100IPaddress
toeth0(1IPaddressperinterface).
ifconfigeth0down
Shutsdowntheeth0interface
(freesitsIPaddress).

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

Networksetup(2)
routeadddefaultgw192.168.0.1
Setsthedefaultrouteforpacketsoutsidethelocal
network.Thegateway(here192.168.0.1)is
responsibleforsendingthemtothenextgateway,etc.,
untilthefinaldestination.
routen
Liststheexistingroutes

noption:immediatelydisplaysipaddresses
insteadoftryingtofindtheirdomain
names

routedeldefault
orroutedel<IP>
Deletesthegivenroute
Usefultoredefineanewroute.

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

Networksetup(3)
YourprogramsneedtoknowwhatIPaddresscorrespondsto
agivenhostname(suchaskernel.org)
DomainNameServers(DNS)takecareofthis.
YoujusthavetospecifytheIPaddressof1ormoreDNS
serversinyour/etc/resolv.conffile:
nameserver217.19.192.132
nameserver212.27.32.177
Thechangestakeeffectimmediately!

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

Networktesting

First,trytopingtheIPaddressofyourgateway.
Thiswillconfirmthatyournetworkadapterworksfine.
Then,makesureyoucanpingthenameserverIPaddress,
whichwillconfirmthatyourgatewayisconfiguredproperly.
Finally,makesureyoucanpinganyhostusingitsname,which
willconfirmthatthenameserverconfigurationiscorrect.

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

Systemadministrationbasics

Filesystemsanddevices

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

Creatingfilesystems
Examples
mkfs.ext2/dev/sda1
FormatsyourUSBkey(/dev/sda1:1stpartitionrawdata)inext2
format.
F:force.Executeeven
mkfs.ext2Fdisk.img
Formatsadiskimagefileinext2format

ifnotarealdevicefile.

mkfs.vfatvF32/dev/sda1(v:verbose)
FormatsyourUSBkeybacktoFAT32format.
mkfs.vfatvF32disk.img
FormatsadiskimagefileinFAT32format.
Blankdiskimagescanbecreatedasinthebelowexample(64MBfile):
ddif=/dev/zeroof=disk.imgbs=1Mcount=64

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

Mountingdevices(1)
Tomakefilesystemsonanydevice
(internalorexternalstorage)
visibleonyoursystem,youhavetomountthem.
Thefirsttime,createamountpointinyoursystem:
mkdir/mnt/usbdisk(example)
Now,mountit:
mounttvfat/dev/sda1/mnt/usbdisk
/dev/sda1:physicaldevice
t:specifiesthefilesystem(format)type
(ext2,ext3,vfat,reiserfs,iso9660...)

rawdata

(filedescriptors
andfilecontents)

mount

file
structure

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

Mountingdevices(2)
Youcanalsomountafilesystemimage
storedinaregularfile(loopdevices)
Usefultodevelopfilesystemsforanothermachine
UsefultoaccessthecontentsofanISOcdromimage
withouthavingtoburnit.
UsefultohaveaLinuxfilesysteminsideafileinaWindows
partition.
cp/dev/sda1usbkey.img
mountolooptvfatusbkey.img/mnt/usbdisk

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

Listingmountedfilesystems
Justusethemountcommandwithnoargument:
/dev/hda6on/typeext3(rw,noatime)
noneon/proctypeproc(rw,noatime)
noneon/systypesysfs(rw)
noneon/dev/ptstypedevpts(rw,gid=5,mode=620)
usbfson/proc/bus/usbtypeusbfs(rw)
/dev/hda4on/datatypeext3(rw,noatime)
noneon/dev/shmtypetmpfs(rw)
/dev/hda1on/wintypevfat(rw,uid=501,gid=501)
noneon/proc/sys/fs/binfmt_misctypebinfmt_misc(rw)

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

Unmountingdevices
umount/mnt/usbdisk
Commitsallpendingwritesandunmountsthegivendevice,
whichcanthenberemovedinasafeway.
Tobeabletounmountadevice,youhavetocloseallthe
openfilesinit:
Closeapplicationsopeningdatainthemountedpartition
Makesurethatnoneofyourshellshaveaworkingdirectoryin
thismountpoint.
Youcanrunthelsof<mountpoint>command(list
openfiles)toviewwhichprocessesstillhaveopenfilesinthe
mountedpartition.

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

Systemadministrationbasics

Packagemanagement

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

Bewareofthedarksideofroot
rootuserprivilegesareonlyneededforveryspecific
taskswithsecurityrisks:mounting,creatingdevice
files,loadingdrivers,startingnetworking,
changingfileownership,packageupgrades...
Evenifyouhavetherootpassword,yourregular
accountshouldbesufficientfor99.9%ofyourtasks
(unlessyouareasystemadministrator).
Inatrainingsession,itisacceptabletouseroot.
Inreallife,youmaynotevenhaveaccesstothis
account,orputyoursystemsanddataatriskifyou
do.

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

Usingtherootaccount
Incaseyoureallywanttouseroot...
Ifyouhavetherootpassword:
su(switchuser)
Inmoderndistributions,thesudocommandgivesyouaccesstosome
rootprivilegeswithyourownuserpassword.
Example:sudomount/dev/hda4/home

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

Softwarepackages
ThedistributionmechanismforsoftwareinGNU/Linuxisdifferent
fromtheoneinWindows
Linuxdistributionsprovidesacentralandcoherentwayof
installing,updatingandremovingapplicationsandlibraries:
packages
Packagescontainstheapplicationorlibraryfiles,andassociated
metainformation,suchastheversionandthedependencies
.debonDebianandUbuntu,.rpmonMandriva,Fedora,OpenSUSE

Packagesarestoredinrepositories,usuallyonHTTPorFTP
servers
Oneshouldonlyusepackagesfromofficialrepositoriesofits
distribution,unlessstrictlyrequired.
16
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Managingsoftwarepackages(1)
InstructionsforDebianbasedGNU/Linuxsystems
(Debian,Ubuntu...)
Packagerepositoriesarespecifiedin
/etc/apt/sources.list
Toupdatepackagerepositorylists:
sudoaptgetupdate
Tofindthenameofapackagetoinstall,thebestistousethe
searchengineonhttp://packages.debian.orgoron
http://packages.ubuntu.com.Youmayalsouse:
aptcachesearch<keyword>

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

Managingsoftwarepackages(2)
Toinstallagivenpackage:
sudoaptgetinstall<package>
Toremoveagivenpackage:
sudoaptgetremove<package>
Toinstallallavailablepackageupdates:
sudoaptgetdistupgrade
Getinformationaboutapackage:
sudoaptcacheshow<package>
Graphicalinterfaces
SynapticforGNOME
AdeptforKDE

Furtherdetailsonpackagemanagement:
http://www.debian.org/doc/manuals/apthowto/
18
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Shuttingdown
halt
Immediatelyhaltsthesystem.
reboot
Immediatelyrebootsthesystem.
[Ctrl][Alt][Del]
AlsoworksonGNU/Linuxtoreboot.
Embeddedsystems:youmustuseanimplementationof
initandcanspecifyanykeycombinationin
/etc/inittab.

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

Relateddocuments

Allourtechnicalpresentations
onhttp://freeelectrons.com/docs
Linuxkernel
Devicedrivers
Architecturespecifics
EmbeddedLinuxsystemdevelopment
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Howtohelp
Youcanhelpustoimproveandmaintainthisdocument...
Bysendingcorrections,suggestions,contributionsand
translations
Byaskingyourorganizationtoorderdevelopment,consulting
andtrainingservicesperformedbytheauthorsofthese
documents(seehttp://freeelectrons.com/).
Bysharingthisdocumentwithyourfriends,colleagues
andwiththelocalFreeSoftwarecommunity.
Byaddinglinksonyourwebsitetoouronlinematerials,
toincreasetheirvisibilityinsearchengineresults.

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

Linuxkernel
Linuxdevicedrivers
Boardsupportcode
Mainstreamingkernelcode
Kerneldebugging
EmbeddedLinuxTraining
Allmaterialsreleasedwithafreelicense!
UnixandGNU/Linuxbasics
Linuxkernelanddriversdevelopment
RealtimeLinux,uClinux
Developmentandprofilingtools
Lightweighttoolsforembeddedsystems
Rootfilesystemcreation
Audioandmultimedia
Systemoptimization

FreeElectrons
Ourservices
CustomDevelopment
Systemintegration
EmbeddedLinuxdemosandprototypes
Systemoptimization
Applicationandinterfacedevelopment
Consultingandtechnicalsupport
Helpindecisionmaking
Systemarchitecture
Systemdesignandperformancereview
Developmenttoolandapplicationsupport
Investigatingissuesandfixingtoolbugs

You might also like