You are on page 1of 35

Chapter - 3

File Systems and


Management of Data
Storages

1
Linux Disk Partitioning (fdisk, parted)

• In most cases, large storage devices are divided into separate


sections called partitions.
• Partitioning also allows you to divide your hard drive into isolated
sections, where each section behaves as its own hard drive.
• Partitioning allows the use of different file systems to be installed
for different kinds of files.
• The fdisk utility could be considered the classic disk partitioning
tool as it is available on several operating systems.
• The utility is called from the "root" user, passing the disk device as
a parameter.
2
Cont’d
• FDISK stands for Fixed Disk Editor, which means it edits the Fixed
Disk (hard drive, floppy disks are removable data and are NOT
fixed).
• FDISK is a tool that allows you to change the partitioning of your
hard disks.
• For example, you can make partitions for DOS, Linux, FreeBSD,
Windows 95, Windows NT, BeOS and many other types of operating
systems.

3
Cont’d

• FDISK is a command-line utility used to create, delete, and


manipulate disk partitions on a hard disk drive.
• It is available on various operating systems such as
Windows, Linux, and macOS.
• This utility is used to manage disk partitions and to set up
the file system on them.

4
Create a Partition
• To create a new partition use the "n" command. The following output shows the creation of a
primary partition using the whole disk.
The choices are highlighted in bold.
Command (m for help): n
Command action
e extended
p primary partition (1-4)p
Partition number (1-4): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519

5
Creating Partitions
• FDISK allows you to create partitions on a hard disk drive.
• You can create primary partitions, extended partitions, and
logical partitions.
• Primary partitions are used to install the operating system
and other software applications.
• Extended partitions are used to create logical partitions.
• Logical partitions are used to store data and files.
6
Cont’d
The above output shows we made the following choices:
n : Create a new partition.
p : We chose to create a primary partition. You can only have 4 primary partitions.
If the disks needs more than 4 partitions, the 4th primary partition should be converted
to a logical partition, so it can hold multiple extended partitions.
1 : We are creating the first primary partition.
We accepted the defaults for the first and last sectors meaning the partition will use
the full disk. If we wanted a specific size we could accept the default first sector, then
specify a size, like "+500M".
p : Display the current partition table. This is optional, but it's work doing to check
your settings are correct.
7
w : Write the partition table to disk and exit.
Hard disk partition

8
Cont’d
The new partition is now visible from the OS.
# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
#
❖Delete a Partition
To delete a partition use the "d" command. The following output
shows the deletion of the partition we just created.
# fdisk /dev/sdb
Command (m for help): p
9
To Delete a partition
➢ The call to "p" is not necessary, but it is worth checking what
partitions are present before attempting to delete them.
➢ In this case, as we only have a single partition, it was chosen by default
when we selected the "d" command.
➢ If there were more than one we would have been prompted to select a
partition number.
➢ After writing the changes to disk, the partition is no longer visible
from the OS.

# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
# 10
Boot Partitions
• Boot partitions are created in a similar way to regular partitions.
Typically you would only expect to create a boot partition during
installation, so you will probably do this using Disk Druid or
Kickstart.
• If you do use fdisk to create a boot partition, the typical size for
Linux boot partitions is 500M and remember to flip the bootable flag
using the "a" command before writing the partition table to disk.
• The output below shows the creation of a boot partition.
• The options are highlighted in bold.
• Notice the boot flag in the output from the "p" command
# fdisk /dev/sdb
11
Parted
• The parted utility is an alternative to fdisk.
• It can perform all the operations of fdisk, but it has additional
functionality, such as resizing and copying partitions and creating file
systems.
• The utility is called from the "root" user, passing the disk device as a
parameter.
• Typing help at the prompt lists the commands available.
# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) 12
Cont’d
When working with a new disk, the first thing we need to do is label the
disk using the mklabel command displayed bellow.
(parted) help mklabel
mklabel,mktable LABEL-TYPE create a new
disklabel (partition table)
LABEL-TYPE is one of: aix, amiga, bsd, dvh, gpt,
mac, msdos, pc98, sun,
loop
(parted)
13
Cont’d

• Oddly enough, we have to use the label type of "msdos" for Linux
partitions.
#(parted) mklabel msdos
Warning: The existing disk label on /dev/sdb
will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted)
14
Cont’d
➢ To check the free space on the drive using the print free command.
#(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 10.7GB 10.7GB Free Space
(parted) 15
Create a Partition using parted
• To create a new partition use the mkpart command.
• If the FS-TYPE parameter is specified, the system ID of the partition is set
accordingly, but no file system is created.
• The following example uses mkpart to create a 2G partition with no file system on it.
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? ext4
Start? 1MB
End? 2GB
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
16
Partition Table: msdos
Cont’d
• Notice the partition starts at "1MB". This is to leave space for the master boot
record.
• The mkpartfs command allows you to create a new partition with a file system, but
when you try to use it you get a warning that the file system creation is not robust.
For this reason, it should probably be avoided.
#(parted) mkpartfs
WARNING: you are attempting to use parted to operate on (mkpartfs) a
file system.
parted's file system manipulation code is not as robust as what you'll find
in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition type? primary/extended?
17
Delete a Partition using parted
• The rm command is used to delete a partition. It accepts the partition number
as a parameter.
• The following example deletes the partition we just created.
#(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 2000MB 1999MB primary
2000MB 10.7GB 8738MB Free Space
18
Cont’d
#(parted) rm 1
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system
Flags
32.3kB 10.7GB 10.7GB Free Space
19
Boot Partitions using parted
• Boot partitions are created in a similar manner to regular partitions,
but the boot flag is set using the toggle or set command after the
partition is created, as shown below.
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? ext4
Start? 1MG
End? 500MB
(parted) toggle 1 boot
(parted) print free 20
Swap Partitions using parted
• Swapping in the operating system is a memory management scheme
that temporarily swaps out an idle or blocked process from the main
memory to secondary memory which ensures proper memory
utilization and memory availability for those processes which are
ready to be executed.
• Swap partitions are created in a similar manner to regular partitions,
but the file system type is set to linux-swap.
• The example below creates a 2G swap partition after the boot
partition created.
21
Swap
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? linux-swap
Start? 500MB
End? 2.5GB
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 500MB 499MB primary boot
2 500MB 2500MB 2000MB primary
2500MB 10.7GB 8238MB Free Space
(parted)
22
Logical Volume Manager (LVM)
• Disk management has always been one of the most important
tasks that system administrators perform.
• Logical Volume Manager (LVM) is a software component that
allows you to create and manage logical volumes on a hard disk
drive.
• It is available on various operating systems such as Linux and
allows for greater flexibility in managing disk space.
• LVM allows you to create logical volumes that span multiple
physical disks, resize logical volumes on the fly, and create
snapshots for backup purposes. 23
Physical Volumes & logical volume

