Computer booting
The lower-level parts of computers
General: Computer power consumption · Computer noises Memory: Some understanding of memory hardware · CPU cache · Flash memory · Virtual memory · Memory mapped IO and files · RAM disk · Memory limits on 32-bit and 64-bit machines Related: Network wiring notes - Power over Ethernet · 19" rack sizes Unsorted: GPU, GPGPU, OpenCL, CUDA notes · Computer booting
|
⌛ This hasn't been updated for a while, so could be outdated (particularly if it's about something that evolves constantly, such as software or research). |
Bootability
Boot(strapp)ing a computer is one or more "load code, then execute" operations, until we are loading an operating system.
This quickly became multiple steps, due to backwards compatibility with historical developments (changes over time, the will to boot from more things.
- Floppies and hard drives have the longest history, so have the most uniform support - the BIOS detects them and standard interrupts deal with them. This makes them easier to work with and more reliable.
- CDROM booting became standard around ~1995
- USB was more finicky for a long time
Because the BIOS is now being replaced with UEFI for let's-make-something-more-standard-and-less-crazy reasons (among others), UEFI boot is a completely different thing from BIOS boot and will probably eventually replace it (right now many things still do both).
Hard drives
The first sector on a hard disk (and other disks) often has the most important data to disk access, originating in convenience.
The concept of a boot sector / boot block / boot loader ((note that the edges between these terms are fuzzy, except in specific contexts)) usually comes down to a small piece of code, often in a fixed or easily located hard drive block.
For example, BIOS hard disk boot is fairly simple code (so small code, which used to matter. The BIOS started as a small piece of IC firmware, order of 8kB in ROM):
Load the first 512 bytes on the disk, check whether it looks like it contains a standard partition table, and whether the disk marked itself bootable, and if so, execute the start of this 512 bytes as CPU-native code.
Old-style: BIOS and MBR
People are now used to calling the first sector on a hard disk (bootable or not) the Master Boot Record (MBR) because that's what it was on DOS/Windows hard drives machines for many years, but this is really just one specific case.
MBR also came to refer to one way of storing partitioning information.
That first block of 512 bytes is called the MBR (Master Boot Record), which in the olden days was mostly:
- 446 bytes of boot code (could be anything any CPU can run, but is often something standardish)
- 16 bytes of partition 1 info
- 16 bytes of partition 2 info
- 16 bytes of partition 3 info
- 16 bytes of partition 4 info
- 2 bytes of boot signature (0x55 0xAA), basically to mark the presence of a MBR, and signal that the disk is (probably) bootable
A more modern (still MBR-style) first sector adds a few more things (within what before was only code),
like disk signatures, timestamps(verify), and some more specific variants [1]
The MBR's boot block could be anything,
but classically the MBR boot code might just the first block of each partition (called its VBR, Volume Boot Record),
see if has bootable code, and execute it (with certain footnotes relating to BIOS APIs of the time).
...and little more, because there's only so much you can do in those first 400-ish bytes of code.
In practice this is often a few steps of 'load and execute', of increasing complexity, where the MBR part is the only really standard part because BIOS booting expects it
Boot-wise, the BIOS knows little more than what disks are present in the system.
BIOS booting more accurately refers to MBR-style booting: It can go through the disks it knows, load the first 512 bytes, check whether there is a valid partition table (but not use it), and check a specific byte says that the drive is bootable - which basically says that the first 440ish bytes here contain code. If so, that code is executed (which, since that's tiny, often then finds and loads larger bootloader).
Because it's 30 years of de facto standards, there is more to it than this.
See many other things, including the BIOS Boot Specification.
And led to tricks like putting more code in pre-set locations (in the first so-many bytes of a disk) so that it could be loaded on every PC before we have a real OS running. e.g. in MSDOS-style partitioning it is fairly likely that the first 32K of the disk are not allocated to a partition (again, historical reasons). If so, you can use that space for more bootloader that is loadable on every PC without knowing anything more. GRUB's stage 1.5 uses this area to store support code to read a number of common filesystems, which help you store boot configuration on a filesystem instead of hardcoding it in an early stage.
Another important detail was that MBR partitioning tables can not address more than 2.2TB of a disk (due to 32-bit LBA addressing. Tl;dr: 512-byte sectors times 32-bit addresses is 2.2TB).
You could solve that with GPT partitioning -- but BIOS wasn't aware of GPT, meaning that once you're in a GPT-aware OS everything's fine, but you couldn't boot off it.
(In practice you need UEFI to boot from this)
There are various technical or just practical ways around this (e.g. put your system on a small drive - SSDs still aren't large enough to be trouble), but eh.
New-style: UEFI (and GPT)
See also:
CD/DVD drives
Network
Preboot eXecution Environment (PXE) allows booting of a computer via the network rather than from a local storage device.
PXE in itself is largely the first part in overall bootstrapping, and the PXE client code has to support the NIC to be able to get onto the network.
As such, it involves NIC-specific code that is often store on a physical ROM on the NIC itself, loaded by the system BIOS. It can also be started via simpler boot methods - floppy, hard disk, CDROM, flash drive or such.
Remote Initial Program Load (RIPL) is a variation on PXE, but used for Novell Netware style booting.
The next steps and the larger setup consists largely of DHCP, and usually TFTP (Trivial FTP, a simple-to-implement protocol to fetch files, in this case the system to boot)
DHCP, beyond its basic (and necessary) function of getting an IP address, is also the basis of the PXE exchange that informs the PXE client where to fetch the boot image from.
See also:
- http://en.wikipedia.org/wiki/Preboot_Execution_Environment
- http://en.wikipedia.org/wiki/Remote_Initial_Program_Load
USB storage
All need support in the motherboard/BIOS to work, some form of which is now almost a given.
USB devices that are *not* Flash sticks
The following refer to boto methods for physical devices that are placed in external housings and connected using USB:
- USB-HDD (USB hard drive)
- USB-ZIP (USB zip drive)
- USB-CDROM (USB CDROM)
- USB-FDD (USB floppy drive),
These are only necessary when the drive is not a recognized BIOS drive (e.g. ATA devices, ATAPI CDROMs), as those can be handled via the BIOS' own INT 13 handling
(regardless of type)(verify)
USB flash memory sticks
GUI tools you may find useful:
- UNetBootin
- Doesn't format. Since it requires/assumes FAT32 formatted devices, you may need to format the stick yourself (though most USB sticks come formatted as FAT32)
- HP USB Disk Storage Format Tool
- Formats FAT32
- Windows 7 USB/DVD Tool
- Formats as NTFS(verify)
- Has a fairly strict assumption hardcoded that makes it dislike a bunch of ISOs (you'll get a "not a valid ISO" message)
And a lot of command-line tools, including
Related software
Unsorted notes
Syslinux as a project covers:
- booting from FAT (SYSLINUX)
- network booting (PXELINUX)
- bootable CD-ROMs (ISOLINUX)
- booting from ext2/ext3/ext4 and others (EXTLINUX)
See also
Technical background:
- http://en.wikipedia.org/wiki/NTLDR
- http://en.wikipedia.org/wiki/GNU_GRUB
- http://en.wikipedia.org/wiki/LILO
- http://en.wikipedia.org/wiki/BOOTMGR
Networked boot:
- http://en.wikipedia.org/wiki/Diskless_node
- http://en.wikipedia.org/wiki/Thin_client
- http://en.wikipedia.org/wiki/Fat_client
- http://en.wikipedia.org/wiki/Preboot_Execution_Environment
- http://syslinux.zytor.com/wiki/index.php/PXELINUX
- http://etherboot.org/wiki/index.php
- http://netboot.sourceforge.net/
USB booting and other:
- http://www.pendrivelinux.com/
- http://www.pendrivelinux.com/testing-your-system-for-usb-boot-compatibility/
- http://www.boot-land.net/forums/index.php?showtopic=5133
- http://article.gmane.org/gmane.linux.distributions.grml.user/1849
- http://wiki.grml.org/doku.php?id=usb
- http://forum.insanelymac.com/index.php?showtopic=115064
- http://syslinux.zytor.com/doc/usbkey.txt
Bootng securely
See also
Secure Boot
Pre-boot authentication
https://en.wikipedia.org/wiki/Pre-boot_authentication
Grub notes
You can
- edit the boot list manually
- use update-grub, which
- which runs grub-mkconfig
- reads config from
- /etc/default/grub
- default options to all linux images
- some general grub config
- files in /etc/grub.d/
- run in (shell expansion) order
- /etc/default/grub
- and generates /boot/grub/grub.cfg
Notes:
- /boot
- historically was a separate partition, purely for low-level reasons, making sure that the first stage of a boot loader can address it (early enough on the disk that LBA addressing isn't required)
- these days it's mostly just useful organisation. It's often not a partition anymore, because those could fill up.
Minimizing boot time
Pre-OS booting
BIOS
UEFI
OS booting
Windows
Basics
Drivers
System services
User profile
"Loading your personal settings" can take long when there's work that holds things and can't be or just isn't postponable.
This includes:
- a roaming profile (network logins) that needs to be copied/synchronized
- ...and there's a lot of stuff in your profile. Simple division: Size divided by network speed. Occasional cleanup can help, but most of us find it easier to just wait.
- note that there are various setups that specifically avoid this by leaving much of your profile network-mounted rather than copied(verify)
- you have persistent network mounts (network shares shown as drives) that either
- cannot be restored (the timeout involved will cause a significant delay)
- are slow because the remote server is slow
- various implied work. A lot of login stuff is simple enough, but it adds up. For example, a desktop background image may take 0.1 to 1 second to load.
Background tools/apps
Windows startup notes
Boot
Bootvis (XP)
Bootvis is a utility that analyses where bootup time is spent (in which drivers and processes, where on which disks, how much CPU time things spend) and visualizes its information in various ways.
Can be used to determine which processes take the most time, which can be used by computer maintainers to see why a computer boots so slowly, and/or whether there is anything that can be avoided at boot time, or completely.
(Note: The following has since been integrated(verify) and is automatically executed every three days, so not relevant to most of us) On Windows XP (specifically), it can also automatically determine how to boot a little faster. To do this, choose 'Trace → Optimize system'. What it actually does is defragment the files used in bootup (recorded in C:\WINDOWS\Prefetch\Layout.ini), moving them to a contiguous section so that the disk can read all of it in a little faster.
BootVis is Microsoft product, but was discontinued it some time ago.
You can still find downloads, both on Microsoft's site (still true?{{verify}) and on other sites.
See also:
- http://en.wikipedia.org/wiki/BootVis
- http://articles.techrepublic.com.com/5100-10878_11-5034622.html
Windows Performance Toolkit (Vista, Win7)
WPT (now one of the parts you can install via the Assessment and Deployment Kit (ADK)) includes a BootVis equivalent for these windows versions.
There are some prefetchish optimizations. Since they are aimed at reducing the effect of HDD latency, they are pointless on SSDs.
Later startup
What gets run when
Note: This is a summary of keys, some of which may only apply to specific windows versions.
When the system boots: (when boot is complete; around when you are presented with a login screen):
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnceEx (verify)
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce\Setup (apparently for windows setup processes)
When any user logs in:
For all user logins ('All users' settings):
- HKLM\Software\Microsoft\Windows\CurrentVersion\Run,
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
- HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
- HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows
- The Startup (the one in the Start Menu) folder, pointed to by HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Common Startup (verify)
For the specific user:
- HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run,
- HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
- HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx (verify)
- Their Startup folder (pointed to by HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Startup (verify))
Notes:
- ...Once entries are deleted just before being run (so not conditional on success)
- The key name is mostly there for human readability, except that starting it with a ! can be used to delay deletion until after running (verify) (test for success or not?(verify))
- ...Ex forms are apparently more controllable
- Run entries are not run in Safe Mode (all of these or just that?(verify))
- Note to admins: on profile creation, entries from the HKEY_USERS\.DEFAULT user are copied in.
To read:
- http://support.microsoft.com/kb/179365
- RunOnceEx: [2], [3]
- Run, RunOnce: [4]
- http://www.absolutestartup.com/help/Winstart.htm
- https://technet.microsoft.com/en-us/magazine/ee851671.aspx
Startup inspection tools
Autoruns
Autoruns is a program that summarizes of things that are automatically loaded and started (more exhaustive than something like msconfig) and allows you to disable loading most of them.
See also
Startup delayers
Startup Delayer and such allow you to start the various things started at login over a longer time instead of all at once, meaning you actually can start using your computer once you see the desktop. (If you spread things like updaters, preloaders, instant messaging, and various use-sometimes utilities over half a minute they'll still be loaded by the time you actually use them)
Things causing windows startup/login to be slow
The double-startup bug
(Windows XP - or whenver not using the Vista/7 search-style menu)
If, like me, you like to organize your Start menu into less than total chaos. You then likely noticed that some items were duplicated, figured out that's because your start menu is a union of the 'all users' start menu and your own, and decided to copy yours to all users, since you are all users anyway.
The problem with that is that windows tried to be smart: it changed the references to your start menu items to where you moved them. Useful, fine, except now your own Startup folder's location changed, to All Users one. The startup mechanism is not smart enough to realize this happened, and still runs both, i.e. runs everything twice.
Few programs care, because most will realize they are already running. It slows down startup a little, and messes up the few things that do care.
You can check whether this happened by looking at HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders. (See Registry editing if you don't know what that meant)
All entries should start with %USERPROFILE%. If the Startup one starts with %ALLUSERSPROFILE%, replace that with %USERPROFILE%, and you'll have it as windows should have left it.
Windows 7 startup and login screen tweaking
- To skip the animating windows logo at boot, run msconfig, go to the Boot tab, and select 'No GUI boot'. The only thing you lose is the ability to tell that boot has frozen at this stage.
- Changing the background (for login and shutdown screen) is best done by using existing OEM styling options. You can do this relatively manually (See e.g. [5]), and there are apparently also programs out there to do it for you (such as [6]).
- Removing the windows logo requires you to edit the base branding DLL at %windir%\Branding\Basebrd\basebrd.dll. You can use a halfway decent resource editor to remove the bitmaps from this DLL. [7]
- It seems you can't remove the ease-of-use button, but you can make it do nothing.
- If you're looking in the sound theme to change the windows startup sound, you can't. You can only enable or disable it - it's a checkbox below that list (a lot of people stare at the list so hard that they miss that)