From owner-freebsd-questions@freebsd.org Thu Feb 8 18:26:50 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2B0DF19907 for ; Thu, 8 Feb 2018 18:26:50 +0000 (UTC) (envelope-from frank2@fjl.co.uk) Received: from bs1.fjl.org.uk (bs1.fjl.org.uk [84.45.41.196]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "bs1.fjl.org.uk", Issuer "bs1.fjl.org.uk" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 3450E74F6B for ; Thu, 8 Feb 2018 18:26:50 +0000 (UTC) (envelope-from frank2@fjl.co.uk) Received: from roundcube.fjl.org.uk (localhost [127.0.0.1]) by bs1.fjl.org.uk (8.14.4/8.14.4) with ESMTP id w18IQl8T010877 for ; Thu, 8 Feb 2018 18:26:47 GMT (envelope-from frank2@fjl.co.uk) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 08 Feb 2018 18:26:47 +0000 From: Frank Leonhardt To: freebsd-questions@freebsd.org Subject: Re: Automount USB drive when connected Organization: FJL Microsystems In-Reply-To: <3BAACBF6-C4E0-44AA-AD5F-277D3C8267C0@kreme.com> References: <3BAACBF6-C4E0-44AA-AD5F-277D3C8267C0@kreme.com> Message-ID: <47f635317b7686004dc0697c3adc1cd3@roundcube.fjl.org.uk> X-Sender: frank2@fjl.co.uk User-Agent: Roundcube Webmail/0.9.2 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2018 18:26:50 -0000 On 2018-02-05 18:00, Cerebus wrote: > I have a USB enclosure that I'd like to be able to walk up to the > machine and plug in and have a series of things happen: > > 1) Disk mounts in /mnt/backup (or wherever, the key is it mounts > without intervention) > 2) a backup script I specify runs when the disk successfully mounts > 3) when complete /mnt/backup unmounts > > I've got step 2 (mostly), and step 3 is trivial, but I can't get step 1 > working > > (To be clear, this disk would never be present at startup. Basically, > walk in, plug in drive, let the backup run, unplug the drive, and > leave. I want this to work without requiring anyone to login) Sorry for late reply... You can probably do this using devd, the "state change" daemon. This can run arbitrary stuff when a hardware change is detected. "man devd" is a good place to start. There's also the "autofs" driver, which I think relies on devd, and passes the request to automountd which does the business for you. THAT SAID, when I've been in the situation you describe it has been having someone plug in a USB HD for an overnight backup, and unplug it the next morning. It was easier to have the cron job do it. One gotcha is that it won't mount a "dirty" FS, and that happened a lot. So the backup job first checked that the drive had appeared in /dev, then fscked the relevent partitions, then mounted it and carried on. Yes, it umounted it afterwards so it could safely be unplugged but....