[리눅스] 로딩시간 길어진 내 그놈 속도 올리기 (feat. Systemd)

2023. 4. 6. 02:35리눅스 실제 사용 팁

작성일 : 2022. 10. 3. 13:47


~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=fc8b3d6e-ec72-4660-8197-826c80194d67 /               ext4    errors=remount-ro 0       1
UUID=A2F0-E129  /boot/efi       vfat    umask=0077      0       1
UUID=33074af0-5372-4842-94d0-5896f25616a9 /home           ext4    defaults        0       2
UUID=072416dc-3ac0-4b43-a2a6-6acba3f9dd60 /tmp            ext4    defaults        0       2
UUID=05ff6ca8-88f5-4e4e-b659-963a6fb9272b /usr            ext4    defaults        0       2
UUID=4db308c1-1dbd-48f3-95b1-756503033bf2 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0

 

언제부턴가 리눅스로 부팅하면 마지막에 뜨는 gdm3 와 로그인 후 실행되는 gnome desktop 이 화면에 뜨기까지 체감시간 5분이 거뜬히 지나가는 현상이 생겼다. 9년 된 노트북에서 HDD 를 떼어 내고 SSD 로 교체한지 얼마나 되었다고 이러는 것인지?!

새 술은 새 가죽부대에 담아야 한다고? 어처구니 없는 소리에 돌 던지고 싶다. 최신 버전인 소프트웨어에 구형 하드웨어가 적응못해서 로딩 속도가 떨어지는 게 원인 아니었다. 왜냐하면 fsck.ext4 /dev/sdb3 로 내 홈계정이 들어 있는 파티션을 청소해주면 시스템이 언제 그랬냐는 듯 생생하게 돌아가기 때문이었다. 문제는 이 작업을 매번 관리자 모드로 부팅한 후에 처리하고 로그아웃해서 gdm 이 실행되는 평상 시 모드로 전환하지 않고 시스템에서 직접 실행하도록 하는 것이었다.

SysInit V 방식이었나? 예전의 유닉스 호환 방식말이다. /etc/inittab 에 실행레벨이 담겨서 /etc/init.d/ 밑에 실행될 서비스 스크립트를 넣고 /etc/rc*.d/ 밑에 걸어주면 알아서 실행되는 방식. 여기에 넣어 봤는데 안되더라.

요즘은 대다수의 리눅스 배포판이 Systemd 로 돌아선 이후부터 공부해야 할 게 또 생겼다. 무슨 파티션 언마운트 후 저널링 체크하고 다시 마운트해주기 위해서 복잡한 과정을 또 알아가야 하나 싶다!

 

출근길에 구글로 찾아낸 systemd 관련 명령 몇 개를 뿌려본다.

`systemctl list-units` 를 실행하면 되게 긴 목록이 주루룩 뜨는데 명령 뒤에 --type 옵션을 덧붙이면 (즉, 마운트 관련은 --type mount) 특정 범주에 속한 목록만 확인할 수 있다.

 

지금 나에게 필요한 라인은 여기!

home.mount                                        loaded active mounted /home

 

내 /home 파티션을 마운트하는 서비스이다.

$ systemctl list-units --type mount
  UNIT                                              LOAD   ACTIVE SUB     DESCRIPTION                                    
  -.mount                                           loaded active mounted Root Mount
  boot-efi.mount                                    loaded active mounted /boot/efi
  dev-hugepages.mount                               loaded active mounted Huge Pages File System
  dev-mqueue.mount                                  loaded active mounted POSIX Message Queue File System
  home.mount                                        loaded active mounted /home
  run-credentials-systemd\x2dsysusers.service.mount loaded active mounted /run/credentials/systemd-sysusers.service
  run-user-1000-doc.mount                           loaded active mounted /run/user/1000/doc
  run-user-1000-gvfs.mount                          loaded active mounted /run/user/1000/gvfs
  run-user-1000.mount                               loaded active mounted /run/user/1000
  snap-bare-5.mount                                 loaded active mounted Mount unit for bare, revision 5
  snap-core18-2560.mount                            loaded active mounted Mount unit for core18, revision 2560
  snap-core18-2566.mount                            loaded active mounted Mount unit for core18, revision 2566
  snap-gnome\x2d3\x2d28\x2d1804-161.mount           loaded active mounted Mount unit for gnome-3-28-1804, revision 161
  snap-gtk\x2dcommon\x2dthemes-1535.mount           loaded active mounted Mount unit for gtk-common-themes, revision 1535
  snap-netflix\x2dweb-1.mount                       loaded active mounted Mount unit for netflix-web, revision 1
  snap-snapd-16778.mount                            loaded active mounted Mount unit for snapd, revision 16778
  snap-snapd-17029.mount                            loaded active mounted Mount unit for snapd, revision 17029
  sys-fs-fuse-connections.mount                     loaded active mounted FUSE Control File System
  sys-kernel-config.mount                           loaded active mounted Kernel Configuration File System
  sys-kernel-debug.mount                            loaded active mounted Kernel Debug File System
  sys-kernel-tracing.mount                          loaded active mounted Kernel Trace File System
  tmp.mount                                         loaded active mounted /tmp
  usr.mount                                         loaded active mounted /usr

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
23 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

 

