We all know that mounting a new partition as /home and maybe /boot is extremely useful. Or mounting a remote directory as /opt can be great for sharing system tools. Are there any other, maybe more esoteric, uses for extra partitions or hard drives or nifty ways to mount external volumes? Maybe even if anyone also has windows machines *shudder*, post some cool tricks involving partitioning and hard drive mounting.
FUSE (Filesystem in USErspace) allows many things to be accessible as ordinary files (not an exhaustive list by any means):
- remote files accessed via FTP
- remote files accessed via ssh
- remote files accessed via WebDAV
- files in archives
- files inside a non-running virtual machine image with xmount
- anything that looks like a file to a Gnome application
- Blogger blogs
There are also many FUSE filesystems that present a view of another filesystem with filtering, renaming or modified metadata or content:
- Keep copies of all past versions of files with copyfs, waybackfs, ...
- Log every action with loggedfs
- Encrypt files transparently with encfs
- Convert audio content with mp3fs
- See a read-only view or change permissions with bindfs
- See a partial read-only view with rofs-filtered
- Convert file name character sets with convmvfs
- Get a case-insensitive view with ciopfs
Most unices have a logical volume manager. Use it.
Filesystems are now designated by meaningful names (like
/dev/mapper/darkstar-home) rather than through drive letters (like
/dev/sda1, oops, it's now
/dev/sdb1because I booted with an external disk plugged in) or with safe but meaningless UUIDs.
Want to move a filesystem to a different disk? Create a physical volume on the new disk, add it to the volume group, and move the logical volume onto the new physical volume. All done without downtime, no unmounting required.
When you make a backup, take a snapshot of the disk and run your backup from the snapshot. That way the backup is a consistent view of the filesystem (i.e., there really was a point in time when the filesystem was in that state). This doesn't hold with naive backups (e.g. file A is backed up, then a program modifies first A then B, then B is backed up: the backup has the new B and the old A).
Need to enlarge a filesystem? Logical volumes don't need to be contiguous, so all you need is enough free space, never mind where.
You have someone who can only access your server over ftp and are confined to their home directory but you realise they they need access to some other directory not in their home folder.
For example bob has ftp access to your web server, but also you want to let him view the log files in /var/logs/httpd/vhosts/bobssite.com/. It is a hassle to reconfigure everything so that apache writes logs for bobssite.com to bobs home folder but you can use the bind option to remount the folder like this
mkdir /home/bob/logs mount --bind /var/logs/httpd/vhosts/bobssite.com /home/bob/logs/
Most unices clean
/tmp on boot. If you do this, there isn't much point in storing the contents of
/tmp on disk in the first place. Many unices allow a filesystem to be stored in memory (the data will be written in the swap if necessary). For some reason, even though Linux has
tmpfs for this, most distributions don't mount
tmpfs. It's easily remedied with a line in
tmpfs /tmp tmpfs mode=1777
By default, the filesystem can grow up to half your RAM. If you have a lot of swap, you might want to allow it to contain bigger files, e.g. to allow up to 2 GB:
tmpfs /tmp tmpfs mode=1777,2g
(Making the filesystem larger has a negligible overhead; the virtual memory usage grows as needed. It's still a good idea to have a limit because a runaway program could fill it very fast, and it's better to run out of
/tmp than to run out of memory available for processes.)
If your OS supports it, make all your filesystems on RAID 1 arrays, even if you they're not replicated. That way, if you ever need to transfer the filesystem to a different disk, you can do it online and quickly by adding the partition on the second disk to the array, rebuilding the array and removing the first disk.
Avoid file access time writing:
You can use alternative device names, e.g. labels or uuids.
For example to identify my MP3 player I use this device name in my fstab:
You can print the uuids of connected devices via the blkid command.
Analogous to that you can set a label at mkfs time or later via e2fstune and comparable tools. Then you can use
in the fstab or at the command line.
Mount an .iso image as a loopback filesystem. I keep a number of .iso files around, and this can be a handy way to copy reference files on the disk image.
stefan@host1:~ $ ls -ld ubuntu-10.04-server-amd64.iso -rw-r--r-- 1 stefan staff 710412288 2010-06-27 11:51 ubuntu-10.04-server-amd64.iso stefan@host1:~ $ mkdir ./ubuntu-10.04-server-amd64 stefan@host1:~ $ sudo mount -o loop ubuntu-10.04-server-amd64.iso ./ubuntu-10.04-server-amd64 stefan@host1:~ $ ls ubuntu-10.04-server-amd64 cdromupgrade doc isolinux pics preseed ubuntu dists install md5sum.txt pool README.diskdefines
Or, if I want to read an offline copy of the installation manual, I can do that from the commandline:
stefanl@host1:~ $ links ubuntu-10.04-server-amd64/doc/install/manual/en/index.html