If you’re connecting an old LVM disk to your Raspberry Pi 4 and want to reuse it, here’s a step-by-step guide on how to detect, activate, and mount the logical volumes (LVs) on that disk.
Step 1: Verify Disk Detection
When you plug in the old disk, first check if the Raspberry Pi detects it using:
sudo lsblk
Look for your disk in the output. For example, it may be listed as /dev/sdX
(where X
is a letter like b
, c
, etc.).
Step 2: Scan for LVM Physical Volumes (PVs)
Once the disk is detected, scan for LVM physical volumes on it:
sudo pvscan
This command will list all available physical volumes. If your old disk contains LVM partitions, it should appear here.
Step 3: Scan for Volume Groups (VGs)
Next, scan for any volume groups (VGs) on the disk:
sudo vgscan
This should detect the volume group associated with the old disk.
Step 4: Activate the Volume Group
After detecting the volume group, you need to activate it to make the logical volumes available:
sudo vgchange -ay
This command activates all volume groups and makes the associated logical volumes available.
Step 5: List Logical Volumes
To see the logical volumes on the activated volume group, run:
sudo lvdisplay
This will show the logical volumes that are part of the activated volume group.
Step 6: Mount the Logical Volumes
Once the logical volumes are detected, mount them to use their contents. First, check the filesystem type of the LV (usually ext4, but it could be different):
sudo blkid /dev/<vg_name>/<lv_name>
Replace <vg_name>
with the name of the volume group and <lv_name>
with the logical volume name. This command will show the filesystem type (like ext4
, xfs
, etc.).
Now, create a mount point and mount the LV:
sudo mkdir /mnt/old_disk sudo mount /dev/<vg_name>/<lv_name> /mnt/old_disk
Replace <vg_name>
and <lv_name>
with the appropriate values.
Step 7: Check the Mount
To ensure the disk is successfully mounted, check it with:
df -h
This will show you all mounted disks and their usage. You should see your old disk mounted at /mnt/old_disk
.
Optional: Add to /etc/fstab
for Auto-Mount
If you want the logical volume to mount automatically on boot, add an entry to /etc/fstab
:
- Open
/etc/fstab
:
sudo nano /etc/fstab
- Add the following line at the end of the file:
/dev/<vg_name>/<lv_name> /mnt/old_disk ext4 defaults 0 2
Replace the values as needed (ensure the filesystem type matches the output of blkid
).
- Save and exit by pressing
CTRL + X
, thenY
, andEnter
.
This will ensure your disk mounts automatically when the Raspberry Pi starts.
Step 8: Cleaning Up (Optional)
If you plan to repurpose the disk and start fresh, you can remove the existing LVM configuration:
- Deactivate the Volume Group:
sudo vgchange -an <vg_name>
- Remove the Logical Volumes:
sudo lvremove /dev/<vg_name>/<lv_name>
- Remove the Volume Group:
sudo vgremove <vg_name>
- Remove the Physical Volume:
sudo pvremove /dev/sdX
After this, you can partition and format the disk as you wish using standard tools like fdisk
and mkfs
.
Would you like to proceed with any of these steps, or do you need further clarification on a specific part?
Explain more:
The line /dev/<vg_name>/<lv_name> /mnt/old_disk ext4 defaults 0 2
is an entry in the /etc/fstab
file, which is used to define how filesystems are mounted automatically at boot. The numbers 0
and 2
at the end of this line have specific purposes related to system checks during boot.
Here’s a breakdown of the entire entry:
/dev/<vg_name>/<lv_name>
: This specifies the device or logical volume to be mounted. It points to the LVM logical volume you want to mount (replace<vg_name>
and<lv_name>
with the actual names)./mnt/old_disk
: This is the mount point where the filesystem will be mounted, i.e., the directory where the content of the logical volume will be accessible.ext4
: This is the filesystem type (in this case,ext4
). If the filesystem on your logical volume is different (e.g.,xfs
orbtrfs
), you would specify that here.defaults
: This defines the default mount options. Thedefaults
option typically includes:rw
: Read-write access.suid
: Allow set-user-identifier (SUID) and set-group-identifier (SGID) bits.dev
: Interpret character or block special devices on the filesystem.exec
: Allow execution of binaries.auto
: Automatically mount at boot.nouser
: Disallow users to mount.async
: Write filesystem operations asynchronously.
0
(Dump flag): This number controls dump behavior, which is a legacy feature for backup. It’s used to determine whether the filesystem should be dumped (backed up) by thedump
utility.0
: Do not dump the filesystem (most common setting).1
: Enable dumping for this filesystem.
2
(FSCK Order): This number controls fsck (filesystem check) behavior, specifying the order in which filesystems are checked during boot. It can be:0
: Do not check the filesystem at boot (common for non-critical or data drives).1
: Perform a check on the root filesystem first (this should only be set for the root filesystem).2
: Check this filesystem after the root filesystem (used for non-root filesystems that should be checked after the root).
In your example:
0
: The filesystem is not scheduled for dumping (backup).2
: The filesystem will be checked at boot, but after the root filesystem (/
). This is the appropriate setting for most non-root filesystems.
Adjusting Values:
- If you don’t want the filesystem to be checked at boot, change the
2
to0
. - If the filesystem is critical and should be checked before others, you can use
1
, but this should be reserved for the root filesystem (/
).
Let me know if you need more details or further clarification!