Linux Basics/Archiving, mounting in depth

Archiving

edit
  • Archiving, compression with tar program

Listing:

tar -tvf file.tar: shows content of file.tar

tar -tvfz file.tar.gz: shows content of mentes.tar.gz

tar -tvfj file.tar.bz2: shows content of mentes.tar.bz2

tar -tvvf file.tar: detailed listing, permissions, owner etc.

Compressing:

tar -cvf file.tar /to/path: compressing data to the given path in tar.

tar -cvfz file.tar.gz /to/path: compressing data to the given path in gzip.

tar -cvfj file.tar.bz2 /to/path: compressing data to the given path in bz2.

Uncompressing: tar -xvf file.tar: Uncompresses file.tar and it puts to a /file folder

tar -xvfz file.tar.gz:Uncompresses gz then tar and it puts to a /file folder

tar -xvfj file.bz2:Uncompresses file.bz2 and it puts to a /file folder

Mounting

edit

Mounting – or connecting devices to the computer. Well, what happens of it doesn't work automatically, for example we didn't mount a hard drive under installation?

This is the base syntax of the mount command:

mount -t type device mount_folder - if we want to mount manually
mount -ta device mount_folder - if we want to detect the file system automatically
  • we mount by detection

type can be:

ext,ext2,ext3,ext4, fat, ISO9660, msdos, ntfs, udf, xfs etc.

if I want to mount a CD then the mounting would be like (from step to step):

mount -t ISO9660 /dev/sr0 /media/cd

Previously files were mounted to /mnt, but modern systems put them into /media folder.

In case of DVD it would be udf. You may ask, but DVD was in ISO too, yes, just in ISO there is a filesize limit, which is 2/4 GB, so in cas of DVD it's impossible to write a file bigger than the limit, even if the one layer - one sided DVD has a capacity of 4.7 GB.

We can give specific parameters at mounting with -o switch, separating them with commas (not all):

async – asynchronized I/O operations -> sync: synchronized I/O operations

atime – it updates the access time of inodes in the filesystem at every access, this is the kernel default.

noatime – it won't update the inode's access time in the filesystem

auto – automatically mounts the partition while booting (we have to do this in the case of non-root drives) and mount -a also does the same

noauto – it won't be mounted automatically, so we have to mount it manually

defaults: rw, suid, dev, exec, auto, nouser, async, and relatime

remount – Attempt to remount an already-mounted filesystem.

ro – read-only

rw – read/write

dev – Interpret character or block special devices on the filesystem.

nouser – Forbid an ordinary (i.e., non-root) user to mount the filesystem.

relatime – Update inode access times relative to modify or change time.

suid –Allow set-user-identifier or set-group-identifier bits to take effect.

other parameters: man mount command / https://linux.die.net/man/8/mount

So how does it work then?

edit

For e.g. we want to mount a device, that is writeable, can be mounted only by root, and we don't want to mount it automatically by boot, it has ext4 filesystem, we want to use the setuid, setgid bits, and it's in the first HDD's first partition, then i have to type this:

mount -t ext4 -o rw,noauto,nouser,suid /dev/sda1 /mnt/data

But first we need to create a folder for the partition we want to mount, else the command will alert that there's no such directory.

sudo mkdir /mnt/data

Then we edit the /etc/fstab file with e.g. nano, and we add the second line's content to the file:

# <file system>    <dir>    <type>   <options>            <dump> <pass>
/dev/sda1        /mnt/data  ext4    rw,noauto,nouser,suid  0     1

Explanation:

file system = this means the partition we want to mount

dir = this means the path we want to mount it

type = type of filesystem

options = options, that i mentioned above

dump = dump should make a copy of the file system or not, 0 means no, 1 means yes

pass = fsck decides by this that in what order it wants to check the filesystems, 1 is the root's, 2 is other file systems', in case of 0 the particular filesystem won't be checked

Unmounting is easier than mounting since just we have to give what we want to remove:

umount /dev/sda1 - we remove the first HDD/SSD's first partition.