How To use Linux Filesystems and Files

*How to make a symbolic link

The command ln -s creates a symbolic link to a file. For example, if you use the command

ln -s myfile pointer

you will create a symbolic link named "pointer" that points to the file "myfile". If you use "ls -i", the two files are listed with different inodes.

ls -i myfile pointer
180506 myfile 180507 pointer

By using "ls -l", the file "pointer" is shown as a symlink pointing to "myfile".

ls -l myfile pointer
lrwxrwxrwx 1 root root 5 Feb 28 17:18 here -> there
-rw-r--r-- 1 root root 5 Feb 28 17:17 there

+How to mount a DOS filesystem

  1. Determine where your dos file system is (This assumes, you can boot to it using lilo).
    1. Type "less /etc/lilo.conf"
    2. Look for the label used by lilo to select dos, such as "dos" and use the associated device. The line on my system is "other=/dev/hda1" so I will use device "/dev/hda1".
  2. Make a subdirectory "/dos" by typing "mkdir dos"
  3. Do the mount by typing "mount /mnt/hda1 /mnt/dos t msdos". To let all users have permission to use the dos partition, type "mount t vfat user,rw,exec,umask=000 /dev/hda1 /mnt/dos".
  4. Edit your /etc/fstab file to include:

    /dev/hda1 /dos vfat defaults 0 0

How to determine file systems already mounted

Type "less /etc/fstab" or "less /etc/mtab". The contents of this file tells all filesystems, their type, etc. The fstab file lists files systems that are mounted when the system started. The mtab file is where the mount command stores the list of filesystems mounted.

+How to determine room used and left on filesystems

df - Disk free space.
du - Disk usage.

*How to set up and mount an NFS filesystem

Server Setup
To set up the server side, edit the file "/etc/exports" as in one of the examples below then type "exportfs -a". Also activate NFS services using linuxconf.
This is the first attempt which is an example of one way to do it:

/tftpboot/10.1.3.116		linux1(rw,no_root_squash)
/tftpboot/filesystems/usr	*.mycompany.com(ro,root_squash)
/tftpboot			linux2(rw,no_root_squash)
/tftpboot			linux3(rw,no_root_squash)
/data				linux4(rw,no_root_squash)

This is the way remote booting was set up for nfs:

/tftpboot/lts/ltsroot	10.1.0.101/255.255.0.0(ro,no_root_squash)
/tftpboot/lts/ltsroot	10.1.200.1/255.255.0.0(ro,no_root_squash)
/tftpboot/lts/ltsroot	10.1.200.2/255.255.0.0(ro,no_root_squash)
/tftpboot/lts/linux3	10.1.200.2/255/255.0.0(rw,no_root_squash)

For a remote boot machine, "linux3", after making a /tmp/mnt directory, type "mnt -n 10.1.0.100:/tftpboot/lts/linux3 /tmp/mnt -t nfs". The -n is only needed if the /etc directory is read only.

For a full explanation of the above options and when to use the no_root_squash option, read "The CTDP Linux User's Guide".

Client Setup
To set up the client side on a fully functional Linux machine type "mount -o rsize=1024,wsize=1024 mymachine:/data /mnt/mymachine/data

*How to format a linux floppy

  1. Type "fdformat /dev/fd0H1440" to format the floppy.
  2. To make a filesystem on the disk type "mkfs -t filesystem -c /dev/fd0H1440" where filesystem is the type of filesystem, usually ext2 (linux native).
  3. Mount the filesystem "mount -t ext2 /dev/fd0 /mnt/floppy".
  4. Use the filesystem by copying to/from /mnt/floppy.

*How to make a file system

Making a swap partition

type "mkswap -c /dev/hda3 10336"

The -c has swap check for bad blocks. The 10336 is the size of the partition in blocks, about 10M. The system enables swap partitions at boot time, but if installing a new system you can type "swapon /dev/hda3" to enable it immediately.

Making an ext2 file system on a floppy

  1. fdformat /dev/fd0H1440
  2. mkfs -t ext2 -c /dev/fd0H1440

Other file systems:
A normal hard drive can have many types of filesystems on it. To create an ext2 file system, type "mke2fs -c /dev/hda2 82080" to create an 82 meg filesystem. Note: mkfs is a front end to many file system types including ext2, minux, and msdos.

*How to check a file system

fsck - Used to check and repair a filesystem.
fsck is a front end to a filesystem type specific fsck.ext2, fsck.minix, and fsck.msdos.
Syntax: fsck -t type device

Ex: fsck -t ext2 /dev/hda3

The program fsck should never be run on a mounted filesystem with write permission since it can damage the filesystem. Unmount the filesystem before running fsck or be sure it is in read only mode.

*How to copy/remove a folder and all its contents with subdirectories

To copy type "cp dpr sourcefile destinationfile"
To remove type "rm rf directoryname"

*Copying a drive

dd if=/dev/hdb1 of=/backup/
cp -dpr / /backup

*Finding files

The locate command allows you to find any filename containing a string you type in. This is database driven, so it's fast. To initially load the database, do the following command, which will take a couple minutes or so to run:

slocate -u

Thereafter, type "locate filename" where "filename" is the name of the file you want to find.

The whereis command is very useful for finding binary programs and their associated man pages.

Redirecting Program output

The shell assigns the number 1 to standard output, and 2 to standard error output.

gcc test.c >& errorsRedirects stdout and stderr to the file errors.
gcc test.c &> errorsSame as above
gcc test.c 2> errorsRedirects error messages to the file errors
gcc test.c 2>errors >/dev/nullRedirects errors to the file errors and throws away the standard output messages.

See the bash(1) man page for more information on redirection of standard output and standard error.

Making a simple Emergency boot floppy

How to make a single boot floppy:

  1. Find the kernel. It is usually /vmlinuz or /boot/vmlinuz. The file vmlinuz may be a softlink to the actual kernel executable. Find the executable kernel.
  2. Copy the kernel image to the floppy.

    dd if=/vmlinuz of=/dev/fd0

  3. Type the command "df" and examine it's output to determine where your root filesystem is. Your root is "/" and is mounted on something like "/dev/hda2".
  4. Set the kernel image on the floppy to the location of your root system.

    rdev /dev/fd0 /dev/hda2

    Your root filesystem may be somewhere other than "/dev/hda2".

  5. Test the floppy by rebooting your system and attempting to boot from it. You can use the command "badblocks /dev/fd01440 1440" to check the floppy for badblocks.

Setting up Removable and External Filesystems to Automatically mount when used

  1. The program "autofs" must be setup to run as a daemon upon system startup. To do this with Redhat Linux, use the program "linuxconf" and select "Control", "Control panel", "Control Service activity". Activate "autofs" using the menu selections.
  2. Edit the file "/etc/auto.master" to the following:
        /mnt     /etc/auto.misc   --timeout 20
    

    The above example sets the program to unmount the device after 20 seconds.

  3. Edit the file "/etc/auto.misc" adding lines like:
          cd	-fstype=iso9660,ro	:/dev/cdrom
          fl	-fstype=auto		:/dev/fd0
    

    This will cause the cd-rom to be mounted when you access the directory "/mnt/cd" and the floppy to be mounted when you access "/mnt/fl". The directories "/mnt/cd" and "mnt/fl" must not exist in order for this to work.

  4. To use automount, put a cd in the CD-ROM drive and type "ls /mnt/cd" or "cd /mnt/cd".
Linux Howtos Contents Page