[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

start-stop-daemon qemu-nbd



start-stop-daemon works as root, but not when sudo with qemu-nbd

my definition of works vs doesn't - i can connect to both (assuming a qcow2 vm):
start-stop-daemon --start -b --exec /usr/bin/qemu-nbd -- nocache template.qcow2
nbd-client localhost 1024 /dev/nbd0
fdisk -l /dev/nbd0 #WORKS

sudo start-stop-daemon --start -b --exec /usr/bin/qemu-nbd -- nocache
template.qcow2
# do the rest as root to be consistent but it doesn't matter
nbd-client localhost 1024 / dev/nbd0
fdisk -l /dev/nbd0 #FAILS


in order to get the image:
qemu-img create -f qcow2 template.qcow2 10G

in order to delete the nbd:
nbd-client -d /dev/nbd0

everything looks the same to me under ps and lsof. i haven't gotten
into memory usage and libraries, but that's probably the same too. i
suspect there's a variable or lack thereof that start-stop-daemon sees
when inside of sudo. also below is the script i've written out
(actually its an extract from a larger script). the script doesn't
delete the device just so i could see the place where it's left off
(it also tries the mkfs because that error message stands out more to
me than sfdisk's)


#!/bin/bash

QCOW=./template.qcow2
SIZE=10G
FSTYPE=ext4

# mount point has to conform to schroot.conf
ROOTDIR=/mnt/chroot

echo "File: $QCOW"
echo "Size: $SIZE"
echo "FS type: $FSTYPE"
echo "Mount point: $ROOTDIR"


echo "Creating qcow2 image...."
qemu-img create -f qcow2 $QCOW $SIZE

echo "Loading NBD kernel module"
if ! echo "modprobe nbd > /dev/null 2>&1" | sudo sh; then
    echo "Failed to load NBD module. Exiting.";
    exit 1;
fi

NBDDEV=/dev/nbd0

echo "Starting NBD daemon"
echo "start-stop-daemon --start -b --chuid root --exec /usr/bin/qemu-nbd -- --no
cache $QCOW" | sudo sh

echo "Starting NBD client"
sudo nbd-client localhost 1024 $NBDDEV

echo "Partitioning and formatting device."
echo "echo \\",,L,*\\" | sfdisk -D $NBDDEV" | sudo sh
sudo mkfs -t ext4 $NBDDEV


Reply to: