Open probonopd opened 2 years ago
I already have script for that - here:
Looks like it assumes ISO9660 all the time? The disk images I mean can have multiple parititions with various filesystems.
What use case do you see here?
I have that random file here that maybe has some filesystem or image on it and lets try to guess-mount it and see what is in there? :)
Indeed. I use disk images (also ones having a partition table and multiple partitions) for many uses all the time.
I have a semi automatic- but very production ready solution :)
First use mine mdconfig.sh script to map that FILE into a DEVICE - like /dev/md0 - for example: https://github.com/vermaden/scripts/blob/master/mdconfig.sh
Then in the file /usr/local/etc/devd/automount_devd.conf file:
Change that:
# PENDRIVE/PHONE/SDCARD insert
notify 100 {
match "system" "DEVFS";
match "type" "CREATE";
match "cdev" "(da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev attach &";
};
# PENDRIVE/PHONE/SDCARD remove
notify 100 {
match "system" "DEVFS";
match "type" "DESTROY";
match "cdev" "(da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev detach &";
};
Into that:
# PENDRIVE/PHONE/SDCARD insert
notify 100 {
match "system" "DEVFS";
match "type" "CREATE";
match "cdev" "(md|da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev attach &";
};
# PENDRIVE/PHONE/SDCARD remove
notify 100 {
match "system" "DEVFS";
match "type" "DESTROY";
match "cdev" "(md|da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev detach &";
};
And restart devd(8) daemon.
That should make automount(8) to also automount the **/dev/md*** devices.
Hi @vermaden, this is a very elegant solution indeed. However, I am getting
2021-11-10 21:32:06 /dev/md1: attach
2021-11-10 21:32:06 /dev/md1p2: attach
2021-11-10 21:32:06 /dev/md1p2: filesystem not supported or no filesystem
2021-11-10 21:32:06 /dev/md1p1: filesystem not supported or no filesystem
2021-11-10 21:32:06 /dev/md1: filesystem not supported or no filesystem
but:
FreeBSD% dd if=/dev/md1 of=/tmp/md1 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes transferred in 0.001204 secs (871149069 bytes/sec)
FreeBSD% file /tmp/md1
/tmp/md1: ISO 9660 CD-ROM filesystem data (DOS/MBR boot sector) 'ISOLBL' (bootable)
FreeBSD% mount -o ro -t cd9660 /dev/md1 /mnt
FreeBSD% ls /mnt
boot chroot dev etc rescue
FreeBSD% umount /mnt
You need to also add 'md' to the 'CD' section in the /usr/local/etc/devd/automount_devd.conf file.
Now I have
# PENDRIVE/PHONE/SDCARD insert
notify 100 {
match "system" "DEVFS";
match "type" "CREATE";
match "cdev" "(md|da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev attach &";
};
# PENDRIVE/PHONE/SDCARD remove
notify 100 {
match "system" "DEVFS";
match "type" "DESTROY";
match "cdev" "(md|da|mmcsd|ugen)[0-9]+.*";
action "/usr/local/sbin/automount $cdev detach &";
};
# CD-ROM media inject
notify 100 {
match "system" "DEVFS";
match "type" "CREATE|MEDIACHANGE";
match "cdev" "(md|cd)[0-9]+.*";
action "/usr/local/sbin/automount $cdev attach &";
};
# CD-ROM media eject
notify 100 {
match "system" "DEVFS";
match "type" "DESTROY";
match "cdev" "(md|cd)[0-9]+.*";
action "/usr/local/sbin/automount $cdev detach &";
};
# CD-ROM no media
notify 100 {
match "system" "CAM";
match "subsystem" "periph";
match "type" "error";
match "cam_status" "0xcc";
match "scsi_status" "2";
match "scsi_sense" "70 02 3a 02";
match "device" "(cd)[0-9]+.*";
action "/usr/local/sbin/automount $device detach &";
};
but with the same result.
Your solution is way more elegant. Is it actually working for you?
I think the devd rule is working, because /usr/sbin/automount
gets invoked when I create a md
device.
What is not working is that /usr/sbin/automount
thinks the filesystem is not supported or there is no filesystem, even though it can be mounted perfectly fine by hand. Maybe it is because -o ro
is needed?
% sudo /usr/local/sbin/automount md1.uzip attach
% cat /var/log/automount.log
/dev/md1.uzip: attach
/dev/md1.uzip: filesystem not supported or no filesystem
Added UZIP support to automount(8).
Here: https://github.com/vermaden/automount/blob/master/automount
The devd(8) additional configs. https://github.com/vermaden/automount/blob/master/automount_devd_diskimage.conf https://github.com/vermaden/automount/blob/master/automount_devd_localdisks.conf
This is more than awesome @vermaden! :+1: Thank you very, very much for this extremely useful tool. It will be front and center in helloSystem, because we will use disk images a lot.
Now, in order for the disk images to be attached to mdX
nodes, and for those mdX
nodes to be destroyed after the user has unmounted all the partitions on the image, this is my current line of thinking -- do you have a better idea?
The check would fail.
This:
mount | grep -e "^$md on" || break
Will not match these:
/dev/md0 on /mnt/tmp1 (msdosfs, local)
/dev/md0s1 on /mnt/tmp2 (msdosfs, local)
/dev/md0p1 on /mnt/tmp3 (msdosfs, local)
Yes, that is what the FIXME
comment was alluding to.
Anyhow, I think this should do it:
mount | grep "^\/dev\/$md[s|p|\.|\ ].*on" || break
Complete script: https://github.com/helloSystem/ISO/blob/experimental/overlays/uzip/automount/files/usr/local/sbin/mount_md
Will go with that and test drive it on helloSystem for a while. If everything goes well and once it is tested properly, would you consider a pull request?
Let's make loop-mouning filesystem images (like ISO files and hard disk images) easier.
Consider adding a loopmount script that would allow all filesystems in a given image file to be mounted with automount.
Something along these lines:
What do you think?