Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
40 views

4.1.file System and Disk Partitions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

4.1.file System and Disk Partitions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

File system types

File system types


Native linux file system formats

File system formats of other systems

Network file system formats

The xfs file system

The ext2, ext3, and ext4 file system

The virtual file system


Native linux file system formats


Linux supports many file system formats

ext2
– Probably the most common 'native' linux file system format

ext3
–Extension of ext2 to support journaling (log of changes), backwards
compatible
– Much faster to check file system consistency after a crash

ext4
ext4 file system is based on the ext3 file system and features a number

of improvements

Xfs
– xfs - is a highly scalable, high-performance file system
-This file system is selected by default and is highly recommended
File system formats of other systems


Linux also supports the native file systems of other operating systems
– Useful on dual-boot systems

FAT, VFAT
– Used on floppies, and Windows 95/98

NTFS
– Used on Windows NT, 2000, XP
– Under linux, only read access is supported reliably

HPFS
– Native file system of OS/2

CDROM
– ISO9660 with Joliet and Rockridge extensions
Network file system formats

Linux can also mount file systems from remote file servers using a

number of file sharing protocols



NFS (Network File System)
– The native UNIX file sharing protocol, originally from Sun Microsystems

SMB (Server Message Block)
The native Windows file sharing protocol, supported on linux by the

Samba package
The xfs file system format

• xfs - is a highly scalable, high-performance file system that supports


file systems up to 16 EiB (approximately 16 billion GiB), files up to 8
EiB (approximately 8 billion GiB), and directory structures containing
tens of millions of entries. Xfs ( from silicon graphics).

• XFS supports metadata journaling, which facilitates quicker crash


recovery. The XFS file system can also be defragmented and resized
while mounted and active.

• This file system is selected by default and is highly recommended.

• The maximum supported size of an XFS file system in Red Hat


Enterprise Linux is currently 1024 TiB.

$ mkfs.xfs /dev/nvme0n1p3
The ext4 file system format

• ext4 - The ext4 file system is based on the ext3 file system and
features a number of improvements.

•These include support for larger file systems and larger files, faster and
more efficient allocation of disk space, no limit on the number of
subdirectories within a directory, faster file system checking, and
more robust journaling.

•The maximum supported size of an ext4 file system in Red Hat


Enterprise Linux is currently 50 TiB.

$ mkfs.ext4 /dev/nvme0n1p3
The ext3 file system format

• ext3 — The ext3 file system is based on the ext2 file system and has
one main advantage -journaling.

• Using a journaling file system reduces time spent recovering a file


system after a crash as there is no need to check the file system for
metadata consistency by running the fsck utility every time a crash
occurs.

• The maximum supported size of an ext3 file system in Red Hat


Enterprise Linux is currently 16 TiB

$ mke2fs -j /dev/nvme0n1p3
The ext2 file system format


ext2 — file system supports standard Unix file types, including
regular files, directories, or symbolic links.
• It provides the ability to assign long file names, up to 255 characters.
• The maximum supported size of an ext2 file system in Red Hat
Enterprise Linux is currently 16 TiB

$ mke2fs /dev/nvme0n1p3
The virtual file system

The linux kernel provides a virtual filesystem layer which hides the

differences between the physical filesystem layouts


– Supports standard UNIX open/close/read/write operations
Provides illusion of UNIX filesystem semantics (e.g. rwx-style access

permissions on FAT filesystems)

Process

Virtual Filesystem Layer

FAT reiser ext4 JFS VFAT NFS SMB

Floppy Hard disk partition Network


Partition management

Partition management

Naming of IDE and SCSI drives

Naming of partitions

Swap partitions

Partitioning guidelines

Partitioning examples

Creating partitions with fdisk

Creating and mounting a file system


Naming of IDE drives

Disk drives and partitions have names in the /dev directory


Modern PCs are able to connect up to 4 IDE drives:


