顯示具有 Rocky 標籤的文章。 顯示所有文章
顯示具有 Rocky 標籤的文章。 顯示所有文章

2025年7月11日 星期五

[研究]Rocky Linux 10.0安裝

[研究]Rocky Linux 10.0安裝

2025-07-11

Rocky Linux 10.0(2025年6月11日;穩定版本)

官方網站

https://rockylinux.org/zh-TW

直接下載

https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10.0-x86_64-dvd1.iso

Click 圖片可以看 100% 原始尺寸






















(完)

2025年6月9日 星期一

2025年3月25日 星期二

[研究]VMware Workstation Pro 17 的 VM 記憶體大小疑問 (Rocky Linux 9.5)

[研究]VMware Workstation Pro 17 的 VM 記憶體大小疑問 (Rocky Linux 9.5)

2025-03-24

在測試安裝某軟體,有記憶體最低需求,軟體並會檢查記憶,實際有點出乎預料。




[user1@localhost ~]$ free -h
               total        used        free      shared  buff/cache   available   
Mem:           3.5Gi       1.4Gi       911Mi        22Mi       1.5Gi       2.2Gi
Swap:          3.9Gi          0B       3.9Gi
[user1@localhost ~]$ cat /proc/meminfo | grep MemTotal
MemTotal:        3713092 kB
[user1@localhost ~]$ 

********************************************************************************

改設定為 5120 MB

[user1@localhost ~]$ free -h
               total        used        free      shared  buff/cache   available
Mem:           4.5Gi       1.5Gi       1.8Gi        24Mi       1.5Gi       3.1Gi
Swap:          3.9Gi          0B       3.9Gi
[user1@localhost ~]$ cat /proc/meminfo | grep MemTotal
MemTotal:        4761668 kB
[user1@localhost ~]$ 

********************************************************************************

要縮減 RAM,要先 Power Off,改設定為 4608 MB

[user1@localhost ~]$ free -h
               total        used        free      shared  buff/cache   available
Mem:           4.0Gi       1.4Gi       2.3Gi        22Mi       556Mi       2.6Gi
Swap:          3.9Gi          0B       3.9Gi
[user1@localhost ~]$ cat /proc/meminfo | grep MemTotal
MemTotal:        4223008 kB
[user1@localhost ~]$ 

********************************************************************************

虛擬機器記憶體限制和硬體版本 
Virtual machine memory limits and hardware versions
https://knowledge.broadcom.com/external/article?legacyId=1014006

(完)

2025年3月12日 星期三

[研究]如何知道作業系統是否為 Rocky Linux ? 版本 ?

[研究]如何知道作業系統是否為 Rocky Linux ? 版本 ?

2025-03-11

方法 1:使用 /etc/os-release


[user1@localhost ~]$ cat /etc/os-release 
NAME="Rocky Linux"
VERSION="9.5 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.5"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.5 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
VENDOR_NAME="RESF"
VENDOR_URL="https://resf.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"   
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.5"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.5"
[user1@localhost ~]$ 

方法 2:使用 hostnamectl

[user1@localhost ~]$ hostnamectl
   Static hostname: (unset)                           
Transient hostname: localhost
         Icon name: computer-vm
           Chassis: vm 🖴
        Machine ID: f93a6377bc174e4b9d27383e42ad3cf7
           Boot ID: 32138075578c4561b55160a033ad5cca
    Virtualization: vmware
  Operating System: Rocky Linux 9.5 (Blue Onyx)       
       CPE OS Name: cpe:/o:rocky:rocky:9::baseos
            Kernel: Linux 5.14.0-503.14.1.el9_5.x86_64
      Architecture: x86-64
   Hardware Vendor: VMware, Inc.
    Hardware Model: VMware Virtual Platform
  Firmware Version: 6.00
[user1@localhost ~]$ 

方法3:檢查 /etc/redhat-release

