Skip to content

Commit 11911c7

Browse files
authored
chore: add operational doc for mounting data disks (#749)
Signed-off-by: Kevin Carter <[email protected]>
1 parent 9cfddcb commit 11911c7

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

docs/openstack-data-disk-recovery.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Instance Data Disk Recovery
2+
3+
Below is an operational guide for OpenStack operators who need to mount (and later unmount) a virtual machine’s data disk for recovery or data inspection. This procedure leverages the Linux Network Block Device (NBD) module (`nbd`) in conjunction with the `qemu-nbd` utility. It assumes intermediate Linux system administration skills and familiarity with OpenStack’s Nova instance storage locations.
4+
5+
## Overview
6+
7+
In an OpenStack environment, each Nova instance’s disk is typically stored under `/var/lib/nova/instances/<INSTANCE_ID>`. Mounting a VM disk directly on a hypervisor or another server can be useful when you need to:
8+
9+
- Recover files from a corrupted or inaccessible instance.
10+
- Inspect or troubleshoot data that may be causing issues within the VM.
11+
- Perform forensics or backups on a specific partition.
12+
13+
The following instructions outline how to attach a VM disk image as a block device, mount it to the filesystem, and then cleanly detach it afterward.
14+
15+
## Prerequisites
16+
17+
1. **Root or Sudo Access**: You must have sufficient privileges to run `modprobe`, `qemu-nbd`, and mount commands.
18+
2. **qemu-nbd Installed**: The `qemu-utils` or `qemu-kvm` package (depending on your distribution) must be installed to provide the `qemu-nbd` command.
19+
3. **Identify the Correct Instance Disk**: Ensure you have the correct path to the VM’s disk file under `/var/lib/nova/instances`.
20+
21+
!!! note
22+
23+
Always confirm the instance UUID (`00000000-0000-0000-0000-000000000000` in the examples) corresponds to the target VM.
24+
25+
## Mounting the VM Disk (Attach Procedure)
26+
27+
Before mounting the VM disk, you need to connect the disk file to a Network Block Device (NBD) and then mount the desired partition. It is recommended that be done only on instances that are powered off.
28+
29+
### Load the NBD Kernel Module
30+
31+
``` shell
32+
modprobe nbd max_part=8
33+
```
34+
35+
- `nbd` is the Network Block Device driver.
36+
- `max_part=8` ensures up to eight partitions can be recognized on each NBD device.
37+
38+
### Connect qemu-nbd to the Disk File
39+
40+
``` shell
41+
qemu-nbd --connect=/dev/nbd0 /var/lib/nova/instances/00000000-0000-0000-0000-000000000000
42+
```
43+
44+
- This command associates the instance disk file with the `/dev/nbd0` block device.
45+
46+
#### Identify Partitions** (Optional but recommended)
47+
48+
``` shell
49+
fdisk /dev/nbd0 -l
50+
```
51+
52+
- Lists all partitions on `/dev/nbd0`, helping you determine which partition to mount.
53+
- Commonly, the first partition is `/dev/nbd0p1`, the second `/dev/nbd0p2`, etc.
54+
55+
### Create a Mount Point
56+
57+
``` shell
58+
mkdir /mnt/00000000-0000-0000-0000-000000000000
59+
```
60+
61+
- Make a new directory where you will mount the disk’s partition.
62+
63+
### Mount the Desired Partition
64+
65+
``` shell
66+
mount /dev/nbd0p1 /mnt/00000000-0000-0000-0000-000000000000
67+
```
68+
69+
- Adapts to whichever partition (`p1`, `p2`, etc.) you need to access.
70+
- At this point, you can navigate to `/mnt/00000000-0000-0000-0000-000000000000` and inspect or recover data.
71+
72+
## Unmounting the VM Disk (Detach Procedure)
73+
74+
When your recovery or data inspection is complete, you should properly unmount the disk and detach the NBD device.
75+
76+
### Unmount the Partition
77+
78+
``` shell
79+
umount /mnt/00000000-0000-0000-0000-000000000000
80+
```
81+
82+
- Ensure no processes are accessing the mount point before unmounting.
83+
84+
### Remove the Mount Point Directory
85+
86+
``` shell
87+
rmdir /mnt/00000000-0000-0000-0000-000000000000
88+
```
89+
90+
- This step is optional but helps keep the filesystem clean.
91+
92+
### Disconnect the qemu-nbd Association
93+
94+
``` shell
95+
qemu-nbd --disconnect /dev/nbd0
96+
```
97+
98+
- Frees the `/dev/nbd0` device from the disk file.
99+
100+
### Remove the NBD Module
101+
102+
``` shell
103+
rmmod nbd
104+
```
105+
106+
- Unloads the `nbd` kernel module if no longer needed.
107+
- This helps prevent accidental reuse of `/dev/nbd0` by another process.
108+
109+
## Additional Considerations
110+
111+
1. **Data Consistency**: Mounting an active disk used by a running VM can lead to data corruption if the VM is simultaneously writing to that disk. Ideally, power off the VM or ensure the disk is not in active use before performing these steps.
112+
2. **Multiple Partitions**: If you have more than one partition (e.g., root on `/dev/nbd0p1`, swap on `/dev/nbd0p2`), mount only the partition(s) you specifically need.
113+
3. **Filesystem Type**: If you encounter errors mounting the filesystem (e.g., an unsupported or unfamiliar file system type), consider specifying the filesystem with `-t`, such as `mount -t ext4 /dev/nbd0p1 /mnt/...`.
114+
4. **Cleanup**: Always remember to unmount and disconnect when finished. Leaving a disk mounted can risk accidental data changes or locks.
115+
116+
## Conclusion
117+
118+
Mounting a VM’s data disk using `qemu-nbd` in an OpenStack environment can greatly simplify recovery, troubleshooting, or forensic efforts. By safely attaching and detaching the disk file, operators can inspect and manipulate VM data without having to boot the instance. With the above procedure, you can maintain a secure, controlled environment for delicate recovery operations.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ nav:
279279
- Nova CPU Allocation Ratio: openstack-cpu-allocation-ratio.md
280280
- Nova PCI Passthrough: openstack-pci-passthrough.md
281281
- Host Aggregates: openstack-host-aggregates.md
282+
- Instance Data Recovery: openstack-data-disk-recovery.md
282283
- Quota Management:
283284
- Quota Management: openstack-quota-managment.md
284285
- Images:

0 commit comments

Comments
 (0)