In my computer, I have a ntfs network disk, and with cygwin and bash I have some automatic script (post-commit git hooks) for copy information to the ntfs disk.
with bash (in cygwin), how I can check if the ntfs is enable ?
if mount | grep -q /path/to/device/or/mount/point ; then
# it's mounted
else
# it's not
fi
Related
I ran the following command to install Nix on my Mac:
sh <(curl -L https://nixos.org/nix/install) --daemon --darwin-use-unencrypted-nix-store-volume
And I got the following error:
error: refusing to create Nix store volume because the boot volume is
FileVault encrypted, but encryption-at-rest is not available.
Manually create a volume for the store and re-run this script.
See https://nixos.org/nix/manual/#sect-macos-installation
https://nixos.org/nix/manual/#sect-macos-installation says:
If you're using a recent Mac with a T2 chip, your drive will still be encrypted at rest (in which case "unencrypted" is a bit of a misnomer). To use this approach, just install Nix with:
sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
If you don't like the sound of this, you'll want to weigh the other approaches and tradeoffs detailed in this section.
I don't have a mac with a T2 chip, so what do I do?
I found some related github issues, but no direct answer.
I chose to use the Use a separate encrypted volume suggestion as outlined in by Philipp Haussleiter:
This approach only works if you have a Disk that is formated with APFS (that should always be the case, if your OS is running of a SSD).
You can check this with:
% diskutil list | grep APFS
…
0: APFS Container Scheme - +250.8 GB disk1
…
Create another Volume on your Disk for NIX:
% sudo diskutil apfs addVolume disk1 'APFS' nix
Will export new APFS Volume "nix" from APFS Container Reference disk1
Started APFS operation on disk1
Preparing to add APFS Volume to APFS Container disk1
Creating APFS Volume
Created new APFS Volume disk1s6
Mounting APFS Volume
Setting volume permissions
Disk from APFS operation: disk1s6
Finished APFS operation on disk1
Your disk may not be named disk1s6. Find the name of your disk with:
% diskutil list | grep nix
4: APFS Volume nix 7.7 GB disk1s6
Again, your disk may not be named disk1s6.
Encrypt disk:
You need to enter a passphrase for the encryption. You have to
remember that passphrase once – you can add it to your key chain later
on. After that the disk encryption will start in the background.
% sudo diskutil apfs encryptvolume disk1s6 -user disk
Passphrase for the new "Disk" user (672C4CFF-34C6-4407-83ED-294C1C42E161):
Repeat passphrase:
Starting background encryption with the new "Disk" crypto user on disk1s6
The new "Disk" user will be the only one who has initial access to disk1s6
The new APFS crypto user UUID will be 672C4CFF-34C6-4407-83ED-294C1C42E161
Background encryption is ongoing; see "diskutil apfs list" to see progress
Setup Mount Point:
MacOS Catalina does not allow to create folders directly under your
Root Path /. But we can use another method to have MacOS create that
folder for us. To do this, we have to add an entry into the file
/etc/synthetic.conf:
% sudo bash -c 'echo nix >> /etc/synthetic.conf'
Now, the next time, the system starts, a mount point /nix will be
created. The next task is to have our Volume mounted at Boot.
Setup Mount:
For the Mount Configuration, we need to the UUID of the Volume. We can
find this via the diskutil tool (again, your disk may not be named
disk1s6):
% diskutil info /dev/disk1s6 | grep UUID
We must edit /etc/fstab with vifs:
% sudo vifs
(vifs behaves just like vi, so use vi commands to edit the file):
UUID=1D9389C1-5676-4077-88F5-8D5304A0B1A6 /nix apfs rw
(Your UUID will be different!)
Reboot. You will get a GUI prompt to enter your encryption passphrase,
and save it to the keychain.
I then ran:
sh <(curl -L https://nixos.org/nix/install) --daemon
The --darwin-use-unencrypted-nix-store-volume option isn't necessary because we have an encrypted volume now.
I've been experimenting with running apps within a chroot-ed directory.
Many apps and binaries require access to items within /dev, such as /dev/null and /dev/random to work.
Is there a way to recreate or bind mount the /dev filesystem within a directory to this end?
I have tried the following without success:
(Where root is the directory I want to chroot into)
$ sudo bindfs -o dev -o allow_other /dev ./root/dev/
Leading to:
$ cat ./root/dev/urandom
cat: ./root/dev/urandom: Operation not permitted
$ mount -t devfs devfs ./root/dev
Leading to:
$ cat ./root/dev/urandom
cat: ./root/dev/urandom: Device not configured
Attempting to manually make the devices with mknod doesn't work either.
$ sudo mknod null c 1 3
$ sudo chmod 666 ./null
$ cat ./null
cat: ./null: Operation not permitted
Is there a way to either use the existing /dev items within a chroot or to recreate them?
Unfortunately, there doesn't appear to be much documentation of using chroot with OSX/macOS on the internet.
Operating System Details: macOS Mojave, 10.14.6. SIP enabled.
Well, this one is mainly on me being dumb.
sudo mount -t devfs devfs ./dev
Works just fine.
If the above command is ran without root, it will bind the devfs devices within ./dev, but all devices will respond with a "Device not configured" error. If it is ran as root, all ./dev devices will work as expected.
I have external SSD with APFS volumes inside, when plug-in this automatic mount at /Volumes/Workspace. Have a way to define to automatic mount in a predefined path?
Take a look at current volumes:
ls /Volumes
Get the UUID of volume:
diskutil info /Volumes/[name] | grep UUID
Create a folder where you wish add the volume:
mkdir -p [/absolute/path/to/folder]
Put follow code at fstab:
echo "UUID=[UUID] [/absolute/path/to/folder] apfs rw" | sudo tee -a /etc/fstab
The example mount a volume with apfs format, but you can use for ntfs, nfs, etc.
Running bash on windows 10, the simple syntax below works when I SSH to my webserver, but not when I exit out and am on my local machine. It doesn't give me an error, but I can see permissions are unchanged. I have to checked that I am set up as an administrator on my computer. Is this an error or is this just a consequence of the local operating system being windows? IF the later, it makes me question the value of using bash on windows if common operations such as this won't work.
$chmod 644 filename
To enable changing file owners & permissions, you need to edit /etc/wsl.conf and insert the below config options:
[automount]
options = "metadata"
Do this inside the WSL shell, potentially needing sudo to edit/create the file.
This may require restarting WSL (such as with wsl --shutdown which is a Windows command, not one within WSL) or the host machine to take effect. This has been possible since 2018:
You can now set the owner and group of files using chmod/chown and modify read/write/execute permissions in WSL. You can also create special files like fifos, unix sockets, and device files. We’re introducing new mounting options with DrvFs for projecting permissions onto files alongside providing new Linux metadata on files and folders.
[cite: Microsoft Dev Blog]
You can also temporarily re-mount a drive with the following commands:
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
...but please note, the command only takes effect in session scope. If you exit current bash, you'll lose your settings (credit: answerer Amade).
Reference:
Automatically Configuring WSL
There was an update to WSL recently (source), which lets you change permissions to files (Insider Build 17063).
All you have to do is to run:
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
Both Amades and Chaos answers are correct.
But it only works for local drives not for mapped network drives. Z: is one of my network drives. Same operation on /mnt/c/Users/xxx/ works fine.
$sudo mount -t drvfs Z: /mnt/z -o metadata
$touch test
$chmod +w test
chmod: changing permissions of 'test': Operation not permitted
This is a known issue, see drvfs: metadata (chmod\chown) possible for mounted SMB drives?
OS: OSX mountain lion
I am trying to write a script that does the following
Check if file1 exist on destination 1 (bitcasa)
if exist then copy source folder to destination 1
if file does not exist find bitcasa process and kill it then wait 60sec then start bicasa.
try again (loop?) #bitcasa sometimes stops working and have to be restarted.
Check if file2 exist on destination 2 (nfs share)
if exist then copy source folder to destination 1
if file does not exist try to mount nfs share.
try again (loop?)
verify copied files
if files copied successfully delete source files
I only want the script to try a few times, if it ant ping the nas host it should give up and try the next time the script runs. I want to run the script every 2h. crontab seam to have been removed in mountain lion.
When I write this down I realize it is a bit more complicated than I first thought.
First regarding mount a nfs share, in OsX if you eject a mounted nfs share the folder in /Volumes gets removed. What is the best way to make sure a nfs share i always mounted if the nas is available? This might be handled outside the script?
If i manually mount the nfs share I will need to create /Volumes/media and this will result in that if I use the gui to mount the share will use /Volumes/media-1/ sins /Volumes/media vill already exist.
Regarding killing a process by name sins I cant know the PID, I tried with linux command i found:
kill ps -ef | grep bitcasa | grep -v grep | awk ‘{print $2}’ this did not work.
I have no idea how to check if all files were successfully copied, maybe rsync can take care of this?
I have started with this (not tested)
#check if bitcasa is running (if file exist)
if [ -f /Volumes/Bitcasa\ Infinite\ Drive/file.ext ]
then
rsync -avz /Users/username/source /Volumes/Bitcasa\ Infinite\ Drive/destination/
else
#Bitcasa might have stopped, check if process i running, kill if it is, then start bitcasa
fi
#Check if nfs share is mounted (if file exist)
if [ -f /Volumes/media/file.ext ]
then
rsync -avz /Users/username/source /Volumes/media/
fi
else
#nfs share (192.168.1.106:/media/) need to be mounted to /Volumes/media
I will do some more work on it myself but I know I will need help.
Or am I doing this way to complicated? maybe a backup program can do this?
For your kill ... ps problem, you can use killall, which kills all processes having a given name
killall bitcasa
or see man ps and use a user defined format, which simplifies the selection
ps -o pid,comm | awk '/bitcasa/ { print $1; }' | xargs kill
For the nas, if you can log into it and install rsync and ssh (or have it already installed), you don't need to mount anything. You can just give 192.168.1.106:/media/ as the destination to rsync and rsync will do everything necessary.
In any case, first check and mount if necessary and then start rsync when everything is set up properly not the other way round
if [ ! -f "/Volumes/Bitcasa Infinite Drive/file.ext" ]; then
# kill bitcasa, restart bitcasa
fi
rsync -avz /Users/username/source "/Volumes/Bitcasa Infinite Drive/destination/"
same for nas
if [ ! -f "/Volumes/media/file.ext" ]; then
# mount nas nfs share
fi
rsync -avz /Users/username/source "/Volumes/media/"
or if you have rsync and ssh on your nas, just
rsync -avz /Users/username/source 192.168.1.106:/media/