Primary Secondary
IDE Interface IDE Interface

Master Master
/dev/hda /dev/hdc
On a typical PC with
one hard drive and
one CD or DVD drive,
Slave Slave
the CD/DVD may be
/dev/hdb /dev/hdd
connected as hdb or
hdc
Naming of SCSI drives


SCSI controllers can handle multiple drives
– They are simply named in order

SCSI controller

Note: Linux sometimes emulates


First device
other devices as SCSI devices;
/dev/sda
e.g. USB memory sticks or
digital cameras

Second device
/dev/sdb

Third device
/dev/sdc
Naming of SCSI drives on Red hat 8


SCSI controllers can handle multiple drives
– They are simply named in order

SCSI controller

Note: Linux sometimes emulates


First device
other devices as SCSI devices;
/dev/nvme0n1
e.g. USB memory sticks or
digital cameras

Second device
/dev/nvme0n2

Third device
/dev/nvme0n3
Naming of partitions


Originally, PCs allowed a maximum of four partitions on a hard drive
– To allow more, one partition can be designated an extended partition
– Multiple logical partitions can be placed within the extended partition
Linux numbers the primary partitions 1, 2, 3 and 4, and the logical

partitions are numbered starting at 5 (even if there are less than 4


primary partitions)

These examples are for a machine with IDE drives:
FIrst drives has
hda1 hda2 hda3 three primary
partitions

Second drive has


hdb1 hdb5 hdb6
hdb2 hdb7 one primary,
one extended,
and three
logical partitions
Swap partitions


It is normal to allocate one or more partitions as swap partitions
– Swap partitions do not contain a filesystem
They are used to increase the available virtual memory space on the

machine beyond the amount of RAM (random access memory)



How big should the swap partition be?
– Hard to give generic advice
A common rule of thumb is to make swap twice the size of RAM for < 2G

and an additional 1X RAM for any more


– Performance degrades significantly if the system does a lot of swapping
Since memory is relatively cheap, a better guideline might be to put

enough RAM in the machine so that it never swaps at all



Partitioning guidelines


The simplest partitioning scheme is to put the entire file system into the
root partition
– Easy, no need to make any up-front decisions about partition sizes

However, there are good reasons for using more partitions
–Keeping the root partition small minimises the amount of file system
that must be intact and available for the system to boot successfully
–Partitions provide a crude way to impose disk space quotas on pieces of
the file system
Partitions are the “unit of administration” of the file system (e.g. Repair,

backup and restore of the file system is on a per-partition basis)


Partitions for “static” pieces of the filesystem (e.g. /usr) can be

mounted read-only, improving security


If your file system spans multiple hard drives, you necessarily have

multiple partitions
Partitioning guidelines (continued)


Directories essential for booting must be on the root partition
– /bin, /sbin, /etc, /lib, ...

Other directories are candidates for being on separate partitions
– /usr May be mounted readonly. Suggested minimum size 2 Gbytes
– /var
– /boot On early PCs this partition needs to be within the first 1024
cylinders. Suggested minimum size 50 Mbyte.
– /home On a server, this partition may be exported to client machines
This is likely to be the largest partition
/tmp Hard to give a specific guideline on the size but 1 Gbyte is

probably
more than enough
– /opt
Partitioning example: dual-boot desktop machine

Small desktop machine with 20 Gbyte hard drive


Windows partition Linux root partition Linux swap


/dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3

10 Gbytes 9.5 Gbytes 512 Mbytes


Partitioning example: server with two hard drives

Server machine with two 80 Gbyte hard drives


/boot partition Linux root partition Linux swap Linux /opt partition
/dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3 /dev/nvme0n1p4

50 Mbytes 5 Gbyte 1 Gbyte 74 Gbyte

/home partition
/dev/nvme0n2p1

80 Gbytes – exported to clients via NFS


Creating partitions with fdisk, gdisk
The command-line tool fdisk allows manipulation of the partition table