• A physical volume is a storage device that is added to the LVM.


• This can be a hard disk drive, solid-state drive, or any other storage
device.
• Physical volumes are divided into physical extents, which are the
smallest unit of storage that can be added to an LVM.
• A logical volume is a virtual disk that is created from a volume group.
• Logical volumes can be resized on the fly, allowing you to add or
remove disk space as needed.
• You can also create snapshots of logical volumes for backup purposes.
24
A disk quota
is a limit that sets the maximum storage space available
for each user in a Linux system .
• Setting up such a limit prevents users from filling the entire file
system in a multi-user environment and disadvantaging other users in
the system.
• There are two basic types of disk quotas.
, limits the
amount of disk space that can be used.
• , limits the
number of files and directories that can be created. 25
Managing Disk Quotas
Implementing a disk quota will prevent users or groups from using too much
storage space on a Linux system.
This is very useful on systems such as file servers that allow many users to
connect and store data, as it ensures that no particular user can utilize an
unexpected amount of storage and interrupt storage or processes on the server
by making it run out of disk space.
Linux administrators should always put a quota on the maximum storage
usage for users, as well as other user environment limits like max number of
processes and open files.

Slide #26
Cont’d
Implementing a disk quota will prevent users or groups from using
too much storage space on a Linux system.
This is very useful on systems such as file servers that allow many
users to connect and store data, as it ensures that no particular user
can utilize an unexpected amount of storage and interrupt storage or
processes on the server by making it run out of disk space.
Linux administrators should always put a quota on the maximum
storage usage for users, as well as other user environment limits like
max number of processes and open files.
Slide #27
Cont’d
There are three major concepts that you should understand
prior to implementing disk quotas:
Hard Limit
The hard limit defines the absolute maximum amount of disk
space that a user or group can use. Once this limit is reached,
no further disk space can be used.
Soft Limit
The soft limit defines the maximum amount of disk space that
can be used. However, unlike the hard limit, the soft limit can
be exceeded for a certain amount of time.
That time is known as the grace period.
Slide #28
Cont’d
Grace Period
The grace period is the time during which the soft limit may be
exceeded.
The grace period can be expressed in seconds, minutes, hours,
days, weeks, or months, giving the system administrator a great
deal of freedom in determining how much time to give users
to get their disk usage below their soft limit.

Slide #29
Managing Disk Quotas
To use disk quota on an Linux system, you need to follow these steps.
1. Install quota
a) sudo apt-get install quota
2. Inform system about quota
a) Edit /ect/fstab
a) append defaults,[usrquota],[grpquota]
3. Remount the disk
a) Mount –o remount /home
4. Create the quota database
a) Quotacheck –c <u/g> filesystem
5) Assign the quotas
a) Assign per user or per group quotas
a) edquota-<u/g> Slide #30
Cont’d
To implement disk quotas, use the following steps:

Enable quotas per file system by modifying /etc/fstab


Remount the file system(s)
Create the quota files and generate the disk usage table
Assign quotas
1. modify /etc/fstab
2. Remounting the file system(s)
3. Running quotacheck
4. Assigning quotas

Slide #31
Cont’d
Enabling Quotas: Edit fstab to enable usrquota

LABEL=/1 / ext3 defaults 11


LABEL=/boot /boot ext3 defaults 12
LABEL=/users /users ext3 exec,dev,suid,rw,usrquota 12
LABEL=/var /var ext3 defaults 12
LABEL=SWAP-sda5 swap swap defaults 00

Slide #32
Cont’d
Remounting the File Systems: Issue the umount command followed
by the mount command to remount the file system in which quota has
been implemented (umount /users;mount /users)

Creating the Quota Database Files: Use quotacheck command to


create quota.user file
quotacheck -cu /users

Assigning Quotas per User: assigning the disk quotas with the
edquota command (edquota <username>)
Disk quotas for user web_cc (uid 524):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 988612 1024000 1075200 7862 0 0

Slide #33
RAID Concepts (Creating and Managing a
RAID-5 Array)
• RAID 5 is a Redundant Array of Independent Disks configuration that
uses disk striping with parity.
• Because data and parity are striped evenly across all of the disks, no single disk
is a bottleneck.
• Striping is the process of storing consecutive segments of data across different
storage devices, and allows for better throughput and performance.
• Striping also allows users to reconstruct data in case of a disk failure.
• RAID's two primary underlying concepts are:
improves performance.
• Using multiple drives properly allows for any one drive to fail without loss of
34
data and without system downtime.
Thanks
THE END OF
CHAPTER 3
35

You might also like