DEPARTMENT OF COMPUTING

IT1100 : Introduction to Operating Systems

Chapter 15


What is a partition?

A partition is just a logical division of your hard drive. This is done to put data in different locations for flexibility, scalability, ease of administration, and a variety of other reasons.

One reason might be so you can install Linux and Windows side-by-side.


What is a partition?

Another reason is to encapsulate your data.


Linux Partitions

In Linux, a minimum of 1 partition is required for the /.

Mounting is the action of connecting a filesystem/partition to a particular point in the / root filesystem. I.e. When a usb stick is inserted, it is assigned a particular mount point and is available to the filesytem tree. - In windows you might have an A:, or B:, or C:, all of which point to different filesystems.


What is Swap?

If RAM fills up, by running too many processes or a process with a memory leak, new processes will fail if your system doesn’t have a way to extend system memory. That’s where a swap area comes in. A swap space is a hard disk partition where your computer can “swap out” data from RAM that isn’t being used at the moment and then “swap in” the data back to RAM when it is again needed. Although it is better to never exceed your RAM (performance takes a hit when you swap), swapping out is better than having processes just fail.


More on Swap

General rule of thumb is to have your swap space be 2x the size of your RAM (if you have less than 1GB of ram, otherwise the same size as RAM)

Windows and Mac OS have their own form of swap files.

Swap isn’t absolutely critical on newer Linux distros but may impact performance if you don’t have it.


More on disk partitions


More on disk partitions


Partitioning outside the installer

Partitioning can be done during the install and after installing as well.


Steps for partitioning

  1. Use cfdisk or another program to partition free space
  2. Run the mkfs command to format the partition(i.e. mkfs.ext2 /dev/sdb5)
  3. Create a mount point (i.e. mkdir testmount)
  4. Run the mount command (i.e. mount /dev/sdb5 testmount)

These steps are clarified during the assignment.


Making mounts persist

When issuing a mount command at the command line, the mount will only persist until the machine is rebooted. If we always want that particular mount to persist we can put an entry in /etc/fstab.

Ubuntu now uses UUID to identify partitions.


Making mounts persist

Why use a UUID instead of /dev/sda1 to identify the device? Say that that you plugged another disk into your computer and booted up. It probably won’t happen, but it is possible that the new disk might be identified as /dev/sda, causing the system to look for the contents of /boot on the first partition of that disk.

This is why the partitions created during installation are identified by a UUID in the /etc/fstab file.

To find out what the UUID is for all devices we can use the block id command:


Making mounts persist

Here is an example entry using the device name instead of the UUID.

Here is a short explanation:


MSDOS


What is the MBR - Old Way

The information about how a hard disk has been partitioned is stored in its first sector (that is, the first sector of the first track on the first disk surface). The first sector is the master boot record (MBR) of the disk; this is the sector that the BIOS reads in and starts when the machine is first booted. The master boot record contains a small program that reads the partition table, checks which partition is active (that is, marked bootable), and reads the first sector of that partition, the partition’s boot sector (the MBR is also a boot sector, but it has a special status and therefore a special name). This boot sector contains another small program that reads the first part of the operating system stored on that partition (assuming it is bootable), and then starts it.


What is the GPT - New Way

To see which partitioning scheme we are using use the following command: sudo parted -l. If we see the ms-dos partition table this is what we are using which is the old MBR method. If you see gpt, you are using the GPT, GUID partition table.

Advantages to the GPT:


Creating a filesystem

After we create the partition, we then proceed to put a filesystem on it. This is accomplished with the mkfs command (or some derivative). What types are available?


Inodes

First watch this video.

The filesystem is made up of inodes - a slot that contains metadata about a file. The inode contains the following.


Inodes

df -i will show us how many inodes we have and how many are available to us.


Viewing inodes

All unique files and directories on the same partition will have a unique inode number

The first number you see on each line is the inode number. The reason you see multiple “1’s” and “2’s” is because of the system partitions created when the computer starts.


Viewing inodes

If you find two filenames on the same partition with the same inode number then the files are not actually different files, but the same file with different names. Such as a hardlink link. Once created, a hardlink will always link to the file using the inode number even if you rename, move or delete the original filename.

Symbolic links, however, get a unique inode number and link to the name of the file not the file itself. So if you change the original filename the symbolic link is broken.


Viewing inodes

If they have the same inode number and you know for sure that they are not the same file, then they are on different partitions.

Log into scratch -


Viewing inodes

Examine inode numbers of the files -

Files can have multiple names. This is why the inode doesn’t store the filename.


Renaming and Moving Files

A file’s inode number stays the same when we rename the file and when moved to another directory on the same device(partition).


Renaming and Moving Files


Renaming and Moving Files

Choose one of the inode numbers and do a search. - find / -inum 147649


Where is the NAME of the file?

The filename or path of the file is NOT in the inode. It’s NOT in the data blocks (With the contents of the file on the Hard Drive). It’s in the metadata of the directory.

You see, the metadata of the directory contains a table of the filenames in the directory, and the matching inodes. Think of it as a table, and the first two entries are always “.” and “..” The first points to the inode of the current directory, and the second points to the inode of the parent directory. The remainder of the entries in the table are the directories and files within the current directory.


Where is the NAME of the file?

When you move or rename a file within the same partition, you don’t actually move the data (contents). That would be Slow. You just create the -name,inode- entry in a new directory, and delete the old entry inside the old directory. In other words, moving a gigabyte file takes very little time. In the same way, you can move/rename directories very easily. That’s why “mv /usr /Old_usr” is so fast, even though “/usr” may contain (for example) 57981 files.

When you copy a file - it does create a duplicate of the same data and the copy gets its own inode number. To copy a gigabyte file or directory takes time because every byte must be copied.


Where is the NAME of the file?

When you create a hard link, it just creates a new name in the table linked to an already existing inode number without moving or copying the file. So if you move, rename or delete one of the hardlink names - all other names linked to that inode still work and the data is still accessible.

Symbolic links break when you move, rename, or delete the file that it links to because they are linked to the filename not the inode number.


Where is the NAME of the file?


Where is the NAME of the file?


Inode Metadata

Run the command ls -la ~/inode-fun. What is the field after the permissions? This is count of hard links to the file.

Look at this output - Yours will look slightly different:

    drwxrwxr-x  3 joe  joe        4096 Oct 22 11:43 .
    drwxrwxr-x 10 joe  joe        4096 Oct 20 11:20 ..
    -rw-rw-r--  2 joe  joe          22 Oct 22 11:23 inode-hardink
    lrwxrwxrwx  1 joe  joe          14 Oct 22 11:21 inode-symlink -> sunshine.txt
    drwxrwxr-x  6 joe  joe        4096 Oct  6 10:15 it1100
    -rw-rw-r--  1 joe  joe          64 Oct 22 11:21 rain-hardlink
    lrwxrwxrwx  1 joe  joe           7 Oct 22 11:43 sun-symlink -> sun.txt
    -rw-rw-r--  1 joe  joe          64 Oct 22 11:43 wind.txt 

Inode Metadata

Last Updated 03/27/2020