https://unix.stackexchange.com/questions/672841/how-to-add-fsck-at-boot-like-a-regular-service

 

How to add fsck at boot like a regular service?

I remember that certain distros, used to run fsck at boot after x boots, in a regular way. How can be added to the boot process the fsck service to be deployed in rpm distro/Fedora,RHEL,Oracle,Suse?

unix.stackexchange.com

 

tune2fs 명령으로 부팅 횟수에 따른 fsck 실행을 설정할 수 있다. 괜히 호들값 떨었네.

`tune2fs -c 1 파티션` 명령으로 마운트 1회가 지난 후, 즉 매회 부팅 시마다 fsck 를 실행할 수 있다는 글을 봤지만, 글쎄? systemd 에서는 먹혀들지 않았다. 다행히도 /usr/local/lib/systemd/system/ 에 직접 서비스를 등록하는 게시글을 따라 하다가 힌트를 발견했다.

 

`systemctl list-units` 실행결과에서 fsck 만 걸러냈더니 /home 에 대한 UUID (blkid) 를 찾을 수 있었다.

systemd-fsck@dev-disk-by\x2duuid-33074af0\x2d5372\x2d4842\x2d94d0\x2d5896f25616a9.service

 

# systemctl list-units | grep fsck
  systemd-fsck@dev-disk-by\x2duuid-072416dc\x2d3ac0\x2d4b43\x2da2a6\x2d6acba3f9dd60.service loaded active     exited    File System Check on /dev/disk/by-uuid/072416dc-3ac0-4b43-a2a6-6acba3f9dd60
  systemd-fsck@dev-disk-by\x2duuid-33074af0\x2d5372\x2d4842\x2d94d0\x2d5896f25616a9.service loaded active     exited    File System Check on /dev/disk/by-uuid/33074af0-5372-4842-94d0-5896f25616a9
  systemd-fsck@dev-disk-by\x2duuid-A2F0\x2dE129.service                                     loaded active     exited    File System Check on /dev/disk/by-uuid/A2F0-E129
  system-systemd\x2dfsck.slice                                                              loaded active     active    Slice /system/systemd-fsck
  systemd-fsckd.socket

 

/etc/fstab 에서 내 /home 에 대한 UUID 를 발견. (33074af0~)

~$ cat /etc/fstab

UUID=33074af0-5372-4842-94d0-5896f25616a9 /home           ext4    defaults        0       2

 

※ fsck 를 실행하는 서비스 파일 - `systemd-fsck@.service` 이것에 아까 맨위에서 언급했던 `home.mount` 를 추가해주기만 하면 된다. (↓↓↓↓↓)

Before=systemd-quotacheck.service shutdown.target home.mount

`Before=` 뒤에 나열된 목록은 현 스크립트가 정의하고 있는 서비스 보다 우선 순위가 낮다.

(이 줄을 재해석하자면, home.mount 이전에 fsck 를 실행하게 함으로써 윈도우즈OS 와 듀얼부팅 및 자주 방치해서 수퍼블럭이 뻑나는 내 구형 노트북에서 더 이상 그놈이 굼뜨지 않고 날개 돋힌 듯 즉시 시작될 수 있게 하는 마법의 묘수!! 라고 할 수 있다!!)

 

/usr/lib/systemd/system$ cat systemd-fsck@.service 
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=File System Check on %f
Documentation=man:systemd-fsck@.service(8)
DefaultDependencies=no
BindsTo=%i.device
Conflicts=shutdown.target
Wants=systemd-fsckd.socket
After=%i.device systemd-fsck-root.service local-fs-pre.target systemd-fsckd.socket
Before=systemd-quotacheck.service shutdown.target home.mount

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/lib/systemd/systemd-fsck %f
TimeoutSec=0

 

서비스 스크립트를 수정한 후에는 systemd 가 인식할 수 있도록 다음 명령을 실행해야 한다. (이건 뭐 fsck 라서 어차피 재부팅 시 적용될 거지만... 명령을 익히기 위해서 알아 놓도록 하자!)

 

# systemctl daemon-reload

(또는 sudo 로 권한처리)

$ sudo systemctl daemon-reload