Difference between revisions of "Zfs nvme log and cache"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "``` sudo nvme list Node Generic SN Model Namespace Usage Format...")
 
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
 
# Add to cache
 
# Add to cache
 
sudo zpool add <pool_name> cache /dev/nvme0n1p2
 
sudo zpool add <pool_name> cache /dev/nvme0n1p2
 +
 +
```
 +
 +
 +
# Removal & Size Updates
 +
 +
 +
To change the size, you must remove the devices from the pool, repartition the drive, and add the new partitions back.
 +
 +
### The Removal Process
 +
 +
When you want to change the size, follow this sequence:
 +
 +
1. **Remove the log (SLOG) device:**
 +
```bash
 +
zpool remove <pool_name> /dev/nvme0n1p1
 +
 +
```
 +
 +
 +
 +
```
 +
    *Note: ZFS will gracefully flush any pending synchronous writes from the SLOG to the main pool before removing the device.*
 +
 +
2.  **Remove the cache (L2ARC) device:**
 +
    ```bash
 +
    zpool remove <pool_name> /dev/nvme0n1p2
 +
 +
```
 +
 +
```
 +
*Note: This is instantaneous as it simply drops the cache.*
 +
 +
```
 +
 +
3. **Repartition the drive:**
 +
Use `parted` or `fdisk` to delete the old partitions and create the new ones to your desired sizes.
 +
4. **Add them back to the pool:**
 +
```bash
 +
zpool add <pool_name> log /dev/nvme0n1p1
 +
zpool add <pool_name> cache /dev/nvme0n1p2
 +
 +
```
 +
 +
 +
 +
```
 +
 +
---
 +
 +
### Architect's Tip: Use LVM for Flexibility
 +
If you anticipate wanting to resize these partitions later without wiping and recreating them, consider using **LVM (Logical Volume Manager)** as an intermediary layer.
 +
 +
1.  Initialize the physical drive as an LVM Physical Volume (PV).
 +
2.  Create a Volume Group (VG).
 +
3.  Create two Logical Volumes (LV) — one for SLOG, one for L2ARC.
 +
4.  Point ZFS to the device-mapper paths (e.g., `/dev/mapper/vgname-lvname`).
 +
 +
**Why do this?**
 +
*  **Elasticity:** You can grow or shrink the logical volumes on the fly.
 +
*  **Abstraction:** You can move your ZFS log/cache to a different physical disk later by using `pvmove` without ever having to `zpool remove` or re-add the devices to ZFS.
 +
 +
**Important Warning:** If you go the LVM route, ensure you are not creating a circular dependency where your root filesystem (and thus LVM) depends on a ZFS pool that is trying to access an LVM volume. Given your expertise, this is likely a non-issue, but it is a common pitfall.
 +
  
 
```
 
```

Latest revision as of 15:42, 22 May 2026

sudo nvme list
Node                  Generic               SN                   Model                                    Namespace  Usage                      Format           FW Rev
--------------------- --------------------- -------------------- ---------------------------------------- ---------- -------------------------- ---------------- --------
/dev/nvme0n1          /dev/ng0n1            CVFT439300062P0EGN   INTEL SSDPEDMD020T4                      0x1          2.00  TB /   2.00  TB    512   B +  0 B   8DV101H0

# 1. Create a new GPT partition table
sudo parted /dev/nvme0n1 mklabel gpt

# 2. Create the first 1TB partition (for SLOG)
sudo parted -a optimal /dev/nvme0n1 mkpart primary 0% 1TB

# 3. Create the second 1TB partition (for L2ARC)
sudo parted -a optimal /dev/nvme0n1 mkpart primary 1TB 100%


lsblk /dev/nvme0n1


# Add to log
sudo zpool add <pool_name> log /dev/nvme0n1p1

# Add to cache
sudo zpool add <pool_name> cache /dev/nvme0n1p2

Removal & Size Updates

To change the size, you must remove the devices from the pool, repartition the drive, and add the new partitions back.

The Removal Process

When you want to change the size, follow this sequence:

  1. Remove the log (SLOG) device:
zpool remove <pool_name> /dev/nvme0n1p1

    *Note: ZFS will gracefully flush any pending synchronous writes from the SLOG to the main pool before removing the device.*

2.  **Remove the cache (L2ARC) device:**
    ```bash
    zpool remove <pool_name> /dev/nvme0n1p2

*Note: This is instantaneous as it simply drops the cache.*

  1. Repartition the drive: Use parted or fdisk to delete the old partitions and create the new ones to your desired sizes.
  2. Add them back to the pool:
zpool add <pool_name> log /dev/nvme0n1p1
zpool add <pool_name> cache /dev/nvme0n1p2

<br />---

### Architect's Tip: Use LVM for Flexibility
If you anticipate wanting to resize these partitions later without wiping and recreating them, consider using **LVM (Logical Volume Manager)** as an intermediary layer.

1.  Initialize the physical drive as an LVM Physical Volume (PV).
2.  Create a Volume Group (VG).
3.  Create two Logical Volumes (LV) — one for SLOG, one for L2ARC.
4.  Point ZFS to the device-mapper paths (e.g., `/dev/mapper/vgname-lvname`).

**Why do this?**
*   **Elasticity:** You can grow or shrink the logical volumes on the fly.
*   **Abstraction:** You can move your ZFS log/cache to a different physical disk later by using `pvmove` without ever having to `zpool remove` or re-add the devices to ZFS.

**Important Warning:** If you go the LVM route, ensure you are not creating a circular dependency where your root filesystem (and thus LVM) depends on a ZFS pool that is trying to access an LVM volume. Given your expertise, this is likely a non-issue, but it is a common pitfall.