# Windows Server

# 疑難雜症



# Windows 10 / 2016+ Join Domain後進入設定跳出rundll32.exe沒有適當的權限

<span lang="EN-US">Windows 10 / 2016 Join Domain</span><span lang="EN-US">前都沒問題，但Join Domain</span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">後變更某些設定時，可能會出現下面錯誤訊息。</span>

[![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-06/scaled-1680-/Gtvimage.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-06/Gtvimage.png)

<span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">需至</span><span lang="EN-US"> gpedit.msc =&gt; </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">電腦設定</span><span lang="EN-US"> =&gt; Windows</span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">設定</span><span lang="EN-US"> =&gt; </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">安全性設定</span><span lang="EN-US"> =&gt; </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">本機原則</span><span lang="EN-US"> =&gt; </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">安全性選項</span><span lang="EN-US"> =&gt; </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">使用者帳戶控制</span><span lang="EN-US"> : </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">內建的</span><span lang="EN-US">Administrator</span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">帳戶</span><span lang="EN-US">xxxxxx </span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">，變更為</span><span lang="EN-US">”</span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">啟用</span><span lang="EN-US">”</span><span style="font-family: '新細明體',serif; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">，**<span style="color: rgb(224, 62, 45);">登出</span>**再登入即可正常運作。</span>

<span lang="EN-US"> </span>

[![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-06/scaled-1680-/CZHimage.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-06/CZHimage.png)

<span lang="EN-US" style="mso-no-proof: yes;"> </span>

<span lang="EN-US"> </span>

# Active Directory GPO 變更 Local Admin Password

### <span style="color: rgb(35, 111, 161);">前言</span>

最近剛好有個有個Case，要透過AD更改Local Admin User Password，紀錄一下設定方式。

<p class="callout warning">‼️請注意，由於密碼是明碼，請在變更完後一段時間將此GPO與ps1刪除，以策安全。</p>

### <span style="color: rgb(35, 111, 161);">環境</span>

Server：Windows 2019 Active Directory

Client：Windows 11 Pro

### <span style="color: rgb(35, 111, 161);">設定方式</span>

1、首先，先建議一個 Power Shell ps1檔備用。

執行命令提示字元 "cmd"，我在 C:\\temp下面透過 Copy con建立一個 Change-LocalAdminPassword.ps1，將下面的指令貼入，最後 Ctrl+Z儲存離開。

```
$newPassword = "密碼"
$adminUsername = "帳號"
$adminUser = [ADSI]"WinNT://./$adminUsername, user"
$adminUser.SetPassword($newPassword)
$adminUser.SetInfo()
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/ZxvIUstlCn.png)

2、至群組原則管理，新增一個物件。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/l4X2RG12kv.png)

建立一條 Change\_LocalAdmin的GPO。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/XSOAGebw5T.png)

3、針對剛剛建立的物件進行編輯。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/FMqkv3uBwB.png)

至 電腦設定 =&gt; 原則 =&gt; 系統管理範本 =&gt; Windows元件 =&gt; Windows PowerShell =&gt; 開啟指令碼執行，允許指令碼執行。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/8uiDCRJorT.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/SRKjwLOL6M.png)

4、至 電腦設定 =&gt; 原則 =&gt; Windows設定 =&gt; 指令碼 =&gt; 啟動，設定Logon Script。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/mhPQhtSLzQ.png)

點選PowerShell指令碼，新增

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/raFiw3lgjM.png)

點選瀏覽，先記下目錄位置

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/woNh8QiPNF.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/PHXbGOqri6.png)

你將會在 C:\\Windows\\SYSVOL\\ 下面找到一樣的路徑，將步驟1建立的ps1檔Copy至此。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/6uPVXnA61e.png)

回到剛剛指令碼的選擇畫面，就可以看到了

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/1JNs1fTMme.png)

變更執行順序後，確定離開

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/4gXpePZpMr.png)

5、此時點選到GPO物件，應該就可以透過下圖看到剛剛設定的內容了。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/DJLmGhKyCF.png)

將此GPO物件，拖曳至我們測試用的 Test OU即可。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/tYpDMCfeyo.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/Wa0D4aDi9l.png)

### <span style="color: rgb(35, 111, 161);">反向檢查</span>

我們到此Test OU的電腦上，執行 gpupdate /force

```
gpupdate /force
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/7xJir77AEo.png)

再執行 gpresult /R，確認 GPO 是否有套到，這樣就可以了喔。

```
gpresult /R
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-12/scaled-1680-/RKif0mw6wL.png)

# Windows Software Raid



# Windows Software Raid - Legacy MBR

### 前言

上次寫到了Linux的Software Raid [https://mdfk.goddamn.idv.tw/books/linux/page/linux-software-raid-mdadm](https://mdfk.goddamn.idv.tw/books/linux/page/linux-software-raid-mdadm)

相對於Linux現在在UEFI Bios上Sofrware Raid設定起來很方便，現在的Windows Software Raid在UEFI Bios上操作起來就如同Legacy Bios上的Linux Software Raid一樣很麻煩，此篇先回顧一下"想當年" Legacy Bios上Windows Software Raid是如何建立的，下一篇再來談現在UEFI Bios上面如何建立。

But ...... 一定要先說在前面，在Windows 2003那個年代除非使用Hardware Raid Card否則是沒什麼更好的Raid選擇，一些最便宜的Server大多都只能用這個方式來達成資料冗餘，但在Windows Software Raid在Intel® 快速儲存技術（Intel RST / IRST / <span class="t55VCb">RSTe / VROC</span>）技術出來之後，現在Windows Software Raid在實務上基本上**<span style="color: rgb(224, 62, 45);">完全沒有人會去使用</span>**，如今一台Workstation等級的機器就算沒有Harware Raid Card都完全支援Intel Software Raid，比起Windows Software Raid來說好用簡單太多Performance又好，這種Windows Software Raid可謂是時代的眼淚，所以基本上此篇分享就是個單純完全無用的技術分享。 <span style="color: rgb(224, 62, 45);">**╮（╯＿╰）╭**</span>

### 設定方式

<p class="callout info">資料來源 : [https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/mirror-system-boot-partition-raid1](https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/mirror-system-boot-partition-raid1)</p>

#### 測試環境

鍵人我使用Hyperv第一代來模擬Legacy Bios環境，HDD1先安裝好Windows 2003 R2 OS，HDD2為同大小完全新的HDD

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ZfFimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/fxJimage.png)

#### 建立鏡像磁碟(Mirror)

至 "電腦管理" =&gt; "磁碟管理"

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/d9Nimage.png)

可看到 磁碟1 (HDD2) 是完全乾淨的磁碟

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/TQ6image.png)

磁碟1 右鍵 =&gt; 初始化磁碟

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/hHPimage.png)

磁碟0 (HDD1) 右鍵 =&gt; 轉換成動態磁碟

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ULBimage.png)

將兩顆磁碟都轉換成動態磁碟，完成後將重新開機

![2024-07-18_17-15_1.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/2024-07-18-17-15-1.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/uRyimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/7TTimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/7SZimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/S9simage.png)

重開機後，再回到磁碟管理，磁碟0 上右鍵 "新增鏡像"

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/15rimage.png)

選取磁碟1(HDD2)作為鏡像目標

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ww8image.png)

靜候Mirror同步完成

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/woximage.png)

Mirror完成

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/9niimage.png)

### 磁碟故障測試

先在桌面上建立一個文字檔，來確認Raid功能是否正常

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/rg0image.png)

關機，將HDD1移除

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/q3Nimage.png)

開機正常，資料正確，來加上一筆資料

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/6DSimage.png)

裝置管理員顯示只有一顆HDD

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/m4Gimage.png)

磁碟管理顯示一顆HDD遺失

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/dspimage.png)

關機，我把HDD2改為IDE 0，增加一顆HDD3設為IDE 1

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Fjzimage.png)

開機正常，裝置管理員顯示為2個HDD

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/TPtimage.png)

磁碟管理員顯示磁碟1 (HDD3)未配置，Mirror失敗

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/am3image.png)

初始化磁碟1 (HDD3)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/5zoimage.png)

移除原本的Mirror

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/rp3image.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/TJGimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/L5gimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Xfsimage.png)

重建Mirror (步驟請參照上面不贅述)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/gn8image.png)

### 切換磁碟開機與重新同步

上面展示了磁碟故障時如何重建Mirror，但如果磁碟不是全死，要如何取出磁碟檢測後讓Raid重新同步 ?

首先我們先到資料匣選項將隱藏檔顯示出來

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Ysdimage.png)

編輯C:\\boot.ini

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/kO1image.png)

複製operating system到第二行，並修改 rdisk 與描述

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/UDyimage.png)

重新開機，出現開機選單就可以選擇你想用哪一顆磁碟開機了，在此我們先選擇用**<span style="color: rgb(224, 62, 45);">HDD3</span>**開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/huLimage.png)

開進OS，桌面上的文字檔再加上一筆註記，我們即將測試移除HDD2

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/kQximage.png)

關機，移除HDD2

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/QWpimage.png)

再次選擇使用**<span style="color: rgb(224, 62, 45);">HDD3</span>**開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/VvFimage.png)

<span style="color: rgb(224, 62, 45);">**錯誤 !!** <span style="color: rgb(0, 0, 0);">這是正常的，因為IDE 0不見了，所以原本 IDE 1 的 HDD3 在系統上被當作 IDE 0了</span></span>

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/4Dximage.png)

選擇第一個開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/sGHimage.png)

開機正常，只剩下一顆HDD

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/i0iimage.png)

HDD3被當作是"磁碟0"了 (因為是IDE 0)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Jzrimage.png)

確認資料正確

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/kQximage.png)

關機，把HDD2加回來

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/QYoimage.png)

使用HDD2開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/sGHimage.png)

<span style="color: rgb(224, 62, 45);">**BSOD !!**</span> <span style="color: rgb(224, 62, 45);">**(ﾉﾟ0ﾟ)ﾉ~**</span> 這是正常的，因為HDD2的資料不同步

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/UzIimage.png)

使用HDD3開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/VvFimage.png)

開機正常，磁碟顯示為2

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ipFimage.png)

磁碟管理顯示"磁碟0" (HDD2) Raid不同步

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Ipximage.png)

在此我們桌面上的文字檔再加上一筆註記，我們來測試Rebuild HDD2

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Vszimage.png)

"磁碟0" (HDD2) 點選 "重新啟動磁碟區"

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/9Cdimage.png)

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/BMAimage.png)

Raid Rebuild 中 ......

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ZRyimage.png)

靜待Raid Rebuid完成

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/4jmimage.png)

重新開機，選擇HDD2開機

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/sGHimage.png)

<span style="color: rgb(224, 62, 45);">**開機正常 !! 資料正確 !! ⸜(｡˃ ᵕ ˂ )⸝♡**</span>

![image.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Vszimage.png)

### 後話

前面說過，在Windows 2003那個年代除非使用Hardware Raid Card否則是沒什麼更好的Raid選擇，一些最便宜的Server大多都只能用這個方式來達成資料冗餘，但在Windows Software Raid在Intel® 快速儲存技術（Intel RST / IRST / <span class="t55VCb">RSTe / VROC</span>）技術出來之後，現在Windows Software Raid在實務上基本上**<span style="color: rgb(224, 62, 45);">完全沒有人會去使用</span>**，如今一台Workstation等級的機器就算沒有Harware Raid Card都完全支援Intel Software Raid，比起Windows Software Raid來說好用簡單太多Performance又好，這種Windows Software Raid可謂是時代的眼淚，現在也許在某些"特殊"的情境下或許會對大家有幫助......吧 (?)

至於UEFI上設定Windows Software Raid的複雜程度就比MBR上高了不少，欲知詳情下回分解 **<span style="color: rgb(224, 62, 45);">( ˶°ㅁ°) !!</span>**

# Windows Software Raid - UEFI GPT

### 前言

延續之前 [Windows Software Raid - Legacy MBR 的技術分享](https://mdfk.goddamn.idv.tw/books/windows-server/page/windows-software-raid-legacy-mbr) ，Windows 2003年代還會有一些低階Server有機會那樣做，在Intel® 快速儲存技術（Intel RST / IRST / <span class="t55VCb">RSTe / VROC</span>）技術出來之後，現在Windows Software Raid在實務上基本上**<span style="color: rgb(224, 62, 45);">完全沒有人會去使用</span>**，如今一台Workstation等級的機器就算沒有Harware Raid Card都完全支援Intel Software Raid，比起Windows Software Raid來說好用簡單太多Performance又好，這種Windows Software Raid可謂是時代的眼淚，此篇 Windows Software Raid - UEFI GPT 相較於 Legacy MBR 在設定上更加麻煩、實用性上更低，基本上就是分享一下現代的Windows Server還是可以在UEFI GPT上還是可以做Software Raid，但...你這輩子應該都不會這樣做。

### 設定方式

<p class="callout info">資料來源 : [https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/set-up-dynamic-boot-partition-mirroring](https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/set-up-dynamic-boot-partition-mirroring)</p>

#### 測試環境  


鍵人我使用Hyperv第二代來模擬UEFI GPT環境，HDD0先安裝好Windows 2022 OS，HDD1為同大小完全新的HDD，同時先刪除Recover磁區 (你真的在Server上用過Recover嗎 ?) **<span style="color: rgb(224, 62, 45);">(¬\_¬")</span>**

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ZCMisJ3dJB.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/a8bq6b2Yf7.png)

#### 建立鏡像磁碟(Mirror)

至 "電腦管理" =&gt; "磁碟管理"，可看到 磁碟1 (HDD1) 是完全乾淨的磁碟

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/vH3dYdTjm5.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/sMulG4AonJ.png)

點及右鍵 =&gt; 連線

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/UdD7ZkjbRv.png)

初始化磁碟

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/tomnpG1T1y.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/y81DtTRKez.png)

以<span style="color: rgb(224, 62, 45);">"**系統管理者身分"**</span>執行Powershell / cmd

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/fijluopNBQ.png)

先刪除HDD1的MSR

```
diskpart
list disk
sel disk 1
list par
sel par 1
delete par override
list par
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/fwByi1bVN1.png)

