nbd编译和使用

uname -r
sudo su
# useradd builder
# groupadd builder
cd /home/centos
# Get Source Code
wget http://vault.centos.org/7.2.1511/updates/Source/SPackages/kernel-3.10.0-327.28.3.el7.src.rpm
rpm -ivh kernel-3.10.0-327.28.3.el7.src.rpm


# Build Preparation
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec
cd ~/rpmbuild/BUILD/kernel-3.10.0-327.28.3.el7/linux-3.10.0-327.28.3.el7.centos.x86_64/


# Build
make menuconfig
# Device Driver -> Block devices -> Set “M” On “Network block device support”


make prepare && make modules_prepare && make
make M=drivers/block -j8
modinfo drivers/block/nbd.ko
cp drivers/block/nbd.ko /lib/modules/3.10.0-327.28.3.el7.x86_64/extra/
depmod -a && sudo modprobe nbd








Issue


Thanks to Soren Hansen for determining that /sys/module/nbd/parameters/max_part was set to 0. I'm not sure if the module was getting loaded before my script (which loads nbd with max_part=15) with the upstream default of '0' now and it wasn't before, but this fixes it for me:
$ sudo rmmod nbd
$ sudo modprobe nbd max_part=15




mount: unknown filesystem type 'LVM2_member'


1. qemu-nbd -c /dev/nbd0 /opt/CentOS-7.2-pv.qcow2


     kpartx -av /dev/nbd0


2.vgscan


3. vgchange -ay centos


4.mount /dev/centos/root /mnt/


5.do everything in /mnt


6.umount /mnt


7.vgchange -an centos




8. kpartx -dv /dev/nbd0


9. qemu-nbd -d /dev/nbd0




windows也可以直接Mount,但是需要安装ntfs-3g包

你可能感兴趣的:(nbd编译和使用)