Filesystems
- What are they?
- methods and data structures that an OS uses to keep track of files
- organizes data on disk
Disks and File Systems
Steps:
- Install a physical drive
- Partition it
- Create a file system on the partition
- Mount the filesystem in the root partition
- Use FS
- Umount FS
HDD Disk terms
- track is circular path on the surface of a disk
- sector is a subdivision of a track
- block is a group of sectors that the operating system can address (point to). A block might be one sector, or it might be several sectors (2,4,8, or even 16). The bigger the drive, the more sectors that a block will hold.
- RPMs?
Physical HDD
Physical SSD
- Do not rely on moving parts or spinning disks
- Data saved to NAND flash
- Has a type of transistor that allows it to maintain state even when no power is supplied.
Physical SSD Terms
- Cell - storage location of bits
- SLC = Single-level cell = one bit per cell
- MLC = multi-level cell = 2 bpc
- TLC = triple-level cell = 3 bpc
- QLC = quad-level = 4 bpc
- Interestingimage and image
Physical SSD Terms
A few more SSD tidbits
- see this
- The important pieces
- block = smallest unit that can be erased. (4 - 8MB?)
- pages = smallest unit that can be written to.
- Each page contains anywhere from 512 – 4,096 bytes (1 byte = 8 bits). Some cells hold just one bit, while others contain up to three depending on the SSD.
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?
- Different OS’s on each partition(multi-boot setups)
- Separate system data from user space data (i.e. home drives)
- Protection (in case of failure, or corruption)
- Able to grow or resize partitions
- Better performance (size of files can determine block sizes across a partition)
More reasons for partitioning (from tldp.org)
Encapsulate your data. Since file system corruption is local to a partition, you stand to lose only some of your data if an accident occurs.
Increase disk space efficiency. You can format partitions with varying block sizes, depending on your usage. If your data is in a large number of small files (less than 1k) and your partition uses 4k sized blocks, you are wasting 3k for every file. In general, you waste on average one half of a block for every file, so matching block size to the average size of your files is important if you have many files.
More reasons for partitioning (from tldp.org)
- Limit data growth. Runaway processes or maniacal users can consume so much disk space that the operating system no longer has room on the hard drive for its bookkeeping operations. This will lead to disaster. By segregating space, you ensure that things other than the operating system die when allocated disk space is exhausted.
Disadvantages of partitioning
- Reduces the total amount of disk space available to the user.
- Increases disk fragmentation?
- Moving files across partitions will require copying of bytes (slower)
Partition Questions
- How many partitions can I have?
- How many do I need?
- Is a drive equal to a partition?
- Is a partition equal to a drive?
MBR = An important partition
MBR is the Master Boot Record.Overview
- Should always be located on the first sector of a hard disk
- contains the disks master partition table
- contains information on what should the system boot next?
- Where is the bootable partition?
- In Linux, this might be stage 1 of Grub.
MBR
Booting
- BIOS?
- POST : BIOS readies various hardware, simple tests done
- could hand off to raid controller or other hardware for init steps
- After handling basic input/output devices of PC, could make selection as to what to boot, or if no selection, BIOS tries to ‘boot’ utilizing preconfigured or default ‘boot device’
- First 512 bytes or MBR of boot device are loaded (usb, disk, other)
MBR
MBR
MBR is configured with a ‘bootable’ partition. So the system will read the first 512 bytes of that partition to figure out what to do next. -> load the bootloader into memory (i.e. Grub, ntldr, bootmgr).
This second stage bootloader is stored on a file on disk
Bootloader
Bootloader
MBR problems
- Maximum addressable storage space is 2TiB
- So, slowly being superseded by the GUID partition table (more on this later)
Partition Details
- MBR originally supported up to 4 primary partitions
- Newer revision allowed one of these 4 to be used as an extended partition
- Any number of logical may be created in the extended partition
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.
Linux Partitions
- In Linux, at least 1 partition is required for the
/
.
Mounting
is the action of connecting a filesystem 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.
More about devices
- Device naming conventions
- IDE drives will be assigned
/dev/hda
through /dev/hdd
- Those drives can then in-turn be partitioned.
/dev/hda1
#first partition on hda
- SCSI drives will be assigned
/dev/sda?
or /dev/sdb?
- Serial ATA will show up like SCSI disks do
Partition tools
- parted
- fdisk
- sfdisk
- cfdisk
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:
- ext3: old linux
- ext4: linux default
- ntfs: windows default
- vfat: flash drives, cameras, minimal
- fat: old dos (windows)
- etc …
Filesystems vs Partitions
The difference between a disk or partition and the filesystem it contains is important. A few programs (including, reasonably enough, programs that create filesystems) operate directly on the raw sectors of a disk or partition; if there is an existing file system there it will be destroyed or seriously corrupted. Most programs operate on a filesystem, and therefore won’t work on a partition that doesn’t contain one (or that contains one of the wrong type).(TLDP)
Creating
Before we can use a disk or a partition as a Filesystem, it needs to be formatted… What does this mean?
- Sets up a logical structure on the disk to store information and files (mkfs)
Steps for partitioning More Detailed
- Use cfdisk or another program to partition free space
- Run the
mkfs
command to set up the filesystem(i.e. mkfs.ext2 /dev/sdb5)
- Create a mount point (i.e.
mkdir testmount
)
- Run the mount command (i.e.
mount /dev/sdb5 testmount
)