因為 Rocky Linux 是 RHEL 相容版本,也可以用:


[user1@localhost ~]$ cat /etc/redhat-release  
Rocky Linux release 9.5 (Blue Onyx)
[user1@localhost ~]$ 


推薦前2個方法。

(完)

2023年6月19日 星期一

[研究]Splunk Server 的 OS 開機跑不完

[研究]Splunk Server 的 OS 開機跑不完

2023-06-19

這台 Splunk Server 9.0.5 安裝於 Rocky Linux 9.2 (類似 CentOS) 上,某次 reboot 後,就卡在開機,/etc/rc.d/rc.local 跑很久。


********************************************************************************
解決:



參考這篇解決

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

(完)

相關

[研究]Splunk Server 的 OS 開機跑不完
https://shaurong.blogspot.com/2023/06/splunk-server-os.html

[研究]Splunk沒有回傳之解決 (SplunkForwarder Service 服務異常)
https://shaurong.blogspot.com/2023/06/splunk-splunkforwarder-service.html

[研究]顯示目前有哪些使用者登入 (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_38.html

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_17.html

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)
https://shaurong.blogspot.com/2023/06/home-rocky-linux-9centos.html

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

2023年6月17日 星期六

[研究]顯示目前有哪些使用者登入 (Rocky Linux 9 / CentOS)

[研究]顯示目前有哪些使用者登入 (Rocky Linux 9 / CentOS)

2023-06-17 

用 who 指令可顯示目前有哪些使用者登入


[root@localhost user1]# who
user1    seat0        2023-06-17 14:12 (login screen)
user1    tty2         2023-06-17 14:12 (tty2)

[root@localhost user1]# whoami
root

[root@localhost user1]# 

whoami 可以顯示目前使用者為誰?

但 root 不在 who 顯示的名單,是因為 root 是 user1 用  su  root 切換身分,而非 root 直接登入。

********************************************************************************

下面這才是只有 root登入的情況


[root@localhost ~]# who
root     seat0        2023-06-17 14:32 (login screen)
root     tty2         2023-06-17 14:32 (tty2)
[root@localhost ~]# 


(完)

相關

[研究]顯示目前有哪些使用者登入 (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_38.html

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_17.html

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)
https://shaurong.blogspot.com/2023/06/home-rocky-linux-9centos.html

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)

2023-06-17

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

********************************************************************************

強制某帳號登出 ?  (需有 root 同等權限)

sudo pkill -u username

例如:

[root@localhost ~]# sudo pkill user2  
[root@localhost ~]# 

********************************************************************************

強制某帳號的某個 Process 程序 (進程)中止 (需有 root 同等權限)

ps -u username

sudo kill -9 PID

sudo pkill process_name

sudo killall process_name

**********

強制 root 以外所有一般使用者帳號登出 ?

sudo pkill -u $(awk -F':' '{ if ( $3 >= 1000 && $1 != "root" ) print $1}' /etc/passwd)

sudo skill -KILL -u $(awk -F':' '{ if ( $3 >= 1000 && $1 != "root" ) print $1}' /etc/passwd)

這個命令會找出 /etc/passwd 檔案中 UID 大於等於 1000 且不是 root 的所有使用者帳號,並使用 skill 命令終止這些使用者的進程。

(完)

相關

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_17.html

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)
https://shaurong.blogspot.com/2023/06/home-rocky-linux-9centos.html

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)

2023-06-17

********************************************************************************

建立一個使用者

[root@localhost ~]# useradd user2

[root@localhost ~]# passwd user2
更改使用者 user2 的密碼。
新 密碼: 
再次輸入新的 密碼: 
passwd:所有核對代符都已成功更新。
[root@localhost ~]# 

/home 和使用者的目錄權限

