How to make usbmount use /etc/fstab configuration - linux

I'm using a Debian wheezy stable and I'm trying to automatically mount a specific usb device in a designated directory when it's plugged (not at boot time or with the mount command).
I know how to mount my device in the directory I want with /etc/fstab and the mount -a command with this /etc/fstab:
UUID="xxxxxxxxxxxxxxxx" /media/myFolder ntfs auto,exec,rw,user,suid,uid=1000 0 0
I also know how to use usbmount to mount a device when it is plugged.
My problem is that usbmount mounts the device in a folder /media/usbX and not in the directory specified in fstab.
I didn't find how to change the configuration of usbmount to make it respect the /etc/fstabfile.
Is it possible and if so how can I do it?

Check out MOUNTPOINTS in /etc/usbmount/usbmount.conf.
# Mountpoints: These directories are eligible as mointpoints for
# removable storage devices. A newly plugged in device is mounted on
# the first directory in this list that exists and on which nothing is
# mounted yet.
MOUNTPOINTS="/media/usb0 /media/usb1 /media/usb2 /media/usb3
/media/usb4 /media/usb5 /media/usb6 /media/usb7"

Related

Getting a mount error when trying to mount device at another mount point after cryptsetup opened LUKS device

I am using Ubuntu 22.04 and would like to mount an opened LUKS device (USB pen drive) in /media/user_name/... for it to show up in the Ubuntu file explorer.
When inserting the drive a dialog immediately opens asking for a password to unlock the drive. Since I am using a key file to unlock the device I cancel the dialog. At this point the drive is visible in file explorer and can be ejected.
In a terminal, I open the device with sudo cryptsetup open /dev/sda1 LuksUsb --type luks2 --key-file the_key_file. The drive now disappears from the file explorer.
With lsblk -o NAME,TYPE,SIZE,FSTYPE,UUID,MOUNTPOINT I see sda, sda1, and LuksUsb.
sda1 has filesystem type crypto_LUKS and LuksUsb no fstype. The device is now also in /dev/mapper/LuksUsb.
Next I want to mount the device in /media/user_name/Luks.
First, creating Luks dir in /media/user_name/ then mounting with mount /dev/mapper/LuksUsb /media/user_name/Luks.
The resulting error message:
mount: /media/user_name/Luks: wrong fs type, bad option, bad superblock on /dev/mapper/LuksUsb, missing codepage or helper program, or other error.
I have tried explicitly passing a filesystem type (-t ext4 in this case) to the mount command, but the outcome is the same.
Also tried mount -t ext4 /dev/sda1 /media/user_name/Luks yields error message mount: /media/user_name/Luks: /dev/sda1 already mounted or mount point busy.
Insights much appreciated.

LXDE & udev on Raspbian --Run script on USB Drive when plugged

Running LXDE on Raspbian.
I want to run a script on a usb flash drive when the device is plugged. Any flash drive, not a specific one.
This is to provide code updates to customers without requiring a keyboard or mouse attached to one of several rpis in a system (they have displays but no input devices). The customer will download a file to a thumbdrive on his own device and then insert it in one of four rpis in the system. The script will "do what it needs" to backup old files and scp new ones to the correct hosts and remote directories in the system
I can write a udev rule that creates a symlink to the flash drive when plugged. The symlink shows up under /dev But, I can't cd into that symlink--I probably have to do a mount first.
By observation, LXDE seems to automount a USB flash drive in /media when plugged. I don't see the name of the mount point (e.g. /media/B85D-6433) when using:
udevadm info -a -p $(udevadm info -q path -n /dev/sda1) | grep -i 6433
or
udevadm info -a -p $(udevadm info -q path -n /dev/sda1) | grep -i B85D
So, I can't figure out where the LXDE will mount the drive without first knowing its name.
1) Is there a way to determine the name of the directory under /media that LXDE will use for the mount point? I could keep a list of what was in /media before and after the plug event and determine it that way, but maybe there's a better way?
2) Instead, should I mount the symlink under /dev to a different place then excecute the script on the usb drive via this new mount point?
3) Other way?
Thanks!