重新建立 EFI Boot磁區與MSR

```
sel disk 0
list par
sel disk 1
create par efi size=100
create par msr size=16
list par
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/HtzqBz9aLg.png)

將 磁碟0、磁碟1 轉換為"動態磁碟"後，離開diskpart

```
sel disk 1
convert dynamic
sel disk 0
convert dynamic
exit
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/6HG2iPtZ85.png)

回到 磁碟管理，點選 磁碟0 上新增鏡像

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ZmRIBBBaTz.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/8At1IsoRub.png)

Mirror進行中

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/8nVcQycoma.png)

Mirror完成

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/j058VndZsz.png)

#### 處理EFI Boot

Mirror是處理好了，但是EFI可不像是MBR直接使用Active來指定開機的磁區，所以在這裡我們必須對HDD1的EFI磁區進行處理，這樣一但出問題HDD1才能夠獨立開機。

首先先進Diskpart，將剛剛未格式化的EFI磁碟格式化為FAT32，並把HDD0 EFI掛載為P、HDD1 EFI掛載為S

```
diskpart
sel disk 1
sel par 1
assign letter=S
format fs=FAT32 quick
sel disk 0
sel par 1
assign letter=P
exit
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/nUhUVWKihs.png)

透過bcdedit /enum可以確認到現在EFI的開機的GUID

```
P:
cd EFI\Microsoft\Boot
bcdedit /enum
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/k5eqp1ZRvu.png)