[root@localhost /]# ls -al
total 24
dr-xr-xr-x.  18 root root  235 Jun 16 14:34 .
dr-xr-xr-x.  18 root root  235 Jun 16 14:34 ..
dr-xr-xr-x.   2 root root    6 May 16  2022 afs
lrwxrwxrwx.   1 root root    7 May 16  2022 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Jun 16 14:55 boot
drwxr-xr-x.  20 root root 3440 Jun 17 13:39 dev
drwxr-xr-x. 130 root root 8192 Jun 17 13:39 etc
drwxr-xr-x.   3 root root   19 Jun 16 14:55 home
lrwxrwxrwx.   1 root root    7 May 16  2022 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 May 16  2022 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 May 16  2022 media
drwxr-xr-x.   3 root root   18 Jun 16 14:35 mnt
drwxr-xr-x.   2 root root    6 May 16  2022 opt
dr-xr-xr-x. 335 root root    0 Jun 17 13:39 proc
dr-xr-x---.   4 root root  180 Jun 17 13:39 root
drwxr-xr-x.  45 root root 1200 Jun 17 13:39 run
lrwxrwxrwx.   1 root root    8 May 16  2022 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 May 16  2022 srv
dr-xr-xr-x.  13 root root    0 Jun 17 13:39 sys
drwxrwxrwt.  21 root root 4096 Jun 17 13:39 tmp
drwxr-xr-x.  12 root root  144 Jun 16 14:34 usr
drwxr-xr-x.  20 root root 4096 Jun 16 14:55 var
[root@localhost /]# ls -al home
total 4
drwxr-xr-x.  3 root  root    19 Jun 16 14:55 .
dr-xr-xr-x. 18 root  root   235 Jun 16 14:34 ..
drwx------. 14 user1 user1 4096 Jun 16 14:55 user1
[root@localhost /]# 


********************************************************************************

在使用 tar 命令打包時,預設情況下,它不會保留目錄的使用者和使用者權限。不過,你可以使用 --same-owner 和 --preserve-permissions 選項來連同目錄的使用者和使用者權限一起打包。

tar --same-owner --preserve-permissions -cvzf archive.tar.gz directory/

--same-owner 選項會保留目錄中檔案的使用者和群組擁有者,以及特殊的使用者識別碼 (UID) 和群組識別碼 (GID)。

--preserve-permissions 選項會保留目錄中檔案的權限模式。

請確保以 root 或具有足夠權限的使用者身分執行 tar 命令,以確保可以訪問並保留目錄的使用者和使用者權限。

tar --same-owner --preserve-permissions -xvzf archive.tar.gz

請注意,在特定的情況下,保留目錄的使用者和使用者權限可能需要特殊的設定或權限。

********************************************************************************

打包 /home 目錄:

sudo tar  --same-owner --preserve-permissions -czvf home_backup.tar.gz /home

把 home 目錄解壓縮在 / 根目錄:

sudo tar  --same-owner --preserve-permissions xzvf home_backup.tar.gz  -C /

(完)

相關

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)
https://shaurong.blogspot.com/2023/06/home-rocky-linux-9centos.html

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)

2023-06-17

開放 root 可以本機登入

Rocky Linux 9 或 CentOS 預設不能用 root 本機登入或 ssh 登入,若要開放

修改 sshd 的設定檔

$ sudo vi /etc/ssh/sshd_config

找到 (約第 40 行)

PermitRootLogin prohibit-password

改為

PermitRootLogin yes

儲存檔案及離開編輯器,重新啟動 sshd:

$ sudo systemctl restart sshd

登出,可以用 root 登入了。


(完)

相關

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)

2023-06-17

********************************************************************************

可以執行 yum  -y  update 更新

執行 reboot

創造可測試的環境

user1@localhost ~]$ cd /boot 

