cryptsetup and umount fail with "target is busy." error - linux

I'm experimenting with cryptsetup. My target is to be able to store data into and encrypted file into a non-encrypted hard drive.
I'm doing the following
mkdir /data/test && /data/test
# Create a key
openssl genrsa -out luks_key 4096
# Create file container
dd if=/dev/zero of=device bs=1G count=50 status=progress
# Create and open luks device
cryptsetup -v -y --batch-mode luksFormat device luks_key
sudo cryptsetup -v --batch-mode --key-file=luks_key --type luks open device device_name
# Format the device
sudo mkfs.ext4 -j /dev/mapper/device_name
# Create mount point
mkdir mount_point
# Mount the device
sudo mount -t ext4 /dev/mapper/device_name mount_point
cd mount_point
sudo dd if=/dev/zero of=random_data.bin bs=1G count=1 status=progress
# This will fail until I close the terminal window with "target is busy." error
sudo umount /data/test/mount_point
cryptsetup -v close device_name
All works well up to the point were I try to unmount. The error is:
umount: /data/test/mount_point: target is busy.
The only way to be able to unmount is to close the terminal window. Opening a second one isn't enough. I'm little bit puzzled :)
I run on LinuxMint 18.04 with Linux kernel 5.15.30-25.
Anyone seeing the same thing?
Thanks,

Related

bash create a floppy file with mbr and mount

I need to create a floppy file to mount and copy files. I also need to change the mbr. When I do this:
mkdir -p disk_images
rm disk_images/floppy.flp
dd if=/dev/zero of=disk_images/floppy.flp bs=1k count=1440
mkdosfs -F 32 disk_images/floppy.flp
mkdir floppydisk
dd status=noxfer conv=notrunc if=build/boot.bin of=disk_images/floppy.flp
sudo mount -t vfat -o loop,defaults disk_images/floppy.flp floppydisk
I get the error
mount: /home/user/myos/floppydisk: wrong fs type, bad option, bad superblock on /dev/loop13, missing codepage or helper program, or other error.
omitting the last dd works but that way, I can't control the mbr.

How to deploy files to /boot partition with Yocto

