UserModeLinux-HOWTO.txt 124 KB

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