<span style="color: rgb(224, 62, 45);">**<span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; font-family: '新細明體',serif; mso-bidi-font-family: 新細明體; mso-ansi-language: EN-US; mso-fareast-language: ZH-TW; mso-bidi-language: AR-SA;">※此指令只能在CMD下執行※</span>**</span>

將現有 {bootmgr} Clone一份出來，並把S設定為相同的{GUID}

```
cmd
bcdedit /copy {bootmgr} /d "Windows Boot Manager Cloned"
bcdedit /set {GUID} device partition=S:
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/O7GV15tWMZ.png)

透過 bcdedit /enum all 可看到剛剛建立出來的開機選項

```
bcdedit /enum all
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Ht95g8oG7T.png)

將剛剛的變更匯出為BCD2

```
bcdedit /export P:\EFI\Microsoft\Boot\BCD2
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/z6Mfk8veQA.png)

將P的資料全部複製到S

```
robocopy p:\ s:\ /e /r:0
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/30ydRxBG5t.png)

將S的BCD2更名為BCD，並刪除P的BCD2

```
S:
cd EFI\Microsoft\Boot
ren BCD2 BCD
del P:\EFI\Microsoft\Boot\BCD2
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/6AVUuXW396.png)

回到diskpart，將磁碟代號 P、S 移除

```
diskpart
list vol
sel vol 1
remove letter P
sel vol 2
remove letter S
exit
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/RTYVtW3JPu.png)