[root@localhost boot]# df -h /boot
檔案系統        容量  已用  可用 已用% 掛載點
/dev/sda1      1014M  292M  723M   29% /boot
[root@localhost boot]# ls -al -h
總用量 242M
dr-xr-xr-x.  5 root root 4.0K  6月  9 09:49 .
dr-xr-xr-x. 18 root root  235  6月  9 09:41 ..
-rw-r--r--.  1 root root 211K  5月 10 01:22 config-5.14.0-284.11.1.el9_2.x86_64
drwxr-xr-x.  3 root root   17  6月  9 09:41 efi
drwx------.  5 root root   97  6月 17 11:47 grub2
-rw-------.  1 root root 125M  6月  9 09:44 initramfs-0-rescue-6ca00049d9c548e09173997ff02535d0.img
-rw-------.  1 root root  56M  6月  9 09:46 initramfs-5.14.0-284.11.1.el9_2.x86_64.img
-rw-------.  1 root root  32M  6月  9 09:49 initramfs-5.14.0-284.11.1.el9_2.x86_64kdump.img
drwxr-xr-x.  3 root root   21  6月  9 09:42 loader
lrwxrwxrwx.  1 root root   52  6月  9 09:43 symvers-5.14.0-284.11.1.el9_2.x86_64.gz -> /lib/modules/5.14.0-284.11.1.el9_2.x86_64/symvers.gz
-rw-------.  1 root root 5.7M  5月 10 01:22 System.map-5.14.0-284.11.1.el9_2.x86_64
-rwxr-xr-x.  1 root root  12M  6月  9 09:44 vmlinuz-0-rescue-6ca00049d9c548e09173997ff02535d0
-rwxr-xr-x.  1 root root  12M  5月 10 01:22 vmlinuz-5.14.0-284.11.1.el9_2.x86_64
-rw-r--r--.  1 root root  167  5月 10 01:21 .vmlinuz-5.14.0-284.11.1.el9_2.x86_64.hmac
[root@localhost boot]# 

[user1@localhost boot]$ ls /boot/grub2/
ls: 無法開啟目錄 '/boot/grub2/': 拒絕不符權限的操作

[user1@localhost boot]$ su root
密碼: 

[root@localhost boot]# ls -al /boot/grub2/
總用量 36
drwx------. 5 root root   97  6月 17 11:47 .
dr-xr-xr-x. 5 root root 4096  6月  9 09:49 ..
-rw-r--r--. 1 root root   64  6月  9 09:45 device.map
drwxr-xr-x. 2 root root   25  6月  9 09:45 fonts
-rw-------. 1 root root 7110  6月  9 09:45 grub.cfg
-rw-------. 1 root root 1024  6月 17 11:47 grubenv
drwxr-xr-x. 2 root root 8192  6月  9 09:45 i386-pc
drwxr-xr-x. 2 root root 4096  6月  9 09:45 locale
[root@localhost boot]# 

上面只有一版 kernel。

(下圖) 開機時如果是類似下面畫面,表示目前只有一個版本 (另一個 rescue 是救援用 )

********************************************************************************

電腦上有很多版 kernel 畫面

********************************************************************************

在 Rocky Linux 9.2(或 CentOS)中,舊版 kernel 通常存放在 /boot 目錄下。你可以按照以下步驟進行舊版 kernel 的刪除:

ls -l /boot

sudo rm /boot/vmlinuz-<版本號碼>

sudo rm /boot/initramfs-<版本號碼>.img

請將 <版本號碼> 替換為你要刪除的舊版 kernel 的實際版本號碼。


刪除相應的 grub 設定文件:

sudo rm /boot/grub2/grub.cfg-<版本號碼>

使用以下命令更新 grub 設定:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

這將會重新生成 grub 的設定文件,確保舊版 kernel 的項目已經被移除。

完成以上步驟後,你已經成功刪除舊版 kernel 檔案。請注意,在刪除 kernel 檔案之前,請確保你保留了穩定且正常運作的 kernel 版本,以確保系統的正常運作。

(完)

相關