Mount another virtual hard disk always belongs root owner, why?

Environment is in virtual box,ubuntu 12.04. It has 2 disks, /dev/sda1 and /dev/sdb1 are both ext4 type filesystem.
Since /dev/sdb1 is add after system installed, so I want to mount it manually. I'd try this command:
sudo mount -o user,defaults /dev/sdb1 ~/project
No errors report. Then I get mount info by mount:
/dev/sdb1 on /home/igsrd/project rw,noexec,nosuid,nodev
But when I ls -l to see /home/igsrd I found its permission is still belongs root, so I can't touch anything in it. Why it still belongs root?
I have another machine running ubuntu 12.04,too. I mount another partition with same option will be fine, correct permission(ownership). Are any differences between them?
*nix permissions on a filesystem that supports them natively, e.g. ext4, will be maintained regardless of how it is mounted when using a proper filesystem driver, e.g. the native ext4 driver built into Linux.
Why don't you just (while still root) do this:
chown -R <your-user-name> ~<your-user-name>/project
?

How to access fstab at reboot phase

How can I access and modify /etc/fstab during reboot (maybe accessing to recovery mode) ?
Why this question :
I have updated the virtualbox guests additions in backtrack 5 (as a Virtualbox VM).
I have modified temporary the fstab file to do that but forgotten to turn it back to initial state, like :
mount /dev/cdrom /cdrom
echo "/dev/cdrom /cdrom0 udf,iso9660 defaults,exec 0 0" >> /etc/fstab
So after the guest additions installed, reboot is blocked on mounting this unexisting point.
Thx
edit: maybe to move to serverfault ?
I see two possible solutions to your problem:
Use the recovery mode (if you don't see that in the grub list, edit the default entry and add the word "single" without quotes to the end of the kernel line)
Mount a random .iso file temporarily
Then remove the offending fstab line.
Another option is to boot a Live OS and mount the root filesystem from there. Then you will be able to edit the fstab file.
Once you have the live OS booted
fdisk -l
-find your root partition (usually in the format sda1, sdc1, sda2, etc)
mkdir /mnt/rootfs
mount /dev/sda2 /mnt/rootfs <--sda2 = root partition found in fdisk
cd /mnt/rootfs/etc
-Fstab file should be in there.

KVM Virtual machine running Windows XP: How to get files from guest to host?

I'm running Ubuntu 10.04, and on it, kvm/qemu. I created a storage device with the 'raw' format and installed XP on it, so I assume the file has ntfs format. I have a file on the XP virtual machine that I want on the host. It's 2gigs, so I can't just use a zip drive or burn it to CD.
I tried mounting the file (winxp.img) using losetup:
$ sudo losetup /dev/loop1 winxp.img
$ sudo losetup -a
/dev/loop1: [0801]:40637460 (/home/robert/kvm/images/winxp.img)
$ sudo mount -t ntfs /dev/loop1 /home/robert/kvm/images/tmp
NTFS signature is missing.
Failed to mount '/dev/loop1': Invalid argument
The device '/dev/loop1' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
I thought that would work. It didn't. Does anyone have another idea?
winxp.img and loop1 is not a single partition (which can be mounted), it is image of full hard disk with own partition table.
You should read partition table from loop1 with fdisk; compute offset of first partition and do:
sudo mount -o offset=N -t ntfs /dev/loop1 /home/robert/kvm/images/tmp
where N is offset in bytes.
Telepathic mode on
N is 32256
Telepathic mode off
and finally, google mode on (I'll google "offset 32256"):
http://en.wikibooks.org/wiki/QEMU/Images#Mounting_an_image_on_the_host
Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256.
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
In my opinion the generic and correct way is via libguestfs http://libguestfs.org/
If you master it, you can open every virtual image in any format and get files or even make snapshots

Resources