到此EFI開機設定全數完成 (累...)

### 磁碟故障測試

關機，到Hyperv "設定"=&gt;"韌體"中已經可以看到HDD1的 "Windows Boot Manager Cloned"

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/HpmynojwZr.png)

移除HDD0

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/F5hOSaZO7f.png)

將Windows Boot Manager Cloned開機順序提高至1

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/3XtytuZafa.png)

開機，使用第一個選項 HDD0 開機

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/fpeHP8emBX.png)

無法開機，正常

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/GDlmPPJhlM.png)

點選Enter，重新選擇HDD1開機

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/8k8sdbwj8I.png)

開機正常，磁碟管理顯示"備援失敗"

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ezQgcu0Q9F.png)

至此，磁碟故障測試完成，如此確認了就算失去任何一顆HDD都能夠正常開機

### 重建Mirror

關機，我們將HDD0掛回來

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/vaT9esPgSw.png)

選擇HDD1開機

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/8k8sdbwj8I.png)

裝置管理員確認已認到2顆HDD

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/RVxBuaZNZW.png)

磁碟顯示Mirror Fail，來移除鏡像

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/alSf1mhx6B.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/J68g5Ln0ky.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/3pvBmioRiZ.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/gvIojMKjnc.png)

點選HDD0，匯入外部磁碟

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/Hj4TNvmhhB.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/ogukO1xfBV.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/802R8NaIWl.png)

將HDD0的舊磁區刪除

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/grOu8ZAsdT.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/T4hfqMWgGt.png)

點選HDD1，重新建立Mirror

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/TloeQC8dY1.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/NQKJl8hRCS.png)

Mirror中

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/9ps9nHnkwa.png)

Mirror完成

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-07/scaled-1680-/OeMMZDEdXH.png)

### 後話

僅以此分享一下即使是現在 UEFI Bios 年代，Windows Software Raid 依然還能用

只是你這輩子應該都不會再去用他 <span lang="EN-US" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; font-family: 標楷體; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: ZH-TW; mso-bidi-language: AR-SA;">……</span><span style="color: rgb(224, 62, 45);"> **╮（╯＿╰）╭**</span>

# Windows功能



# Windows Server Data Deduplication 檔案層級重複資料刪除

### <span style="color: rgb(35, 111, 161);">前言</span>

