Speeding Up Ubuntu Boot
Using Linux for daily work, boot speeds gradually decrease over time. The Ubuntu distribution includes Snap, which further slows down boot speeds. While boot speed is largely determined by hardware configuration, optimizing your software environment and maintaining good user habits are also crucial.
The following are common methods I've found to speed up booting:
1. GRUB_TIMEOUT Setting
This sets the number of seconds after which the GRUB menu disappears. The default is 5 seconds. To balance configurability and speed, I chose 2 seconds. A setting of 0 means skipping and proceeding to the next step. The English explanation is as follows:
'GRUB_TIMEOUT'
Boot the default entry this many seconds after the menu is displayed, unless a key is pressed. The default is ‘5’. Set to ‘0’ to boot immediately without displaying the menu, or to ‘-1’ to wait indefinitely.
1➜ ~ egrep -v '^#|^$' /etc/default/grub
2GRUB_DEFAULT="0"
3GRUB_TIMEOUT_STYLE="menu"
4GRUB_TIMEOUT=2
5GRUB_DISTRIBUTOR="`lsb_release -i -s 2> /dev/null || echo Debian`"
6GRUB_CMDLINE_LINUX_DEFAULT=""
7GRUB_CMDLINE_LINUX=""
8GRUB_GFXMODE="1920x1440x32"
9export GRUB_COLOR_NORMAL="light-gray/black"
10export GRUB_COLOR_HIGHLIGHT="magenta/black"
11GRUB_THEME="/boot/grub/themes/ubuntu-/theme.txt"
After making any changes to GRUB, run sudo update-grub
for them to take effect.
Please be extremely cautious when making changes to GRUB, especially if you don't understand the changes. This can cause problems with booting into the system, and repairing the system can be difficult, especially for experts.
2. Analyze system service startup with systemd-analyze
Use the following command to determine which program is causing slow boot times. Disable any unused programs with sudo systemctl disable xxx.service
.
- systemd-analyze prints boot time information
- systemd-analyze blame sorts service startup times from longest to shortest (reference)
- systemd-analyze critical-chain lists critical chains that slow down boot speed (really important)
- systemd-analyze plot > ~/boot.svg generates a vector diagram of detailed boot information (focus on the red areas in the color image)
1➜ ~ systemd-analyze
2Startup finished in 7.103s (firmware) + 4.614s (loader) + 19.164s (kernel) + 8.308s (userspace) = 39.191s
3graphical.target reached after 7.992s in userspace.
4➜ ~ systemd-analyze blame | head -n 10
51.860s systemd-udev-settle.service
61.686s zfs-volume-wait.service
71.683s zfs-mount.service
8680mslm-sensors.service
9605ms accounts-daemon.service
10553ms dnsmasq.service
11490ms systemd-logind.service
12480ms udisks2.service
13427ms ModemManager.service
14341ms systemd-udev-trigger.service
15➜ ~ systemd-analyze critical-chain
16The time when unit became active or started is printed after the "@" character.
17The time the unit took to start is printed after the "+" character.
18
19graphical.target @7.992s
20└─multi-user.target @7.989s
21└─kerneloops.service @7.952s +33ms
22└─nss-lookup.target @7.948s
23└─dnsmasq.service @7.392s +553ms
24└─network.target @7.339s
25└─NetworkManager.service @7.146s +191ms
26└─dbus.service @6.989s +103ms
27└─basic.target @6.956s
28└─sockets.target @6.955s
29└─virtlogd-admin.socket @6.954s
30└─virtlogd.socket @6.953s
31└─sysinit.target @6.926s
32└─systemd-timesyncd.service @6.809s +116ms
33└─systemd-tmpfiles-setup.service @6.753s +46ms
34└─local-fs.target @6.743s └─zfs-mount.service @5.059s +1.683s
35└─boot.mount @5.034s +17ms
36└─local-fs-pre.target @2.816s
37└─systemd-tmpfiles-setup-dev.service @2.794s +20ms
38└─systemd-sysusers.service @2.773s +19ms
39└─systemd-remount-fs.service @2.641s +111ms
40└─systemd-journald.socket @2.523s
41└─system.slice @2.485s
42└─-.slice @2.485s
It's worth noting that snap software often starts many loopxx.device services, which significantly slows down boot speed. I don't use snap software anyway, so I just delete it.
1sudo apt-get purge snapd
3. Check startup software
Press the 'Win' key on your keyboard (between Ctrl and Alt in the lower-left corner) and search for 'Startup Applications'. Delete unnecessary startup applications, leaving only the essential ones. Travel light and run faster.
4. Remove unnecessary startup services
List all enabled services in the system, review them one by one, and remove any that are unnecessary based on your specific situation.
1systemctl list-unit-files --state=enabled
For example, since my work computer doesn't need this printer service (my company uses cloud printing), I can disable it with sudo systemctl disable cups-browsed.service
This process can generally significantly improve boot time. Some may say, "I'm working in embedded systems and can customize the kernel and perform various startup optimizations myself, but this is beyond the scope of this article (this article is intended for average Linux desktop users).
Also, when discussing Linux booting, we have to mention plymouth-quit-wait.service
and apt-daily.service
. Actually, neither service affects boot speed. See these two links: plymouth and apt-daily.
Verification method:
1systemctl list-dependencies plymouth-quit-wait.service
2systemctl list-dependencies --reverse apt-daily
Next, let's talk about Plymouth. I've often been confused by this name, but it wasn't until I dug deeper that I discovered the fascinating story behind it. At first, I thought it was "ply + mouth" (what does "ply" stand for + mouth), and I was a bit confused. It actually refers to the British port city of Plymouth.
Why is Plymouth related to Linux booting? Wikipedia explains:
Plymouth is a free application that provides bootsplash for Linux. The program is named after Plymouth Rock, a name that symbolizes the program's Plymouth serves as the first point of entry for users to interact with a computer system.
Plymouth is the Linux startup animation (analogous to the animated effect when brand logos like Windows and Mac appear). The name Plymouth comes from Plymouth Rock, also known as the Immigrant Rock, now a cultural landmark in the United States. The first stepping stone in the New World is analogous to the first computer program for user interaction.
Background on Immigrant Rock:
Anyone familiar with American history knows that American history began with a group of Puritans from England, and Plymouth was their first place of residence. Plymouth is located in Massachusetts, about an hour's drive from Boston.
In September 1620, unbearable religious oppression in continental Europe, some English Puritans left Plymouth, England, on fishing boats for the American colonies, seeking greater freedom of faith. With only limited navigational knowledge, the Puritans crossed the Atlantic. The long journey, coupled with unpredictable weather, caused all other ships to sink, but only the Mayflower successfully landed on New England. They named the land they left Plymouth, and American history was written from then on. During the harsh first winter, resources in the uncultivated land were scarce, and many of the Puritans died of disease and starvation. In dire straits, the Indians sent turkeys and other food, which helped the remaining people barely survive. Fortunately, they had a bountiful harvest the following year. To thank God for the bountiful harvest and the Indians for their gifts, they held a carnival, which became the forerunner of Thanksgiving.
To commemorate the landing, they carved a rock with the number 1620 on it. Today, this land is protected as a U.S. national park, where staff dress in 17th-century clothing and speak in authentic medieval dialects and accents. Almost everything you see here is a complete replica of a 17th-century style.
Plymouth was created by Ray Strode, an American engineer working at Red Hat. It's perfectly fine for an American engineer to use American allusions.
Image of the Immigrant Rock:
Finally, some people like the boot animation, while others don't. How can I disable it? Without the animation, the command line displays the boot process, which I personally prefer. A quick glance at it daily might help me spot potential problems.
Change the grub configuration file /etc/default/grub
:
Before modification:
1GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
After modification:
1GRUB_CMDLINE_LINUX_DEFAULT=""
File example:
1➜ ~ egrep -v '^#|^$' /etc/default/grub
2GRUB_DEFAULT="0"
3GRUB_TIMEOUT_STYLE="menu"
4GRUB_TIMEOUT=2
5GRUB_DISTRIBUTOR="`lsb_release -i -s 2> /dev/null || echo Debian`"
6GRUB_CMDLINE_LINUX_DEFAULT=""
7GRUB_CMDLINE_LINUX=""
8GRUB_GFXMODE="1920x1440x32"
9export GRUB_COLOR_NORMAL="light-gray/black"
10export GRUB_COLOR_HIGHLIGHT="magenta/black"
11GRUB_THEME="/boot/grub/themes/ubuntu-/theme.txt"
GRUB_GFXMODE="1920x1440x32"
This controls the boot terminal resolution. The following parameters come from (different for each person):
1➜ ~ sudo hwinfo --framebuffer
2[sudo] password for mephisto:
302: None 00.0: 11001 VESA Framebuffer
4[Created at bios.459]
5Unique ID: rdCR.jB2oURqGEo2
6Hardware Class: framebuffer
7Model: "Intel(R) SKL Mobile/Desktop Graphics Controller"
8Vendor: "Intel Corporation"
9Device: "Intel(R) SKL Mobile/Desktop Graphics Controller"
10SubVendor: "Intel(R) SKL Mobile/Desktop Graphics Chipset Accelerated VGA BIOS"
11SubDevice:
12Revision: "Hardware Version 0.0"
13Memory Size: 31 MB + 960 kB
14Memory Range: 0x00000000-0x01feffff (rw)
15Mode 0x033c: 1920x1440 (+1920), 8 bits
16Mode 0x034d: 1920x1440 (+3840), 16 bits
17Mode 0x035c: 1920x1440 (+7680), 24 bits
18Mode 0x033a: 1600x1200 (+1600), 8 bits
19Mode 0x034b: 1600x1200 (+3200), 16 bits
20Mode 0x035a: 1600x1200 (+6400), 24 bits
21Mode 0x0307: 1280x1024 (+1280), 8 bits
22Mode 0x031a: 1280x1024 (+2560), 16 bits
23Mode 0x031b: 1280x1024 (+5120), 24 bits
24Mode 0x0305: 1024x768 (+1024), 8 bits
25Mode 0x0317: 1024x768 (+2048), 16 bits
26Mode 0x0318: 1024x768 (+4096), 24 bits
27Mode 0x0312: 640x480 (+2560), 24 bits
28Mode 0x0314: 800x600 (+1600), 16 bits
29Mode 0x0315: 800x600 (+3200), 24 bits
30Mode 0x0301: 640x480 (+640), 8 bits
31Mode 0x0303: 800x600 (+832), 8 bits
32Mode 0x0311: 640x480 (+1280), 16 bits
33Mode 0x037d: 0x0 (+0), 8 bits
34Mode 0x037e: 0x0 (+0), 16 bits
35Mode 0x037f: 0x0 (+0), 24 bits
36Config Status: cfg=new, avail=yes, need=no, active=unknown
Again, be careful when modifying the GRUB configuration. Always run sudo update-grub
after making any changes.
Copyright statement:
- All content that is not sourced is original., please do not reprint without authorization (because the typesetting is often disordered after reprinting, the content is uncontrollable, and cannot be continuously updated, etc.);
- For non-profit purposes, to deduce any content of this blog, please give the relevant webpage address of this site in the form of 'source of original text' or 'reference link' (for the convenience of readers).
See Also:
- Manually Upgrading LibreOffice in Ubuntu
- Ubuntu 22.10 connection bluetooth headset error 'br-connection-profile-unavailable solution'
- Ubuntu connects AirPods headphones
- Set Alacritty as the Default Terminal in Ubuntu
- Ubuntu install WeChat
- Ubuntu notify-send Scheduled Notifications
- Ubuntu Change Login Wallpaper
- Batch Convert PNG Images to WebP
- Install the latest version of Git from source on Ubuntu
- Install Your Favorite Fonts in Linux