You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

393 lines
44 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <meta name="mobile-web-app-capable" content="yes">
  10. <title>
  11. Lab 2: OS main components - HackMD
  12. </title>
  13. <link rel="icon" type="image/png" href="https://hackmd.io/favicon.png">
  14. <link rel="apple-touch-icon" href="https://hackmd.io/apple-touch-icon.png">
  15. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
  16. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
  17. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" integrity="sha256-3iu9jgsy9TpTwXKb7bNQzqWekRX7pPK+2OLj3R922fo=" crossorigin="anonymous" />
  18. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.5.0/octicons.min.css" integrity="sha256-QiWfLIsCT02Sdwkogf6YMiQlj4NE84MKkzEMkZnMGdg=" crossorigin="anonymous" />
  19. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.min.css" integrity="sha256-vtR0hSWRc3Tb26iuN2oZHt3KRUomwTufNIf5/4oeCyg=" crossorigin="anonymous" />
  20. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@hackmd/emojify.js@2.1.0/dist/css/basic/emojify.min.css" integrity="sha256-UOrvMOsSDSrW6szVLe8ZDZezBxh5IoIfgTwdNDgTjiU=" crossorigin="anonymous" />
  21. <style>
  22. @import url(https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i|Source+Code+Pro:300,400,500|Source+Sans+Pro:300,300i,400,400i,600,600i|Source+Serif+Pro&subset=latin-ext);.hljs{display:block;background:#fff;padding:.5em;color:#333;overflow-x:auto}.hljs-comment,.hljs-meta{color:#969896}.hljs-emphasis,.hljs-quote,.hljs-string,.hljs-strong,.hljs-template-variable,.hljs-variable{color:#df5000}.hljs-keyword,.hljs-selector-tag,.hljs-type{color:#a71d5d}.hljs-attribute,.hljs-bullet,.hljs-literal,.hljs-number,.hljs-symbol{color:#0086b3}.hljs-built_in,.hljs-builtin-name{color:#005cc5}.hljs-name,.hljs-section{color:#63a35c}.hljs-tag{color:#333}.hljs-attr,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-selector-pseudo,.hljs-title{color:#795da3}.hljs-addition{color:#55a532;background-color:#eaffea}.hljs-deletion{color:#bd2c00;background-color:#ffecec}.hljs-link{text-decoration:underline}.markdown-body{font-size:16px;line-height:1.5;word-wrap:break-word}.markdown-body:after,.markdown-body:before{display:table;content:""}.markdown-body:after{clear:both}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body .absent{color:#c00}.markdown-body .anchor{float:left;padding-right:4px;margin-left:-20px;line-height:1}.markdown-body .anchor:focus{outline:none}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body hr{height:.25em;padding:0;margin:24px 0;background-color:#e7e7e7;border:0}.markdown-body blockquote{font-size:16px;padding:0 1em;color:#777;border-left:.25em solid #ddd}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body kbd,.popover kbd{display:inline-block;padding:3px 5px;font-size:11px;line-height:10px;color:#555;vertical-align:middle;background-color:#fcfcfc;border:1px solid #ccc;border-bottom-color:#bbb;border-radius:3px;box-shadow:inset 0 -1px 0 #bbb}.markdown-body .loweralpha{list-style-type:lower-alpha}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{color:#000;vertical-align:middle;visibility:hidden}.markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{visibility:visible}.markdown-body h1 code,.markdown-body h1 tt,.markdown-body h2 code,.markdown-body h2 tt,.markdown-body h3 code,.markdown-body h3 tt,.markdown-body h4 code,.markdown-body h4 tt,.markdown-body h5 code,.markdown-body h5 tt,.markdown-body h6 code,.markdown-body h6 tt{font-size:inherit}.markdown-body h1{font-size:2em}.markdown-body h1,.markdown-body h2{padding-bottom:.3em;border-bottom:1px solid #eee}.markdown-body h2{font-size:1.5em}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{font-size:.85em;color:#777}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol.no-list,.markdown-body ul.no-list{padding:0;list-style-type:none}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body li>p{margin-top:16px}.markdown-body li+li{padding-top:.25em}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body table{display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}.markdown-body table th{font-weight:700}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #ddd}.markdown-body table tr{background-color:#fff;border-top:1px solid #ccc}.markdown-body table tr:nth-child(2n){background-color:#f8f8f8}.markdown-body img{max-width:100%;box-sizing:content-box;background-color:#fff}.markdown-body img[align=right]{padding-left:20px}.markdown-body img[align=left]{padding-right:20px}.markdown-body .emoji{max-width:none;vertical-align:text-top;background-color:transparent}.markdown-body span.frame{display:block;overflow:hidden}.markdown-body span.frame>span{display:block;float:left;width:auto;padding:7px;margin:13px 0 0;overflow:hidden;border:1px solid #ddd}.markdown-body span.frame span img{display:block;float:left}.markdown-body span.frame span span{display:block;padding:5px 0 0;clear:both;color:#333}.markdown-body span.align-center{display:block;overflow:hidden;clear:both}.markdown-body span.align-center>span{display:block;margin:13px auto 0;overflow:hidden;text-align:center}.markdown-body span.align-center span img{margin:0 auto;text-align:center}.markdown-body span.align-right{display:block;overflow:hidden;clear:both}.markdown-body span.align-right>span{display:block;margin:13px 0 0;overflow:hidden;text-align:right}.markdown-body span.align-right span img{margin:0;text-align:right}.markdown-body span.float-left{display:block;float:left;margin-right:13px;overflow:hidden}.markdown-body span.float-left span{margin:13px 0 0}.markdown-body span.float-right{display:block;float:right;margin-left:13px;overflow:hidden}.markdown-body span.float-right>span{display:block;margin:13px auto 0;overflow:hidden;text-align:right}.markdown-body code,.markdown-body tt{padding:0;padding-top:.2em;padding-bottom:.2em;margin:0;font-size:85%;background-color:rgba(0,0,0,.04);border-radius:3px}.markdown-body code:after,.markdown-body code:before,.markdown-body tt:after,.markdown-body tt:before{letter-spacing:-.2em;content:"\00a0"}.markdown-body code br,.markdown-body tt br{display:none}.markdown-body del code{text-decoration:inherit}.markdown-body pre{word-wrap:normal}.markdown-body pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:transparent;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f7f7f7;border-radius:3px}.markdown-body pre code,.markdown-body pre tt{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown-body pre code:after,.markdown-body pre code:before,.markdown-body pre tt:after,.markdown-body pre tt:before{content:normal}.markdown-body .csv-data td,.markdown-body .csv-data th{padding:5px;overflow:hidden;font-size:12px;line-height:1;text-align:left;white-space:nowrap}.markdown-body .csv-data .blob-line-num{padding:10px 8px 9px;text-align:right;background:#fff;border:0}.markdown-body .csv-data tr{border-top:0}.markdown-body .csv-data th{font-weight:700;background:#f8f8f8;border-top:0}.news .alert .markdown-body blockquote{padding:0 0 0 40px;border:0 none}.activity-tab .news .alert .commits,.activity-tab .news .markdown-body blockquote{padding-left:0}.task-list-item{list-style-type:none}.task-list-item label{font-weight:400}.task-list-item.enabled label{cursor:pointer}.task-list-item+.task-list-item{margin-top:3px}.task-list-item-checkbox{float:left;margin:.31em 0 .2em -1.3em!important;vertical-align:middle;cursor:default!important}.markdown-body{padding-top:40px;padding-bottom:40px;max-width:758px;overflow:visible!important;position:relative}.markdown-body .emoji{vertical-align:top}.markdown-body pre{border:inherit!important}.markdown-body code{color:inherit!important}.markdown-body pre code .wrapper{display:-moz-inline-flex;display:-ms-inline-flex;display:-o-inline-flex;display:inline-flex}.markdown-body pre code .gutter{float:left;overflow:hidden;-webkit-user-select:none;user-select:none}.markdown-body pre code .gutter.linenumber{text-align:right;position:relative;display:inline-block;cursor:default;z-index:4;padding:0 8px 0 0;min-width:20px;box-sizing:content-box;color:#afafaf!important;border-right:3px solid #6ce26c!important}.markdown-body pre code .gutter.linenumber>span:before{content:attr(data-linenumber)}.markdown-body pre code .code{float:left;margin:0 0 0 16px}.markdown-body .gist .line-numbers{border-left:none;border-top:none;border-bottom:none}.markdown-body .gist .line-data{border:none}.markdown-body .gist table{border-spacing:0;border-collapse:inherit!important}.markdown-body code[data-gist-id]{background:none;padding:0}.markdown-body code[data-gist-id]:after,.markdown-body code[data-gist-id]:before{content:""}.markdown-body code[data-gist-id] .blob-num{border:unset}.markdown-body code[data-gist-id] table{overflow:unset;margin-bottom:unset}.markdown-body code[data-gist-id] table tr{background:unset}.markdown-body[dir=rtl] pre{direction:ltr}.markdown-body[dir=rtl] code{direction:ltr;unicode-bidi:embed}.markdown-body .alert>p:last-child{margin-bottom:0}.markdown-body pre.abc,.markdown-body pre.flow-chart,.markdown-body pre.graphviz,.markdown-body pre.mermaid,.markdown-body pre.sequence-diagram,.markdown-body pre.vega{text-align:center;background-color:inherit;border-radius:0;white-space:inherit;overflow:visible}.markdown-body pre.abc>code,.markdown-body pre.flow-chart>code,.markdown-body pre.graphviz>code,.markdown-body pre.mermaid>code,.markdown-body pre.sequence-diagram>code,.markdown-body pre.vega>code{text-align:left}.markdown-body pre.abc>svg,.markdown-body pre.flow-chart>svg,.markdown-body pre.graphviz>svg,.markdown-body pre.mermaid>svg,.markdown-body pre.sequence-diagram>svg,.markdown-body pre.vega>svg{max-width:100%;height:100%}.markdown-body pre>code.wrap{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}.markdown-body .alert>p:last-child,.markdown-body .alert>ul:last-child{margin-bottom:0}.markdown-body summary{display:list-item}.markdown-body summary:focus{outline:none}.markdown-body details summary{cursor:pointer}.markdown-body details:not([open])>:not(summary){display:none}.markdown-body figure{margin:1em 40px}.markdown-body .mark,.markdown-body mark{background-color:#fff1a7}.vimeo,.youtube{cursor:pointer;display:table;text-align:center;background-position:50%;background-repeat:no-repeat;background-size:contain;background-color:#000;overflow:hidden}.vimeo,.youtube{position:relative;width:100%}.youtube{padding-bottom:56.25%}.vimeo img{width:100%;object-fit:contain;z-index:0}.youtube img{object-fit:cover;z-index:0}.vimeo iframe,.youtube iframe,.youtube img{width:100%;height:100%;position:absolute;top:0;left:0}.vimeo iframe,.youtube iframe{vertical-align:middle;z-index:1}.vimeo .icon,.youtube .icon{position:absolute;height:auto;width:auto;top:50%;left:50%;transform:translate(-50%,-50%);color:#fff;opacity:.3;transition:opacity .2s;z-index:0}.vimeo:hover .icon,.youtube:hover .icon{opacity:.6;transition:opacity .2s}.slideshare .inner,.speakerdeck .inner{position:relative;width:100%}.slideshare .inner iframe,.speakerdeck .inner iframe{position:absolute;top:0;bottom:0;left:0;right:0;width:100%;height:100%}.figma{display:table;position:relative;width:100%;padding-bottom:56.25%}.figma iframe{position:absolute;top:0;bottom:0;left:0;right:0;width:100%;height:100%;border:1px solid #eee}.markmap-container{height:300px}.markmap-container>svg{width:100%;height:100%}.MJX_Assistive_MathML{display:none}#MathJax_Message{z-index:1000!important}.ui-infobar{position:relative;z-index:2;max-width:760px;margin:25px auto -25px;color:#777}.toc .invisable-node{list-style-type:none}.ui-toc{position:fixed;bottom:20px;z-index:998}.ui-toc.both-mode{margin-left:8px}.ui-toc.both-mode .ui-toc-label{height:40px;padding:10px 4px;border-top-left-radius:0;border-bottom-left-radius:0}.ui-toc-label{background-color:#e6e6e6;border:none;color:#868686;transition:opacity .2s}.ui-toc .open .ui-toc-label{opacity:1;color:#fff;transition:opacity .2s}.ui-toc-label:focus{opacity:.3;background-color:#ccc;color:#000}.ui-toc-label:hover{opacity:1;background-color:#ccc;transition:opacity .2s}.ui-toc-dropdown{margin-top:20px;margin-bottom:20px;padding-left:10px;padding-right:10px;max-width:45vw;width:25vw;max-height:70vh;overflow:auto;text-align:inherit}.ui-toc-dropdown>.toc{max-height:calc(70vh - 100px);overflow:auto}.ui-toc-dropdown[dir=rtl] .nav{padding-right:0;letter-spacing:.0029em}.ui-toc-dropdown a{overflow:hidden;text-overflow:ellipsis;white-space:pre}.ui-toc-dropdown .nav>li>a{display:block;padding:4px 20px;font-size:13px;font-weight:500;color:#767676}.ui-toc-dropdown .nav>li:first-child:last-child>ul,.ui-toc-dropdown .toc.expand ul{display:block}.ui-toc-dropdown .nav>li>a:focus,.ui-toc-dropdown .nav>li>a:hover{padding-left:19px;color:#000;text-decoration:none;background-color:transparent;border-left:1px solid #000}.ui-toc-dropdown[dir=rtl] .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav>li>a:hover{padding-right:19px;border-left:none;border-right:1px solid #000}.ui-toc-dropdown .nav>.active:focus>a,.ui-toc-dropdown .nav>.active:hover>a,.ui-toc-dropdown .nav>.active>a{padding-left:18px;font-weight:700;color:#000;background-color:transparent;border-left:2px solid #000}.ui-toc-dropdown[dir=rtl] .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav>.active>a{padding-right:18px;border-left:none;border-right:2px solid #000}.ui-toc-dropdown .nav .nav{display:none;padding-bottom:10px}.ui-toc-dropdown .nav>.active>ul{display:block}.ui-toc-dropdown .nav .nav>li>a{padding-top:1px;padding-bottom:1px;padding-left:30px;font-size:12px;font-weight:400}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a{padding-right:30px}.ui-toc-dropdown .nav .nav>li>ul>li>a{padding-top:1px;padding-bottom:1px;padding-left:40px;font-size:12px;font-weight:400}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a{padding-right:40px}.ui-toc-dropdown .nav .nav>li>a:focus,.ui-toc-dropdown .nav .nav>li>a:hover{padding-left:29px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:hover{padding-right:29px}.ui-toc-dropdown .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown .nav .nav>li>ul>li>a:hover{padding-left:39px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:hover{padding-right:39px}.ui-toc-dropdown .nav .nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>a{padding-left:28px;font-weight:500}.ui-toc-dropdown[dir=rtl] .nav .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>a{padding-right:28px}.ui-toc-dropdown .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>a{padding-left:38px;font-weight:500}.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active>a{padding-right:38px}.markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,sans-serif}html[lang^=ja] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS\ ゴシック,sans-serif}html[lang=zh-tw] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html[lang=zh-cn] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}html .markdown-body[lang^=ja]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS\ ゴシック,sans-serif}html .markdown-body[lang=zh-tw]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html .markdown-body[lang=zh-cn]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}html[lang^=ja] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Meiryo UI,MS PGothic,MS\ Pゴシック,sans-serif}html[lang=zh-tw] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Microsoft JhengHei UI,微軟正黑UI,sans-serif}html[lang=zh-cn] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Microsoft YaHei UI,微软雅黑UI,sans-serif}html .ui-toc-dropdown[lang^=ja]{font-family:Source Sans Pro,Helvetica,Arial,Meiryo UI,MS PGothic,MS\ Pゴシック,sans-serif}html .ui-toc-dropdown[lang=zh-tw]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft JhengHei UI,微軟正黑UI,sans-serif}html .ui-toc-dropdown[lang=zh-cn]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft YaHei UI,微软雅黑UI,sans-serif}.ui-affix-toc{position:fixed;top:0;max-width:15vw;max-height:70vh;overflow:auto}.back-to-top,.expand-toggle,.go-to-bottom{display:block;padding:4px 10px;margin-top:10px;margin-left:10px;font-size:12px;font-weight:500;color:#999}.back-to-top:focus,.back-to-top:hover,.expand-toggle:focus,.expand-toggle:hover,.go-to-bottom:focus,.go-to-bottom:hover{color:#563d7c;text-decoration:none}.back-to-top,.go-to-bottom{margin-top:0}.ui-user-icon{width:20px;height:20px;display:block;border-radius:50%;margin-top:2px;margin-bottom:2px;margin-right:5px;background-position:50%;background-repeat:no-repeat;background-size:cover}.ui-user-icon.small{width:18px;height:18px;display:inline-block;vertical-align:middle;margin:0 0 .2em}.ui-infobar>small>span{line-height:22px}.ui-infobar>small .dropdown{display:inline-block}.ui-infobar>small .dropdown a:focus,.ui-infobar>small .dropdown a:hover{text-decoration:none}.ui-more-info{color:#888;cursor:pointer;vertical-align:middle}.ui-more-info .fa{font-size:16px}.ui-connectedGithub,.ui-published-note{color:#888}.ui-connectedGithub{line-height:23px;white-space:nowrap}.ui-connectedGithub a.file-path{color:#888;text-decoration:none;padding-left:22px}.ui-connectedGithub a.file-path:active,.ui-connectedGithub a.file-path:hover{color:#888;text-decoration:underline}.ui-connectedGithub .fa{font-size:20px}.ui-published-note .fa{font-size:20px;vertical-align:top}.unselectable{-webkit-user-select:none;-o-user-select:none;user-select:none}.selectable{-webkit-user-select:text;-o-user-select:text;user-select:text}.inline-spoiler-section{cursor:pointer}.inline-spoiler-section .spoiler-text{border-radius:2px;background-color:#333}.inline-spoiler-section .spoiler-text>*{opacity:0}.inline-spoiler-section .spoiler-img{filter:blur(10px)}.inline-spoiler-section.raw{border-radius:2px;background-color:#333}.inline-spoiler-section.raw>*{opacity:0}.inline-spoiler-section.unveil{cursor:auto}.inline-spoiler-section.unveil .spoiler-text{background-color:rgba(51,51,51,.1)}.inline-spoiler-section.unveil .spoiler-text>*{opacity:1}.inline-spoiler-section.unveil .spoiler-img{filter:none}@media print{blockquote,div,img,pre,table{page-break-inside:avoid!important}a[href]:after{font-size:12px!important}}.markdown-body.slides{position:relative;z-index:1;color:#222}.markdown-body.slides:before{content:"";display:block;position:absolute;top:0;left:0;right:0;bottom:0;z-index:-1;background-color:currentColor;box-shadow:0 0 0 50vw}.markdown-body.slides section[data-markdown]{position:relative;margin-bottom:1.5em;background-color:#fff;text-align:center}.markdown-body.slides section[data-markdown] code{text-align:left}.markdown-body.slides section[data-markdown]:before{content:"";display:block;padding-bottom:56.23%}.markdown-body.slides section[data-markdown]>div:first-child{position:absolute;top:50%;left:1em;right:1em;transform:translateY(-50%);max-height:100%;overflow:hidden}.markdown-body.slides section[data-markdown]>ul{display:inline-block}.markdown-body.slides>section>section+section:after{content:"";position:absolute;top:-1.5em;right:1em;height:1.5em;border:3px solid #777}.site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,sans-serif}html[lang^=ja] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS\ ゴシック,sans-serif}html[lang=zh-tw] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html[lang=zh-cn] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}body{font-smoothing:subpixel-antialiased!important;-webkit-font-smoothing:subpixel-antialiased!important;-moz-osx-font-smoothing:auto!important;-webkit-overflow-scrolling:touch;letter-spacing:.025em;font-family:Source Sans Pro,Helvetica,Arial,sans-serif}html[lang^=ja] body{font-family:Source Sans Pro,Helvetica,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS\ ゴシック,sans-serif}html[lang=zh-tw] body{font-family:Source Sans Pro,Helvetica,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html[lang=zh-cn] body{font-family:Source Sans Pro,Helvetica,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}abbr[title]{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}abbr[data-original-title],abbr[title]{cursor:help}body.modal-open{overflow-y:auto;padding-right:0!important}svg{text-shadow:none}
  23. </style>
  24. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  25. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  26. <!--[if lt IE 9]>
  27. <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js" integrity="sha256-3Jy/GbSLrg0o9y5Z5n1uw0qxZECH7C6OQpVBgNFYa0g=" crossorigin="anonymous"></script>
  28. <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js" integrity="sha256-g6iAfvZp+nDQ2TdTR/VVKJf3bGro4ub5fvWSWVRi2NE=" crossorigin="anonymous"></script>
  29. <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js" integrity="sha256-8E4Is26QH0bD52WoQpcB+R/tcWQtpzlCojrybUd7Mxo=" crossorigin="anonymous"></script>
  30. <![endif]-->
  31. </head>
  32. <body>
  33. <div id="doc" class="markdown-body container-fluid comment-enabled" data-hard-breaks="true"><h1 id="Lab-2-OS-main-components" data-id="Lab-2-OS-main-components"><a class="anchor hidden-xs" href="#Lab-2-OS-main-components" title="Lab-2-OS-main-components"><span class="octicon octicon-link"></span></a><span>Lab 2: OS main components</span></h1><h2 id="Environment-Preparation" data-id="Environment-Preparation"><a class="anchor hidden-xs" href="#Environment-Preparation" title="Environment-Preparation"><span class="octicon octicon-link"></span></a><span>Environment Preparation</span></h2><ol>
  34. <li><span>Ensure that you enabled EFI standard of booting. How did you check this?</span></li>
  35. </ol><hr><h2 id="Exercise-1-GPT-partition" data-id="Exercise-1-GPT-partition"><a class="anchor hidden-xs" href="#Exercise-1-GPT-partition" title="Exercise-1-GPT-partition"><span class="octicon octicon-link"></span></a><span>Exercise 1: GPT partition</span></h2><ul>
  36. <li><span>Check the currently connected storage devices</span><pre><code>$ fdisk -l
  37. </code></pre>
  38. <span>Locate the bootable device on your machine from the output</span><pre><code>Disk /dev/sda: 931,53 GiB, 1000204886016 bytes, 1953525168 sectors
  39. Disk model: WDC WD10EZEX-60M
  40. Units: sectors of 1 * 512 = 512 bytes
  41. Sector size (logical/physical): 512 bytes / 4096 bytes
  42. I/O size (minimum/optimal): 4096 bytes / 4096 bytes
  43. Disklabel type: gpt
  44. Disk identifier: F3C9420A-67A8-4E94-B0E1-F0CED23135AC
  45. </code></pre>
  46. </li>
  47. </ul><h3 id="MBR-Dump-and-Analysis" data-id="MBR-Dump-and-Analysis"><a class="anchor hidden-xs" href="#MBR-Dump-and-Analysis" title="MBR-Dump-and-Analysis"><span class="octicon octicon-link"></span></a><span>MBR Dump and Analysis</span></h3><ul>
  48. <li>
  49. <p><span>MBR starts at logical block address (LBA) 0 of the GPT layout. Use dd to dump the first 512 bytes from LBA 0.</span></p>
  50. <pre><code>$ sudo dd if=/dev/sda bs=512 count=1 skip=0 &gt; lba.0
  51. </code></pre>
  52. <blockquote>
  53. <p><span>The </span><code>if</code><span> option specifies the disk we want to dump from, </span><code>bs</code><span> indicates the LBA size, </span><code>count</code><span> specifies how many LBAs we want to dump, and </span><code>skip</code><span> indicates the sector we will start the dump from.</span></p>
  54. </blockquote>
  55. </li>
  56. <li>
  57. <p><span>Use hexedit to view the MBR dump.</span></p>
  58. <pre><code>$ hexedit lba.0
  59. </code></pre>
  60. <pre><code>000001B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  61. 000001C0 02 00 EE FF FF FF 01 00 00 00 AF 6D 70 74 00 00 ...........mpt..
  62. 000001D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  63. 000001E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  64. 000001F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA ..............U.
  65. </code></pre>
  66. <blockquote>
  67. <p><span>At index </span><code>1BE</code><span>, the value </span><code>00</code><span> indicates that it is not a bootable MBR device.</span><br>
  68. <code>00 02 00</code><span> (</span><code>512</code><span> in decimal) indicates where the GPT header is located.</span></p>
  69. </blockquote>
  70. </li>
  71. </ul><h3 id="GPT-Header-Dump-and-Analysis" data-id="GPT-Header-Dump-and-Analysis"><a class="anchor hidden-xs" href="#GPT-Header-Dump-and-Analysis" title="GPT-Header-Dump-and-Analysis"><span class="octicon octicon-link"></span></a><span>GPT Header Dump and Analysis</span></h3><ul>
  72. <li>
  73. <p><span>GPT header starts from LBA 1. Use dd to dump the 512 bytes in sector 1:</span></p>
  74. <pre><code>$ sudo dd if=/dev/sda bs=512 count=1 skip=1 &gt; lba.1
  75. </code></pre>
  76. </li>
  77. <li>
  78. <p><span>View the GPT dump with hexedit</span></p>
  79. <pre><code>$ hexedit lba.1
  80. </code></pre>
  81. <pre><code>00000000 45 46 49 20 50 41 52 54 00 00 01 00 5C 00 00 00 EFI PART....\...
  82. 00000010 A6 5A 8D 0B 00 00 00 00 01 00 00 00 00 00 00 00 .Z..............
  83. 00000020 AF 6D 70 74 00 00 00 00 22 00 00 00 00 00 00 00 .mpt....".......
  84. 00000030 8E 6D 70 74 00 00 00 00 0A 42 C9 F3 A8 67 94 4E .mpt.....B...g.N
  85. 00000040 B0 E1 F0 CE D2 31 35 AC 02 00 00 00 00 00 00 00 .....15.........
  86. 00000050 80 00 00 00 80 00 00 00 FB B5 7D D9 00 00 00 00 ..........}.....
  87. 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  88. </code></pre>
  89. <blockquote>
  90. <p><span>Notice</span><code>45 46 49 20 50 41 52 54</code><span> or </span><code>EFI PART</code><span> identifies this as an EFI-compatible GPT header.</span></p>
  91. </blockquote>
  92. <blockquote>
  93. <p><span>Additional material</span><br>
  94. <span>GUID Partition Table </span><a href="http://www.ntfs.com/guid-part-table.htm" target="_blank" rel="noopener"><span>http://www.ntfs.com/guid-part-table.htm</span></a></p>
  95. </blockquote>
  96. </li>
  97. </ul><h3 id="Questions-to-answer" data-id="Questions-to-answer"><a class="anchor hidden-xs" href="#Questions-to-answer" title="Questions-to-answer"><span class="octicon octicon-link"></span></a><span>Questions to answer</span></h3><ol>
  98. <li><span>What is fdisk utility used for?</span></li>
  99. <li><span>Show the bootable device(s) on your machine, and identify which partition(s) are bootable.</span></li>
  100. <li><span>What is logical block address?</span></li>
  101. <li><span>Why did we specify the </span><code>count</code><span>, the </span><code>bs</code><span>, and the </span><code>skip</code><span> options when using dd?</span></li>
  102. <li><span>Why does a GPT formatted disk have the MBR?</span></li>
  103. <li><span>Name two differences between primary and logical partitions in an MBR partitioning scheme</span></li>
  104. </ol><h2 id="Exercise-2---UEFI-Booting" data-id="Exercise-2---UEFI-Booting"><a class="anchor hidden-xs" href="#Exercise-2---UEFI-Booting" title="Exercise-2---UEFI-Booting"><span class="octicon octicon-link"></span></a><span>Exercise 2 - UEFI Booting</span></h2><p><span>The Unified Extensible Firmware Interface Specification describes an interface between the operating system and the platform firmware.</span></p><h3 id="1-Boot-sequence" data-id="1-Boot-sequence"><a class="anchor hidden-xs" href="#1-Boot-sequence" title="1-Boot-sequence"><span class="octicon octicon-link"></span></a><span>1. Boot sequence</span></h3><ul>
  105. <li>
  106. <p><span>Platform initialization to prepare the hardware (memory, storage devices, peripherals).</span></p>
  107. </li>
  108. <li>
  109. <p><span>Power on Self Test (POST)</span></p>
  110. </li>
  111. <li>
  112. <p><span>The firmware has the BootEntry variables in the NVRAM (non-volatile random-access memory). This contains a list of bootable devices and programs on the computer.</span><br>
  113. <span>The BootOrder is the sequence that the firmware will check for system boot files.</span><br>
  114. <span>To view the boot entry on a UEFI enabled system, run </span><code>efibootmgr -v</code></p>
  115. <pre><code>$ efibootmgr -v
  116. BootCurrent: 0012
  117. Timeout: 1 seconds
  118. BootOrder: 0012,0010,0011,000D,0001,0009,0008,0000,0002
  119. Boot0000* Windows Boot Manager VenHw(99e27c00cb...)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...a................
  120. Boot0001* debian VenHw(99e275eb...)
  121. Boot0002* ubuntu VenHw(99e27b...)
  122. Boot0008* Generic Usb Device VenHw(99e275b...)
  123. Boot0009* CD/DVD Device VenHw(99e275cb...)
  124. Boot000D* Realtek PXE B01 D00 BBS(Network,,0x0)..BO
  125. Boot0010* TOSHIBA DT01ACA050 LENOVO BBS(HD,,0x0)..BO
  126. Boot0011* TOSHIBA HDWD130 BBS(HD,,0x0)..BO
  127. Boot0012* ubuntu HD(2,GPT,14fc7215-4232-53ac-dbd0-9a1e007acead,0x1000,0x100800)/File(\EFI\Ubuntu\shimx64.efi)..BO
  128. </code></pre>
  129. <p><span>From the output above, shim is going to be loaded first on the system.</span></p>
  130. <blockquote>
  131. <p><span>Shim is the pre-bootloader that runs on UEFI systems. It is signed by Microsoft, and it is used to load the “real” bootloader: GRUB.</span></p>
  132. </blockquote>
  133. </li>
  134. <li>
  135. <p><span>The firmware validates and loads the shim binary.</span></p>
  136. <pre><code>$ ls -lah /boot/efi/EFI/ubuntu/
  137. </code></pre>
  138. </li>
  139. <li>
  140. <p><span>Shim then loads GRUB bootloader.</span></p>
  141. <blockquote>
  142. <p><span>Shim reads the partition table of the storage and mounts the EFI System Partition (ESP). The EFI partition is typically mounted at </span><code>/boot/efi/</code><span> on Ubuntu and all specific Ubuntu files are located at </span><code>/boot/efi/EFI/ubuntu/</code><span>.</span></p>
  143. </blockquote>
  144. <pre><code>$ ls -lah /boot/efi/
  145. </code></pre>
  146. </li>
  147. <li>
  148. <p><span>The UEFI boot manager selects the GRUB file located at </span><code>/boot/efi/EFI/ubuntu/grub*.efi</code><span> and runs it.</span></p>
  149. <blockquote>
  150. <p><span>The user will be prompted to select an application to run if there are other UEFI applications in the ESP root directory.</span></p>
  151. </blockquote>
  152. </li>
  153. <li>
  154. <p><span>GRUB will determine which operating system kernel to start based on the configuration. The operating system kernel is loaded into memory and the control of the system is transferred to it.</span></p>
  155. <blockquote>
  156. <p><span>GRUB provides more compatibility for UEFI firmware. When loaded, GRUB can boot kernel images from all devices, partitions, and file systems it supports without being restricted to the capabilities of UEFI (FAT). GRUB also gives users the privilege to make changes during boot time which includes: modifying initrd, changing boot entries, and selecting kernels.</span><br>
  157. <img src="https://i.imgur.com/iQ0TaxG.png" alt="" loading="lazy"></p>
  158. </blockquote>
  159. </li>
  160. <li>
  161. <p><span>Once loaded, the kernel will disable the firmware’s Boot Services.</span></p>
  162. </li>
  163. </ul><h3 id="Questions-to-answer1" data-id="Questions-to-answer"><a class="anchor hidden-xs" href="#Questions-to-answer1" title="Questions-to-answer1"><span class="octicon octicon-link"></span></a><span>Questions to answer</span></h3><ol>
  164. <li><span>Why is Shim used to load the GRUB bootloader?</span></li>
  165. <li><span>Can you locate your grub configuration file? Show the path.</span></li>
  166. <li><span>According to the boot order, what is the third boot device on your computer? How did you check this?</span></li>
  167. </ol><h2 id="Exercise-3-Filesystem" data-id="Exercise-3-Filesystem"><a class="anchor hidden-xs" href="#Exercise-3-Filesystem" title="Exercise-3-Filesystem"><span class="octicon octicon-link"></span></a><span>Exercise 3: Filesystem</span></h2><ul>
  168. <li><span>View filesystem of block devices</span><pre><code>$ lsblk -f
  169. </code></pre>
  170. </li>
  171. <li><span>View all </span><code>/dev</code><span> filesystems</span><pre><code>$ ls -lah /dev
  172. </code></pre>
  173. </li>
  174. <li><span>View memory info from the </span><code>/proc</code><span> filesystem</span><pre><code>$ cat /proc/meminfo
  175. </code></pre>
  176. </li>
  177. </ul><h3 id="Questions-to-answer2" data-id="Questions-to-answer"><a class="anchor hidden-xs" href="#Questions-to-answer2" title="Questions-to-answer2"><span class="octicon octicon-link"></span></a><span>Questions to answer</span></h3><ol>
  178. <li><span>How many inodes are in use on your system?</span></li>
  179. <li><span>What is the filesystem type of the EFI partition?</span></li>
  180. <li><span>What device is mounted at your root </span><code>/</code><span> directory? Show proof.</span></li>
  181. <li><span>What is your partition UUID?</span></li>
  182. <li><span>Show at least two methods of viewing the UUID of a block device.</span></li>
  183. <li><span>What is the function of </span><code>/dev/zero</code><span>?</span></li>
  184. </ol></div>
  185. <div class="ui-toc dropup unselectable hidden-print" style="display:none;">
  186. <div class="pull-right dropdown">
  187. <a id="tocLabel" class="ui-toc-label btn btn-default" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="Table of content">
  188. <i class="fa fa-bars"></i>
  189. </a>
  190. <ul id="ui-toc" class="ui-toc-dropdown dropdown-menu" aria-labelledby="tocLabel">
  191. <div class="toc"><ul class="nav">
  192. <li><a href="#Lab-2-OS-main-components" title="Lab 2: OS main components">Lab 2: OS main components</a><ul class="nav">
  193. <li><a href="#Environment-Preparation" title="Environment Preparation">Environment Preparation</a></li>
  194. <li><a href="#Exercise-1-GPT-partition" title="Exercise 1: GPT partition">Exercise 1: GPT partition</a><ul class="nav">
  195. <li><a href="#MBR-Dump-and-Analysis" title="MBR Dump and Analysis">MBR Dump and Analysis</a></li>
  196. <li><a href="#GPT-Header-Dump-and-Analysis" title="GPT Header Dump and Analysis">GPT Header Dump and Analysis</a></li>
  197. <li><a href="#Questions-to-answer" title="Questions to answer">Questions to answer</a></li>
  198. </ul>
  199. </li>
  200. <li><a href="#Exercise-2---UEFI-Booting" title="Exercise 2 - UEFI Booting">Exercise 2 - UEFI Booting</a><ul class="nav">
  201. <li><a href="#1-Boot-sequence" title="1. Boot sequence">1. Boot sequence</a></li>
  202. <li><a href="#Questions-to-answer1" title="Questions to answer">Questions to answer</a></li>
  203. </ul>
  204. </li>
  205. <li><a href="#Exercise-3-Filesystem" title="Exercise 3: Filesystem">Exercise 3: Filesystem</a><ul class="nav">
  206. <li><a href="#Questions-to-answer2" title="Questions to answer">Questions to answer</a></li>
  207. </ul>
  208. </li>
  209. </ul>
  210. </li>
  211. </ul>
  212. </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
  213. </ul>
  214. </div>
  215. </div>
  216. <div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:17px;display:none;" null null>
  217. <div class="toc"><ul class="nav">
  218. <li><a href="#Lab-2-OS-main-components" title="Lab 2: OS main components">Lab 2: OS main components</a><ul class="nav">
  219. <li><a href="#Environment-Preparation" title="Environment Preparation">Environment Preparation</a></li>
  220. <li><a href="#Exercise-1-GPT-partition" title="Exercise 1: GPT partition">Exercise 1: GPT partition</a><ul class="nav">
  221. <li><a href="#MBR-Dump-and-Analysis" title="MBR Dump and Analysis">MBR Dump and Analysis</a></li>
  222. <li><a href="#GPT-Header-Dump-and-Analysis" title="GPT Header Dump and Analysis">GPT Header Dump and Analysis</a></li>
  223. <li><a href="#Questions-to-answer" title="Questions to answer">Questions to answer</a></li>
  224. </ul>
  225. </li>
  226. <li><a href="#Exercise-2---UEFI-Booting" title="Exercise 2 - UEFI Booting">Exercise 2 - UEFI Booting</a><ul class="nav">
  227. <li><a href="#1-Boot-sequence" title="1. Boot sequence">1. Boot sequence</a></li>
  228. <li><a href="#Questions-to-answer1" title="Questions to answer">Questions to answer</a></li>
  229. </ul>
  230. </li>
  231. <li><a href="#Exercise-3-Filesystem" title="Exercise 3: Filesystem">Exercise 3: Filesystem</a><ul class="nav">
  232. <li><a href="#Questions-to-answer2" title="Questions to answer">Questions to answer</a></li>
  233. </ul>
  234. </li>
  235. </ul>
  236. </li>
  237. </ul>
  238. </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
  239. </div>
  240. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
  241. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous" defer></script>
  242. <script src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.6.0/gist-embed.min.js" integrity="sha256-KyF2D6xPIJUW5sUDSs93vWyZm+1RzIpKCexxElmxl8g=" crossorigin="anonymous" defer></script>
  243. <script>
  244. var markdown = $(".markdown-body");
  245. //smooth all hash trigger scrolling
  246. function smoothHashScroll() {
  247. var hashElements = $("a[href^='#']").toArray();
  248. for (var i = 0; i < hashElements.length; i++) {
  249. var element = hashElements[i];
  250. var $element = $(element);
  251. var hash = element.hash;
  252. if (hash) {
  253. $element.on('click', function (e) {
  254. // store hash
  255. var hash = this.hash;
  256. if ($(hash).length <= 0) return;
  257. // prevent default anchor click behavior
  258. e.preventDefault();
  259. // animate
  260. $('body, html').stop(true, true).animate({
  261. scrollTop: $(hash).offset().top
  262. }, 100, "linear", function () {
  263. // when done, add hash to url
  264. // (default click behaviour)
  265. window.location.hash = hash;
  266. });
  267. });
  268. }
  269. }
  270. }
  271. smoothHashScroll();
  272. var toc = $('.ui-toc');
  273. var tocAffix = $('.ui-affix-toc');
  274. var tocDropdown = $('.ui-toc-dropdown');
  275. //toc
  276. tocDropdown.click(function (e) {
  277. e.stopPropagation();
  278. });
  279. var enoughForAffixToc = true;
  280. function generateScrollspy() {
  281. $(document.body).scrollspy({
  282. target: ''
  283. });
  284. $(document.body).scrollspy('refresh');
  285. if (enoughForAffixToc) {
  286. toc.hide();
  287. tocAffix.show();
  288. } else {
  289. tocAffix.hide();
  290. toc.show();
  291. }
  292. $(document.body).scroll();
  293. }
  294. function windowResize() {
  295. //toc right
  296. var paddingRight = parseFloat(markdown.css('padding-right'));
  297. var right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
  298. toc.css('right', right + 'px');
  299. //affix toc left
  300. var newbool;
  301. var rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
  302. //for ipad or wider device
  303. if (rightMargin >= 133) {
  304. newbool = true;
  305. var affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
  306. var left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
  307. tocAffix.css('left', left + 'px');
  308. } else {
  309. newbool = false;
  310. }
  311. if (newbool != enoughForAffixToc) {
  312. enoughForAffixToc = newbool;
  313. generateScrollspy();
  314. }
  315. }
  316. $(window).resize(function () {
  317. windowResize();
  318. });
  319. $(document).ready(function () {
  320. windowResize();
  321. generateScrollspy();
  322. });
  323. //remove hash
  324. function removeHash() {
  325. window.location.hash = '';
  326. }
  327. var backtotop = $('.back-to-top');
  328. var gotobottom = $('.go-to-bottom');
  329. backtotop.click(function (e) {
  330. e.preventDefault();
  331. e.stopPropagation();
  332. if (scrollToTop)
  333. scrollToTop();
  334. removeHash();
  335. });
  336. gotobottom.click(function (e) {
  337. e.preventDefault();
  338. e.stopPropagation();
  339. if (scrollToBottom)
  340. scrollToBottom();
  341. removeHash();
  342. });
  343. var toggle = $('.expand-toggle');
  344. var tocExpand = false;
  345. checkExpandToggle();
  346. toggle.click(function (e) {
  347. e.preventDefault();
  348. e.stopPropagation();
  349. tocExpand = !tocExpand;
  350. checkExpandToggle();
  351. })
  352. function checkExpandToggle () {
  353. var toc = $('.ui-toc-dropdown .toc');
  354. var toggle = $('.expand-toggle');
  355. if (!tocExpand) {
  356. toc.removeClass('expand');
  357. toggle.text('Expand all');
  358. } else {
  359. toc.addClass('expand');
  360. toggle.text('Collapse all');
  361. }
  362. }
  363. function scrollToTop() {
  364. $('body, html').stop(true, true).animate({
  365. scrollTop: 0
  366. }, 100, "linear");
  367. }
  368. function scrollToBottom() {
  369. $('body, html').stop(true, true).animate({
  370. scrollTop: $(document.body)[0].scrollHeight
  371. }, 100, "linear");
  372. }
  373. </script>
  374. </body>
  375. </html>