![understanding-dedup-how-dedup-works-4.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/understanding-dedup-how-dedup-works-4.gif)

Windows Server 從 2012開始支援<span style="color: rgb(45, 194, 107);">**檔案層級**</span><span style="color: rgb(224, 62, 45);">**重複資料刪除**</span>，Windows 2012當年僅支援單線程處理所以其實不好用，Windows Server 2016之後開始支援多線程處理，Windows Server 2019開始支援ReFS的重複資料刪除，且現今大部分主流備份系統都支援Dedupe Volume的備份還原，讓整個Solution好用很多，但鍵人發現此功能仍鮮少人知故特別在此分享推廣一下。

### <span style="color: rgb(35, 111, 161);">系統需求</span>

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/u6YtzKfrC2.png)

**<span style="color: rgb(230, 126, 35);">OS：</span>** Windows Server 2012 以上，但建議在Windows Server 2016 以上使用

**<span style="color: rgb(230, 126, 35);">CPU：</span>** 至少4 Core，但多一點比較好

**<span style="color: rgb(230, 126, 35);">Memory：</span>** 系統最少保留 4GB+ 且每 1TB 需要 1GB RAM，如果需要Dedupe的Volume 10TB，記憶體需要 14GB (4GB+10GB)

<span style="color: rgb(230, 126, 35);">**最小可Dedupe檔案大小：**</span> 預設32KB，但可以透過Powershell變更檔案大小

**<span style="color: rgb(230, 126, 35);">磁碟格式：</span>** NTFS / ReFS (2019+)

<span style="color: rgb(230, 126, 35);">**磁碟大小支援：**</span> Windows 2016後可支援最大 64TB的空間進行Dedupe，根據不同的 Cluster Size 可支援的大小不同，Windows預設Cluster Size為4KB下最大空間僅支援16TB。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/vwTzRXmMVZ.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/kMlayIpZ1T.png)

**<span style="color: rgb(230, 126, 35);">適用情境：</span>** File Server、HyperV、HyperV Cluster、Backup Storage

<p class="callout warning"><span style="color: rgb(224, 62, 45);">HyperV 高IO Production 環境下不建議使用</span></p>

**<span style="color: rgb(230, 126, 35);">預期Dedupe效率：</span>** 根據Microsoft官方說法如下

[![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/UWb6w8Q5a6.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/UWb6w8Q5a6.png)

### <span style="color: rgb(35, 111, 161);">運作原理</span>

1\. 掃描檔案系統以尋找符合最佳化原則的檔案。

![understanding-dedup-how-dedup-works-1.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/understanding-dedup-how-dedup-works-1.gif)

2\. 將檔案分成可變更大小的區塊。

![understanding-dedup-how-dedup-works-2.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/understanding-dedup-how-dedup-works-2.gif)

3\. 識別唯一的區塊。

![understanding-dedup-how-dedup-works-3.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/understanding-dedup-how-dedup-works-3.gif)

4\. 將區塊放入區塊存放區，並選擇性壓縮。

![understanding-dedup-how-dedup-works-4.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/jOvunderstanding-dedup-how-dedup-works-4.gif)

5\. 使用重新分析點將區塊存放區中的原始檔案資料流取代為現在已最佳化的檔案。

![understanding-dedup-how-dedup-works-5.gif](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/understanding-dedup-how-dedup-works-5.gif)

<p class="callout info">詳細請參照 [https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/overview](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/overview)</p>

### <span style="color: rgb(35, 111, 161);">安裝設定過程</span>

#### <span style="color: rgb(35, 111, 161);">安裝步驟</span>

1\. 伺服器管理員 =&gt; 管理 =&gt; 新增角色及功能 。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/4jiXub9reS.png)

2\. 展開 檔案和存放服務，點選 重複資料刪除。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/OsIwOHtFD6.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/qqNwhpD0Z1.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/i8lcBi4ks1.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/l1MDl2rSPg.png)

3\. 新增所需要的功能並安裝。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/9zGo4Q30r2.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/baJjgP1Orj.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/vTey0ZUYR2.png)

4\. 安裝完成 全文完 ...... 沒有開玩笑的啦 .o(≧∀≦)o

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/ozbFKf2R5R.png)

5\. 在Service中會出現兩個Dedupe的服務

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/nfTgitpwp8.png)


#### <span style="color: rgb(35, 111, 161);">評估Dedupe效益</span>

Windows有提供預先評估工具來評估Dedupe是否有效益，如果效益不佳就不要使用將服務移除就好

首先我先將Windows Server 2022 ISO Copy 至 D:\\，並且再複製一份

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/LK3yTw3Rl9.png)

先看一下2022 ISO檔大小5.29GB

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/MSI4683URf.png)

磁碟大小 10.7GB

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/sfWfgjbp2W.png)

執行Dedupe評估工具DDPEVAL.EXE