[研究]舊版 kernel 放在哪裡? 如何刪除 ? (Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/kernel-rocky-linux-92-centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割

[研究]Splunk - Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割

2023-06-17、2023-06-19更新

因為 Splunk Enterprise Server 的根目錄空間有些不夠,所以研究

********************************************************************************

請開放開放 root 本機登入,確認沒有其他使用者登入,或強制他們登出  (否則後面無法 umount  /home )

[研究]開放 root 本機登入 (Splunk - Rocky Linux 9.2 / CentOS)
https://shaurong.blogspot.com/2023/06/root-splunk-rocky-linux-92-centos.html

[研究]如何強制某帳號登出 ? (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_17.html

[研究]顯示目前有哪些使用者登入 (Rocky Linux 9 / CentOS)
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos_38.html

********************************************************************************

以 root 登入,檢視各磁碟分割空間 大小,考慮 /home 目錄內容要拷貝到哪去

[root@localhost ~]# df -h
檔案系統             容量  已用  可用 已用% 掛載點
devtmpfs             4.0M     0  4.0M    0% /dev
tmpfs                1.8G     0  1.8G    0% /dev/shm
tmpfs                727M   13M  715M    2% /run
/dev/mapper/rl-root   64G  4.5G   60G    7% /
/dev/mapper/rl-home   32G  260M   31G    1% /home
/dev/sda1           1014M  292M  723M   29% /boot
tmpfs                364M  100K  364M    1% /run/user/1000
[root@localhost ~]# 

檢視 /home 目錄及子目錄總大小

[root@localhost ~]# du -sh /home
4.5M	/home
[root@localhost ~]# 

注意,如果 /home 有使用者資料,要先打包拷貝走 (含權限),否則就不用備份:

sudo tar  --same-owner --preserve-permissions -czvf home_backup.tar.gz /home

****************************************

如果有一般使用者登入,或一般使用者登入再 su root 切換,是無法 umount  /home


[user1@localhost ~]$ umount /home
umount: /home: target is busy.
[user1@localhost ~]$

註:可以用下面指令列出哪個 ProcessID 正在使用 /home,然後 kill 掉,但實際測試太多了。

sudo lsof | grep '/home'

sudo kill PID

****************************************

註:如果不想整個 /home 併入根目錄磁碟分割,可用磁碟分割澃 fdisk 或 parted 對 /home 進行縮減,不在本篇研究。

****************************************

把 /home 掛載先卸載,編輯 /etc/fstab 註解掉 /home

[root@localhost ~]# umount /home
[root@localhost ~]# vi /etc/fstab  

fstab 內容,把 /home 那行最開始加讓 # 進行註解,存檔

#
# /etc/fstab
# Created by anaconda on Fri Jun  9 01:40:24 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root     /                       xfs     defaults        0 0
UUID=9d7f7518-07d0-4539-8819-b985633fd2a3 /boot                   xfs     defaults        0 0
#/dev/mapper/rl-home     /home                   xfs     defaults        0 0
/dev/mapper/rl-swap     none                    swap    defaults        0 0
~      

接下來的操作,lv (Logic Volume) 的名稱要對應 /etc/fstab 的內容

lvremove /dev/mapper/rl-home  移除該 lv

lvextend -l +100%FREE /dev/mapper/rl-root   所有空間加到 另一個 lv 

xfs_growfs /dev/mapper/rl-root  延展該 lv 使用全部空間

[root@localhost ~]# umount /home

[root@localhost ~]# vi /etc/fstab

[root@localhost ~]# lvremove  /dev/mapper/rl-home
Do you really want to remove active logical volume rl/home? [y/n]: y
  Logical volume "home" successfully removed.

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/rl-root
  Size of logical volume rl/root changed from 63.88 GiB (16354 extents) to 95.07 GiB (24338 extents).
  Logical volume rl/root successfully resized.

[root@localhost ~]# xfs_growfs /dev/mapper/rl-root
meta-data=/dev/mapper/rl-root    isize=512    agcount=4, agsize=4186624 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=16746496, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=8177, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 16746496 to 24922112

[root@localhost ~]# df -h
檔案系統             容量  已用  可用 已用% 掛載點
devtmpfs             4.0M     0  4.0M    0% /dev
tmpfs                1.8G     0  1.8G    0% /dev/shm
tmpfs                727M   13M  715M    2% /run
/dev/mapper/rl-root   96G  4.9G   91G    6% /
/dev/sda1           1014M  292M  723M   29% /boot
[root@localhost ~]# 


結果可見 /home 磁碟分割不存在了,空間全部合併到 根目錄磁碟分割了。


****************************************

如果 /home 有使用者資料,拷貝回來 (包含原來權限)

把 home 目錄解壓縮在 / 根目錄:

sudo tar  --same-owner --preserve-permissions xzvf home_backup.tar.gz  -C /

****************************************

/home 和使用者目錄、檔案權限

[user1@localhost /]$ ls -al  /
總用量 24
dr-xr-xr-x.  18 root root  235  6月  9 09:41 .
dr-xr-xr-x.  18 root root  235  6月  9 09:41 ..
dr-xr-xr-x.   2 root root    6  5月 16  2022 afs
lrwxrwxrwx.   1 root root    7  5月 16  2022 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096  6月  9 09:49 boot
drwxr-xr-x.  20 root root 3420  6月 19 09:33 dev
drwxr-xr-x. 130 root root 8192  6月 19 09:33 etc
drwxr-xr-x.   3 root root   19  6月  9 09:56 home
lrwxrwxrwx.   1 root root    7  5月 16  2022 lib -> usr/lib
lrwxrwxrwx.   1 root root    9  5月 16  2022 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6  5月 16  2022 media
drwxr-xr-x.   3 root root   18  6月  9 09:41 mnt
drwxr-xr-x.   2 root root    6  5月 16  2022 opt
dr-xr-xr-x. 339 root root    0  6月 19 09:33 proc
dr-xr-x---.   4 root root  161  6月  9 09:58 root
drwxr-xr-x.  46 root root 1220  6月 19 09:34 run
lrwxrwxrwx.   1 root root    8  5月 16  2022 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6  5月 16  2022 srv
dr-xr-xr-x.  13 root root    0  6月 19 09:33 sys
drwxrwxrwt.  23 root root 4096  6月 19 09:34 tmp
drwxr-xr-x.  12 root root  144  6月  9 09:41 usr
drwxr-xr-x.  20 root root 4096  6月  9 09:49 var
[user1@localhost /]$ ls -al /home
總用量 4
drwxr-xr-x.  3 root  root    19  6月  9 09:56 .
dr-xr-xr-x. 18 root  root   235  6月  9 09:41 ..
drwx------. 14 user1 user1 4096  6月  9 09:56 user1
[user1@localhost /]$

(完)

相關

[研究]把 /home 打包複製、解壓複製回 (Rocky Linux 9、CentOS)
https://shaurong.blogspot.com/2023/06/home-rocky-linux-9centos.html

[研究]Rocky Linux 9.2 / CentOS 把 /home 空間合併到 / 根目錄分割https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos-home.html

[研究] Rocky Linux 9 / CentOS 查詢磁碟分割上、目錄的空間佔用情況
https://shaurong.blogspot.com/2023/06/rocky-linux-9-centos.html

[研究]Rocky Linux 9.2 , CentOS 安裝時手動分割磁區
https://shaurong.blogspot.com/2023/06/rocky-linux-92-centos.html

[研究]Rocky Linux 8.8、9.2預設分割大小測試
https://shaurong.blogspot.com/2023/06/rocky-linux-8892.html

[研究]Splunk 9.0.5 (on Rocky Linux 9.2) 回傳停止之解決
https://shaurong.blogspot.com/2023/06/splunk-905-on-rocky-linux-92.html