4.1.file System and Disk Partitions
4.1.file System and Disk Partitions
●
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
●
Samba package
The xfs file system format
$ 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.
$ 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.
$ 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
●
Process
Partition management
●
Naming of partitions
Swap partitions
Partitioning guidelines
Partitioning examples
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
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
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
●
●
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
–
●
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,
–
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
/boot partition Linux root partition Linux swap Linux /opt partition
/dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3 /dev/nvme0n1p4
/home partition
/dev/nvme0n2p1
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
(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
# 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
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
# mke2fs -j /dev/nvme0n1p3
# mkfs.xfs /dev/nvme0n1p3
●
To Create an ext4 file system
# mkfs.ext4 /dev/nvme0n1p3
Creating a file system
●
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
# 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
# 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)
# 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
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)
●
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
●
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
–
●
By default, only root can mount and unmount file systems
There is a common requirement to allow non-root users to mount and
–
●
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
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
●
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