Mount

From Leo's Notes
Last edited on 30 December 2021, at 21:21.


Mounting Tips & Tricks for Linux.

Mounting Filesystems

ISO Disk Images

To mount a .iso image, use iso9660 type:

mount -o loop -t iso9660 <isofile> <destination>

Samba Network Shares

See: Mounting Samba (CIFS) shares

/etc/fstab

The filesystem tab file contains all filesystems that the system should mount on start up. Each line of the file defines a filesystem that should be mounted. Example entries from Wikipedia shows various examples for different file systems:

# device-spec   mount-point     fs-type      options                                          dump pass
LABEL=/         /               ext4         defaults                                            1 1
/dev/sda6       none            swap         defaults                                            0 0
none            /dev/pts        devpts       gid=5,mode=620                                      0 0
none            /proc           proc         defaults                                            0 0
none            /dev/shm        tmpfs        defaults                                            0 0

# Removable media
/dev/cdrom      /mnt/cdrom      udf,iso9660  noauto,owner,ro                                     0 0

# NTFS Windows 7 partition
/dev/sda1       /mnt/Windows    ntfs-3g      quiet,defaults,locale=en_US.utf8,umask=0,noexec     0 0

# Partition shared by Windows and Linux
/dev/sda7       /mnt/shared     vfat         umask=000                                           0 0

# mounting tmpfs
tmpfs           /mnt/tmpfschk   tmpfs        size=100m                                           0 0

# mounting cifs
//cifs_server_name/ashare  /store/pingu    cifs         credentials=/root/smbpass.txt                       0 0

# mounting NFS
nfs_server_name:/store    /store          nfs          rw                                                  0 0

Each field in order are:

Device Spec The device name, label, UUID that defines the data source, hardware, or partition
Mount Point The mount point of the filesystem. Swap partitions or specific files is set to 'none'
Filesystem Type The filesystem type of this device.
Mount Options Mount options used by the filesystem. 'defaults' refers to the filesystem defaults.
Dump Determines how often the filesystem should be backed up by the dump program. 0 to never backup.
Pass Determines the order in which the fsck program will check devices for errors on startup. 1 for root filesystem. 2 to check after root. 0 to disable.


Tips

Remounting from Read-Only to Read-Write

You can remount something that's mounted read-only by using the remount option.

# mount -o remount,rw /

Mounting a disk image without root

Using udisksctl, you can mount disk images without requiring root or sudoers access.

$ dd if=/dev/zero of=test.img bs=1M count=100
$ udisksctl loop-setup -f test.img
Mapped file $PATH_TO_IMAGE as /dev/loop0.

Depending on your system, this may have triggered the loopmount to automount somewhere in /run/media/username. If nothing was mounted, manually mount the loopmount device:

$ udisksctl mount -b /dev/loop0
Mounted /dev/loop0 at /media/$USER/$IMAGE_NAME

To unmount the filesystem:

$ udisksctl unmount -b /dev/loop0
$ udisksctl loop-delete -b /dev/loop0

See Also: https://wiki.debian.org/ManipulatingISOs

Mounting disk image partitions

To mount a specific partition inside a disk image, use the fdisk utility to see where the partition boundaries are.

# fdisk -l out.bin
Disk out.bin: 58.6 MiB, 61440000 bytes, 120000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000981cb

Device     Boot  Start     End Sectors  Size Id Type
out.bin1          8192  122879  114688   56M  c W95 FAT32 (LBA)
out.bin2        122880 5785599 5662720  2.7G 83 Linux

The first partition starts on sector 8192. Since each sector is 512 bytes, we can mount this particular partition by passing an offset of 8192 * 512 bytes.

# mount -o loop,offset=$((8192 * 512)) out.bin /mnt/card

Alternatively, you may want to set up a loopback device specifically for a partition using losetup:

# losetup /dev/loop0 disk.img -o $((10860003 * 512))
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext3 filesystem data
# mount /dev/loop0 /mnt
[...]
# umount /mnt
# losetup -d /dev/loop0


Troubleshooting

Samba Network Shares

The first time I ran mount -a, I got the following error:

root@server:~# mount -a
mount: wrong fs type, bad option, bad superblock on //box/Volume_1,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

with dmesg showing:

CIFS VFS: No username specified
CIFS VFS: cifs_mount failed w/return code = -22

Error -22 means the executable doesn't exist. To resolve this, install cifs-utils

# yum -y install cifs-utils


See Also

  1. http://madduck.net/blog/2006.10.20:loop-mounting-partitions-from-a-disk-image/
  2. https://en.wikipedia.org/wiki/Fstab