```
ddpeval "D:" /V
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/zl1Sw56qgy.png)

由上面結果看來可Dedupe 57%，再來複製第三份 2022 ISO

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/jP355haSsB.png)

再跑一次評估工具，預估可以Dedupe 78%

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/D8vSOIMxhc.png)


#### <span style="color: rgb(35, 111, 161);">設定Dedupe</span>

至 伺服器管理員 =&gt; 檔案和存放服務

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/VqWzfHHhbT.png)

選取 磁碟 =&gt; 設定重複資料刪除

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/KpQnEaHRke.png)

依據你的用途選擇對應的Dedupe政策

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/w2kB5z1zwa.png)

預設的政策內容差異請參照

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/understand](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/understand)</p>

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/vZ5daQpjTz.png)

在這邊我們選擇檔案伺服器，順便看一下預設的最佳化排程

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/LerNpXGivY.png)

有啟用背景最佳化，這樣已足夠，確認後離開

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/5zM59uoRbh.png)


#### <span style="color: rgb(35, 111, 161);">Dedupe常用指令</span>

先來介紹一下一些Dedupe常用的指令，後面會用到，參考資料

<p class="callout info">[https://learn.microsoft.com/en-us/powershell/module/deduplication/](https://learn.microsoft.com/en-us/powershell/module/deduplication/)</p>

```
Get-DedupVolume
Get-DedupStatus
Get-DedupSchedule
Get-DedupJob
```


#### <span style="color: rgb(35, 111, 161);">執行Dedupe最佳化</span>

預設狀況，背景最佳化會每天自動進行數次，我們可以透過 Get-DedupSchedule 來看最佳化的排程

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/k0ZzywHMog.png)

或者可以到工作排程器來查看執行狀況

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/L4hAvP2SDU.png)

這裡我們可以利用Powershell手動進行最佳化，參考資料

<p class="callout info">[https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831602(v=ws.11)](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831602(v=ws.11))</p>

```
Start-DedupJob -Volume "D:" -Type Optimization -Memory 50
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/SgTg2TlAyJ.png)

透過 Get-DedupJob 指令來觀察任務執行狀況

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/Jafrsx9M0T.png)

同時也可以透過資源監視器，看到Dedupe進行的狀態

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/QsaqFGQjoC.png)

靜待 Get-dedupJob 沒有顯示任何Job時，最佳化完成

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/iMcPYYu00J.png)

#### <span style="color: rgb(35, 111, 161);">確認Dedupe結果</span>

透過 Get-DedupStatus、Get-DedupVolume 來確認 Dedupe 結果

