This document discusses storage management in Linux. It covers disk partitioning, file systems, logical volume management (LVM), and some common tools. It describes:
1. How hard disks can be partitioned into primary, extended, and logical partitions using tools like fdisk and parted.
2. The components of storage including files, directories, file systems, and how logical and physical storage relate.
3. How LVM allows logical volumes to span physical disks, be dynamically resized, and helps solve issues with traditional partitioning.
4. Common commands to manage physical volumes, volume groups, and logical volumes with LVM.
5. Hard disk partitions
• IDE and SCSI hard disks can be partitioned
• Maximum of four primary partitions
• One primary partition may be an extended partition
• An extended partition can hold an unlimited amount of
logical partitions (Linux: max 59 for IDE, 11 for SCSI)
master boot record
partition table
Windows
Linux /
Linux /home
Linux swap
sda: The first sector of the disk contains the MBR
and Partition Table
sda1: First primary partition holds a Windows
filesystem
sda2: Second primary partition is an extended
partition and holds three logical partitions
sda5: First logical partition holds a Linux
filesystem that will be mounted as /
sda6: Second logical partition holds a Linux
filesystem that will be mounted as /home
sda7: Third logical partition holds a Linux swap
space
6. Partitioning tools
• fdisk
– Virtually every PC OS comes with a tool fdisk to create
partitions for that OS
• Linux, Windows, and so forth
• parted
– GPLed Linux program, available at www.gnu.org
– Can create/resize/move/delete partitions
• GParted, QTParted
– GUI utilities that use GNU Parted
– Can create/resize/move/delete partitions
• Disk Druid and others
– Partitioning program integrated in Linux install program
7. Steps for creating and using partitions in Linux
Step 1: Creating a partition
Step 2: Formatting a partition
Step 3: Mounting a partition
8. fdisk utility
fdisk also known as format disk is a dialog-driven command in Linux
used for creating and manipulating disk partition table. It is used for the
view, create, delete, change, resize, copy and move partitions on a
hard drive using the dialog-driven interface.
fdisk allows you to create a maximum of four primary partitions and the
number of logical partition depends on the size of the hard disk you are
using. It allows the user:
• To Create space for new partitions.
• Organizing space for new drives.
• Re-organizing old drives.
• Copying or Moving data to new disks(partitions).
9. • Syntax :
# fdisk [options] device
View All Disk Partitions:
# fdisk –l
View Partition on a Specific Disk:
# fdisk –l /dev/sda
• To check either disk is detected or not
# dmesg | grep sd
10. 1. View all Disk Partitions in Linux
The following basic command list all existing disk partition on your system. The
‘-l‘ argument stand for (listing all partitions) is used with fdisk command to view
all available partitions on Linux. The partitions are displayed by their device’s
names. For example: /dev/sda, /dev/sdb or /dev/sdc.
11. 2. View Specific Disk Partition in Linux
• To view all partitions of specific hard disk use the option ‘-l‘ with
device name. For example, the following command will display all
disk partitions of device /dev/sda. If you’ve different device names,
simple write device name as /dev/sdb or /dev/sdc.
12. 3. Check all Available fdisk Commands
• If you would like to view all commands which are available for fdisk. Simply
use the following command by mentioning the hard disk name such as
/dev/sda as shown below. The following command will give you output
similar to below.
13. • Type ‘m‘ to see the list of all available commands of fdisk
which can be operated on /dev/sda hard disk. After, I
enter ‘m‘ on the screen, you will see the all available
options for fdisk that you can be used on the /dev/sda
device.
14.
15. 4. Print all Partition Table in Linux
• To print all partition table of hard disk, you must be on command mode of
specific hard disk say /dev/sda.
From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter
‘p‘, it will print the specific /dev/sda partition table.
16. 6. Create a New Partition in Linux
• If you’ve free space left on one of your device say /dev/sda and would like
to create a new partition under it. Then you must be in fdisk command mode
of /dev/sda. Type the following command to enter into command mode of
specific hard disk.
After entering in command mode, now press “n” command to create a new
partition under /dev/sda with specific size. This can be demonstrated with
the help of following given output.
17. While creating a new partition, it will ask you two options ‘extended‘ or
‘primary‘ partition creation. Press ‘e‘ for extended partition and ‘p‘ for primary
partition. Then it will ask you to enter following two inputs.
• First cylinder number of the partition to be create.
• Last cylinder number of the partition to be created (Last cylinder, +cylinders
or +size).
You can enter the size of cylinder by adding “+5000M” in last cylinder. Here, ‘+‘
means addition and 5000M means size of new partition (i.e 5000MB). Please
keep in mind that after creating a new partition, you should run ‘w‘ command to
alter and save new changes to partition table and finally reboot your system to
verify newly created partition.
18. 7. How to Check Size of a Partition in Linux
• By default, fdisk command shows the boot flag (i.e. ‘*‘)
symbol on first partition. If you want to enable or disable
boot flag on a specific partition, do the following steps.
• Press ‘p‘ command to view the current partition table,
you see there is a boot flag (asterisk (*) symbol in
orange color) on /dev/sda1 disk as shown below.
19. • Next enter command ‘a‘ to disable boot flag, then enter partition
number ‘1‘ as (i.e. /dev/sda1) in my case. This will disable boot flag
on the partition /dev/sda1. This will remove the asterisk (*) flag.
20. 6. Delete a Hard Disk Partition
To delete a partition for the hard disk and free up space occupied by that
partition for example /dev/sdb. Go to the command menu using following:
$ sudo fdisk /dev/sda
and then type d to go to the delete partition menu. It will prompt the partition
number you want to delete(type the number).
23. • To create an ext file system use :
# mkfs.ext2 /dev/sdb6
# mkfs.ext3 /dev/sdb6
# mkfs.ext4 /dev/sdb6
• To create xfs file system install package xfsprogs:
# yum install xfsprogs
# mkfs.xfs /dev/sdb6
• To create jfs file system install package jfsutils :
# yum install jfsutils
# mkfs.jfs /dev/sdb6
Creating file System on partation
24. Creating swap partition
• To create and activate swap partition
# mkswap /dev/sdb5
To activate swap partition
# swapon /dev/sdb5
To check swap partition is activated or not :
# dmesg | tail –n 1 or use
# free -m
25. To tune file system
• Use tune2fs tool
# tune2fs
# tune2fs –l /dev/sdb6
# tune2fs [options] <partition name>
# tune2fs -c 0 –m 0 /dev/sdb6
26. Mounting a partition:
• Create directory under /mnt directory
#mkdir /mnt/data
• Use mount command to mount partition to a
created directory under /mnt
# mount /dev/sdb6 /mnt/data
• Use following commands to check either
partition is mounted or not
#df
#dmesg
# mount
27. Unmounting file system
• Use umount command
# umount /mnt/data
• To check whether any links are open use:
# lsof /mnt/data 6
28. Auto mounting a partation
• For auto mounting make entry into
/etc/fstab file
•
29. Traditional disk storage
PROBLEMS:
• Fixed partitions
• Expanding size of the partition
• Limitation on size of a file system and a file
• Contiguous data requirement
• Time and effort required in planning ahead
Partition 1
Partition 2
Partition 3
Partition 4
Partition 5
30. Benefits of the LVM(Logical Volumes Management)
• Logical volumes solve noncontiguous space problems
• Logical volumes can span disks
• Logical volume sizes can be dynamically increased
• Logical volumes can be mirrored
• Physical volumes are easily added to the system
• Logical volumes can be relocated
• Volume group and logical volume statistics can be collected
These tasks can be performed dynamically!
31. Logical volume management
• Logical volume management solves the disadvantages of
traditional disk storage:
– One or more physical volumes (hard disks, partitions) are assigned to
a volume group (VG)
– All physical volumes (PV) are split into physical extents (PE) of
identical size (default 4 MB)
– PEs in a VG can be combined into logical volumes (LV), which can
be used like any block device
• An LV can span multiple disks
• To increase the size of an LV, add PEs
• To increase the size of a VG, add PVs
32. Logical volume management on Linux
PE PE PE
PE PE PE
PE PE PE
PE PE PE
PE PE PE
PE PE PE
volume group
physical volume
(hard disk or partition)
physical volume
(hard disk or partition)
logical volume
33. LVM has three layers :
• Bottom layer : Physical volumes
• Middle layer : Volume group
• Top layer : Logical volume
34. Commands for Physical Volume & Volume Group:
• For Physical Volume :
# pvcreate
# pvremove
# pvdisplay / pvs
• For Volume Group :
# vgcreate
# vgremove
# vgextend
# vgreduce
#vgdisplay / vgs
35. 1. Creating Groups and Volumes
1. Creating Physical volume :
# pvcreate /dev/sdb6
• To display all the physical volumes created :
# pvs
2. Now create Volume Group :
# vgs - to check available groups
Create new Volume group :
# vgcreate mygrp /dev/sdb6
3. Extend or reduce volume group
# vgextend vg_linuxhost /dev/sdb6
# vgreduce vg_linuxhost /dev/sdb6
37. LVM implementation overview
• Add hard disks and/or create partitions (type 0x8e) on existing
hard disks
• Initialize physical volumes (disks or partitions)
# pvcreate /dev/sda3
# pvcreate /dev/sdb
• Create volume group vg00 with physical volumes
# vgcreate vg00 /dev/sda3 /dev/sdb
• Create logical volume lv00 in volume group
# lvcreate -L 50M -n lv00 vg00
• Can now use /dev/vg00/lv00 as block device
38. Recovering from Failure
• File system and auto recovering tools
• Ext2 ,Ext3, Ext4 -- e2fsck
• XFS File system -- xfs_repair
• JFS File System -- jfs_fsck