Disks and File Systems

Steps:


What is a partition?

A logical division of a hard disk. The OS treats a partition as if it were a distinct physical device.


Why partition?


More reasons for partitioning (from tldp.org)


More reasons for partitioning (from tldp.org)


Linux Partitions


Partition Details


Primary vs Logical

One primary partition of a hard drive may be subpartitioned. These are logical partitions. This effectively allows us to skirt the historical four partition limitation.

The primary partition used to house the logical partitions is called an extended partition and it has its own file system type (0x05). Unlike primary partitions, logical partitions must be contiguous. Each logical partition contains a pointer to the next logical partition, which implies that the number of logical partitions is unlimited. However, linux imposes limits on the total number of any type of partition on a drive, so this effectively limits the number of logical partitions. This is at most 15 partitions total on an SCSI disk and 63 total on an IDE disk.


More about devices


Partition tools


Filesystem Types

Once we have partitioned the disk, then we choose the way it should be formatted. What type of data organization do we want on the disk?

Types to choose from:


The EXT filesystem


The EXT filesystem tools


What is an inode?


Viewing inodes


More testing with inodes


Other inode implications


More Inode stuff

Where is the NAME of the file. Or the Path? It’s NOT in the inode. It’s NOT in the data blocks. It’s in the directory. That’s right. A “file” is really in three (or more) places on the disk.

You see, the directory is just a table that contains the filenames in the directory, and the matching inode. 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.


One more piece of information

When you create a hard link, it just created a new name in the table, along with the inode, without moving the file. When you move a file (or rename it), you don’t copy the data. That would be Slow. You just create the (name,inode) entry in a new directory, and delete the old entry in the table inside the old directory entry. 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.


Inode Examples


Inode Examples


Finding with inodes.


Which filesytem type should I use?


Steps for partitioning More Detailed

  1. Use cfdisk or another program to partition free space
  2. Run the mkfs command to set up the filesystem(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)

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.


Fstab explained

Here is a short explanation:


One more note about fstab

Ubuntu now uses UUID to identify partitions. To find out what the UUID is for a particular device we can use:

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.


What is the MBR

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.


Side Note about MBR Partitioning

We have been examining how partitioning has been done using the MBR. To see if we are in-fact using the MBR partitioning scheme we can do a sudo parted -l. If we see the ms-dos partition table this is what we are using.

There are new and better alternatives to using the MBR partition table such as the GUID partition table (GPT).