```
Get-DedupStatus
Get-DedupVolume
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/qAjvJaanhN.png)

由上圖可知，總共4個檔案節省了16.8GB，Dedupe Rate 71%

可以看到磁碟已使用空間變大了

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/CeO1iu2VTm.png)

或者也可以透過 伺服器管理員 =&gt; 磁碟 =&gt; 內容 來確認 Dedupe 狀況

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/9M7haApCCp.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/pdbRRw0EXB.png)

#### <span style="color: rgb(35, 111, 161);">檔案顯示差異</span>

要如何知道哪個檔案有Dedupe過，那些沒有Dedupe過 ? 從檔案的磁碟大小即可分辨

[![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/PfjErzMV0g.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/PfjErzMV0g.png)

[![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/pO8g41ris6.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/pO8g41ris6.png)

Dedupe過後，檔案的磁碟大小不見得會是0，但肯定很小

### <span style="color: rgb(35, 111, 161);">實務案例</span>

看Lab沒啥感覺，來看看天殺の鍵人我的實際專案建置狀況

#### <span style="color: rgb(35, 111, 161);">案例一：檔案伺服器</span>

20TB 檔案伺服器，8,082,185個檔案與目錄僅占<span style="color: rgb(45, 194, 107);">**5.23TB**</span>，Dedupe Rate <span style="color: rgb(224, 62, 45);">**72%**</span>，節省了**<span style="color: rgb(224, 62, 45);">13.75TB</span>**，如果沒有Dedupe則需要 5.23+13.75=**<span style="color: rgb(224, 62, 45);">18.98TB</span>**

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/EaZnBGpqHU.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/bIwzczmbOY.png)


#### <span style="color: rgb(35, 111, 161);">案例二：HyperV Host(單台)</span>

1.71TB HyperV Host，64個檔案與目錄僅占<span style="color: rgb(45, 194, 107);">**484GB**</span>，Dedupe Rate <span style="color: rgb(224, 62, 45);">**73%**</span>，節省了**<span style="color: rgb(224, 62, 45);">1.34TB</span>**，如果沒有Dedupe則需要 0.48+1.34=**<span style="color: rgb(224, 62, 45);">1.82TB <span style="color: rgb(230, 126, 35);">(根本超過本身的磁碟空間大小)</span></span>**

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/AeGpoYHMly.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/v8qEyUvjzB.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/huuu01hONc.png)


#### <span style="color: rgb(35, 111, 161);">案例三：HyperV Cluster</span>

7TB HyperV Cluster，185個檔案與目錄僅占<span style="color: rgb(45, 194, 107);">**4.16TB**</span>，Dedupe Rate <span style="color: rgb(224, 62, 45);">**59%**</span>，節省了**<span style="color: rgb(224, 62, 45);">6.17TB</span>**，如果沒有Dedupe則需要 4.16+6.17=**<span style="color: rgb(224, 62, 45);">10.33TB <span style="color: rgb(230, 126, 35);">(根本超過本身的磁碟空間大小)</span></span>**

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/5ZPXW2G52B.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/4JQBIyNN84.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/JJ7dS5UH5j.png)

### <span style="color: rgb(35, 111, 161);">優化校調</span>

由於Windows Server Data Deduplication會去定期將所有檔案作Optimize最佳化運算，但由於Optimize不外乎就是大量的IO讀寫，有些時候有可能會影響Service Performance，比方說User可能會跟你說有時候會很慢，此時可以透過下面兩個方式調整優化。

#### <span style="color: rgb(35, 111, 161);">排除不需要Optimize的物件</span>

在Dedupe設定中，可以排除副檔名與目錄，以下圖為例，我將D:\\temp排除不作Dedupe，以此來加速Optimize最佳化運算，以降低高IO讀寫對系統的Impact

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/Ha8UTdW0hO.png)

#### <span style="color: rgb(35, 111, 161);">最佳化排程調整</span>

由於Default Optimize最佳化運算排程一天會跑個3次左右，你發現會影響Service Performance，尤其是Hyperv的環境下，User跟你說裡面的虛擬機有時候正常但有時候回應很慢，你可能會發現慢的時候Guest OS的 IO Latency很高，同時以 Get-DedupJob 確認Hyperv Host是正在進行Optimize最佳化運算導致，此時就建議自行更改Optimize最佳化運算的排程，更改Optimize最佳化運算排程方式有二。

##### <span style="color: rgb(35, 111, 161);">第一種方式</span>

透過剛剛Dedupe GUI設定，設定Dedupe排程

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/6Id0BdrUXn.png)

取消 背景最佳化，排除User會使用、備份系統運作、內部Guest OS排程，自行評估使用時段設定一個時間。

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/ykWekltfj8.png)

設定完成後可透過 Get-DedupSchedule 指令或工作排程器來確認排程是否正確

```
Get-DedupSchedule
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/k3A63wCciU.png)

[![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/vB6S6qorxM.png)](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/vB6S6qorxM.png)


##### <span style="color: rgb(35, 111, 161);">第二種方式</span>

透過Powershell設定，停用預設排程並設定新排程，範例如下請參照

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/advanced-settings](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/advanced-settings)</p>

```
Set-DedupSchedule -Name BackgroundOptimization -Enabled $false
Set-DedupSchedule -Name PriorityOptimization -Enabled $false
New-DedupSchedule -Name "NightlyOptimization" -Type Optimization -DurationHours 11 -Memory 50 -Cores 80 -Priority High -Days @(1,2,3,4,5) -Start (Get-Date "2016-08-08 19:00:00")
```

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/3HFeTSVxOm.png)

### <span style="color: rgb(35, 111, 161);">Un-Dedupe</span>

Powershell請參照

<p class="callout info">[https://learn.microsoft.com/en-us/powershell/module/deduplication/expand-dedupfile?view=windowsserver2022-ps](https://learn.microsoft.com/en-us/powershell/module/deduplication/expand-dedupfile?view=windowsserver2022-ps)</p>

```
Expand-DedupFile -Path "D:\Share\"
```

### <span style="color: rgb(35, 111, 161);">Pros &amp; Cons</span>

說到這邊，相信大家都已經開始深深愛上Windows Server Data Deduplication 了，但在此還是要提一下Dedupe的優缺點。

#### <span style="color: rgb(230, 126, 35);">缺點</span>

1. 系統資源需求較高，Storage越大所需要的記憶體越多。
2. 讀取一般檔案時是去讀取分散的Chunk，連續讀取速度相較於沒有Dedupe時慢。
3. 會需要定時進行Optimize、Garbage Collect、Scrubbing，此時磁碟的高IO可能會導致IO Latency明顯增加，進而造成服務回應變慢。
4. 影像、音樂、串流 檔案無任何Dedupe效果，如果仍然想確認可執行DDPEVAL.EXE進行評估。
5. 如果有長官詢問檔案有多大你可以回答這個問題，但你無法回答把這個檔案放到File Server上會額外使用多少空間，你也無法回答刪除這些檔案後能夠釋放多少空間。
6. **<span style="color: rgb(224, 62, 45);">由於Chunk的唯一性，請好好的作好Raid與Backup，一旦磁碟壞軌資料損毀你無法預期會有多大的影響。</span>**
7. **<span style="color: rgb(224, 62, 45);">使用Robocopy可能會出問題，不是不能用但請先搞清楚那些參數不能用，請參照下方。</span>**

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/interop#robocopy](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/interop)</p>

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/asmmSCJWXt.png)