on a hard drive
– Has a rather clunky user interface
– The following slides show a typical dialog

Can be used non-interactively to list the partition table:
# fdisk -l
Disk /dev/nvme0n1: 40 GiB, 42949672960 bytes, 83886080 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x3ca3de2a

Device Boot Start End Sectors Size Id Type

/dev/nvme0n1p1 * 2048 3907583 3905536 1.9G 83 Linux

/dev/nvme0n1p2 3907584 46899199 42991616 20.5G 8e Linux LVM


Creating partitions with parted
The GNU parted is a partitioning tool that works with MBR, GPT, APM,

and BSD disk labels, and other disk types.



You start GNU Parted much as you start fdisk; that is, by typing its name
followed by the device you want to modify /dev/nvme0n1

To use parted to create a GPT disk, use the mklabel command
(parted) mklabel gpt

Then to create a new partition, use the mkpart command:
(parted) mkpart primary ext4 1024kb 2tb
# parted /dev/nvme0n1

GNU Parted 3.2 (Section Omitted)

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) print
– Disk Flags:
– Number Start End Size Type File system Flags
– 1 1049kB 2001MB 2000MB primary xfs boot
– 2 2001MB 24.0GB 22.0GB primary lvm

Creating partitions with cfdisk

The tool cfdisk provides a slightly better interface



Creating partitions with fdisk

# fdisk /dev/nvme0n1
Display the existing
Command (m for help): p
partition table
Disk /dev/nvme0n1: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3ca3de2a

Device Boot Start End Sectors Size Id Type


