How to replace a book disk in Proxmox
A Proxmox VE node may be running 24 hours a day for years. This might lead to the boot disk wearing out and in need or replacement. This guide lets you swap the drive out for a new one without data loss.
Note that this method works if you instlled Proxmox using ZFS.
Setup
Get your new drive ready, and make sure it is the same size or larger than the old one. Plug in your drive into an empty bay in the Proxmox machine, or attach it with an enclosure using USB. The idea is to have both drives available to Proxmox.
Let's assume
Old drive: /dev/sda
New drive: /dev/sdb
Step 1: Prepare partitions on the new drive
The easy way to do this is to copy over the partitions using sfdisk
sfdisk -d /dev/sda > pve-boot-partitions.txt
cat pve-boot-partitions.txt
label: gpt
label-id: FDB673E1-0941-43AB-BB02-B8A6C3D0D0F8
device: /dev/sda
unit: sectors
first-lba: 34
last-lba: 122142686
sector-size: 512
/dev/sad1 : start= 34, size= 2014, type=21686148-6449-6E6F-744E-656564454649, uuid=4CC31FA5-A6FC-42DB-9071-DF76FBA08F60
/dev/sad2 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=B0560706-84DB-45B1-AF0D-BB32DD7F4476
/dev/sda3 : start= 1050624, size= 121085953, type=6A898CC3-1DD2-11B2-99A6-080020736631, uuid=D8BA81D1-0C84-49A8-99B6-F32C041A2FF3
This is also the input to sfdisk
. By modifying the following in this file, it
can be used to create partitions on the new drive.
- Remove last-blk line. This is tell
sfdisk
to use the entire disk. - Remove UUIDs for all partition. This will let
sfdisk
generate new UUIDs for the new drive. - Replace size with
-
for the last partition. This will letsfdisk
use the remaining space on the disk for the last partition.
It should look like this:
# cat pve-boot-partitions.txt
label: gpt
label-id: FDB673E1-0941-43AB-BB02-B8A6C3D0D0F8
device: /dev/sda
unit: sectors
first-lba: 34
sector-size: 512
/dev/sad1 : start= 34, size= 2014, type=21686148-6449-6E6F-744E-656564454649
/dev/sad2 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
/dev/sda3 : start= 1050624, size= -, type=6A898CC3-1DD2-11B2-99A6-080020736631
Use this file to create the partitions on the new drive:
# sfdisk /dev/sdb < pve-boot-partitions.txt
Check that the partitions are created correctly:
# lsblk /dev/sda /dev/sdb
Learn more about the partitions in Proxmox in the Proxmox documentation.
Step 2: Copy the partitions
Now that the partitions are created, we can copy the data.
First up is the BIOS boot partition.
# dd if=/dev/sda1 of=/dev/sdb1
Next, the EFI system partition.
Create the filesystem on the new drive, by simply copying over from the old drive
# dd if=/dev/sda2 of=/dev/sdb2
Check if you are using EFI or Grub bootloader
# proxmox-boot-tool status
If you are using EFI, you can skip the grub at the end of the command.
proxmox-boot-tool init /dev/sdb2 [grub]
Step 3: Create a mirrored ZFS pool
The idea is to create a mirrored ZFS pool with the two drives and detach the old drive.
# zpool replace -f rpool /dev/sda3 /dev/sdb3
This will start the resilvering process, which will copy the data from the old drive to the new drive. You can check the status of the resilvering process with:
# zpool status rpool
Once the resilvering is complete, you can boot from the new drive.
Conculsion
Always use ZFS during installation of Proxmox. By using ZFS, you can easily replace drives without data loss.