#### <span style="color: rgb(45, 194, 107);">優點</span>

1. 大幅降低 File Server、Hyperv、Backup 所需要的磁碟空間。
2. 當作File Server使用時，完全可以依照原來Windows權限設定方式設定。
3. **<span style="color: rgb(224, 62, 45);">儘管讀取一般檔案時是去讀取分散的Chunk，連續讀取速度相較於沒有Dedupe時慢，某些文獻上有提到由於Hyperv在讀取一般磁碟時會Bypass Cache，但是由於Chunk可以透過記憶體快取，所以做了 Data Deduplication 反而有助於改善Hyperv BootStorm(開機風暴)問題。</span>**

<p class="callout info">參考資料：[https://aidanfinn.com/?p=14863](https://aidanfinn.com/?p=14863)</p>

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-09/scaled-1680-/REQ2g8SQh6.png)

### <span style="color: rgb(35, 111, 161);">結語</span>

Windows Server Data Deduplication 此功能有著大幅降低所需要的磁碟空間顯著的優點，但同時也有一些不能忽視的缺點，審慎妥善的評估情境是否適用、作好萬全的防護措施，Windows Server Data Deduplication 絕對能帶給你前所未有的絕妙體驗。

### <span style="color: rgb(35, 111, 161);">參考資料</span>

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/overview](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/overview)</p>

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/understand](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/understand)</p>

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/install-enable](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/install-enable)</p>

<p class="callout info">[https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/interop](https://learn.microsoft.com/zh-tw/windows-server/storage/data-deduplication/interop)</p>

<p class="callout info">[https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831700(v=ws.11)](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831700(v=ws.11))</p>

<p class="callout info">[https://learn.microsoft.com/en-us/powershell/module/deduplication/](https://learn.microsoft.com/en-us/powershell/module/deduplication/)</p>

<p class="callout info">[https://learn.microsoft.com/en-us/windows-server/storage/file-server/ntfs-overview](https://learn.microsoft.com/en-us/windows-server/storage/file-server/ntfs-overview)</p>

# Windows Server LACP 設定

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/EKnR8nww5s.png)

### <span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline; color: rgb(35, 111, 161);">前言</span>

<span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">Windows在2008 R2以前並沒有OS內建的LACP可以設定，所以2003當年像是HP就有提供Network Configuration Utility程式來做NIC Teaming，直到2012之後才內建了LACP設定，此篇帶大家看看怎麼設定Windows Server LACP。</span>

<span style="color: rgb(230, 126, 35);">\#Windows Server 2003 年代 HP Network Configuration Utility 畫面</span>

![112422.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/112422.png)


### <span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline; color: rgb(35, 111, 161);">環境說明</span>

<span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">**<span style="color: rgb(22, 145, 121);">OS：</span>**Windows Server 2022</span>

<span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">**<span style="color: rgb(22, 145, 121);">Switch</span>**<span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">**<span style="color: rgb(22, 145, 121);">：</span>**找台可以做LACP的Switch</span></span>

> <span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;"><span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">鍵人我在這裡是用 Cisco 2960G、</span></span>QNAP Switch M3224-24T MC-LAG 來進行 LACP 測試  
> Qnap Switch 詳細介紹請參照：[https://mdfk.goddamn.idv.tw/books/qnap/page/qnap-switch-m3224-24t-mc-lag-multi-chassis-link-aggregation](https://mdfk.goddamn.idv.tw/books/qnap/page/qnap-switch-m3224-24t-mc-lag-multi-chassis-link-aggregation)

### <span style="box-sizing: border-box; outline-color: var(--color-primary); outline-width: 1px; margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline; color: rgb(35, 111, 161);">Windows Server LACP 設定</span>

至 伺服器管理員 =&gt; 本機伺服器 =&gt; NIC Teaming

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/f8xblh2JJF.png)

點選 工作 =&gt; 新增小組

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/0pJ2DATYlr.png)

將Server的兩張網卡選起來，模式選擇LACP動態

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/WBikBKJtbt.png)

建立完成

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/QRQi9ptrw7.png)

此時，將 Switch 的 LACP Port 接到 Server的NIC1、NIC2，如果一切都ok，LACP應該就起來了

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/O67QHHXeMJ.png)

![圖片.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/ydmYKyIXH6.png)

用Cisco 2960G來測試，可透過指令來確認LACP狀態

```
show etherchannel summary
show etherchannel port-channel
```

![8fmnEeq31Y.png](https://mdfk.goddamn.idv.tw/uploads/images/gallery/2024-10/scaled-1680-/8fmneeq31y.png)

**<span style="color: rgb(22, 145, 121);">全文完，就這麼簡單 ......</span>**