/dev/nvme0n1p1 * 2048 3907583 3905536 1.9G 83 Linux
/dev/nvme0n1p2 3907584 46899199 42991616 20.5G 8e Linux LVM
Command (m for help): n
Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e): e Create an extended partition
spanning the whole of
Selected partition 4 the rest of the disk
First sector (48852992-83886079, default 48852992):
Last sector, +sectors or +size{K,M,G,T,P} (48852992-83886079, default

Created a new partition 4 of type 'Extended' and of size 16.7 GiB.


Creating partitions with fdisk (continued)

Create a logical partition


Command (m for help): n (sda5) of 500 Mbytes
All primary partitions are in use.
Adding logical partition 5
First sector (48855040-83886079, default 48855040):
Last sector, +sectors or +size{K,M,G,T,P} (48855040-83886079, default 83886079):
+1G

Created a new partition 5 of type 'Linux' and of size 1 GiB.

Redisplay the partition


Command (m for help): p table to verify
Disk /dev/nvme0n1: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3ca3de2a

Device Boot Start End Sectors Size Id Type


/dev/nvme0n1p1 * 2048 3907583 3905536 1.9G 83 Linux
/dev/nvme0n1p2 3907584 46899199 42991616 20.5G 8e Linux LVM
/dev/nvme0n1p3 46899200 48852991 1953792 954M 83 Linux
/dev/nvme0n1p4 48852992 83886079 35033088 16.7G 5 Extended
/dev/nvme0n1p5 48855040 50952191 2097152 1G 83 Linux
Creating partitions with fdisk (continued)

Finally, the new partition


Command (m for help): w table is written to the disk
The partition table has been altered. and fdisk exits
Failed to add partition 5 to system: Device or resource busy

The kernel still uses the old partitions. The new table will be used a
Syncing disks.

#partprobe

It is apparently necessary
to reboot to force the
kernel to use the new table
Creating a file system

After creating a partition you need to build a filesystem on it


mke2fs - create an ext2/ext3/ext4 filesystem


For example, to build an ext3 filesystem on /dev/nvme0n1p3


# mke2fs -j /dev/nvme0n1p3

-j specifies that a journal Specifies the inode The partition name


should be created. Without density in bytes per
this, an ext2 file system is inode. (It's usually
created OK to accept the
default)

To create an xsf file system on /dev/nvme0n1p3


# mkfs.xfs /dev/nvme0n1p3

To Create an ext4 file system
# mkfs.ext4 /dev/nvme0n1p3
Creating a file system

After creating a partition you need to build a filesystem on it



To Create an ext4 file system
# mkfs.ext4 /dev/nvme0n1p3
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and
65536 inodes
Filesystem UUID: 8b65e3df-f860-4e12-9cde-
e3ff8be45e5d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting
information: done
Creating a file system

After creating a partition you need to build a filesystem on it


To create an xsf file system on /dev/nvme0n1p3


# mkfs.xfs /dev/nvme0n1p3
meta-data=/dev/nvme0n1p5 isize=512
agcount=4, agsize=65536 blks
= sectsz=512
attr=2, projid32bit=1
= crc=1
finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096
blocks=262144, imaxpct=25
= sunit=0
output omitted…...
Mounting a file system


Our new partition must be mounted before it can be accessed

If necessary, create a mount point first:
# mkdir /media/new1

Now attach the partition to the mount point:
# mount /dev/nvme0n1p3 /media/new1

Finally, we can copy some files onto the new partition, for example:
# cp -r /usr/share/man /media/new1

To unmount the partition:
# umount /dev/nvme0n1p3 Note the command is
umount not unmount
– Or ...
# umount /media/new
Exercise: Creating new partitions

In this exercise we will create two new disk partitions, each of 500 Mbytes, on
the free space on the hard drive. We will format one of these partitions as an
ext4 file system and the other as an xfs file system. Create the first partition
using fdisk:

1. Log in as root

2. Enter the command:

# fdisk /dev/nvme0n1
3. At the fdisk command prompt, enter the command 'p' to show the current
partition table.
How many partitions are currently defined? _____________________________
What are the device names of these partitions? _________________________
What is the highest cylinder number on the hard drive? __________________
What is the highest cylinder number currently in use in a partition? _______
continued ...
Exercise (continued)

4. Following the example in the notes, use fdisk to create an extended partition
(sda4) spanning the whole of the remaining free space on the disk
5. Print the partition table to verify the result.
Write down the device name of your new partition: _____________________
6. Write out the partition table and exit from fdisk
7. Back at the shell prompt, enter the command 'partprobe'.
8. After the machine has rebooted, log back in as root.
9. Following the example in the notes, create an xfs filesystem on the new
partition.
( Be very careful not to re-format any of the other partitions. If you are in any
doubt what the device name of the new partition is, ask your instructor.)
Exercise (continued)

Write down the command you used:


_______________________________________
11. Create a mount point called “/new1” for the new partition:

Write down the command you used: ______________________________


12. Mount the new filesystem onto the new mount point.
Write down the command you used: _____________________________
13. Run the command

# ls -a /new1
What directory exists on an empty xfs file system? ______________________

End of exercise
Partitioning using GUI


GNOME comes with a partitioning tool called “Disks”
– Start disk utility by typing disk in search show applications
– You need to create a free space using fdisk first

Partitioning using GUI


GParted enables point-and-click partition management, including
partition moving and resizing.
$ apt-get install gparted
Mount options and the fstab file


Mount options and
the fstab file
Mount options

The fstab file


Mounting removable media
Mount options

Mount has many options. Here are a few:


Option Meaning
-r Mount the partition read-only
Mount a f ile system of the specif ied type (for example, ext2, ext3,
-t type iso9660, msdos, nfs, reiserfs, smbfs) Normally not necessary as mount
will f igure out the f ile system type automatically
-a Mount all the f ile systems listed in /etc/fstab
-o noexec Do not allow f iles on this f ile system to be executed
-o nodev Do not allow device f iles to be recognised on this f ilesystem
-o nosuid Do not allow programs on this f ile system to run “set user ID”
-o ro Mount the partition read-only (same as -r)
-o remount Remount the partition (e.g. To change from read-only to read-write)

Options following -o can be combined in a comma-separated list, e.g.


# mount -t ext2 -o ro,nodev,noexec /dev/nvme0n1p3 /data1


The /etc/fstab file


The /etc/fstab file helps automate the mounting of file systems

Entries in the file serve two purposes
– They specify file systems to be mounted automatically at boot time
–They associate a set of mount options and a mount point with a file
system allowing it to be mounted using only a single argument to mount
$ vi /etc/fstab

#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more
info
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=82026ef6-f464-4f88-b137-a0e87feeb531 /boot xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/sr0 /media/cdrom0 auto defaults 0 0

Partition Mount Filesystem Mount Dump and fsck


name point type options parameters
Mount options in the fstab file


The fourth field in fstab supplies options to use with the mount
command.

The noauto option
Specifies that the file system is not to be mounted at boot time. The

purpose of such entries is to simplify the mount command. For example


with fstab as shown, either of the commands
$ mount /dev/fd0
$ mount /media/floppy
– Would be taken to mean:
$ mount -o noauto,user,sync /dev/fd0 /media/floppy
Mounting removable media


By default, only root can mount and unmount file systems
There is a common requirement to allow non-root users to mount and

unmount removable media such as floppies, CDs and DVDs


–The user option allows ordinary users to mount and unmount this
filesystem. (Once mounted, only the user who mounted it can unmount
it)

Removable media allow the introduction of 'uncontrolled' files and may
carry security risks; e.g.
– A shell owned by root with the setuid bit on
– A device file entry for /dev/hda1 with mode rw-rw-rw
– Any malicious executable

There are mount options to eliminate these risks:
– nosuid, nodev, noexec
– The user option implies nosuid, nodev and noexec
Mounting flash drive

Use fdisk -l to see the list of partitions in your system.
# fdisk -l
Disk /dev/sda: 255 heads, 63 sectors, 3648 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System


/dev/sda1 * 1 784 6297448+ 83 Linux
/dev/sda2 785 850 530145 82 Linux swap


Plug the flash drive on the virtual machine and issue fdisk -l again
# fdisk -l
Disk /dev/sda: 255 heads, 63 sectors, 3648 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System


/dev/sda1 * 1 784 6297448+ 83 Linux
/dev/sda2 785 850 530145 82 Linux swap

/dev/sdb1 1 7557 60653552 c FAT32



Now we can mount it
# mkdir /media/flashdisk
# mount -t vfat /dev/sdb1 /media/flashdisk
Exercise: Modifying /etc/fstab

1. Modify your fstab so that the two partitions you previously created are
automatically mounted onto /new1 and /new2 when the system is
booted.
2. Reboot the system to verify.
Maintaining integrity of File Systems


Can run fsck to check or repair the filesystems of the target system
# fsck /dev/nvme0n1p3


du displays disk usage statistics for directories
# du /etc/rc.d
Option Meaning
-c show grand total
-a show all f ile not just directories
-h human readable format as M (Megabytes) or G(Giga bites)
-S include subdirectories too


df file system info
# df /dev/nvme0n1p3
Quiz


What is the device name for the slave IDE drive attached to the primary
IDE controller?
What is the device name for the first logical partition on the master IDE

drive attached to the secondary IDE controller?



In a long directory listing (i.e. The output of ls -l) what does it mean if
the first character on the line is a 'b'?
– In which directory might you find such an entry?
Give two reasons why you might prefer not to put the entire file system

of a linux system into the root partition



Assuming this line in /etc/fstab:
/dev/fd0 /media/floppy auto noauto,user 0 0
What do the options noauto,user mean?
True or False?

Linux can read the NTFS file system format as used by Microsoft

Windows
– Microsoft windows can read the ext2 file system as used by Linux
– On an ext2 file system the inode table is expanded on demand
– Only root can mount removable media into the file system
All the file systems listed in /etc/fstab are automatically mounted at

boot time

You might also like