Mount loop device with FUSE - linux

So let's say I have a file attached to a loop device /dev/loop1 how could I mount that using fuse (filesystem in user space) ?

If you're using fuse, you don't need a loop device at all, and can directly mount the file itself. So, you can do either this:
$ sudo ext4fuse test.ext4 /mnt
Or, if for some bizarre reason you really want to use a loop device, this:
$ sudo losetup /dev/loop0 test.ext4
$ sudo ext4fuse /dev/loop0 /mnt

Once you set the permissions of the loop device so that the fuse process can access it, you can mount it the same way as any other device.

Related

Load root filesystem from USB device

I'm trying to make a fast reboot to the other Linux system. First step is kernel loading, I make it with
sudo kexec --append='$(cat /proc/cmdline)' -l new_kernel.img --reuse-cmdline
sudo kexec -e
It works fine, but loads only kernel, not entire system.
How can I mount an *.img file with OS resources, located at USB as /? Preferable during kernel loading, but afterwards mount is still suitable. *.img format is not necessary, it can be unpacked before
As stark said, pivot root() was the call I was searching for. Commands to make a USB located at /dev/sdb1 a root directory:
sudo -s
mkdir /newroot
mount /dev/sdb1 /newroot
cd /newroot
mkdir oldroot
pivot_root . oldroot/
switch_root() deletes all files at the previous root dir, also there are few other differences, this answer might be useful

Ubuntu: create a new partition on /dev/sdb1 (which still has 1.5tb of free space) and mount it on /tmp/

As you can see /dev/sda is mounted to /. Thats where /tmp/ is located as shown image. Since It is running out of space on my / partition,I can't install caffe, and there is error: No space left on device.
Now I want to create a new partition on /dev/sdb1 (which still has 1.5tb of free space) and mount it on /tmp/.
Could you guys tell me how to create a new partition for solving this issue by linux command.
thanks
Just give the following command
To unmont the existing volume give the following
sudo umount /dev/sdb1
Note:- Make sure no process is using the particular directory
Then again mount it to /tmp
sudo mount /dev/sdb1 /tmp
or
cd /dev/ && sudo mount sdb1 /tmp

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
?

What happens if you mount to a non-empty mount point with fuse?

I am new to fuse. When I try to run a FUSE client program I get this error:
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
I understand that a mountpoint is the directory where you will logically attach the FUSE filesystem. What will happen if I mount to this location? What are the dangers? Is it just that the directory will be overwritten? Basically: what will happen if you mount to a non empty directory?
You need to make sure that the files on the device mounted by fuse will not have the same paths and file names as files which already existing in the nonempty mountpoint. Otherwise this would lead to confusion. If you are sure, pass -o nonempty to the mount command.
You can try what is happening using the following commands.. (Linux rocks!) .. without destroying anything..
// create 10 MB file
dd if=/dev/zero of=partition bs=1024 count=10240
// create loopdevice from that file
sudo losetup /dev/loop0 ./partition
// create filesystem on it
sudo e2mkfs.ext3 /dev/loop0
// mount the partition to temporary folder and create a file
mkdir test
sudo mount -o loop /dev/loop0 test
echo "bar" | sudo tee test/foo
# unmount the device
sudo umount /dev/loop0
# create the file again
echo "bar2" > test/foo
# now mount the device (having file with same name on it)
# and see what happens
sudo mount -o loop /dev/loop0 test
Just add -o nonempty in command line, like this:
s3fs -o nonempty <bucket-name> </mount/point/>
Apparently nothing happens, it fails in a non-destructive way and gives you a warning.
I've had this happen as well very recently. One way you can solve this is by moving all the files in the non-empty mount point to somewhere else, e.g.:
mv /nonEmptyMountPoint/* ~/Desktop/mountPointDump/
This way your mount point is now empty, and your mount command will work.
For me the error message goes away if I unmount the old mount before mounting it again:
fusermount -u /mnt/point
If it's not already mounted you get a non-critical error:
$ fusermount -u /mnt/point
fusermount: entry for /mnt/point not found in /etc/mtab
So in my script I just put unmount it before mounting it.
Just set "nonempty" as an optional value in your /etc/fstab
For example:
## mount a bucket
/usr/local/bin/s3fs#{your_bucket_name} {local_mounted_dir} fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
## mount a sub-directory of bucket, Do like this:
/usr/local/bin/s3fs#{your_bucket_name}:{sub_dir} {local_mounted_dir} fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
force it with -l
sudo umount -l ${HOME}/mount_dir

Delete mounting directory after umount -l

I'm working on Linux OpenWrt where I have to mount and umount manually USB disks when they are attached to the router.
I'm using this script: http://wiki.openwrt.org/doc/howto/writable_ntfs#with.a.custom.hotplug.script to mount and unmount automatically USB disks the problem is that it doesn't delete the mounting directory after umount -l /dev/$device. My application on the router needs to check if the USB disk is present or not by checking if /mnt/sda1 exists or not
My question is: is it dangerous to add rm -r sda1 after umount -l /dev/$device, or is there a risk that rm -r sda1 will remove files in sda1 ?
It should be safe to delete the directory after the umount if you check for the success of the umount command before but I would suggest to change you script to check if the mountpoint it's listed in the mount table instead with mount | grep sda1

Resources