I'm trying to deploy some binary files to /boot in a Yocto image for RPi CM3 but it deploys them to the wrong location.
do_install() {
install -d ${D}/boot/overlays
install -m 0664 ${WORKDIR}/*.dtb ${D}/boot/overlays/
install -m 0664 ${WORKDIR}/*.dtbo ${D}/boot/overlays/
}
The files are deployed to /boot in the / partition of the final image, but not to the /boot partition. So they are not available at boot time.
I already googled and studied the kernel recipes (and classes) of the Poky distribution but I didn't find the mechanism it uses how to ensure that the files are deployed to the boot image (and not to the /boot dir in the root image).
Any help is appreciated :)
Update #1
In my local.conf I did:
IMAGE_BOOT_FILES_append = " \
overlays/3dlab-nano-player.dtbo \
overlays/adau1977-adc.dtbo \
...
"
And in my rpi3-overlays.bb
do_deploy() {
install -d ${DEPLOYDIR}/${PN}
install -m 0664 ${WORKDIR}/*.dtb ${DEPLOYDIR}/${PN}
install -m 0664 ${WORKDIR}/*.dtbo ${DEPLOYDIR}/${PN}
touch ${DEPLOYDIR}/${PN}/${PN}-${PV}.stamp
}
Using this the image builds, but the files stillt don't get deployed in the /boot partition.
Using RPI_KERNEL_DEVICETREE_OVERLAYS I get a build error because the kernel recipe tries to build the dtbo files like dts files.
RPI images are created with sdimage-raspberrypi.wks WIC wks file. It contains:
part /boot --source bootimg-partition ...
so it uses bootimg-partition.py wic plugin to generate /boot partition. It copies every files defined by IMAGE_BOOT_FILES variable.
It seems you want to add some devicetree overlays, so you need to modify machine configuration and more specifically RPI_KERNEL_DEVICETREE_OVERLAYS variable. IMAGE_BOOT_FILES variable is set in rpi-base.inc.
If you don't have any custom machine or custom distro defined, you can add it in local.conf:
RPI_KERNEL_DEVICETREE_OVERLAYS_append = " <deploy-path>/<dto-path>"
You can see here how to add files in deploy directory.
After too many hours of investigation it turned out, that deploying files to other partitions than / is not easily possible. I now went the way of a post-processing script that mounts the final image, deploys the additional files and unmounts it.
# Ensure the first loopback device is free to use
sudo -n losetup -d /dev/loop0 || true
# Create a loopback device for the given image
sudo -n losetup -Pf ../deploy/images/bapi/ba.rootfs.rpi-sdimg
# Mount the loopback device
mkdir -p tmp
sudo -n mount /dev/loop0p1 tmp
# Deploy files
sudo -n cp -n ../../meta-ba-rpi-cm3/recipes-core/rpi3-overlays/files/* tmp/overlays/
sudo -n cp ../../conf/config.txt tmp/config.txt
sudo -n cp ../../conf/cmdline.txt tmp/cmdline.txt
# Unmount the image and free the loopback device
sudo -n umount tmp
sudo -n losetup -d /dev/loop0

busybox init script. Mount not found

I'm running in to what appears to be a bit of an odd one.
Base machine is Ubuntu 18.04. I'm experimenting with creating a custom initramfs + init script to use with custom compiled kernels that are being used with qemu instances.
From the directory I'm using as the base for the initramfs:
[~/initramfs] $ find .
.
./proc
./root
./dev
./dev/console
./dev/sda1
./dev/null
./dev/tty
./sbin
./init
./etc
./lib64
./mnt
./mnt/root
./lib
./bin
./bin/busybox
./sys
Just the basics needed for now. The busybox binary comes from the busybox-static package, and I've confirmed it's statically complied:
[~/initramfs]$ ldd bin/busybox
not a dynamic executable
In the init script, I have:
#!/bin/busybox sh
mount -t proc none /proc
mount -t sysfs none /sys
echo "Hi there"
umount /sys
umount /proc
poweroff
From there, create an initramfs.gz:
find . -print0 | cpio --null --create --verbose --format=newc | pigz --best > ~/initramfs.gz
When I set that as the target initrd for qemu, kernel starts up as expected, then:
[ 0.777443] Run /init as init process
/init: line 3: mount: not found
/init: line 4: mount: not found
Hi there
/init: line 8: umount: not found
/init: line 9: umount: not found
/init: line 11: poweroff: not found
mount is part of busybox. So that's strange.
If I modify the init script and put in /bin/busybox sh as the first command to be executed, that gets me to a busybox shell as you'd expect.
[ 0.789949] Run /init as init process
BusyBox v1.27.2 (Ubuntu 1:1.27.2-2ubuntu3.2) built-in shell (ash)
Enter 'help' for a list of built-in commands.
sh: can't access tty; job control turned off
/ # [ 1.364618] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3
[ 1.386482] tsc: Refined TSC clocksource calibration: 3392.105 MHz
[ 1.388387] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x30e52cb7a6c, max_idle_ns: 440795310382 ns
[ 1.391965] clocksource: Switched to clocksource tsc
/ #
And then help shows:
/ # help
Built-in commands:
------------------
. : [ [[ alias bg break cd chdir command continue echo eval exec[ 71.772009] random: fast init done
exit export false fg getopts hash help history jobs kill let
local printf pwd read readonly return set shift source test times
trap true type ulimit umask unalias unset wait [ [[ acpid adjtimex
ar arp arping ash awk basename blkdiscard blockdev brctl bunzip2
bzcat bzip2 cal cat chgrp chmod chown chpasswd chroot chvt clear
cmp cp cpio crond crontab cttyhack cut date dc dd deallocvt depmod
devmem df diff dirname dmesg dnsdomainname dos2unix dpkg dpkg-deb
du dumpkmap dumpleases echo ed egrep env expand expr factor fallocate
false fatattr fdisk fgrep find fold free freeramdisk fsfreeze
fstrim ftpget ftpput getopt getty grep groups gunzip gzip halt
head hexdump hostid hostname httpd hwclock i2cdetect i2cdump
i2cget i2cset id ifconfig ifdown ifup init insmod ionice ip ipcalc
ipneigh kill killall klogd last less link linux32 linux64 linuxrc
ln loadfont loadkmap logger login logname logread losetup ls
lsmod lsscsi lzcat lzma lzop md5sum mdev microcom mkdir mkdosfs
mke2fs mkfifo mknod mkpasswd mkswap mktemp modinfo modprobe more
mount mt mv nameif nc netstat nl nproc nsenter nslookup od openvt
partprobe passwd paste patch pidof ping ping6 pivot_root poweroff
printf ps pwd rdate readlink realpath reboot renice reset rev
rm rmdir rmmod route rpm rpm2cpio run-parts sed seq setkeycodes
setpriv setsid sh sha1sum sha256sum sha512sum shred shuf sleep
sort ssl_client start-stop-daemon stat static-sh strings stty
su sulogin svc swapoff swapon switch_root sync sysctl syslogd
tac tail tar taskset tee telnet telnetd test tftp time timeout
top touch tr traceroute traceroute6 true truncate tty tunctl
ubirename udhcpc udhcpd uevent umount uname uncompress unexpand
uniq unix2dos unlink unlzma unshare unxz unzip uptime usleep
uudecode uuencode vconfig vi w watch watchdog wc wget which who
whoami xargs xxd xz xzcat yes zcat
So I go looking for mount, and discover which isn't found either. Oh but it works if I prepend it with /bin/busybox to call it direct...:
/ # type mount
mount is mount
/ # which mount
sh: which: not found
/ # /bin/busybox which mount
/ #
and I can execute the commands successfully if I add /bin/busybox to them:
/ # /bin/busybox mount -t proc none /proc
/ #
It seems really random what will and what won't work from busybox, what does and what doesn't get found, e.g. find is fine:
/ # find
.
./test
./sys
./bin
./bin/busybox
./lib
./mnt
./mnt/root
./lib64
./etc
./init
./sbin
./proc
./root
./dev
./dev/tty
./dev/null
./dev/sda1
./dev/console
I can work around this by prepending every command in the init file with /bin/busybox, but I'd really rather not if I don't have to!
You have to symlink all the applets you want, e.g. ln -s /bin/busybox /bin/mount. See USAGE in the busybox docs:
USAGE
BusyBox is a multi-call binary. A multi-call binary is an
executable program that performs the same job as more than one utility
program. That means there is just a single BusyBox binary, but that
single binary acts like a large number of utilities. This allows
BusyBox to be smaller since all the built-in utility programs (we call
them applets) can share code for many common operations.
You can also invoke BusyBox by issuing a command as an argument on the
command line. For example, entering
/bin/busybox ls
will also cause BusyBox to behave as 'ls'.
Of course, adding '/bin/busybox' into every command would be painful.
So most people will invoke BusyBox using links to the BusyBox binary.
For example, entering
ln -s /bin/busybox ls
./ls
will cause BusyBox to behave as 'ls' (if the 'ls' command has been compiled into BusyBox). Generally speaking, you should never
need to make all these links yourself, as the BusyBox build system
will do this for you when you run the 'make install' command.
If you invoke BusyBox with no arguments, it will provide you with a
list of the applets that have been compiled into your BusyBox binary.
The commands that happen to work without it are the ones implemented as fork-free and therefore can be invoked as builtins.

Testing a linux kernel in qemu [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have just built the 3.13.3 kernel from kernel.org on my ubuntu 12.04 computer. I ran the make menuconfig command and then I did make which built the kernel and the modules. I want to run the kernel in the qemu emulator (qemu-system-x86_64) so I can start testing and building on top of it. Curently I am getting it to run with qemu-system-x86_64 -kernel bzImage however it is not booting properly. What changes should I make in order to make the kernel boot properly?
You need to have a bootable disk first of all. Have you tried booting without -kernel and specifying the disk to boot from ?
If and only if that works, then think about using -kernel as an optimization
to test out new kernels
Making a bootable disk can be a challenge unless you take the easy route and use dd to make a large empty file e.g.
sudo dd if=/dev/zero of=$OUTPUT_DISK bs=4096 count=524288
then boot qemu with the linux iso you downloaded and also tell it to use this disk (-hda) and let the installer set the disk up for you
If making a bootable disk by hand, I've done this a couple of times - not easy, but the following steps may help you. You need to format the disk, create partitions, install grub and then boot
Personally I would take the easy route and install to disk via linux installer
#!/bin/sh
#
# Change these settings
#
INPUT_ISO=mydownloadedlinux.iso
OUTPUT_DISK=mydisk
KERNEL_IMAGE_NAME=linux-kernel
QEMU=qemu-system-x86_64
#
# Stuff you should not need to change
#
TMP_BOOTDISK=/tmp/disk.$$
ISO_MOUNT_DIR=/mnt/iso
#
# Choose DOS or Linux disks
#
PARTITION_TYPE=ext2
MKFS_TYPE=ext2
#
# Mount the ISO
#
sudo mkdir -p $ISO_MOUNT_DIR
sudo umount $ISO_MOUNT_DIR 2>/dev/null
sudo mount -o loop -t iso9660 $INPUT_ISO $ISO_MOUNT_DIR
#
# Make a new disk
#
sudo dd if=/dev/zero of=$OUTPUT_DISK bs=4096 count=524288
LOOP=`sudo losetup -f --show $OUTPUT_DISK`
LOOPDEV=`echo $LOOP | sed 's/.*loop/loop/g'`
echo "Loopback device $LOOP, ($LOOPDEV)"
#
# Make two partitions on the disk
#
sudo parted -s $LOOP mktable msdos \
mkpart primary $PARTITION_TYPE 32K 50% \
mkpart primary $PARTITION_TYPE 50% 95%
#
# Make one bootable
#
sudo parted -s $LOOP set 1 boot on
sudo kpartx -l $LOOP
sudo kpartx -a $LOOP
#
# Make the filesystems
#
sudo mkfs.$MKFS_TYPE /dev/mapper/${LOOPDEV}p1
sudo mkfs.$MKFS_TYPE /dev/mapper/${LOOPDEV}p2
#
# List what we made
#
sudo kpartx -l -v $LOOP
#
# Mount this temporary disk so we can install grub on it
#
sudo mkdir -p $TMP_BOOTDISK
sudo mount /dev/mapper/${LOOPDEV}p1 $TMP_BOOTDISK
sudo grub-install --boot-directory=/$TMP_BOOTDISK $LOOP
#
# Make grub boot config
#
cat >/tmp/grub.cfg <<%%
serial
#terminal_input --append serial_com0
#terminal_output --append serial_com0
configfile /mybootfile
%%
cat >/tmp/mybootfile <<%%
set timeout=5
set default=0
menuentry 'mylinux' {
insmod ext2
set root='(hd0,1)'
linux /$KERNEL_IMAGE_NAME bigphysarea=28000
initrd /rootfs.img.gz
}
%%
#
# Just copy all the files off of the ISO into the mounted temp disk
# This would be the tricky part as you need enough so linux can boot
#
sudo cp -r $ISO_MOUNT_DIR/* $TMP_BOOTDISK
#
# But use our grub files we made above
#
sudo cp /tmp/grub.cfg $TMP_BOOTDISK/grub/grub.cfg
sudo cp /tmp/mybootfile $TMP_BOOTDISK/mybootfile
#
# Show all the files on the temp disk and then unmuont it
#
find $TMP_BOOTDISK
sudo umount $TMP_BOOTDISK
sudo losetup -d $LOOP
#
# Convert the temp disk from raw to vmdk format
#
sudo qemu-img convert $OUTPUT_DISK -O vmdk $OUTPUT_DISK.vmdk
#
# Boot the vmdk
#
sudo $QEMU -boot d -m 4096 \
-enable-kvm \
-drive file=$OUTPUT_DISK.vmdk,if=virtio,media=disk \
-serial telnet:localhost:4444,nowait,server,telnet \
-net nic,model=e1000,vlan=0 -net user \

Using Optware packages and startup scripts on dd-wrt router

I'm trying to run a mumble server (umurmur) on my dd-wrt router (Buffalo WZR-HP-AG300H). I flashed one of the recent community versions of dd-wrt on the device (SVN Rev.: 23320), it has an Atheros CPU inside.
After that I mounted a USB pendrive into the filesystem using these guides (Guide 1, Guide 2) and created writable directories. Here is my startup-script saved to nvram (via web-gui)
EDIT: USB pendrive should be partioned before using it with DD-Wrt.
#!/bin/sh
sleep 5
insmod mbcache
insmod jbd
insmod ext3
mkdir '/mnt/part1'
mkdir '/mnt/part2'
mount -t ext3 -o noatime /dev/sda5 /mnt/part1 # /dev/sda5 -> partition on USB pendrive
mount -t ext3 -o noatime /dev/sda7 /mnt/part2 # /dev/sda7 -> partition on USB pendrive
swapon /dev/sda6 # /dev/sda6 -> partition on USB pendrive
sleep 2
if [ -f /mnt/part1/optware.enable ];then
#mount -o bind /mnt/part2 /mnt/part1/root
mount -o bind /mnt/part1 /jffs
mount -o bind /mnt/part1/etc /etc
mount -o bind /mnt/part1/opt /opt
mount -o bind /mnt/part1/root /tmp/root
else
exit
fi
if [ -d /opt/usr ]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/usr/lib:/opt/lib:/opt/usr/lib:/jffs/usr/lib:/jffs/usr/local/lib
export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/jffs/bin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
export IPKG_INSTROOT=/opt
else
exit
fi
The script works well and I can use opkg to install packages. I can also run umurmur manually but I'm struggling on making umurmur autostart. I recognized that the umurmur startup script placed in /opt/etc/init.d/ requires arguments like start and stop but it seems they are called without any arguments.
Another way described here did not work too.
Has anyone a working solution on problems like these? Please help!
Optware runs on Broadcom routers only. Your's has an Atheros chipset.
Taken from this page: Link
Its unclear i the page you referred to has changed - and indeed my setup is fairly different to yours, but to get scripts working on startup I did the following -
mkdir -p /jffs/etc/config
copy script into /jffs/etc/config directory, renaming it to end with .startup
chmod 755 /jffs/etc/config/scriptname.startup

Resources