Skip to content

Instantly share code, notes, and snippets.

@alicefr
Last active March 11, 2021 09:04
Show Gist options
  • Save alicefr/691b1e047f40402f63291b09f51d65e6 to your computer and use it in GitHub Desktop.
Save alicefr/691b1e047f40402f63291b09f51d65e6 to your computer and use it in GitHub Desktop.
Access remote disk
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-test Bound local-pv-25a396e8 34Gi RWO local 52m
$ kubectl apply -f expose-pvc-nbd.yaml
service/virt configured
pod/virt configured
# In another console
$ kubectl port-forward pod/virt 8080:8080
Handling connection for 8080
# Access locally the disk with guestfs
$ guestfish --format=raw -a nbd://0.0.0.0:8080
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: ‘help’ for help on commands
‘man’ to read the manual
‘quit’ to quit the shell
><fs> run
><fs> list-filesystems
/dev/sda: ext4
><fs>
><fs> touch /test
><fs> ls /
lost+found
test
><fs> exit
# Or you can run other libguestfs tools
$ virt-rescue --format=raw -a nbd://0.0.0.0:8080
Welcome to virt-rescue, the libguestfs rescue shell.
Note: The contents of / (root) are the rescue appliance.
You have to mount the guest’s partitions under /sysroot
before you can examine them.
><rescue> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1G 0 disk
sdb 8:16 0 4G 0 disk /
><rescue> mount /dev/sda /sysroot/
><rescue> ls /sysroot/
lost+found test
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
name: virt
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
run: virt
status:
loadBalancer: {}
---
---
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: virt
name: virt
spec:
containers:
- args:
- "qemu-nbd"
- "-f"
- "raw"
- "-t"
- "-p"
- "8080"
- "/disks/disk.img"
image: afrosirh/debug-virt
name: virt
ports:
- containerPort: 8080
resources: {}
volumeMounts:
- mountPath: "/disks"
name: pvc
volumes:
- name: pvc
persistentVolumeClaim:
claimName: pvc-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment