UserModeLinux-HOWTO.txt 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589
  1. User Mode Linux HOWTO
  2. User Mode Linux Core Team
  3. Mon Nov 18 14:16:16 EST 2002
  4. This document describes the use and abuse of Jeff Dike's User Mode
  5. Linux: a port of the Linux kernel as a normal Intel Linux process.
  6. ______________________________________________________________________
  7. Table of Contents
  8. 1. Introduction
  9. 1.1 How is User Mode Linux Different?
  10. 1.2 Why Would I Want User Mode Linux?
  11. 2. Compiling the kernel and modules
  12. 2.1 Compiling the kernel
  13. 2.2 Compiling and installing kernel modules
  14. 2.3 Compiling and installing uml_utilities
  15. 3. Running UML and logging in
  16. 3.1 Running UML
  17. 3.2 Logging in
  18. 3.3 Examples
  19. 4. UML on 2G/2G hosts
  20. 4.1 Introduction
  21. 4.2 The problem
  22. 4.3 The solution
  23. 5. Setting up serial lines and consoles
  24. 5.1 Specifying the device
  25. 5.2 Specifying the channel
  26. 5.3 Examples
  27. 6. Setting up the network
  28. 6.1 General setup
  29. 6.2 Userspace daemons
  30. 6.3 Specifying ethernet addresses
  31. 6.4 UML interface setup
  32. 6.5 Multicast
  33. 6.6 TUN/TAP with the uml_net helper
  34. 6.7 TUN/TAP with a preconfigured tap device
  35. 6.8 Ethertap
  36. 6.9 The switch daemon
  37. 6.10 Slip
  38. 6.11 Slirp
  39. 6.12 pcap
  40. 6.13 Setting up the host yourself
  41. 7. Sharing Filesystems between Virtual Machines
  42. 7.1 A warning
  43. 7.2 Using layered block devices
  44. 7.3 Note!
  45. 7.4 Another warning
  46. 7.5 uml_moo : Merging a COW file with its backing file
  47. 8. Creating filesystems
  48. 8.1 Create the filesystem file
  49. 8.2 Assign the file to a UML device
  50. 8.3 Creating and mounting the filesystem
  51. 9. Host file access
  52. 9.1 Using hostfs
  53. 9.2 hostfs as the root filesystem
  54. 9.3 Building hostfs
  55. 10. The Management Console
  56. 10.1 version
  57. 10.2 halt and reboot
  58. 10.3 config
  59. 10.4 remove
  60. 10.5 sysrq
  61. 10.6 help
  62. 10.7 cad
  63. 10.8 stop
  64. 10.9 go
  65. 11. Kernel debugging
  66. 11.1 Starting the kernel under gdb
  67. 11.2 Examining sleeping processes
  68. 11.3 Running ddd on UML
  69. 11.4 Debugging modules
  70. 11.5 Attaching gdb to the kernel
  71. 11.6 Using alternate debuggers
  72. 12. Kernel debugging examples
  73. 12.1 The case of the hung fsck
  74. 12.2 Episode 2: The case of the hung fsck
  75. 13. What to do when UML doesn't work
  76. 13.1 Strange compilation errors when you build from source
  77. 13.2 (obsolete)
  78. 13.3 A variety of panics and hangs with /tmp on a reiserfs filesystem
  79. 13.4 The compile fails with errors about conflicting types for 'open', 'dup', and 'waitpid'
  80. 13.5 UML doesn't work when /tmp is an NFS filesystem
  81. 13.6 UML hangs on boot when compiled with gprof support
  82. 13.7 syslogd dies with a SIGTERM on startup
  83. 13.8 TUN/TAP networking doesn't work on a 2.4 host
  84. 13.9 You can network to the host but not to other machines on the net
  85. 13.10 I have no root and I want to scream
  86. 13.11 UML build conflict between ptrace.h and ucontext.h
  87. 13.12 The UML BogoMips is exactly half the host's BogoMips
  88. 13.13 When you run UML, it immediately segfaults
  89. 13.14 xterms appear, then immediately disappear
  90. 13.15 Any other panic, hang, or strange behavior
  91. 14. Diagnosing Problems
  92. 14.1 Case 1 : Normal kernel panics
  93. 14.2 Case 2 : Tracing thread panics
  94. 14.3 Case 3 : Tracing thread panics caused by other threads
  95. 14.4 Case 4 : Hangs
  96. 15. Thanks
  97. 15.1 Code and Documentation
  98. 15.2 Flushing out bugs
  99. 15.3 Buglets and clean-ups
  100. 15.4 Case Studies
  101. 15.5 Other contributions
  102. ______________________________________________________________________
  103. 1. Introduction
  104. Welcome to User Mode Linux. It's going to be fun.
  105. 1.1. How is User Mode Linux Different?
  106. Normally, the Linux Kernel talks straight to your hardware (video
  107. card, keyboard, hard drives, etc), and any programs which run ask the
  108. kernel to operate the hardware, like so:
  109. +-----------+-----------+----+
  110. | Process 1 | Process 2 | ...|
  111. +-----------+-----------+----+
  112. | Linux Kernel |
  113. +----------------------------+
  114. | Hardware |
  115. +----------------------------+
  116. The User Mode Linux Kernel is different; instead of talking to the
  117. hardware, it talks to a `real' Linux kernel (called the `host kernel'
  118. from now on), like any other program. Programs can then run inside
  119. User-Mode Linux as if they were running under a normal kernel, like
  120. so:
  121. +----------------+
  122. | Process 2 | ...|
  123. +-----------+----------------+
  124. | Process 1 | User-Mode Linux|
  125. +----------------------------+
  126. | Linux Kernel |
  127. +----------------------------+
  128. | Hardware |
  129. +----------------------------+
  130. 1.2. Why Would I Want User Mode Linux?
  131. 1. If User Mode Linux crashes, your host kernel is still fine.
  132. 2. You can run a usermode kernel as a non-root user.
  133. 3. You can debug the User Mode Linux like any normal process.
  134. 4. You can run gprof (profiling) and gcov (coverage testing).
  135. 5. You can play with your kernel without breaking things.
  136. 6. You can use it as a sandbox for testing new apps.
  137. 7. You can try new development kernels safely.
  138. 8. You can run different distributions simultaneously.
  139. 9. It's extremely fun.
  140. 2. Compiling the kernel and modules
  141. 2.1. Compiling the kernel
  142. Compiling the user mode kernel is just like compiling any other
  143. kernel. Let's go through the steps, using 2.4.0-prerelease (current
  144. as of this writing) as an example:
  145. 1. Download the latest UML patch from
  146. the download page <http://user-mode-linux.sourceforge.net/
  147. In this example, the file is uml-patch-2.4.0-prerelease.bz2.
  148. 2. Download the matching kernel from your favourite kernel mirror,
  149. such as:
  150. ftp://ftp.ca.kernel.org/pub/kernel/v2.4/linux-2.4.0-prerelease.tar.bz2
  151. <ftp://ftp.ca.kernel.org/pub/kernel/v2.4/linux-2.4.0-prerelease.tar.bz2>
  152. .
  153. 3. Make a directory and unpack the kernel into it.
  154. host%
  155. mkdir ~/uml
  156. host%
  157. cd ~/uml
  158. host%
  159. tar -xzvf linux-2.4.0-prerelease.tar.bz2
  160. 4. Apply the patch using
  161. host%
  162. cd ~/uml/linux
  163. host%
  164. bzcat uml-patch-2.4.0-prerelease.bz2 | patch -p1
  165. 5. Run your favorite config; `make xconfig ARCH=um' is the most
  166. convenient. `make config ARCH=um' and 'make menuconfig ARCH=um'
  167. will work as well. The defaults will give you a useful kernel. If
  168. you want to change something, go ahead, it probably won't hurt
  169. anything.
  170. Note: If the host is configured with a 2G/2G address space split
  171. rather than the usual 3G/1G split, then the packaged UML binaries
  172. will not run. They will immediately segfault. See ``UML on 2G/2G
  173. hosts'' for the scoop on running UML on your system.
  174. 6. Finish with `make linux ARCH=um': the result is a file called
  175. `linux' in the top directory of your source tree.
  176. Make sure that you don't build this kernel in /usr/src/linux. On some
  177. distributions, /usr/include/asm is a link into this pool. The user-
  178. mode build changes the other end of that link, and things that include
  179. <asm/anything.h> stop compiling.
  180. The sources are also available from cvs at the project's cvs page,
  181. which has directions on getting the sources. You can also browse the
  182. CVS pool from there.
  183. If you get the CVS sources, you will have to check them out into an
  184. empty directory. You will then have to copy each file into the
  185. corresponding directory in the appropriate kernel pool.
  186. If you don't have the latest kernel pool, you can get the
  187. corresponding user-mode sources with
  188. host% cvs co -r v_2_3_x linux
  189. where 'x' is the version in your pool. Note that you will not get the
  190. bug fixes and enhancements that have gone into subsequent releases.
  191. 2.2. Compiling and installing kernel modules
  192. UML modules are built in the same way as the native kernel (with the
  193. exception of the 'ARCH=um' that you always need for UML):
  194. host% make modules ARCH=um
  195. Any modules that you want to load into this kernel need to be built in
  196. the user-mode pool. Modules from the native kernel won't work.
  197. You can install them by using ftp or something to copy them into the
  198. virtual machine and dropping them into /lib/modules/`uname -r`.
  199. You can also get the kernel build process to install them as follows:
  200. 1. with the kernel not booted, mount the root filesystem in the top
  201. level of the kernel pool:
  202. host% mount root_fs mnt -o loop
  203. 2. run
  204. host%
  205. make modules_install INSTALL_MOD_PATH=`pwd`/mnt ARCH=um
  206. 3. unmount the filesystem
  207. host% umount mnt
  208. 4. boot the kernel on it
  209. When the system is booted, you can use insmod as usual to get the
  210. modules into the kernel. A number of things have been loaded into UML
  211. as modules, especially filesystems and network protocols and filters,
  212. so most symbols which need to be exported probably already are.
  213. However, if you do find symbols that need exporting, let us
  214. <http://user-mode-linux.sourceforge.net/> know, and
  215. they'll be "taken care of".
  216. 2.3. Compiling and installing uml_utilities
  217. Many features of the UML kernel require a user-space helper program,
  218. so a uml_utilities package is distributed separately from the kernel
  219. patch which provides these helpers. Included within this is:
  220. o port-helper - Used by consoles which connect to xterms or ports
  221. o tunctl - Configuration tool to create and delete tap devices
  222. o uml_net - Setuid binary for automatic tap device configuration
  223. o uml_switch - User-space virtual switch required for daemon
  224. transport
  225. The uml_utilities tree is compiled with:
  226. host#
  227. make && make install
  228. Note that UML kernel patches may require a specific version of the
  229. uml_utilities distribution. If you don't keep up with the mailing
  230. lists, ensure that you have the latest release of uml_utilities if you
  231. are experiencing problems with your UML kernel, particularly when
  232. dealing with consoles or command-line switches to the helper programs
  233. 3. Running UML and logging in
  234. 3.1. Running UML
  235. It runs on 2.2.15 or later, and all 2.4 kernels.
  236. Booting UML is straightforward. Simply run 'linux': it will try to
  237. mount the file `root_fs' in the current directory. You do not need to
  238. run it as root. If your root filesystem is not named `root_fs', then
  239. you need to put a `ubd0=root_fs_whatever' switch on the linux command
  240. line.
  241. You will need a filesystem to boot UML from. There are a number
  242. available for download from here <http://user-mode-
  243. linux.sourceforge.net/> . There are also several tools
  244. <http://user-mode-linux.sourceforge.net/> which can be
  245. used to generate UML-compatible filesystem images from media.
  246. The kernel will boot up and present you with a login prompt.
  247. Note: If the host is configured with a 2G/2G address space split
  248. rather than the usual 3G/1G split, then the packaged UML binaries will
  249. not run. They will immediately segfault. See ``UML on 2G/2G hosts''
  250. for the scoop on running UML on your system.
  251. 3.2. Logging in
  252. The prepackaged filesystems have a root account with password 'root'
  253. and a user account with password 'user'. The login banner will
  254. generally tell you how to log in. So, you log in and you will find
  255. yourself inside a little virtual machine. Our filesystems have a
  256. variety of commands and utilities installed (and it is fairly easy to
  257. add more), so you will have a lot of tools with which to poke around
  258. the system.
  259. There are a couple of other ways to log in:
  260. o On a virtual console
  261. Each virtual console that is configured (i.e. the device exists in
  262. /dev and /etc/inittab runs a getty on it) will come up in its own
  263. xterm. If you get tired of the xterms, read ``Setting up serial
  264. lines and consoles'' to see how to attach the consoles to
  265. something else, like host ptys.
  266. o Over the serial line
  267. In the boot output, find a line that looks like:
  268. serial line 0 assigned pty /dev/ptyp1
  269. Attach your favorite terminal program to the corresponding tty. I.e.
  270. for minicom, the command would be
  271. host% minicom -o -p /dev/ttyp1
  272. o Over the net
  273. If the network is running, then you can telnet to the virtual
  274. machine and log in to it. See ``Setting up the network'' to learn
  275. about setting up a virtual network.
  276. When you're done using it, run halt, and the kernel will bring itself
  277. down and the process will exit.
  278. 3.3. Examples
  279. Here are some examples of UML in action:
  280. o A login session <http://user-mode-linux.sourceforge.net/login.html>
  281. o A virtual network <http://user-mode-linux.sourceforge.net/net.html>
  282. 4. UML on 2G/2G hosts
  283. 4.1. Introduction
  284. Most Linux machines are configured so that the kernel occupies the
  285. upper 1G (0xc0000000 - 0xffffffff) of the 4G address space and
  286. processes use the lower 3G (0x00000000 - 0xbfffffff). However, some
  287. machine are configured with a 2G/2G split, with the kernel occupying
  288. the upper 2G (0x80000000 - 0xffffffff) and processes using the lower
  289. 2G (0x00000000 - 0x7fffffff).
  290. 4.2. The problem
  291. The prebuilt UML binaries on this site will not run on 2G/2G hosts
  292. because UML occupies the upper .5G of the 3G process address space
  293. (0xa0000000 - 0xbfffffff). Obviously, on 2G/2G hosts, this is right
  294. in the middle of the kernel address space, so UML won't even load - it
  295. will immediately segfault.
  296. 4.3. The solution
  297. The fix for this is to rebuild UML from source after enabling
  298. CONFIG_HOST_2G_2G (under 'General Setup'). This will cause UML to
  299. load itself in the top .5G of that smaller process address space,
  300. where it will run fine. See ``Compiling the kernel and modules'' if
  301. you need help building UML from source.
  302. 5. Setting up serial lines and consoles
  303. It is possible to attach UML serial lines and consoles to many types
  304. of host I/O channels by specifying them on the command line.
  305. You can attach them to host ptys, ttys, file descriptors, and ports.
  306. This allows you to do things like
  307. o have a UML console appear on an unused host console,
  308. o hook two virtual machines together by having one attach to a pty
  309. and having the other attach to the corresponding tty
  310. o make a virtual machine accessible from the net by attaching a
  311. console to a port on the host.
  312. The general format of the command line option is device=channel.
  313. 5.1. Specifying the device
  314. Devices are specified with "con" or "ssl" (console or serial line,
  315. respectively), optionally with a device number if you are talking
  316. about a specific device.
  317. Using just "con" or "ssl" describes all of the consoles or serial
  318. lines. If you want to talk about console #3 or serial line #10, they
  319. would be "con3" and "ssl10", respectively.
  320. A specific device name will override a less general "con=" or "ssl=".
  321. So, for example, you can assign a pty to each of the serial lines
  322. except for the first two like this:
  323. ssl=pty ssl0=tty:/dev/tty0 ssl1=tty:/dev/tty1
  324. The specificity of the device name is all that matters; order on the
  325. command line is irrelevant.
  326. 5.2. Specifying the channel
  327. There are a number of different types of channels to attach a UML
  328. device to, each with a different way of specifying exactly what to
  329. attach to.
  330. o pseudo-terminals - device=pty pts terminals - device=pts
  331. This will cause UML to allocate a free host pseudo-terminal for the
  332. device. The terminal that it got will be announced in the boot
  333. log. You access it by attaching a terminal program to the
  334. corresponding tty:
  335. o screen /dev/pts/n
  336. o screen /dev/ttyxx
  337. o minicom -o -p /dev/ttyxx - minicom seems not able to handle pts
  338. devices
  339. o kermit - start it up, 'open' the device, then 'connect'
  340. o terminals - device=tty:tty device file
  341. This will make UML attach the device to the specified tty (i.e
  342. con1=tty:/dev/tty3
  343. will attach UML's console 1 to the host's /dev/tty3). If the tty that
  344. you specify is the slave end of a tty/pty pair, something else must
  345. have already opened the corresponding pty in order for this to work.
  346. o xterms - device=xterm
  347. UML will run an xterm and the device will be attached to it.
  348. o Port - device=port:port number
  349. This will attach the UML devices to the specified host port.
  350. Attaching console 1 to the host's port 9000 would be done like
  351. this:
  352. con1=port:9000
  353. Attaching all the serial lines to that port would be done similarly:
  354. ssl=port:9000
  355. You access these devices by telnetting to that port. Each active tel-
  356. net session gets a different device. If there are more telnets to a
  357. port than UML devices attached to it, then the extra telnet sessions
  358. will block until an existing telnet detaches, or until another device
  359. becomes active (i.e. by being activated in /etc/inittab).
  360. This channel has the advantage that you can both attach multiple UML
  361. devices to it and know how to access them without reading the UML boot
  362. log. It is also unique in allowing access to a UML from remote
  363. machines without requiring that the UML be networked. This could be
  364. useful in allowing public access to UMLs because they would be
  365. accessible from the net, but wouldn't need any kind of network
  366. filtering or access control because they would have no network access.
  367. If you attach the main console to a portal, then the UML boot will
  368. appear to hang. In reality, it's waiting for a telnet to connect, at
  369. which point the boot will proceed.
  370. o already-existing file descriptors - device=file descriptor
  371. If you set up a file descriptor on the UML command line, you can
  372. attach a UML device to it. This is most commonly used to put the
  373. main console back on stdin and stdout after assigning all the other
  374. consoles to something else:
  375. con0=fd:0,fd:1 con=pts
  376. o Nothing - device=null
  377. This allows the device to be opened, in contrast to 'none', but
  378. reads will block, and writes will succeed and the data will be
  379. thrown out.
  380. o None - device=none
  381. This causes the device to disappear.
  382. You can also specify different input and output channels for a device
  383. by putting a comma between them:
  384. ssl3=tty:/dev/tty2,xterm
  385. will cause serial line 3 to accept input on the host's /dev/tty2 and
  386. display output on an xterm. That's a silly example - the most common
  387. use of this syntax is to reattach the main console to stdin and stdout
  388. as shown above.
  389. If you decide to move the main console away from stdin/stdout, the
  390. initial boot output will appear in the terminal that you're running
  391. UML in. However, once the console driver has been officially
  392. initialized, then the boot output will start appearing wherever you
  393. specified that console 0 should be. That device will receive all
  394. subsequent output.
  395. 5.3. Examples
  396. There are a number of interesting things you can do with this
  397. capability.
  398. First, this is how you get rid of those bleeding console xterms by
  399. attaching them to host ptys:
  400. con=pty con0=fd:0,fd:1
  401. This will make a UML console take over an unused host virtual console,
  402. so that when you switch to it, you will see the UML login prompt
  403. rather than the host login prompt:
  404. con1=tty:/dev/tty6
  405. You can attach two virtual machines together with what amounts to a
  406. serial line as follows:
  407. Run one UML with a serial line attached to a pty -
  408. ssl1=pty
  409. Look at the boot log to see what pty it got (this example will assume
  410. that it got /dev/ptyp1).
  411. Boot the other UML with a serial line attached to the corresponding
  412. tty -
  413. ssl1=tty:/dev/ttyp1
  414. Log in, make sure that it has no getty on that serial line, attach a
  415. terminal program like minicom to it, and you should see the login
  416. prompt of the other virtual machine.
  417. 6. Setting up the network
  418. This page describes how to set up the various transports and to
  419. provide a UML instance with network access to the host, other machines
  420. on the local net, and the rest of the net.
  421. As of 2.4.5, UML networking has been completely redone to make it much
  422. easier to set up, fix bugs, and add new features.
  423. There is a new helper, uml_net, which does the host setup that
  424. requires root privileges.
  425. There are currently five transport types available for a UML virtual
  426. machine to exchange packets with other hosts:
  427. o ethertap
  428. o TUN/TAP
  429. o Multicast
  430. o a switch daemon
  431. o slip
  432. o slirp
  433. o pcap
  434. The TUN/TAP, ethertap, slip, and slirp transports allow a UML
  435. instance to exchange packets with the host. They may be directed
  436. to the host or the host may just act as a router to provide access
  437. to other physical or virtual machines.
  438. The pcap transport is a synthetic read-only interface, using the
  439. libpcap binary to collect packets from interfaces on the host and
  440. filter them. This is useful for building preconfigured traffic
  441. monitors or sniffers.
  442. The daemon and multicast transports provide a completely virtual
  443. network to other virtual machines. This network is completely
  444. disconnected from the physical network unless one of the virtual
  445. machines on it is acting as a gateway.
  446. With so many host transports, which one should you use? Here's when
  447. you should use each one:
  448. o ethertap - if you want access to the host networking and it is
  449. running 2.2
  450. o TUN/TAP - if you want access to the host networking and it is
  451. running 2.4. Also, the TUN/TAP transport is able to use a
  452. preconfigured device, allowing it to avoid using the setuid uml_net
  453. helper, which is a security advantage.
  454. o Multicast - if you want a purely virtual network and you don't want
  455. to set up anything but the UML
  456. o a switch daemon - if you want a purely virtual network and you
  457. don't mind running the daemon in order to get somewhat better
  458. performance
  459. o slip - there is no particular reason to run the slip backend unless
  460. ethertap and TUN/TAP are just not available for some reason
  461. o slirp - if you don't have root access on the host to setup
  462. networking, or if you don't want to allocate an IP to your UML
  463. o pcap - not much use for actual network connectivity, but great for
  464. monitoring traffic on the host
  465. Ethertap is available on 2.4 and works fine. TUN/TAP is preferred
  466. to it because it has better performance and ethertap is officially
  467. considered obsolete in 2.4. Also, the root helper only needs to
  468. run occasionally for TUN/TAP, rather than handling every packet, as
  469. it does with ethertap. This is a slight security advantage since
  470. it provides fewer opportunities for a nasty UML user to somehow
  471. exploit the helper's root privileges.
  472. 6.1. General setup
  473. First, you must have the virtual network enabled in your UML. If are
  474. running a prebuilt kernel from this site, everything is already
  475. enabled. If you build the kernel yourself, under the "Network device
  476. support" menu, enable "Network device support", and then the three
  477. transports.
  478. The next step is to provide a network device to the virtual machine.
  479. This is done by describing it on the kernel command line.
  480. The general format is
  481. eth <n> = <transport> , <transport args>
  482. For example, a virtual ethernet device may be attached to a host
  483. ethertap device as follows:
  484. eth0=ethertap,tap0,fe:fd:0:0:0:1,192.168.0.254
  485. This sets up eth0 inside the virtual machine to attach itself to the
  486. host /dev/tap0, assigns it an ethernet address, and assigns the host
  487. tap0 interface an IP address.
  488. Note that the IP address you assign to the host end of the tap device
  489. must be different than the IP you assign to the eth device inside UML.
  490. If you are short on IPs and don't want to consume two per UML, then
  491. you can reuse the host's eth IP address for the host ends of the tap
  492. devices. Internally, the UMLs must still get unique IPs for their eth
  493. devices. You can also give the UMLs non-routable IPs (192.168.x.x or
  494. 10.x.x.x) and have the host masquerade them. This will let outgoing
  495. connections work, but incoming connections won't without more work,
  496. such as port forwarding from the host.
  497. Also note that when you configure the host side of an interface, it is
  498. only acting as a gateway. It will respond to pings sent to it
  499. locally, but is not useful to do that since it's a host interface.
  500. You are not talking to the UML when you ping that interface and get a
  501. response.
  502. You can also add devices to a UML and remove them at runtime. See the
  503. ``The Management Console'' page for details.
  504. The sections below describe this in more detail.
  505. Once you've decided how you're going to set up the devices, you boot
  506. UML, log in, configure the UML side of the devices, and set up routes
  507. to the outside world. At that point, you will be able to talk to any
  508. other machines, physical or virtual, on the net.
  509. If ifconfig inside UML fails and the network refuses to come up, run
  510. tell you what went wrong.
  511. 6.2. Userspace daemons
  512. You will likely need the setuid helper, or the switch daemon, or both.
  513. They are both installed with the RPM and deb, so if you've installed
  514. either, you can skip the rest of this section.
  515. If not, then you need to check them out of CVS, build them, and
  516. install them. The helper is uml_net, in CVS /tools/uml_net, and the
  517. daemon is uml_switch, in CVS /tools/uml_router. They are both built
  518. with a plain 'make'. Both need to be installed in a directory that's
  519. in your path - /usr/bin is recommend. On top of that, uml_net needs
  520. to be setuid root.
  521. 6.3. Specifying ethernet addresses
  522. Below, you will see that the TUN/TAP, ethertap, and daemon interfaces
  523. allow you to specify hardware addresses for the virtual ethernet
  524. devices. This is generally not necessary. If you don't have a
  525. specific reason to do it, you probably shouldn't. If one is not
  526. specified on the command line, the driver will assign one based on the
  527. device IP address. It will provide the address fe:fd:nn:nn:nn:nn
  528. where nn.nn.nn.nn is the device IP address. This is nearly always
  529. sufficient to guarantee a unique hardware address for the device. A
  530. couple of exceptions are:
  531. o Another set of virtual ethernet devices are on the same network and
  532. they are assigned hardware addresses using a different scheme which
  533. may conflict with the UML IP address-based scheme
  534. o You aren't going to use the device for IP networking, so you don't
  535. assign the device an IP address
  536. If you let the driver provide the hardware address, you should make
  537. sure that the device IP address is known before the interface is
  538. brought up. So, inside UML, this will guarantee that:
  539. UML#
  540. ifconfig eth0 192.168.0.250 up
  541. If you decide to assign the hardware address yourself, make sure that
  542. the first byte of the address is even. Addresses with an odd first
  543. byte are broadcast addresses, which you don't want assigned to a
  544. device.
  545. 6.4. UML interface setup
  546. Once the network devices have been described on the command line, you
  547. should boot UML and log in.
  548. The first thing to do is bring the interface up:
  549. UML# ifconfig ethn ip-address up
  550. You should be able to ping the host at this point.
  551. To reach the rest of the world, you should set a default route to the
  552. host:
  553. UML# route add default gw host ip
  554. Again, with host ip of 192.168.0.4:
  555. UML# route add default gw 192.168.0.4
  556. This page used to recommend setting a network route to your local net.
  557. This is wrong, because it will cause UML to try to figure out hardware
  558. addresses of the local machines by arping on the interface to the
  559. host. Since that interface is basically a single strand of ethernet
  560. with two nodes on it (UML and the host) and arp requests don't cross
  561. networks, they will fail to elicit any responses. So, what you want
  562. is for UML to just blindly throw all packets at the host and let it
  563. figure out what to do with them, which is what leaving out the network
  564. route and adding the default route does.
  565. Note: If you can't communicate with other hosts on your physical
  566. ethernet, it's probably because of a network route that's
  567. automatically set up. If you run 'route -n' and see a route that
  568. looks like this:
  569. Destination Gateway Genmask Flags Metric Ref Use Iface
  570. 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  571. with a mask that's not 255.255.255.255, then replace it with a route
  572. to your host:
  573. UML#
  574. route del -net 192.168.0.0 dev eth0 netmask 255.255.255.0
  575. UML#
  576. route add -host 192.168.0.4 dev eth0
  577. This, plus the default route to the host, will allow UML to exchange
  578. packets with any machine on your ethernet.
  579. 6.5. Multicast
  580. The simplest way to set up a virtual network between multiple UMLs is
  581. to use the mcast transport. This was written by Harald Welte and is
  582. present in UML version 2.4.5-5um and later. Your system must have
  583. multicast enabled in the kernel and there must be a multicast-capable
  584. network device on the host. Normally, this is eth0, but if there is
  585. no ethernet card on the host, then you will likely get strange error
  586. messages when you bring the device up inside UML.
  587. To use it, run two UMLs with
  588. eth0=mcast
  589. on their command lines. Log in, configure the ethernet device in each
  590. machine with different IP addresses:
  591. UML1# ifconfig eth0 192.168.0.254
  592. UML2# ifconfig eth0 192.168.0.253
  593. and they should be able to talk to each other.
  594. The full set of command line options for this transport are
  595. ethn=mcast,ethernet address,multicast
  596. address,multicast port,ttl
  597. Harald's original README is here <http://user-mode-linux.source-
  598. forge.net/> and explains these in detail, as well as
  599. some other issues.
  600. There is also a related point-to-point only "ucast" transport.
  601. This is useful when your network does not support multicast, and
  602. all network connections are simple point to point links.
  603. The full set of command line options for this transport are
  604. ethn=ucast,ethernet address,remote address,listen port,remote port
  605. 6.6. TUN/TAP with the uml_net helper
  606. TUN/TAP is the preferred mechanism on 2.4 to exchange packets with the
  607. host. The TUN/TAP backend has been in UML since 2.4.9-3um.
  608. The easiest way to get up and running is to let the setuid uml_net
  609. helper do the host setup for you. This involves insmod-ing the tun.o
  610. module if necessary, configuring the device, and setting up IP
  611. forwarding, routing, and proxy arp. If you are new to UML networking,
  612. do this first. If you're concerned about the security implications of
  613. the setuid helper, use it to get up and running, then read the next
  614. section to see how to have UML use a preconfigured tap device, which
  615. avoids the use of uml_net.
  616. If you specify an IP address for the host side of the device, the
  617. uml_net helper will do all necessary setup on the host - the only
  618. requirement is that TUN/TAP be available, either built in to the host
  619. kernel or as the tun.o module.
  620. The format of the command line switch to attach a device to a TUN/TAP
  621. device is
  622. eth <n> =tuntap,,, <IP address>
  623. For example, this argument will attach the UML's eth0 to the next
  624. available tap device and assign an ethernet address to it based on its
  625. IP address
  626. eth0=tuntap,,,192.168.0.254
  627. Note that the IP address that must be used for the eth device inside
  628. UML is fixed by the routing and proxy arp that is set up on the
  629. TUN/TAP device on the host. You can use a different one, but it won't
  630. work because reply packets won't reach the UML. This is a feature.
  631. It prevents a nasty UML user from doing things like setting the UML IP
  632. to the same as the network's nameserver or mail server.
  633. There are a couple potential problems with running the TUN/TAP
  634. transport on a 2.4 host kernel
  635. o TUN/TAP seems not to work on 2.4.3 and earlier. Upgrade the host
  636. kernel or use the ethertap transport.
  637. o With an upgraded kernel, TUN/TAP may fail with
  638. File descriptor in bad state
  639. This is due to a header mismatch between the upgraded kernel and the
  640. kernel that was originally installed on the machine. The fix is to
  641. make sure that /usr/src/linux points to the headers for the running
  642. kernel.
  643. These were pointed out by Tim Robinson <timro at trkr dot net> in
  644. <http://www.geocrawler.com/> name="this uml-
  645. user post"> .
  646. 6.7. TUN/TAP with a preconfigured tap device
  647. If you prefer not to have UML use uml_net (which is somewhat
  648. insecure), with UML 2.4.17-11, you can set up a TUN/TAP device
  649. beforehand. The setup needs to be done as root, but once that's done,
  650. there is no need for root assistance. Setting up the device is done
  651. as follows:
  652. o Create the device with tunctl (available from the UML utilities
  653. tarball)
  654. host# tunctl -u uid
  655. where uid is the user id or username that UML will be run as. This
  656. will tell you what device was created.
  657. o Configure the device IP (change IP addresses and device name to
  658. suit)
  659. host# ifconfig tap0 192.168.0.254 up
  660. o Set up routing and arping if desired - this is my recipe, there are
  661. other ways of doing the same thing
  662. host#
  663. bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
  664. host#
  665. route add -host 192.168.0.253 dev tap0
  666. host#
  667. bash -c 'echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp'
  668. host#
  669. arp -Ds 192.168.0.253 eth0 pub
  670. Note that this must be done every time the host boots - this configu-
  671. ration is not stored across host reboots. So, it's probably a good
  672. idea to stick it in an rc file. An even better idea would be a little
  673. utility which reads the information from a config file and sets up
  674. devices at boot time.
  675. o Rather than using up two IPs and ARPing for one of them, you can
  676. also provide direct access to your LAN by the UML by using a
  677. bridge.
  678. host#
  679. brctl addbr br0
  680. host#
  681. ifconfig eth0 0.0.0.0 promisc up
  682. host#
  683. ifconfig tap0 0.0.0.0 promisc up
  684. host#
  685. ifconfig br0 192.168.0.1 netmask 255.255.255.0 up
  686. host#
  687. brctl stp br0 off
  688. host#
  689. brctl setfd br0 1
  690. host#
  691. brctl sethello br0 1
  692. host#
  693. brctl addif br0 eth0
  694. host#
  695. brctl addif br0 tap0
  696. Note that 'br0' should be setup using ifconfig with the existing IP
  697. address of eth0, as eth0 no longer has its own IP.
  698. o
  699. Also, the /dev/net/tun device must be writable by the user running
  700. UML in order for the UML to use the device that's been configured
  701. for it. The simplest thing to do is
  702. host# chmod 666 /dev/net/tun
  703. Making it world-writable looks bad, but it seems not to be
  704. exploitable as a security hole. However, it does allow anyone to cre-
  705. ate useless tap devices (useless because they can't configure them),
  706. which is a DOS attack. A somewhat more secure alternative would to be
  707. to create a group containing all the users who have preconfigured tap
  708. devices and chgrp /dev/net/tun to that group with mode 664 or 660.
  709. o Once the device is set up, run UML with 'eth0=tuntap,device name'
  710. (i.e. 'eth0=tuntap,tap0') on the command line (or do it with the
  711. mconsole config command).
  712. o Bring the eth device up in UML and you're in business.
  713. If you don't want that tap device any more, you can make it non-
  714. persistent with
  715. host# tunctl -d tap device
  716. Finally, tunctl has a -b (for brief mode) switch which causes it to
  717. output only the name of the tap device it created. This makes it
  718. suitable for capture by a script:
  719. host# TAP=`tunctl -u 1000 -b`
  720. 6.8. Ethertap
  721. Ethertap is the general mechanism on 2.2 for userspace processes to
  722. exchange packets with the kernel.
  723. To use this transport, you need to describe the virtual network device
  724. on the UML command line. The general format for this is
  725. eth <n> =ethertap, <device> , <ethernet address> , <tap IP address>
  726. So, the previous example
  727. eth0=ethertap,tap0,fe:fd:0:0:0:1,192.168.0.254
  728. attaches the UML eth0 device to the host /dev/tap0, assigns it the
  729. ethernet address fe:fd:0:0:0:1, and assigns the IP address
  730. 192.168.0.254 to the tap device.
  731. The tap device is mandatory, but the others are optional. If the
  732. ethernet address is omitted, one will be assigned to it.
  733. The presence of the tap IP address will cause the helper to run and do
  734. whatever host setup is needed to allow the virtual machine to
  735. communicate with the outside world. If you're not sure you know what
  736. you're doing, this is the way to go.
  737. If it is absent, then you must configure the tap device and whatever
  738. arping and routing you will need on the host. However, even in this
  739. case, the uml_net helper still needs to be in your path and it must be
  740. setuid root if you're not running UML as root. This is because the
  741. tap device doesn't support SIGIO, which UML needs in order to use
  742. something as a source of input. So, the helper is used as a
  743. convenient asynchronous IO thread.
  744. If you're using the uml_net helper, you can ignore the following host
  745. setup - uml_net will do it for you. You just need to make sure you
  746. have ethertap available, either built in to the host kernel or
  747. available as a module.
  748. If you want to set things up yourself, you need to make sure that the
  749. appropriate /dev entry exists. If it doesn't, become root and create
  750. it as follows:
  751. mknod /dev/tap <minor> c 36 <minor> + 16
  752. For example, this is how to create /dev/tap0:
  753. mknod /dev/tap0 c 36 0 + 16
  754. You also need to make sure that the host kernel has ethertap support.
  755. If ethertap is enabled as a module, you apparently need to insmod
  756. ethertap once for each ethertap device you want to enable. So,
  757. host#
  758. insmod ethertap
  759. will give you the tap0 interface. To get the tap1 interface, you need
  760. to run
  761. host#
  762. insmod ethertap unit=1 -o ethertap1
  763. 6.9. The switch daemon
  764. Note: This is the daemon formerly known as uml_router, but which was
  765. renamed so the network weenies of the world would stop growling at me.
  766. The switch daemon, uml_switch, provides a mechanism for creating a
  767. totally virtual network. By default, it provides no connection to the
  768. host network (but see -tap, below).
  769. The first thing you need to do is run the daemon. Running it with no
  770. arguments will make it listen on a default pair of unix domain
  771. sockets.
  772. If you want it to listen on a different pair of sockets, use
  773. -unix control socket data socket
  774. If you want it to act as a hub rather than a switch, use
  775. -hub
  776. If you want the switch to be connected to host networking (allowing
  777. the umls to get access to the outside world through the host), use
  778. -tap tap0
  779. Note that the tap device must be preconfigured (see "TUN/TAP with a
  780. preconfigured tap device", above). If you're using a different tap
  781. device than tap0, specify that instead of tap0.
  782. uml_switch can be backgrounded as follows
  783. host%
  784. uml_switch [ options ] < /dev/null > /dev/null
  785. The reason it doesn't background by default is that it listens to
  786. stdin for EOF. When it sees that, it exits.
  787. The general format of the kernel command line switch is
  788. ethn=daemon,ethernet address,socket
  789. type,control socket,data socket
  790. You can leave off everything except the 'daemon'. You only need to
  791. specify the ethernet address if the one that will be assigned to it
  792. isn't acceptable for some reason. The rest of the arguments describe
  793. how to communicate with the daemon. You should only specify them if
  794. you told the daemon to use different sockets than the default. So, if
  795. you ran the daemon with no arguments, running the UML on the same
  796. machine with
  797. eth0=daemon
  798. will cause the eth0 driver to attach itself to the daemon correctly.
  799. 6.10. Slip
  800. Slip is another, less general, mechanism for a process to communicate
  801. with the host networking. In contrast to the ethertap interface,
  802. which exchanges ethernet frames with the host and can be used to
  803. transport any higher-level protocol, it can only be used to transport
  804. IP.
  805. The general format of the command line switch is
  806. ethn=slip,slip IP
  807. The slip IP argument is the IP address that will be assigned to the
  808. host end of the slip device. If it is specified, the helper will run
  809. and will set up the host so that the virtual machine can reach it and
  810. the rest of the network.
  811. There are some oddities with this interface that you should be aware
  812. of. You should only specify one slip device on a given virtual
  813. machine, and its name inside UML will be 'umn', not 'eth0' or whatever
  814. you specified on the command line. These problems will be fixed at
  815. some point.
  816. 6.11. Slirp
  817. slirp uses an external program, usually /usr/bin/slirp, to provide IP
  818. only networking connectivity through the host. This is similar to IP
  819. masquerading with a firewall, although the translation is performed in
  820. user-space, rather than by the kernel. As slirp does not set up any
  821. interfaces on the host, or changes routing, slirp does not require
  822. root access or setuid binaries on the host.
  823. The general format of the command line switch for slirp is:
  824. ethn=slirp,ethernet address,slirp path
  825. The ethernet address is optional, as UML will set up the interface
  826. with an ethernet address based upon the initial IP address of the
  827. interface. The slirp path is generally /usr/bin/slirp, although it
  828. will depend on distribution.
  829. The slirp program can have a number of options passed to the command
  830. line and we can't add them to the UML command line, as they will be
  831. parsed incorrectly. Instead, a wrapper shell script can be written or
  832. the options inserted into the /.slirprc file. More information on
  833. all of the slirp options can be found in its man pages.
  834. The eth0 interface on UML should be set up with the IP 10.2.0.15,
  835. although you can use anything as long as it is not used by a network
  836. you will be connecting to. The default route on UML should be set to
  837. use
  838. UML#
  839. route add default dev eth0
  840. slirp provides a number of useful IP addresses which can be used by
  841. UML, such as 10.0.2.3 which is an alias for the DNS server specified
  842. in /etc/resolv.conf on the host or the IP given in the 'dns' option
  843. for slirp.
  844. Even with a baudrate setting higher than 115200, the slirp connection
  845. is limited to 115200. If you need it to go faster, the slirp binary
  846. needs to be compiled with FULL_BOLT defined in config.h.
  847. 6.12. pcap
  848. The pcap transport is attached to a UML ethernet device on the command
  849. line or with uml_mconsole with the following syntax:
  850. ethn=pcap,host interface,filter
  851. expression,option1,option2
  852. The expression and options are optional.
  853. The interface is whatever network device on the host you want to
  854. sniff. The expression is a pcap filter expression, which is also what
  855. tcpdump uses, so if you know how to specify tcpdump filters, you will
  856. use the same expressions here. The options are up to two of
  857. 'promisc', control whether pcap puts the host interface into
  858. promiscuous mode. 'optimize' and 'nooptimize' control whether the pcap
  859. expression optimizer is used.
  860. Example:
  861. eth0=pcap,eth0,tcp
  862. eth1=pcap,eth0,!tcp
  863. will cause the UML eth0 to emit all tcp packets on the host eth0 and
  864. the UML eth1 to emit all non-tcp packets on the host eth0.
  865. 6.13. Setting up the host yourself
  866. If you don't specify an address for the host side of the ethertap or
  867. slip device, UML won't do any setup on the host. So this is what is
  868. needed to get things working (the examples use a host-side IP of
  869. 192.168.0.251 and a UML-side IP of 192.168.0.250 - adjust to suit your
  870. own network):
  871. o The device needs to be configured with its IP address. Tap devices
  872. are also configured with an mtu of 1484. Slip devices are
  873. configured with a point-to-point address pointing at the UML ip
  874. address.
  875. host# ifconfig tap0 arp mtu 1484 192.168.0.251 up
  876. host#
  877. ifconfig sl0 192.168.0.251 pointopoint 192.168.0.250 up
  878. o If a tap device is being set up, a route is set to the UML IP.
  879. UML# route add -host 192.168.0.250 gw 192.168.0.251
  880. o To allow other hosts on your network to see the virtual machine,
  881. proxy arp is set up for it.
  882. host# arp -Ds 192.168.0.250 eth0 pub
  883. o Finally, the host is set up to route packets.
  884. host# echo 1 > /proc/sys/net/ipv4/ip_forward
  885. 7. Sharing Filesystems between Virtual Machines
  886. 7.1. A warning
  887. Don't attempt to share filesystems simply by booting two UMLs from the
  888. same file. That's the same thing as booting two physical machines
  889. from a shared disk. It will result in filesystem corruption.
  890. 7.2. Using layered block devices
  891. The way to share a filesystem between two virtual machines is to use
  892. the copy-on-write (COW) layering capability of the ubd block driver.
  893. As of 2.4.6-2um, the driver supports layering a read-write private
  894. device over a read-only shared device. A machine's writes are stored
  895. in the private device, while reads come from either device - the
  896. private one if the requested block is valid in it, the shared one if
  897. not. Using this scheme, the majority of data which is unchanged is
  898. shared between an arbitrary number of virtual machines, each of which
  899. has a much smaller file containing the changes that it has made. With
  900. a large number of UMLs booting from a large root filesystem, this
  901. leads to a huge disk space saving. It will also help performance,
  902. since the host will be able to cache the shared data using a much
  903. smaller amount of memory, so UML disk requests will be served from the
  904. host's memory rather than its disks.
  905. To add a copy-on-write layer to an existing block device file, simply
  906. add the name of the COW file to the appropriate ubd switch:
  907. ubd0=root_fs_cow,root_fs_debian_22
  908. where 'root_fs_cow' is the private COW file and 'root_fs_debian_22' is
  909. the existing shared filesystem. The COW file need not exist. If it
  910. doesn't, the driver will create and initialize it. Once the COW file
  911. has been initialized, it can be used on its own on the command line:
  912. ubd0=root_fs_cow
  913. The name of the backing file is stored in the COW file header, so it
  914. would be redundant to continue specifying it on the command line.
  915. 7.3. Note!
  916. When checking the size of the COW file in order to see the gobs of
  917. space that you're saving, make sure you use 'ls -ls' to see the actual
  918. disk consumption rather than the length of the file. The COW file is
  919. sparse, so the length will be very different from the disk usage.
  920. Here is a 'ls -l' of a COW file and backing file from one boot and
  921. shutdown:
  922. host% ls -l cow.debian debian2.2
  923. -rw-r--r-- 1 jdike jdike 492504064 Aug 6 21:16 cow.debian
  924. -rwxrw-rw- 1 jdike jdike 537919488 Aug 6 20:42 debian2.2
  925. Doesn't look like much saved space, does it? Well, here's 'ls -ls':
  926. host% ls -ls cow.debian debian2.2
  927. 880 -rw-r--r-- 1 jdike jdike 492504064 Aug 6 21:16 cow.debian
  928. 525832 -rwxrw-rw- 1 jdike jdike 537919488 Aug 6 20:42 debian2.2
  929. Now, you can see that the COW file has less than a meg of disk, rather
  930. than 492 meg.
  931. 7.4. Another warning
  932. Once a filesystem is being used as a readonly backing file for a COW
  933. file, do not boot directly from it or modify it in any way. Doing so
  934. will invalidate any COW files that are using it. The mtime and size
  935. of the backing file are stored in the COW file header at its creation,
  936. and they must continue to match. If they don't, the driver will
  937. refuse to use the COW file.
  938. If you attempt to evade this restriction by changing either the
  939. backing file or the COW header by hand, you will get a corrupted
  940. filesystem.
  941. Among other things, this means that upgrading the distribution in a
  942. backing file and expecting that all of the COW files using it will see
  943. the upgrade will not work.
  944. 7.5. uml_moo : Merging a COW file with its backing file
  945. Depending on how you use UML and COW devices, it may be advisable to
  946. merge the changes in the COW file into the backing file every once in
  947. a while.
  948. The utility that does this is uml_moo. Its usage is
  949. host% uml_moo COW file new backing file
  950. There's no need to specify the backing file since that information is
  951. already in the COW file header. If you're paranoid, boot the new
  952. merged file, and if you're happy with it, move it over the old backing
  953. file.
  954. uml_moo creates a new backing file by default as a safety measure. It
  955. also has a destructive merge option which will merge the COW file
  956. directly into its current backing file. This is really only usable
  957. when the backing file only has one COW file associated with it. If
  958. there are multiple COWs associated with a backing file, a -d merge of
  959. one of them will invalidate all of the others. However, it is
  960. convenient if you're short of disk space, and it should also be
  961. noticeably faster than a non-destructive merge.
  962. uml_moo is installed with the UML deb and RPM. If you didn't install
  963. UML from one of those packages, you can also get it from the UML
  964. utilities <http://user-mode-linux.sourceforge.net/
  965. utilities> tar file in tools/moo.
  966. 8. Creating filesystems
  967. You may want to create and mount new UML filesystems, either because
  968. your root filesystem isn't large enough or because you want to use a
  969. filesystem other than ext2.
  970. This was written on the occasion of reiserfs being included in the
  971. 2.4.1 kernel pool, and therefore the 2.4.1 UML, so the examples will
  972. talk about reiserfs. This information is generic, and the examples
  973. should be easy to translate to the filesystem of your choice.
  974. 8.1. Create the filesystem file
  975. dd is your friend. All you need to do is tell dd to create an empty
  976. file of the appropriate size. I usually make it sparse to save time
  977. and to avoid allocating disk space until it's actually used. For
  978. example, the following command will create a sparse 100 meg file full
  979. of zeroes.
  980. host%
  981. dd if=/dev/zero of=new_filesystem seek=100 count=1 bs=1M
  982. 8.2. Assign the file to a UML device
  983. Add an argument like the following to the UML command line:
  984. ubd4=new_filesystem
  985. making sure that you use an unassigned ubd device number.
  986. 8.3. Creating and mounting the filesystem
  987. Make sure that the filesystem is available, either by being built into
  988. the kernel, or available as a module, then boot up UML and log in. If
  989. the root filesystem doesn't have the filesystem utilities (mkfs, fsck,
  990. etc), then get them into UML by way of the net or hostfs.
  991. Make the new filesystem on the device assigned to the new file:
  992. host# mkreiserfs /dev/ubd/4
  993. <----------- MKREISERFSv2 ----------->
  994. ReiserFS version 3.6.25
  995. Block size 4096 bytes
  996. Block count 25856
  997. Used blocks 8212
  998. Journal - 8192 blocks (18-8209), journal header is in block 8210
  999. Bitmaps: 17
  1000. Root block 8211
  1001. Hash function "r5"
  1002. ATTENTION: ALL DATA WILL BE LOST ON '/dev/ubd/4'! (y/n)y
  1003. journal size 8192 (from 18)
  1004. Initializing journal - 0%....20%....40%....60%....80%....100%
  1005. Syncing..done.
  1006. Now, mount it:
  1007. UML#
  1008. mount /dev/ubd/4 /mnt
  1009. and you're in business.
  1010. 9. Host file access
  1011. If you want to access files on the host machine from inside UML, you
  1012. can treat it as a separate machine and either nfs mount directories
  1013. from the host or copy files into the virtual machine with scp or rcp.
  1014. However, since UML is running on the host, it can access those
  1015. files just like any other process and make them available inside the
  1016. virtual machine without needing to use the network.
  1017. This is now possible with the hostfs virtual filesystem. With it, you
  1018. can mount a host directory into the UML filesystem and access the
  1019. files contained in it just as you would on the host.
  1020. 9.1. Using hostfs
  1021. To begin with, make sure that hostfs is available inside the virtual
  1022. machine with
  1023. UML# cat /proc/filesystems
  1024. . hostfs should be listed. If it's not, either rebuild the kernel
  1025. with hostfs configured into it or make sure that hostfs is built as a
  1026. module and available inside the virtual machine, and insmod it.
  1027. Now all you need to do is run mount:
  1028. UML# mount none /mnt/host -t hostfs
  1029. will mount the host's / on the virtual machine's /mnt/host.
  1030. If you don't want to mount the host root directory, then you can
  1031. specify a subdirectory to mount with the -o switch to mount:
  1032. UML# mount none /mnt/home -t hostfs -o /home
  1033. will mount the hosts's /home on the virtual machine's /mnt/home.
  1034. 9.2. hostfs as the root filesystem
  1035. It's possible to boot from a directory hierarchy on the host using
  1036. hostfs rather than using the standard filesystem in a file.
  1037. To start, you need that hierarchy. The easiest way is to loop mount
  1038. an existing root_fs file:
  1039. host# mount root_fs uml_root_dir -o loop
  1040. You need to change the filesystem type of / in etc/fstab to be
  1041. 'hostfs', so that line looks like this:
  1042. /dev/ubd/0 / hostfs defaults 1 1
  1043. Then you need to chown to yourself all the files in that directory
  1044. that are owned by root. This worked for me:
  1045. host# find . -uid 0 -exec chown jdike {} \;
  1046. Next, make sure that your UML kernel has hostfs compiled in, not as a
  1047. module. Then run UML with the boot device pointing at that directory:
  1048. ubd0=/path/to/uml/root/directory
  1049. UML should then boot as it does normally.
  1050. 9.3. Building hostfs
  1051. If you need to build hostfs because it's not in your kernel, you have
  1052. two choices:
  1053. o Compiling hostfs into the kernel:
  1054. Reconfigure the kernel and set the 'Host filesystem' option under
  1055. o Compiling hostfs as a module:
  1056. Reconfigure the kernel and set the 'Host filesystem' option under
  1057. be in arch/um/fs/hostfs/hostfs.o. Install that in
  1058. /lib/modules/`uname -r`/fs in the virtual machine, boot it up, and
  1059. UML# insmod hostfs
  1060. 10. The Management Console
  1061. The UML management console is a low-level interface to the kernel,
  1062. somewhat like the i386 SysRq interface. Since there is a full-blown
  1063. operating system under UML, there is much greater flexibility possible
  1064. than with the SysRq mechanism.
  1065. There are a number of things you can do with the mconsole interface:
  1066. o get the kernel version
  1067. o add and remove devices
  1068. o halt or reboot the machine
  1069. o Send SysRq commands
  1070. o Pause and resume the UML
  1071. You need the mconsole client (uml_mconsole) which is present in CVS
  1072. (/tools/mconsole) in 2.4.5-9um and later, and will be in the RPM in
  1073. 2.4.6.
  1074. You also need CONFIG_MCONSOLE (under 'General Setup') enabled in UML.
  1075. When you boot UML, you'll see a line like:
  1076. mconsole initialized on /home/jdike/.uml/umlNJ32yL/mconsole
  1077. If you specify a unique machine id one the UML command line, i.e.
  1078. umid=debian
  1079. you'll see this
  1080. mconsole initialized on /home/jdike/.uml/debian/mconsole
  1081. That file is the socket that uml_mconsole will use to communicate with
  1082. UML. Run it with either the umid or the full path as its argument:
  1083. host% uml_mconsole debian
  1084. or
  1085. host% uml_mconsole /home/jdike/.uml/debian/mconsole
  1086. You'll get a prompt, at which you can run one of these commands:
  1087. o version
  1088. o halt
  1089. o reboot
  1090. o config
  1091. o remove
  1092. o sysrq
  1093. o help
  1094. o cad
  1095. o stop
  1096. o go
  1097. 10.1. version
  1098. This takes no arguments. It prints the UML version.
  1099. (mconsole) version
  1100. OK Linux usermode 2.4.5-9um #1 Wed Jun 20 22:47:08 EDT 2001 i686
  1101. There are a couple actual uses for this. It's a simple no-op which
  1102. can be used to check that a UML is running. It's also a way of
  1103. sending an interrupt to the UML. This is sometimes useful on SMP
  1104. hosts, where there's a bug which causes signals to UML to be lost,
  1105. often causing it to appear to hang. Sending such a UML the mconsole
  1106. version command is a good way to 'wake it up' before networking has
  1107. been enabled, as it does not do anything to the function of the UML.
  1108. 10.2. halt and reboot
  1109. These take no arguments. They shut the machine down immediately, with
  1110. no syncing of disks and no clean shutdown of userspace. So, they are
  1111. pretty close to crashing the machine.
  1112. (mconsole) halt
  1113. OK
  1114. 10.3. config
  1115. "config" adds a new device to the virtual machine. Currently the ubd
  1116. and network drivers support this. It takes one argument, which is the
  1117. device to add, with the same syntax as the kernel command line.
  1118. (mconsole)
  1119. config ubd3=/home/jdike/incoming/roots/root_fs_debian22
  1120. OK
  1121. (mconsole) config eth1=mcast
  1122. OK
  1123. 10.4. remove
  1124. "remove" deletes a device from the system. Its argument is just the
  1125. name of the device to be removed. The device must be idle in whatever
  1126. sense the driver considers necessary. In the case of the ubd driver,
  1127. the removed block device must not be mounted, swapped on, or otherwise
  1128. open, and in the case of the network driver, the device must be down.
  1129. (mconsole) remove ubd3
  1130. OK
  1131. (mconsole) remove eth1
  1132. OK
  1133. 10.5. sysrq
  1134. This takes one argument, which is a single letter. It calls the
  1135. generic kernel's SysRq driver, which does whatever is called for by
  1136. that argument. See the SysRq documentation in Documentation/sysrq.txt
  1137. in your favorite kernel tree to see what letters are valid and what
  1138. they do.
  1139. 10.6. help
  1140. "help" returns a string listing the valid commands and what each one
  1141. does.
  1142. 10.7. cad
  1143. This invokes the Ctl-Alt-Del action on init. What exactly this ends
  1144. up doing is up to /etc/inittab. Normally, it reboots the machine.
  1145. With UML, this is usually not desired, so if a halt would be better,
  1146. then find the section of inittab that looks like this
  1147. # What to do when CTRL-ALT-DEL is pressed.
  1148. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
  1149. and change the command to halt.
  1150. 10.8. stop
  1151. This puts the UML in a loop reading mconsole requests until a 'go'
  1152. mconsole command is received. This is very useful for making backups
  1153. of UML filesystems, as the UML can be stopped, then synced via 'sysrq
  1154. s', so that everything is written to the filesystem. You can then copy
  1155. the filesystem and then send the UML 'go' via mconsole.
  1156. Note that a UML running with more than one CPU will have problems
  1157. after you send the 'stop' command, as only one CPU will be held in a
  1158. mconsole loop and all others will continue as normal. This is a bug,
  1159. and will be fixed.
  1160. 10.9. go
  1161. This resumes a UML after being paused by a 'stop' command. Note that
  1162. when the UML has resumed, TCP connections may have timed out and if
  1163. the UML is paused for a long period of time, crond might go a little
  1164. crazy, running all the jobs it didn't do earlier.
  1165. 11. Kernel debugging
  1166. Note: The interface that makes debugging, as described here, possible
  1167. is present in 2.4.0-test6 kernels and later.
  1168. Since the user-mode kernel runs as a normal Linux process, it is
  1169. possible to debug it with gdb almost like any other process. It is
  1170. slightly different because the kernel's threads are already being
  1171. ptraced for system call interception, so gdb can't ptrace them.
  1172. However, a mechanism has been added to work around that problem.
  1173. In order to debug the kernel, you need build it from source. See
  1174. ``Compiling the kernel and modules'' for information on doing that.
  1175. Make sure that you enable CONFIG_DEBUGSYM and CONFIG_PT_PROXY during
  1176. the config. These will compile the kernel with -g, and enable the
  1177. ptrace proxy so that gdb works with UML, respectively.
  1178. 11.1. Starting the kernel under gdb
  1179. You can have the kernel running under the control of gdb from the
  1180. beginning by putting 'debug' on the command line. You will get an
  1181. xterm with gdb running inside it. The kernel will send some commands
  1182. to gdb which will leave it stopped at the beginning of start_kernel.
  1183. At this point, you can get things going with 'next', 'step', or
  1184. 'cont'.
  1185. There is a transcript of a debugging session here <debug-
  1186. session.html> , with breakpoints being set in the scheduler and in an
  1187. interrupt handler.
  1188. 11.2. Examining sleeping processes
  1189. Not every bug is evident in the currently running process. Sometimes,
  1190. processes hang in the kernel when they shouldn't because they've
  1191. deadlocked on a semaphore or something similar. In this case, when
  1192. you ^C gdb and get a backtrace, you will see the idle thread, which
  1193. isn't very relevant.
  1194. What you want is the stack of whatever process is sleeping when it
  1195. shouldn't be. You need to figure out which process that is, which is
  1196. generally fairly easy. Then you need to get its host process id,
  1197. which you can do either by looking at ps on the host or at
  1198. task.thread.extern_pid in gdb.
  1199. Now what you do is this:
  1200. o detach from the current thread
  1201. (UML gdb) det
  1202. o attach to the thread you are interested in
  1203. (UML gdb) att <host pid>
  1204. o look at its stack and anything else of interest
  1205. (UML gdb) bt
  1206. Note that you can't do anything at this point that requires that a
  1207. process execute, e.g. calling a function
  1208. o when you're done looking at that process, reattach to the current
  1209. thread and continue it
  1210. (UML gdb)
  1211. att 1
  1212. (UML gdb)
  1213. c
  1214. Here, specifying any pid which is not the process id of a UML thread
  1215. will cause gdb to reattach to the current thread. I commonly use 1,
  1216. but any other invalid pid would work.
  1217. 11.3. Running ddd on UML
  1218. ddd works on UML, but requires a special kludge. The process goes
  1219. like this:
  1220. o Start ddd
  1221. host% ddd linux
  1222. o With ps, get the pid of the gdb that ddd started. You can ask the
  1223. gdb to tell you, but for some reason that confuses things and
  1224. causes a hang.
  1225. o run UML with 'debug=parent gdb-pid=<pid>' added to the command line
  1226. - it will just sit there after you hit return
  1227. o type 'att 1' to the ddd gdb and you will see something like
  1228. 0xa013dc51 in __kill ()
  1229. (gdb)
  1230. o At this point, type 'c', UML will boot up, and you can use ddd just
  1231. as you do on any other process.
  1232. 11.4. Debugging modules
  1233. gdb has support for debugging code which is dynamically loaded into
  1234. the process. This support is what is needed to debug kernel modules
  1235. under UML.
  1236. Using that support is somewhat complicated. You have to tell gdb what
  1237. object file you just loaded into UML and where in memory it is. Then,
  1238. it can read the symbol table, and figure out where all the symbols are
  1239. from the load address that you provided. It gets more interesting
  1240. when you load the module again (i.e. after an rmmod). You have to
  1241. tell gdb to forget about all its symbols, including the main UML ones
  1242. for some reason, then load then all back in again.
  1243. There's an easy way and a hard way to do this. The easy way is to use
  1244. the umlgdb expect script written by Chandan Kudige. It basically
  1245. automates the process for you.
  1246. First, you must tell it where your modules are. There is a list in
  1247. the script that looks like this:
  1248. set MODULE_PATHS {
  1249. "fat" "/usr/src/uml/linux-2.4.18/fs/fat/fat.o"
  1250. "isofs" "/usr/src/uml/linux-2.4.18/fs/isofs/isofs.o"
  1251. "minix" "/usr/src/uml/linux-2.4.18/fs/minix/minix.o"
  1252. }
  1253. You change that to list the names and paths of the modules that you
  1254. are going to debug. Then you run it from the toplevel directory of
  1255. your UML pool and it basically tells you what to do:
  1256. ******** GDB pid is 21903 ********
  1257. Start UML as: ./linux <kernel switches> debug gdb-pid=21903
  1258. GNU gdb 5.0rh-5 Red Hat Linux 7.1
  1259. Copyright 2001 Free Software Foundation, Inc.
  1260. GDB is free software, covered by the GNU General Public License, and you are
  1261. welcome to change it and/or distribute copies of it under certain conditions.
  1262. Type "show copying" to see the conditions.
  1263. There is absolutely no warranty for GDB. Type "show warranty" for details.
  1264. This GDB was configured as "i386-redhat-linux"...
  1265. (gdb) b sys_init_module
  1266. Breakpoint 1 at 0xa0011923: file module.c, line 349.
  1267. (gdb) att 1
  1268. After you run UML and it sits there doing nothing, you hit return at
  1269. the 'att 1' and continue it:
  1270. Attaching to program: /home/jdike/linux/2.4/um/./linux, process 1
  1271. 0xa00f4221 in __kill ()
  1272. (UML gdb) c
  1273. Continuing.
  1274. At this point, you debug normally. When you insmod something, the
  1275. expect magic will kick in and you'll see something like:
  1276. *** Module hostfs loaded ***
  1277. Breakpoint 1, sys_init_module (name_user=0x805abb0 "hostfs",
  1278. mod_user=0x8070e00) at module.c:349
  1279. 349 char *name, *n_name, *name_tmp = NULL;
  1280. (UML gdb) finish
  1281. Run till exit from #0 sys_init_module (name_user=0x805abb0 "hostfs",
  1282. mod_user=0x8070e00) at module.c:349
  1283. 0xa00e2e23 in execute_syscall (r=0xa8140284) at syscall_kern.c:411
  1284. 411 else res = EXECUTE_SYSCALL(syscall, regs);
  1285. Value returned is $1 = 0
  1286. (UML gdb)
  1287. p/x (int)module_list + module_list->size_of_struct
  1288. $2 = 0xa9021054
  1289. (UML gdb) symbol-file ./linux
  1290. Load new symbol table from "./linux"? (y or n) y
  1291. Reading symbols from ./linux...
  1292. done.
  1293. (UML gdb)
  1294. add-symbol-file /home/jdike/linux/2.4/um/arch/um/fs/hostfs/hostfs.o 0xa9021054
  1295. add symbol table from file "/home/jdike/linux/2.4/um/arch/um/fs/hostfs/hostfs.o" at
  1296. .text_addr = 0xa9021054
  1297. (y or n) y
  1298. Reading symbols from /home/jdike/linux/2.4/um/arch/um/fs/hostfs/hostfs.o...
  1299. done.
  1300. (UML gdb) p *module_list
  1301. $1 = {size_of_struct = 84, next = 0xa0178720, name = 0xa9022de0 "hostfs",
  1302. size = 9016, uc = {usecount = {counter = 0}, pad = 0}, flags = 1,
  1303. nsyms = 57, ndeps = 0, syms = 0xa9023170, deps = 0x0, refs = 0x0,
  1304. init = 0xa90221f0 <init_hostfs>, cleanup = 0xa902222c <exit_hostfs>,
  1305. ex_table_start = 0x0, ex_table_end = 0x0, persist_start = 0x0,
  1306. persist_end = 0x0, can_unload = 0, runsize = 0, kallsyms_start = 0x0,
  1307. kallsyms_end = 0x0,
  1308. archdata_start = 0x1b855 <Address 0x1b855 out of bounds>,
  1309. archdata_end = 0xe5890000 <Address 0xe5890000 out of bounds>,
  1310. kernel_data = 0xf689c35d <Address 0xf689c35d out of bounds>}
  1311. >> Finished loading symbols for hostfs ...
  1312. That's the easy way. It's highly recommended. The hard way is
  1313. described below in case you're interested in what's going on.
  1314. Boot the kernel under the debugger and load the module with insmod or
  1315. modprobe. With gdb, do:
  1316. (UML gdb) p module_list
  1317. This is a list of modules that have been loaded into the kernel, with
  1318. the most recently loaded module first. Normally, the module you want
  1319. is at module_list. If it's not, walk down the next links, looking at
  1320. the name fields until find the module you want to debug. Take the
  1321. address of that structure, and add module.size_of_struct (which in
  1322. 2.4.10 kernels is 96 (0x60)) to it. Gdb can make this hard addition
  1323. for you :-):
  1324. (UML gdb)
  1325. printf "%#x\n", (int)module_list module_list->size_of_struct
  1326. The offset from the module start occasionally changes (before 2.4.0,
  1327. it was module.size_of_struct + 4), so it's a good idea to check the
  1328. init and cleanup addresses once in a while, as describe below. Now
  1329. do:
  1330. (UML gdb)
  1331. add-symbol-file /path/to/module/on/host that_address
  1332. Tell gdb you really want to do it, and you're in business.
  1333. If there's any doubt that you got the offset right, like breakpoints
  1334. appear not to work, or they're appearing in the wrong place, you can
  1335. check it by looking at the module structure. The init and cleanup
  1336. fields should look like:
  1337. init = 0x588066b0 <init_hostfs>, cleanup = 0x588066c0 <exit_hostfs>
  1338. with no offsets on the symbol names. If the names are right, but they
  1339. are offset, then the offset tells you how much you need to add to the
  1340. address you gave to add-symbol-file.
  1341. When you want to load in a new version of the module, you need to get
  1342. gdb to forget about the old one. The only way I've found to do that
  1343. is to tell gdb to forget about all symbols that it knows about:
  1344. (UML gdb) symbol-file
  1345. Then reload the symbols from the kernel binary:
  1346. (UML gdb) symbol-file /path/to/kernel
  1347. and repeat the process above. You'll also need to re-enable break-
  1348. points. They were disabled when you dumped all the symbols because
  1349. gdb couldn't figure out where they should go.
  1350. 11.5. Attaching gdb to the kernel
  1351. If you don't have the kernel running under gdb, you can attach gdb to
  1352. it later by sending the tracing thread a SIGUSR1. The first line of
  1353. the console output identifies its pid:
  1354. tracing thread pid = 20093
  1355. When you send it the signal:
  1356. host% kill -USR1 20093
  1357. you will get an xterm with gdb running in it.
  1358. If you have the mconsole compiled into UML, then the mconsole client
  1359. can be used to start gdb:
  1360. (mconsole) (mconsole) config gdb=xterm
  1361. will fire up an xterm with gdb running in it.
  1362. 11.6. Using alternate debuggers
  1363. UML has support for attaching to an already running debugger rather
  1364. than starting gdb itself. This is present in CVS as of 17 Apr 2001.
  1365. I sent it to Alan for inclusion in the ac tree, and it will be in my
  1366. 2.4.4 release.
  1367. This is useful when gdb is a subprocess of some UI, such as emacs or
  1368. ddd. It can also be used to run debuggers other than gdb on UML.
  1369. Below is an example of using strace as an alternate debugger.
  1370. To do this, you need to get the pid of the debugger and pass it in
  1371. with the
  1372. If you are using gdb under some UI, then tell it to 'att 1', and
  1373. you'll find yourself attached to UML.
  1374. If you are using something other than gdb as your debugger, then
  1375. you'll need to get it to do the equivalent of 'att 1' if it doesn't do
  1376. it automatically.
  1377. An example of an alternate debugger is strace. You can strace the
  1378. actual kernel as follows:
  1379. o Run the following in a shell
  1380. host%
  1381. sh -c 'echo pid=$$; echo -n hit return; read x; exec strace -p 1 -o strace.out'
  1382. o Run UML with 'debug' and 'gdb-pid=<pid>' with the pid printed out
  1383. by the previous command
  1384. o Hit return in the shell, and UML will start running, and strace
  1385. output will start accumulating in the output file.
  1386. Note that this is different from running
  1387. host% strace ./linux
  1388. That will strace only the main UML thread, the tracing thread, which
  1389. doesn't do any of the actual kernel work. It just oversees the vir-
  1390. tual machine. In contrast, using strace as described above will show
  1391. you the low-level activity of the virtual machine.
  1392. 12. Kernel debugging examples
  1393. 12.1. The case of the hung fsck
  1394. When booting up the kernel, fsck failed, and dropped me into a shell
  1395. to fix things up. I ran fsck -y, which hung:
  1396. Setting hostname uml [ OK ]
  1397. Checking root filesystem
  1398. /dev/fhd0 was not cleanly unmounted, check forced.
  1399. Error reading block 86894 (Attempt to read block from filesystem resulted in short read) while reading indirect blocks of inode 19780.
  1400. /dev/fhd0: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
  1401. (i.e., without -a or -p options)
  1402. [ FAILED ]
  1403. *** An error occurred during the file system check.
  1404. *** Dropping you to a shell; the system will reboot
  1405. *** when you leave the shell.
  1406. Give root password for maintenance
  1407. (or type Control-D for normal startup):
  1408. [root@uml /root]# fsck -y /dev/fhd0
  1409. fsck -y /dev/fhd0
  1410. Parallelizing fsck version 1.14 (9-Jan-1999)
  1411. e2fsck 1.14, 9-Jan-1999 for EXT2 FS 0.5b, 95/08/09
  1412. /dev/fhd0 contains a file system with errors, check forced.
  1413. Pass 1: Checking inodes, blocks, and sizes
  1414. Error reading block 86894 (Attempt to read block from filesystem resulted in short read) while reading indirect blocks of inode 19780. Ignore error? yes
  1415. Inode 19780, i_blocks is 1548, should be 540. Fix? yes
  1416. Pass 2: Checking directory structure
  1417. Error reading block 49405 (Attempt to read block from filesystem resulted in short read). Ignore error? yes
  1418. Directory inode 11858, block 0, offset 0: directory corrupted
  1419. Salvage? yes
  1420. Missing '.' in directory inode 11858.
  1421. Fix? yes
  1422. Missing '..' in directory inode 11858.
  1423. Fix? yes
  1424. The standard drill in this sort of situation is to fire up gdb on the
  1425. signal thread, which, in this case, was pid 1935. In another window,
  1426. I run gdb and attach pid 1935.
  1427. ~/linux/2.3.26/um 1016: gdb linux
  1428. GNU gdb 4.17.0.11 with Linux support
  1429. Copyright 1998 Free Software Foundation, Inc.
  1430. GDB is free software, covered by the GNU General Public License, and you are
  1431. welcome to change it and/or distribute copies of it under certain conditions.
  1432. Type "show copying" to see the conditions.
  1433. There is absolutely no warranty for GDB. Type "show warranty" for details.
  1434. This GDB was configured as "i386-redhat-linux"...
  1435. (gdb) att 1935
  1436. Attaching to program `/home/dike/linux/2.3.26/um/linux', Pid 1935
  1437. 0x100756d9 in __wait4 ()
  1438. Let's see what's currently running:
  1439. (gdb) p current_task.pid
  1440. $1 = 0
  1441. It's the idle thread, which means that fsck went to sleep for some
  1442. reason and never woke up.
  1443. Let's guess that the last process in the process list is fsck:
  1444. (gdb) p current_task.prev_task.comm
  1445. $13 = "fsck.ext2\000\000\000\000\000\000"
  1446. It is, so let's see what it thinks it's up to:
  1447. (gdb) p current_task.prev_task.thread
  1448. $14 = {extern_pid = 1980, tracing = 0, want_tracing = 0, forking = 0,
  1449. kernel_stack_page = 0, signal_stack = 1342627840, syscall = {id = 4, args = {
  1450. 3, 134973440, 1024, 0, 1024}, have_result = 0, result = 50590720},
  1451. request = {op = 2, u = {exec = {ip = 1350467584, sp = 2952789424}, fork = {
  1452. regs = {1350467584, 2952789424, 0 <repeats 15 times>}, sigstack = 0,
  1453. pid = 0}, switch_to = 0x507e8000, thread = {proc = 0x507e8000,
  1454. arg = 0xaffffdb0, flags = 0, new_pid = 0}, input_request = {
  1455. op = 1350467584, fd = -1342177872, proc = 0, pid = 0}}}}
  1456. The interesting things here are the fact that its .thread.syscall.id
  1457. is __NR_write (see the big switch in arch/um/kernel/syscall_kern.c or
  1458. the defines in include/asm-um/arch/unistd.h), and that it never
  1459. returned. Also, its .request.op is OP_SWITCH (see
  1460. arch/um/include/user_util.h). These mean that it went into a write,
  1461. and, for some reason, called schedule().
  1462. The fact that it never returned from write means that its stack should
  1463. be fairly interesting. Its pid is 1980 (.thread.extern_pid). That
  1464. process is being ptraced by the signal thread, so it must be detached
  1465. before gdb can attach it:
  1466. (gdb) call detach(1980)
  1467. Program received signal SIGSEGV, Segmentation fault.
  1468. <function called from gdb>
  1469. The program being debugged stopped while in a function called from GDB.
  1470. When the function (detach) is done executing, GDB will silently
  1471. stop (instead of continuing to evaluate the expression containing
  1472. the function call).
  1473. (gdb) call detach(1980)
  1474. $15 = 0
  1475. The first detach segfaults for some reason, and the second one
  1476. succeeds.
  1477. Now I detach from the signal thread, attach to the fsck thread, and
  1478. look at its stack:
  1479. (gdb) det
  1480. Detaching from program: /home/dike/linux/2.3.26/um/linux Pid 1935
  1481. (gdb) att 1980
  1482. Attaching to program `/home/dike/linux/2.3.26/um/linux', Pid 1980
  1483. 0x10070451 in __kill ()
  1484. (gdb) bt
  1485. #0 0x10070451 in __kill ()
  1486. #1 0x10068ccd in usr1_pid (pid=1980) at process.c:30
  1487. #2 0x1006a03f in _switch_to (prev=0x50072000, next=0x507e8000)
  1488. at process_kern.c:156
  1489. #3 0x1006a052 in switch_to (prev=0x50072000, next=0x507e8000, last=0x50072000)
  1490. at process_kern.c:161
  1491. #4 0x10001d12 in schedule () at core.c:777
  1492. #5 0x1006a744 in __down (sem=0x507d241c) at semaphore.c:71
  1493. #6 0x1006aa10 in __down_failed () at semaphore.c:157
  1494. #7 0x1006c5d8 in segv_handler (sc=0x5006e940) at trap_user.c:174
  1495. #8 0x1006c5ec in kern_segv_handler (sig=11) at trap_user.c:182
  1496. #9 <signal handler called>
  1497. #10 0x10155404 in errno ()
  1498. #11 0x1006c0aa in segv (address=1342179328, is_write=2) at trap_kern.c:50
  1499. #12 0x1006c5d8 in segv_handler (sc=0x5006eaf8) at trap_user.c:174
  1500. #13 0x1006c5ec in kern_segv_handler (sig=11) at trap_user.c:182
  1501. #14 <signal handler called>
  1502. #15 0xc0fd in ?? ()
  1503. #16 0x10016647 in sys_write (fd=3,
  1504. buf=0x80b8800 <Address 0x80b8800 out of bounds>, count=1024)
  1505. at read_write.c:159
  1506. #17 0x1006d5b3 in execute_syscall (syscall=4, args=0x5006ef08)
  1507. at syscall_kern.c:254
  1508. #18 0x1006af87 in really_do_syscall (sig=12) at syscall_user.c:35
  1509. #19 <signal handler called>
  1510. #20 0x400dc8b0 in ?? ()
  1511. The interesting things here are :
  1512. o There are two segfaults on this stack (frames 9 and 14)
  1513. o The first faulting address (frame 11) is 0x50000800
  1514. (gdb) p (void *)1342179328
  1515. $16 = (void *) 0x50000800
  1516. The initial faulting address is interesting because it is on the idle
  1517. thread's stack. I had been seeing the idle thread segfault for no
  1518. apparent reason, and the cause looked like stack corruption. In hopes
  1519. of catching the culprit in the act, I had turned off all protections
  1520. to that stack while the idle thread wasn't running. This apparently
  1521. tripped that trap.
  1522. However, the more immediate problem is that second segfault and I'm
  1523. going to concentrate on that. First, I want to see where the fault
  1524. happened, so I have to go look at the sigcontent struct in frame 8:
  1525. (gdb) up
  1526. #1 0x10068ccd in usr1_pid (pid=1980) at process.c:30
  1527. 30 kill(pid, SIGUSR1);
  1528. (gdb)
  1529. #2 0x1006a03f in _switch_to (prev=0x50072000, next=0x507e8000)
  1530. at process_kern.c:156
  1531. 156 usr1_pid(getpid());
  1532. (gdb)
  1533. #3 0x1006a052 in switch_to (prev=0x50072000, next=0x507e8000, last=0x50072000)
  1534. at process_kern.c:161
  1535. 161 _switch_to(prev, next);
  1536. (gdb)
  1537. #4 0x10001d12 in schedule () at core.c:777
  1538. 777 switch_to(prev, next, prev);
  1539. (gdb)
  1540. #5 0x1006a744 in __down (sem=0x507d241c) at semaphore.c:71
  1541. 71 schedule();
  1542. (gdb)
  1543. #6 0x1006aa10 in __down_failed () at semaphore.c:157
  1544. 157 }
  1545. (gdb)
  1546. #7 0x1006c5d8 in segv_handler (sc=0x5006e940) at trap_user.c:174
  1547. 174 segv(sc->cr2, sc->err & 2);
  1548. (gdb)
  1549. #8 0x1006c5ec in kern_segv_handler (sig=11) at trap_user.c:182
  1550. 182 segv_handler(sc);
  1551. (gdb) p *sc
  1552. Cannot access memory at address 0x0.
  1553. That's not very useful, so I'll try a more manual method:
  1554. (gdb) p *((struct sigcontext *) (&sig + 1))
  1555. $19 = {gs = 0, __gsh = 0, fs = 0, __fsh = 0, es = 43, __esh = 0, ds = 43,
  1556. __dsh = 0, edi = 1342179328, esi = 1350378548, ebp = 1342630440,
  1557. esp = 1342630420, ebx = 1348150624, edx = 1280, ecx = 0, eax = 0,
  1558. trapno = 14, err = 4, eip = 268480945, cs = 35, __csh = 0, eflags = 66118,
  1559. esp_at_signal = 1342630420, ss = 43, __ssh = 0, fpstate = 0x0, oldmask = 0,
  1560. cr2 = 1280}
  1561. The ip is in handle_mm_fault:
  1562. (gdb) p (void *)268480945
  1563. $20 = (void *) 0x1000b1b1
  1564. (gdb) i sym $20
  1565. handle_mm_fault + 57 in section .text
  1566. Specifically, it's in pte_alloc:
  1567. (gdb) i line *$20
  1568. Line 124 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1569. starts at address 0x1000b1b1 <handle_mm_fault+57>
  1570. and ends at 0x1000b1b7 <handle_mm_fault+63>.
  1571. To find where in handle_mm_fault this is, I'll jump forward in the
  1572. code until I see an address in that procedure:
  1573. (gdb) i line *0x1000b1c0
  1574. Line 126 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1575. starts at address 0x1000b1b7 <handle_mm_fault+63>
  1576. and ends at 0x1000b1c3 <handle_mm_fault+75>.
  1577. (gdb) i line *0x1000b1d0
  1578. Line 131 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1579. starts at address 0x1000b1d0 <handle_mm_fault+88>
  1580. and ends at 0x1000b1da <handle_mm_fault+98>.
  1581. (gdb) i line *0x1000b1e0
  1582. Line 61 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1583. starts at address 0x1000b1da <handle_mm_fault+98>
  1584. and ends at 0x1000b1e1 <handle_mm_fault+105>.
  1585. (gdb) i line *0x1000b1f0
  1586. Line 134 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1587. starts at address 0x1000b1f0 <handle_mm_fault+120>
  1588. and ends at 0x1000b200 <handle_mm_fault+136>.
  1589. (gdb) i line *0x1000b200
  1590. Line 135 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1591. starts at address 0x1000b200 <handle_mm_fault+136>
  1592. and ends at 0x1000b208 <handle_mm_fault+144>.
  1593. (gdb) i line *0x1000b210
  1594. Line 139 of "/home/dike/linux/2.3.26/um/include/asm/pgalloc.h"
  1595. starts at address 0x1000b210 <handle_mm_fault+152>
  1596. and ends at 0x1000b219 <handle_mm_fault+161>.
  1597. (gdb) i line *0x1000b220
  1598. Line 1168 of "memory.c" starts at address 0x1000b21e <handle_mm_fault+166>
  1599. and ends at 0x1000b222 <handle_mm_fault+170>.
  1600. Something is apparently wrong with the page tables or vma_structs, so
  1601. lets go back to frame 11 and have a look at them:
  1602. #11 0x1006c0aa in segv (address=1342179328, is_write=2) at trap_kern.c:50
  1603. 50 handle_mm_fault(current, vma, address, is_write);
  1604. (gdb) call pgd_offset_proc(vma->vm_mm, address)
  1605. $22 = (pgd_t *) 0x80a548c
  1606. That's pretty bogus. Page tables aren't supposed to be in process
  1607. text or data areas. Let's see what's in the vma:
  1608. (gdb) p *vma
  1609. $23 = {vm_mm = 0x507d2434, vm_start = 0, vm_end = 134512640,
  1610. vm_next = 0x80a4f8c, vm_page_prot = {pgprot = 0}, vm_flags = 31200,
  1611. vm_avl_height = 2058, vm_avl_left = 0x80a8c94, vm_avl_right = 0x80d1000,
  1612. vm_next_share = 0xaffffdb0, vm_pprev_share = 0xaffffe63,
  1613. vm_ops = 0xaffffe7a, vm_pgoff = 2952789626, vm_file = 0xafffffec,
  1614. vm_private_data = 0x62}
  1615. (gdb) p *vma.vm_mm
  1616. $24 = {mmap = 0x507d2434, mmap_avl = 0x0, mmap_cache = 0x8048000,
  1617. pgd = 0x80a4f8c, mm_users = {counter = 0}, mm_count = {counter = 134904288},
  1618. map_count = 134909076, mmap_sem = {count = {counter = 135073792},
  1619. sleepers = -1342177872, wait = {lock = <optimized out or zero length>,
  1620. task_list = {next = 0xaffffe63, prev = 0xaffffe7a},
  1621. __magic = -1342177670, __creator = -1342177300}, __magic = 98},
  1622. page_table_lock = {}, context = 138, start_code = 0, end_code = 0,
  1623. start_data = 0, end_data = 0, start_brk = 0, brk = 0, start_stack = 0,
  1624. arg_start = 0, arg_end = 0, env_start = 0, env_end = 0, rss = 1350381536,
  1625. total_vm = 0, locked_vm = 0, def_flags = 0, cpu_vm_mask = 0, swap_cnt = 0,
  1626. swap_address = 0, segments = 0x0}
  1627. This also pretty bogus. With all of the 0x80xxxxx and 0xaffffxxx
  1628. addresses, this is looking like a stack was plonked down on top of
  1629. these structures. Maybe it's a stack overflow from the next page:
  1630. (gdb) p vma
  1631. $25 = (struct vm_area_struct *) 0x507d2434
  1632. That's towards the lower quarter of the page, so that would have to
  1633. have been pretty heavy stack overflow:
  1634. (gdb) x/100x $25
  1635. 0x507d2434: 0x507d2434 0x00000000 0x08048000 0x080a4f8c
  1636. 0x507d2444: 0x00000000 0x080a79e0 0x080a8c94 0x080d1000
  1637. 0x507d2454: 0xaffffdb0 0xaffffe63 0xaffffe7a 0xaffffe7a
  1638. 0x507d2464: 0xafffffec 0x00000062 0x0000008a 0x00000000
  1639. 0x507d2474: 0x00000000 0x00000000 0x00000000 0x00000000
  1640. 0x507d2484: 0x00000000 0x00000000 0x00000000 0x00000000
  1641. 0x507d2494: 0x00000000 0x00000000 0x507d2fe0 0x00000000
  1642. 0x507d24a4: 0x00000000 0x00000000 0x00000000 0x00000000
  1643. 0x507d24b4: 0x00000000 0x00000000 0x00000000 0x00000000
  1644. 0x507d24c4: 0x00000000 0x00000000 0x00000000 0x00000000
  1645. 0x507d24d4: 0x00000000 0x00000000 0x00000000 0x00000000
  1646. 0x507d24e4: 0x00000000 0x00000000 0x00000000 0x00000000
  1647. 0x507d24f4: 0x00000000 0x00000000 0x00000000 0x00000000
  1648. 0x507d2504: 0x00000000 0x00000000 0x00000000 0x00000000
  1649. 0x507d2514: 0x00000000 0x00000000 0x00000000 0x00000000
  1650. 0x507d2524: 0x00000000 0x00000000 0x00000000 0x00000000
  1651. 0x507d2534: 0x00000000 0x00000000 0x507d25dc 0x00000000
  1652. 0x507d2544: 0x00000000 0x00000000 0x00000000 0x00000000
  1653. 0x507d2554: 0x00000000 0x00000000 0x00000000 0x00000000
  1654. 0x507d2564: 0x00000000 0x00000000 0x00000000 0x00000000
  1655. 0x507d2574: 0x00000000 0x00000000 0x00000000 0x00000000
  1656. 0x507d2584: 0x00000000 0x00000000 0x00000000 0x00000000
  1657. 0x507d2594: 0x00000000 0x00000000 0x00000000 0x00000000
  1658. 0x507d25a4: 0x00000000 0x00000000 0x00000000 0x00000000
  1659. 0x507d25b4: 0x00000000 0x00000000 0x00000000 0x00000000
  1660. It's not stack overflow. The only "stack-like" piece of this data is
  1661. the vma_struct itself.
  1662. At this point, I don't see any avenues to pursue, so I just have to
  1663. admit that I have no idea what's going on. What I will do, though, is
  1664. stick a trap on the segfault handler which will stop if it sees any
  1665. writes to the idle thread's stack. That was the thing that happened
  1666. first, and it may be that if I can catch it immediately, what's going
  1667. on will be somewhat clearer.
  1668. 12.2. Episode 2: The case of the hung fsck
  1669. After setting a trap in the SEGV handler for accesses to the signal
  1670. thread's stack, I reran the kernel.
  1671. fsck hung again, this time by hitting the trap:
  1672. Setting hostname uml [ OK ]
  1673. Checking root filesystem
  1674. /dev/fhd0 contains a file system with errors, check forced.
  1675. Error reading block 86894 (Attempt to read block from filesystem resulted in short read) while reading indirect blocks of inode 19780.
  1676. /dev/fhd0: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
  1677. (i.e., without -a or -p options)
  1678. [ FAILED ]
  1679. *** An error occurred during the file system check.
  1680. *** Dropping you to a shell; the system will reboot
  1681. *** when you leave the shell.
  1682. Give root password for maintenance
  1683. (or type Control-D for normal startup):
  1684. [root@uml /root]# fsck -y /dev/fhd0
  1685. fsck -y /dev/fhd0
  1686. Parallelizing fsck version 1.14 (9-Jan-1999)
  1687. e2fsck 1.14, 9-Jan-1999 for EXT2 FS 0.5b, 95/08/09
  1688. /dev/fhd0 contains a file system with errors, check forced.
  1689. Pass 1: Checking inodes, blocks, and sizes
  1690. Error reading block 86894 (Attempt to read block from filesystem resulted in short read) while reading indirect blocks of inode 19780. Ignore error? yes
  1691. Pass 2: Checking directory structure
  1692. Error reading block 49405 (Attempt to read block from filesystem resulted in short read). Ignore error? yes
  1693. Directory inode 11858, block 0, offset 0: directory corrupted
  1694. Salvage? yes
  1695. Missing '.' in directory inode 11858.
  1696. Fix? yes
  1697. Missing '..' in directory inode 11858.
  1698. Fix? yes
  1699. Untested (4127) [100fe44c]: trap_kern.c line 31
  1700. I need to get the signal thread to detach from pid 4127 so that I can
  1701. attach to it with gdb. This is done by sending it a SIGUSR1, which is
  1702. caught by the signal thread, which detaches the process:
  1703. kill -USR1 4127
  1704. Now I can run gdb on it:
  1705. ~/linux/2.3.26/um 1034: gdb linux
  1706. GNU gdb 4.17.0.11 with Linux support
  1707. Copyright 1998 Free Software Foundation, Inc.
  1708. GDB is free software, covered by the GNU General Public License, and you are
  1709. welcome to change it and/or distribute copies of it under certain conditions.
  1710. Type "show copying" to see the conditions.
  1711. There is absolutely no warranty for GDB. Type "show warranty" for details.
  1712. This GDB was configured as "i386-redhat-linux"...
  1713. (gdb) att 4127
  1714. Attaching to program `/home/dike/linux/2.3.26/um/linux', Pid 4127
  1715. 0x10075891 in __libc_nanosleep ()
  1716. The backtrace shows that it was in a write and that the fault address
  1717. (address in frame 3) is 0x50000800, which is right in the middle of
  1718. the signal thread's stack page:
  1719. (gdb) bt
  1720. #0 0x10075891 in __libc_nanosleep ()
  1721. #1 0x1007584d in __sleep (seconds=1000000)
  1722. at ../sysdeps/unix/sysv/linux/sleep.c:78
  1723. #2 0x1006ce9a in stop () at user_util.c:191
  1724. #3 0x1006bf88 in segv (address=1342179328, is_write=2) at trap_kern.c:31
  1725. #4 0x1006c628 in segv_handler (sc=0x5006eaf8) at trap_user.c:174
  1726. #5 0x1006c63c in kern_segv_handler (sig=11) at trap_user.c:182
  1727. #6 <signal handler called>
  1728. #7 0xc0fd in ?? ()
  1729. #8 0x10016647 in sys_write (fd=3, buf=0x80b8800 "R.", count=1024)
  1730. at read_write.c:159
  1731. #9 0x1006d603 in execute_syscall (syscall=4, args=0x5006ef08)
  1732. at syscall_kern.c:254
  1733. #10 0x1006af87 in really_do_syscall (sig=12) at syscall_user.c:35
  1734. #11 <signal handler called>
  1735. #12 0x400dc8b0 in ?? ()
  1736. #13 <signal handler called>
  1737. #14 0x400dc8b0 in ?? ()
  1738. #15 0x80545fd in ?? ()
  1739. #16 0x804daae in ?? ()
  1740. #17 0x8054334 in ?? ()
  1741. #18 0x804d23e in ?? ()
  1742. #19 0x8049632 in ?? ()
  1743. #20 0x80491d2 in ?? ()
  1744. #21 0x80596b5 in ?? ()
  1745. (gdb) p (void *)1342179328
  1746. $3 = (void *) 0x50000800
  1747. Going up the stack to the segv_handler frame and looking at where in
  1748. the code the access happened shows that it happened near line 110 of
  1749. block_dev.c:
  1750. (gdb) up
  1751. #1 0x1007584d in __sleep (seconds=1000000)
  1752. at ../sysdeps/unix/sysv/linux/sleep.c:78
  1753. ../sysdeps/unix/sysv/linux/sleep.c:78: No such file or directory.
  1754. (gdb)
  1755. #2 0x1006ce9a in stop () at user_util.c:191
  1756. 191 while(1) sleep(1000000);
  1757. (gdb)
  1758. #3 0x1006bf88 in segv (address=1342179328, is_write=2) at trap_kern.c:31
  1759. 31 KERN_UNTESTED();
  1760. (gdb)
  1761. #4 0x1006c628 in segv_handler (sc=0x5006eaf8) at trap_user.c:174
  1762. 174 segv(sc->cr2, sc->err & 2);
  1763. (gdb) p *sc
  1764. $1 = {gs = 0, __gsh = 0, fs = 0, __fsh = 0, es = 43, __esh = 0, ds = 43,
  1765. __dsh = 0, edi = 1342179328, esi = 134973440, ebp = 1342631484,
  1766. esp = 1342630864, ebx = 256, edx = 0, ecx = 256, eax = 1024, trapno = 14,
  1767. err = 6, eip = 268550834, cs = 35, __csh = 0, eflags = 66070,
  1768. esp_at_signal = 1342630864, ss = 43, __ssh = 0, fpstate = 0x0, oldmask = 0,
  1769. cr2 = 1342179328}
  1770. (gdb) p (void *)268550834
  1771. $2 = (void *) 0x1001c2b2
  1772. (gdb) i sym $2
  1773. block_write + 1090 in section .text
  1774. (gdb) i line *$2
  1775. Line 209 of "/home/dike/linux/2.3.26/um/include/asm/arch/string.h"
  1776. starts at address 0x1001c2a1 <block_write+1073>
  1777. and ends at 0x1001c2bf <block_write+1103>.
  1778. (gdb) i line *0x1001c2c0
  1779. Line 110 of "block_dev.c" starts at address 0x1001c2bf <block_write+1103>
  1780. and ends at 0x1001c2e3 <block_write+1139>.
  1781. Looking at the source shows that the fault happened during a call to
  1782. copy_from_user to copy the data into the kernel:
  1783. 107 count -= chars;
  1784. 108 copy_from_user(p,buf,chars);
  1785. 109 p += chars;
  1786. 110 buf += chars;
  1787. p is the pointer which must contain 0x50000800, since buf contains
  1788. 0x80b8800 (frame 8 above). It is defined as:
  1789. p = offset + bh->b_data;
  1790. I need to figure out what bh is, and it just so happens that bh is
  1791. passed as an argument to mark_buffer_uptodate and mark_buffer_dirty a
  1792. few lines later, so I do a little disassembly:
  1793. (gdb) disas 0x1001c2bf 0x1001c2e0
  1794. Dump of assembler code from 0x1001c2bf to 0x1001c2d0:
  1795. 0x1001c2bf <block_write+1103>: addl %eax,0xc(%ebp)
  1796. 0x1001c2c2 <block_write+1106>: movl 0xfffffdd4(%ebp),%edx
  1797. 0x1001c2c8 <block_write+1112>: btsl $0x0,0x18(%edx)
  1798. 0x1001c2cd <block_write+1117>: btsl $0x1,0x18(%edx)
  1799. 0x1001c2d2 <block_write+1122>: sbbl %ecx,%ecx
  1800. 0x1001c2d4 <block_write+1124>: testl %ecx,%ecx
  1801. 0x1001c2d6 <block_write+1126>: jne 0x1001c2e3 <block_write+1139>
  1802. 0x1001c2d8 <block_write+1128>: pushl $0x0
  1803. 0x1001c2da <block_write+1130>: pushl %edx
  1804. 0x1001c2db <block_write+1131>: call 0x1001819c <__mark_buffer_dirty>
  1805. End of assembler dump.
  1806. At that point, bh is in %edx (address 0x1001c2da), which is calculated
  1807. at 0x1001c2c2 as %ebp + 0xfffffdd4, so I figure exactly what that is,
  1808. taking %ebp from the sigcontext_struct above:
  1809. (gdb) p (void *)1342631484
  1810. $5 = (void *) 0x5006ee3c
  1811. (gdb) p 0x5006ee3c+0xfffffdd4
  1812. $6 = 1342630928
  1813. (gdb) p (void *)$6
  1814. $7 = (void *) 0x5006ec10
  1815. (gdb) p *((void **)$7)
  1816. $8 = (void *) 0x50100200
  1817. Now, I look at the structure to see what's in it, and particularly,
  1818. what its b_data field contains:
  1819. (gdb) p *((struct buffer_head *)0x50100200)
  1820. $13 = {b_next = 0x50289380, b_blocknr = 49405, b_size = 1024, b_list = 0,
  1821. b_dev = 15872, b_count = {counter = 1}, b_rdev = 15872, b_state = 24,
  1822. b_flushtime = 0, b_next_free = 0x501001a0, b_prev_free = 0x50100260,
  1823. b_this_page = 0x501001a0, b_reqnext = 0x0, b_pprev = 0x507fcf58,
  1824. b_data = 0x50000800 "", b_page = 0x50004000,
  1825. b_end_io = 0x10017f60 <end_buffer_io_sync>, b_dev_id = 0x0,
  1826. b_rsector = 98810, b_wait = {lock = <optimized out or zero length>,
  1827. task_list = {next = 0x50100248, prev = 0x50100248}, __magic = 1343226448,
  1828. __creator = 0}, b_kiobuf = 0x0}
  1829. The b_data field is indeed 0x50000800, so the question becomes how
  1830. that happened. The rest of the structure looks fine, so this probably
  1831. is not a case of data corruption. It happened on purpose somehow.
  1832. The b_page field is a pointer to the page_struct representing the
  1833. 0x50000000 page. Looking at it shows the kernel's idea of the state
  1834. of that page:
  1835. (gdb) p *$13.b_page
  1836. $17 = {list = {next = 0x50004a5c, prev = 0x100c5174}, mapping = 0x0,
  1837. index = 0, next_hash = 0x0, count = {counter = 1}, flags = 132, lru = {
  1838. next = 0x50008460, prev = 0x50019350}, wait = {
  1839. lock = <optimized out or zero length>, task_list = {next = 0x50004024,
  1840. prev = 0x50004024}, __magic = 1342193708, __creator = 0},
  1841. pprev_hash = 0x0, buffers = 0x501002c0, virtual = 1342177280,
  1842. zone = 0x100c5160}
  1843. Some sanity-checking: the virtual field shows the "virtual" address of
  1844. this page, which in this kernel is the same as its "physical" address,
  1845. and the page_struct itself should be mem_map[0], since it represents
  1846. the first page of memory:
  1847. (gdb) p (void *)1342177280
  1848. $18 = (void *) 0x50000000
  1849. (gdb) p mem_map
  1850. $19 = (mem_map_t *) 0x50004000
  1851. These check out fine.
  1852. Now to check out the page_struct itself. In particular, the flags
  1853. field shows whether the page is considered free or not:
  1854. (gdb) p (void *)132
  1855. $21 = (void *) 0x84
  1856. The "reserved" bit is the high bit, which is definitely not set, so
  1857. the kernel considers the signal stack page to be free and available to
  1858. be used.
  1859. At this point, I jump to conclusions and start looking at my early
  1860. boot code, because that's where that page is supposed to be reserved.
  1861. In my setup_arch procedure, I have the following code which looks just
  1862. fine:
  1863. bootmap_size = init_bootmem(start_pfn, end_pfn - start_pfn);
  1864. free_bootmem(__pa(low_physmem) + bootmap_size, high_physmem - low_physmem);
  1865. Two stack pages have already been allocated, and low_physmem points to
  1866. the third page, which is the beginning of free memory.
  1867. The init_bootmem call declares the entire memory to the boot memory
  1868. manager, which marks it all reserved. The free_bootmem call frees up
  1869. all of it, except for the first two pages. This looks correct to me.
  1870. So, I decide to see init_bootmem run and make sure that it is marking
  1871. those first two pages as reserved. I never get that far.
  1872. Stepping into init_bootmem, and looking at bootmem_map before looking
  1873. at what it contains shows the following:
  1874. (gdb) p bootmem_map
  1875. $3 = (void *) 0x50000000
  1876. Aha! The light dawns. That first page is doing double duty as a
  1877. stack and as the boot memory map. The last thing that the boot memory
  1878. manager does is to free the pages used by its memory map, so this page
  1879. is getting freed even its marked as reserved.
  1880. The fix was to initialize the boot memory manager before allocating
  1881. those two stack pages, and then allocate them through the boot memory
  1882. manager. After doing this, and fixing a couple of subsequent buglets,
  1883. the stack corruption problem disappeared.
  1884. 13. What to do when UML doesn't work
  1885. 13.1. Strange compilation errors when you build from source
  1886. As of test11, it is necessary to have "ARCH=um" in the environment or
  1887. on the make command line for all steps in building UML, including
  1888. clean, distclean, or mrproper, config, menuconfig, or xconfig, dep,
  1889. and linux. If you forget for any of them, the i386 build seems to
  1890. contaminate the UML build. If this happens, start from scratch with
  1891. host%
  1892. make mrproper ARCH=um
  1893. and repeat the build process with ARCH=um on all the steps.
  1894. See ``Compiling the kernel and modules'' for more details.
  1895. Another cause of strange compilation errors is building UML in
  1896. /usr/src/linux. If you do this, the first thing you need to do is
  1897. clean up the mess you made. The /usr/src/linux/asm link will now
  1898. point to /usr/src/linux/asm-um. Make it point back to
  1899. /usr/src/linux/asm-i386. Then, move your UML pool someplace else and
  1900. build it there. Also see below, where a more specific set of symptoms
  1901. is described.
  1902. 13.3. A variety of panics and hangs with /tmp on a reiserfs filesys-
  1903. tem
  1904. I saw this on reiserfs 3.5.21 and it seems to be fixed in 3.5.27.
  1905. Panics preceded by
  1906. Detaching pid nnnn
  1907. are diagnostic of this problem. This is a reiserfs bug which causes a
  1908. thread to occasionally read stale data from a mmapped page shared with
  1909. another thread. The fix is to upgrade the filesystem or to have /tmp
  1910. be an ext2 filesystem.
  1911. 13.4. The compile fails with errors about conflicting types for
  1912. 'open', 'dup', and 'waitpid'
  1913. This happens when you build in /usr/src/linux. The UML build makes
  1914. the include/asm link point to include/asm-um. /usr/include/asm points
  1915. to /usr/src/linux/include/asm, so when that link gets moved, files
  1916. which need to include the asm-i386 versions of headers get the
  1917. incompatible asm-um versions. The fix is to move the include/asm link
  1918. back to include/asm-i386 and to do UML builds someplace else.
  1919. 13.5. UML doesn't work when /tmp is an NFS filesystem
  1920. This seems to be a similar situation with the ReiserFS problem above.
  1921. Some versions of NFS seems not to handle mmap correctly, which UML
  1922. depends on. The workaround is have /tmp be a non-NFS directory.
  1923. 13.6. UML hangs on boot when compiled with gprof support
  1924. If you build UML with gprof support and, early in the boot, it does
  1925. this
  1926. kernel BUG at page_alloc.c:100!
  1927. you have a buggy gcc. You can work around the problem by removing
  1928. UM_FASTCALL from CFLAGS in arch/um/Makefile-i386. This will open up
  1929. another bug, but that one is fairly hard to reproduce.
  1930. 13.7. syslogd dies with a SIGTERM on startup
  1931. The exact boot error depends on the distribution that you're booting,
  1932. but Debian produces this:
  1933. /etc/rc2.d/S10sysklogd: line 49: 93 Terminated
  1934. start-stop-daemon --start --quiet --exec /sbin/syslogd -- $SYSLOGD
  1935. This is a syslogd bug. There's a race between a parent process
  1936. installing a signal handler and its child sending the signal. See
  1937. this uml-devel post <http://www.geocrawler.com/lists/3/Source-
  1938. Forge/709/0/6612801> for the details.
  1939. 13.8. TUN/TAP networking doesn't work on a 2.4 host
  1940. There are a couple of problems which were
  1941. <http://www.geocrawler.com/lists/3/SourceForge/597/0/> name="pointed
  1942. out"> by Tim Robinson <timro at trkr dot net>
  1943. o It doesn't work on hosts running 2.4.7 (or thereabouts) or earlier.
  1944. The fix is to upgrade to something more recent and then read the
  1945. next item.
  1946. o If you see
  1947. File descriptor in bad state
  1948. when you bring up the device inside UML, you have a header mismatch
  1949. between the original kernel and the upgraded one. Make /usr/src/linux
  1950. point at the new headers. This will only be a problem if you build
  1951. uml_net yourself.
  1952. 13.9. You can network to the host but not to other machines on the
  1953. net
  1954. If you can connect to the host, and the host can connect to UML, but
  1955. you cannot connect to any other machines, then you may need to enable
  1956. IP Masquerading on the host. Usually this is only experienced when
  1957. using private IP addresses (192.168.x.x or 10.x.x.x) for host/UML
  1958. networking, rather than the public address space that your host is
  1959. connected to. UML does not enable IP Masquerading, so you will need
  1960. to create a static rule to enable it:
  1961. host%
  1962. iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  1963. Replace eth0 with the interface that you use to talk to the rest of
  1964. the world.
  1965. Documentation on IP Masquerading, and SNAT, can be found at
  1966. www.netfilter.org <http://www.netfilter.org> .
  1967. If you can reach the local net, but not the outside Internet, then
  1968. that is usually a routing problem. The UML needs a default route:
  1969. UML#
  1970. route add default gw gateway IP
  1971. The gateway IP can be any machine on the local net that knows how to
  1972. reach the outside world. Usually, this is the host or the local net-
  1973. work's gateway.
  1974. Occasionally, we hear from someone who can reach some machines, but
  1975. not others on the same net, or who can reach some ports on other
  1976. machines, but not others. These are usually caused by strange
  1977. firewalling somewhere between the UML and the other box. You track
  1978. this down by running tcpdump on every interface the packets travel
  1979. over and see where they disappear. When you find a machine that takes
  1980. the packets in, but does not send them onward, that's the culprit.
  1981. 13.10. I have no root and I want to scream
  1982. Thanks to Birgit Wahlich for telling me about this strange one. It
  1983. turns out that there's a limit of six environment variables on the
  1984. kernel command line. When that limit is reached or exceeded, argument
  1985. processing stops, which means that the 'root=' argument that UML
  1986. usually adds is not seen. So, the filesystem has no idea what the
  1987. root device is, so it panics.
  1988. The fix is to put less stuff on the command line. Glomming all your
  1989. setup variables into one is probably the best way to go.
  1990. 13.11. UML build conflict between ptrace.h and ucontext.h
  1991. On some older systems, /usr/include/asm/ptrace.h and
  1992. /usr/include/sys/ucontext.h define the same names. So, when they're
  1993. included together, the defines from one completely mess up the parsing
  1994. of the other, producing errors like:
  1995. /usr/include/sys/ucontext.h:47: parse error before
  1996. `10'
  1997. plus a pile of warnings.
  1998. This is a libc botch, which has since been fixed, and I don't see any
  1999. way around it besides upgrading.
  2000. 13.12. The UML BogoMips is exactly half the host's BogoMips
  2001. On i386 kernels, there are two ways of running the loop that is used
  2002. to calculate the BogoMips rating, using the TSC if it's there or using
  2003. a one-instruction loop. The TSC produces twice the BogoMips as the
  2004. loop. UML uses the loop, since it has nothing resembling a TSC, and
  2005. will get almost exactly the same BogoMips as a host using the loop.
  2006. However, on a host with a TSC, its BogoMips will be double the loop
  2007. BogoMips, and therefore double the UML BogoMips.
  2008. 13.13. When you run UML, it immediately segfaults
  2009. If the host is configured with the 2G/2G address space split, that's
  2010. why. See ``UML on 2G/2G hosts'' for the details on getting UML to
  2011. run on your host.
  2012. 13.14. xterms appear, then immediately disappear
  2013. If you're running an up to date kernel with an old release of
  2014. uml_utilities, the port-helper program will not work properly, so
  2015. xterms will exit straight after they appear. The solution is to
  2016. upgrade to the latest release of uml_utilities. Usually this problem
  2017. occurs when you have installed a packaged release of UML then compiled
  2018. your own development kernel without upgrading the uml_utilities from
  2019. the source distribution.
  2020. 13.15. Any other panic, hang, or strange behavior
  2021. If you're seeing truly strange behavior, such as hangs or panics that
  2022. happen in random places, or you try running the debugger to see what's
  2023. happening and it acts strangely, then it could be a problem in the
  2024. host kernel. If you're not running a stock Linus or -ac kernel, then
  2025. try that. An early version of the preemption patch and a 2.4.10 SuSE
  2026. kernel have caused very strange problems in UML.
  2027. Otherwise, let me know about it. Send a message to one of the UML
  2028. mailing lists - either the developer list - user-mode-linux-devel at
  2029. lists dot sourceforge dot net (subscription info) or the user list -
  2030. user-mode-linux-user at lists dot sourceforge do net (subscription
  2031. info), whichever you prefer. Don't assume that everyone knows about
  2032. it and that a fix is imminent.
  2033. If you want to be super-helpful, read ``Diagnosing Problems'' and
  2034. follow the instructions contained therein.
  2035. 14. Diagnosing Problems
  2036. If you get UML to crash, hang, or otherwise misbehave, you should
  2037. report this on one of the project mailing lists, either the developer
  2038. list - user-mode-linux-devel at lists dot sourceforge dot net
  2039. (subscription info) or the user list - user-mode-linux-user at lists
  2040. dot sourceforge dot net (subscription info). When you do, it is
  2041. likely that I will want more information. So, it would be helpful to
  2042. read the stuff below, do whatever is applicable in your case, and
  2043. report the results to the list.
  2044. For any diagnosis, you're going to need to build a debugging kernel.
  2045. The binaries from this site aren't debuggable. If you haven't done
  2046. this before, read about ``Compiling the kernel and modules'' and
  2047. ``Kernel debugging'' UML first.
  2048. 14.1. Case 1 : Normal kernel panics
  2049. The most common case is for a normal thread to panic. To debug this,
  2050. you will need to run it under the debugger (add 'debug' to the command
  2051. line). An xterm will start up with gdb running inside it. Continue
  2052. it when it stops in start_kernel and make it crash. Now ^C gdb and
  2053. If the panic was a "Kernel mode fault", then there will be a segv
  2054. frame on the stack and I'm going to want some more information. The
  2055. stack might look something like this:
  2056. (UML gdb) backtrace
  2057. #0 0x1009bf76 in __sigprocmask (how=1, set=0x5f347940, oset=0x0)
  2058. at ../sysdeps/unix/sysv/linux/sigprocmask.c:49
  2059. #1 0x10091411 in change_sig (signal=10, on=1) at process.c:218
  2060. #2 0x10094785 in timer_handler (sig=26) at time_kern.c:32
  2061. #3 0x1009bf38 in __restore ()
  2062. at ../sysdeps/unix/sysv/linux/i386/sigaction.c:125
  2063. #4 0x1009534c in segv (address=8, ip=268849158, is_write=2, is_user=0)
  2064. at trap_kern.c:66
  2065. #5 0x10095c04 in segv_handler (sig=11) at trap_user.c:285
  2066. #6 0x1009bf38 in __restore ()
  2067. I'm going to want to see the symbol and line information for the value
  2068. of ip in the segv frame. In this case, you would do the following:
  2069. (UML gdb) i sym 268849158
  2070. and
  2071. (UML gdb) i line *268849158
  2072. The reason for this is the __restore frame right above the segv_han-
  2073. dler frame is hiding the frame that actually segfaulted. So, I have
  2074. to get that information from the faulting ip.
  2075. 14.2. Case 2 : Tracing thread panics
  2076. The less common and more painful case is when the tracing thread
  2077. panics. In this case, the kernel debugger will be useless because it
  2078. needs a healthy tracing thread in order to work. The first thing to
  2079. do is get a backtrace from the tracing thread. This is done by
  2080. figuring out what its pid is, firing up gdb, and attaching it to that
  2081. pid. You can figure out the tracing thread pid by looking at the
  2082. first line of the console output, which will look like this:
  2083. tracing thread pid = 15851
  2084. or by running ps on the host and finding the line that looks like
  2085. this:
  2086. jdike 15851 4.5 0.4 132568 1104 pts/0 S 21:34 0:05 ./linux [(tracing thread)]
  2087. If the panic was 'segfault in signals', then follow the instructions
  2088. above for collecting information about the location of the seg fault.
  2089. If the tracing thread flaked out all by itself, then send that
  2090. backtrace in and wait for our crack debugging team to fix the problem.
  2091. 14.3. Case 3 : Tracing thread panics caused by other threads
  2092. However, there are cases where the misbehavior of another thread
  2093. caused the problem. The most common panic of this type is:
  2094. wait_for_stop failed to wait for <pid> to stop with <signal number>
  2095. In this case, you'll need to get a backtrace from the process men-
  2096. tioned in the panic, which is complicated by the fact that the kernel
  2097. debugger is defunct and without some fancy footwork, another gdb can't
  2098. attach to it. So, this is how the fancy footwork goes:
  2099. In a shell:
  2100. host% kill -STOP pid
  2101. Run gdb on the tracing thread as described in case 2 and do:
  2102. (host gdb) call detach(pid)
  2103. If you get a segfault, do it again. It always works the second time.
  2104. Detach from the tracing thread and attach to that other thread:
  2105. (host gdb) detach
  2106. (host gdb) attach pid
  2107. If gdb hangs when attaching to that process, go back to a shell and
  2108. do:
  2109. host%
  2110. kill -CONT pid
  2111. And then get the backtrace:
  2112. (host gdb) backtrace
  2113. 14.4. Case 4 : Hangs
  2114. Hangs seem to be fairly rare, but they sometimes happen. When a hang
  2115. happens, we need a backtrace from the offending process. Run the
  2116. kernel debugger as described in case 1 and get a backtrace. If the
  2117. current process is not the idle thread, then send in the backtrace.
  2118. You can tell that it's the idle thread if the stack looks like this:
  2119. #0 0x100b1401 in __libc_nanosleep ()
  2120. #1 0x100a2885 in idle_sleep (secs=10) at time.c:122
  2121. #2 0x100a546f in do_idle () at process_kern.c:445
  2122. #3 0x100a5508 in cpu_idle () at process_kern.c:471
  2123. #4 0x100ec18f in start_kernel () at init/main.c:592
  2124. #5 0x100a3e10 in start_kernel_proc (unused=0x0) at um_arch.c:71
  2125. #6 0x100a383f in signal_tramp (arg=0x100a3dd8) at trap_user.c:50
  2126. If this is the case, then some other process is at fault, and went to
  2127. sleep when it shouldn't have. Run ps on the host and figure out which
  2128. process should not have gone to sleep and stayed asleep. Then attach
  2129. to it with gdb and get a backtrace as described in case 3.
  2130. 15. Thanks
  2131. A number of people have helped this project in various ways, and this
  2132. page gives recognition where recognition is due.
  2133. If you're listed here and you would prefer a real link on your name,
  2134. or no link at all, instead of the despammed email address pseudo-link,
  2135. let me know.
  2136. If you're not listed here and you think maybe you should be, please
  2137. let me know that as well. I try to get everyone, but sometimes my
  2138. bookkeeping lapses and I forget about contributions.
  2139. 15.1. Code and Documentation
  2140. Rusty Russell <rusty at linuxcare.com.au> -
  2141. o wrote the HOWTO <http://user-mode-
  2142. linux.sourceforge.net/UserModeLinux-HOWTO.html>
  2143. o prodded me into making this project official and putting it on
  2144. SourceForge
  2145. o came up with the way cool UML logo <http://user-mode-
  2146. linux.sourceforge.net/uml-small.png>
  2147. o redid the config process
  2148. Peter Moulder <reiter at netspace.net.au> - Fixed my config and build
  2149. processes, and added some useful code to the block driver
  2150. Bill Stearns <wstearns at pobox.com> -
  2151. o HOWTO updates
  2152. o lots of bug reports
  2153. o lots of testing
  2154. o dedicated a box (uml.ists.dartmouth.edu) to support UML development
  2155. o wrote the mkrootfs script, which allows bootable filesystems of
  2156. RPM-based distributions to be cranked out
  2157. o cranked out a large number of filesystems with said script
  2158. Jim Leu <jleu at mindspring.com> - Wrote the virtual ethernet driver
  2159. and associated usermode tools
  2160. Lars Brinkhoff <http://lars.nocrew.org/> - Contributed the ptrace
  2161. proxy from his own project <http://a386.nocrew.org/> to allow easier
  2162. kernel debugging
  2163. Andrea Arcangeli <andrea at suse.de> - Redid some of the early boot
  2164. code so that it would work on machines with Large File Support
  2165. Chris Emerson <http://www.chiark.greenend.org.uk/~cemerson/> - Did
  2166. the first UML port to Linux/ppc
  2167. Harald Welte <laforge at gnumonks.org> - Wrote the multicast
  2168. transport for the network driver
  2169. Jorgen Cederlof - Added special file support to hostfs
  2170. Greg Lonnon <glonnon at ridgerun dot com> - Changed the ubd driver
  2171. to allow it to layer a COW file on a shared read-only filesystem and
  2172. wrote the iomem emulation support
  2173. Henrik Nordstrom <http://hem.passagen.se/hno/> - Provided a variety
  2174. of patches, fixes, and clues
  2175. Lennert Buytenhek - Contributed various patches, a rewrite of the
  2176. network driver, the first implementation of the mconsole driver, and
  2177. did the bulk of the work needed to get SMP working again.
  2178. Yon Uriarte - Fixed the TUN/TAP network backend while I slept.
  2179. Adam Heath - Made a bunch of nice cleanups to the initialization code,
  2180. plus various other small patches.
  2181. Matt Zimmerman - Matt volunteered to be the UML Debian maintainer and
  2182. is doing a real nice job of it. He also noticed and fixed a number of
  2183. actually and potentially exploitable security holes in uml_net. Plus
  2184. the occasional patch. I like patches.
  2185. James McMechan - James seems to have taken over maintenance of the ubd
  2186. driver and is doing a nice job of it.
  2187. Chandan Kudige - wrote the umlgdb script which automates the reloading
  2188. of module symbols.
  2189. Steve Schmidtke - wrote the UML slirp transport and hostaudio drivers,
  2190. enabling UML processes to access audio devices on the host. He also
  2191. submitted patches for the slip transport and lots of other things.
  2192. David Coulson <http://davidcoulson.net> -
  2193. o Set up the usermodelinux.org <http://usermodelinux.org> site,
  2194. which is a great way of keeping the UML user community on top of
  2195. UML goings-on.
  2196. o Site documentation and updates
  2197. o Nifty little UML management daemon UMLd
  2198. <http://uml.openconsultancy.com/umld/>
  2199. o Lots of testing and bug reports
  2200. 15.2. Flushing out bugs
  2201. o Yuri Pudgorodsky
  2202. o Gerald Britton
  2203. o Ian Wehrman
  2204. o Gord Lamb
  2205. o Eugene Koontz
  2206. o John H. Hartman
  2207. o Anders Karlsson
  2208. o Daniel Phillips
  2209. o John Fremlin
  2210. o Rainer Burgstaller
  2211. o James Stevenson
  2212. o Matt Clay
  2213. o Cliff Jefferies
  2214. o Geoff Hoff
  2215. o Lennert Buytenhek
  2216. o Al Viro
  2217. o Frank Klingenhoefer
  2218. o Livio Baldini Soares
  2219. o Jon Burgess
  2220. o Petru Paler
  2221. o Paul
  2222. o Chris Reahard
  2223. o Sverker Nilsson
  2224. o Gong Su
  2225. o johan verrept
  2226. o Bjorn Eriksson
  2227. o Lorenzo Allegrucci
  2228. o Muli Ben-Yehuda
  2229. o David Mansfield
  2230. o Howard Goff
  2231. o Mike Anderson
  2232. o John Byrne
  2233. o Sapan J. Batia
  2234. o Iris Huang
  2235. o Jan Hudec
  2236. o Voluspa
  2237. 15.3. Buglets and clean-ups
  2238. o Dave Zarzycki
  2239. o Adam Lazur
  2240. o Boria Feigin
  2241. o Brian J. Murrell
  2242. o JS
  2243. o Roman Zippel
  2244. o Wil Cooley
  2245. o Ayelet Shemesh
  2246. o Will Dyson
  2247. o Sverker Nilsson
  2248. o dvorak
  2249. o v.naga srinivas
  2250. o Shlomi Fish
  2251. o Roger Binns
  2252. o johan verrept
  2253. o MrChuoi
  2254. o Peter Cleve
  2255. o Vincent Guffens
  2256. o Nathan Scott
  2257. o Patrick Caulfield
  2258. o jbearce
  2259. o Catalin Marinas
  2260. o Shane Spencer
  2261. o Zou Min
  2262. o Ryan Boder
  2263. o Lorenzo Colitti
  2264. o Gwendal Grignou
  2265. o Andre' Breiler
  2266. o Tsutomu Yasuda
  2267. 15.4. Case Studies
  2268. o Jon Wright
  2269. o William McEwan
  2270. o Michael Richardson
  2271. 15.5. Other contributions
  2272. Bill Carr <Bill.Carr at compaq.com> made the Red Hat mkrootfs script
  2273. work with RH 6.2.
  2274. Michael Jennings <mikejen at hevanet.com> sent in some material which
  2275. is now gracing the top of the index page <http://user-mode-
  2276. linux.sourceforge.net/> of this site.
  2277. SGI <http://www.sgi.com> (and more specifically Ralf Baechle <ralf at
  2278. uni-koblenz.de> ) gave me an account on oss.sgi.com
  2279. <http://www.oss.sgi.com> . The bandwidth there made it possible to
  2280. produce most of the filesystems available on the project download
  2281. page.
  2282. Laurent Bonnaud <Laurent.Bonnaud at inpg.fr> took the old grotty
  2283. Debian filesystem that I've been distributing and updated it to 2.2.
  2284. It is now available by itself here.
  2285. Rik van Riel gave me some ftp space on ftp.nl.linux.org so I can make
  2286. releases even when Sourceforge is broken.
  2287. Rodrigo de Castro looked at my broken pte code and told me what was
  2288. wrong with it, letting me fix a long-standing (several weeks) and
  2289. serious set of bugs.
  2290. Chris Reahard built a specialized root filesystem for running a DNS
  2291. server jailed inside UML. It's available from the download
  2292. <http://user-mode-linux.sourceforge.net/dl-sf.html> page in the Jail
  2293. Filesystems section.