philroche
11/15/2016 - 11:21 AM

Reproduce unmounting of /dev after running apt-key in chroot

Reproduce unmounting of /dev after running apt-key in chroot

# Get the squashfs file system for the image we want to alter 
wget http://cloud-images.ubuntu.com/yakkety/current/yakkety-server-cloudimg-amd64.squashfs
# Extract the squashfs filesystem to a local directory
unsquashfs yakkety-server-cloudimg-amd64.squashfs
# Mount and bind local /dev/ to local directory squashfs-root/dev
sudo mount --bind /dev/ squashfs-root/dev
# Update the resolv.conf so that we can make network calls within a chroot
sudo rm squashfs-root/etc/resolv.conf
sudo cp /etc/resolv.conf squashfs-root/etc/
# Add the Google Cloud Packages signing key
sudo chroot squashfs-root/ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3746C208A7317B0F
# Try to unmount squashfs-root/dev
sudo umount squashfs-root/dev
# The result is:
# umount: /home/ubuntu/squashfs-root/dev: target is busy
#        (In some cases useful info about processes that
#         use the device is found by lsof(8) or fuser(1).)