1. Disk Partitioning
Here is the disk layout example for partitions in linux being used for file system mount points. The following show the output of available disks in the system. Where /dev/sda and /dev/sdb are the disks available.
/dev/sda – has three partitions sda1, sda2,sda3.
/dev/sdb – No partitions
| susevm:~ # fdisk –l Disk /dev/sda: 21.6 GB, 21613379584 bytes, 42213632 sectors Device Boot Start End Blocks Id System Disk /dev/sdb: 10.8 GB, 10836967424 bytes, 21165952 sectors |
Look at the below image where it has file systems on partitions created from /dev/sda.
Now lets see how to create partitions on existing disk, /dev/sdb.
Create Partitions:
#fdisk /dev/sdb
m – for help
n – new partition
p – partition type ( You can make primary or extented partitions )
assign the partition number (1-4) .. as you can create only 4 primary partitions on disk with msdos label.
w – write changes to the disk ( which will create or delete the partition request you made with fdisk)
| susevm:~ # fdisk /dev/sdb Changes will remain in memory only, until you decide to write them. Device does not contain a recognized partition table Command (m for help): m Command (m for help): n Command (m for help): w Calling ioctl() to re-read partition table. |
check the partition you created.
| susevm:~ # fdisk -l /dev/sdb Disk /dev/sdb: 10.8 GB, 10836967424 bytes, 21165952 sectors Device Boot Start End Blocks Id System |
Create file system:
Create a file system on the linux disk partition.
| susevm:~ # mkfs.ext3 /dev/sdb1 Allocating group tables: done |
Mount the file system . Now “/opt/” is allocated with a dedicated file system space of “5GB”
| susevm:~ # mount /dev/sdb1 /opt/ |
Now lets create a filesystem, following with “ logical volume management” .
2. Logical Volume Manager
The hierarchy follows:
.Physical Volumes ( Created on the disks or disks partitions. eg: /dev/sdb, /dev/sdb1 )
.Volume Groups ( Created using the available physical volumes, you can use single or multiple PV’s to create a VG. But you cannot use a single PV for multiple volume groups).
.Logical Volumes ( Logical volumes are created on Volume Groups. You can create one or more logical volumes on the volume group depending on the available space on the VG.)
Now lets start with two disks in our system, /dev/sdb and /dev/sdc. Using logical volume manager(lvm), you will have better leverage in managing available file system space, over to the file systems you create over disks partitions directly.
Example file system layout with logical volumes from multiple disks.
List the available disks with lsscsi or you can use the following.
fdisk -l or lsblk (shows the available disks and partitions on those. Try checking with all for better understanding.)
| susevm:~ # lsscsi |
Here we use /dev/sdb and /dev/sdc
Create Physical volumes :
| susevm:~ # pvcreate /dev/sdb /dev/sdc |
Create Volume Group:
Create Volume Group using PV’s /dev/sdb and /dev/sdc.
| susevm:~ # vgcreate vg01 /dev/sdb /dev/sdc |
Now you have Volume Group “vg01” with 20G free space. Where the above output shows the number of PV’s used, number of LV’s available on VG as well.
Create Logical Volumes:
Creating the logical volumes with specific size .
Here -L is the logical volume size ( can be in K, M, or G etc.. )
-n -- Name of the logical volume.
So the following indicates that, you are requesting your system to create a logical volume of size 5G, with name “lvol01”, on the Volume Group “vg01”(/dev/vg01).
| susevm:~ # lvcreate -L 5G -n lvol01 /dev/vg01 |
Also you can create logical volumes with -l option where you specify the percentage of space to be used from the Volume Group. Here we are issuing a command to create an LV with name “lvol02” using 50% of the available space from the Volume Group “vg01”.
| susevm:~ # lvcreate -l 50%FREE -n lvol02 /dev/vg01 lvol02 logical volume created. Now you have two logical volumes in active state. Check available free space on the VG. susevm:~ # vgs |
Create file system type “ext3” on “lvol02”
Create a File System: ( eg: ext3)
| susevm:~ # mkfs.ext3 /dev/vg01/lvol02 Allocating group tables: done |
With this, you have 7.5 G of available ext3 file system space.
Mounting file system:
mount this volume to /opt.
| susevm:~ # mount /dev/vg01/lvol02 /opt |
Now lets say we might be needing 10GB of space for /opt, we can extend the logical volume to 10GB and then resize the filesystem to 10GB. For that you need to have free space on the Volume Group to extend the logical volume.
Using “lvextend”, we can extend the logical volume.
| susevm:~ # vgs |
LV is extended but still your filesystem size will show 7.5G, until you resize the filesystem space.
| susevm:~ # df -h |
Resize file system with “resize2fs” command.
Note: resize2fs can be run on a mounted filesystem from kernel versions 2.6 or later. ( check kernel version with uname -r).
| susevm:~ # resize2fs /dev/vg01/lvol02 susevm:~ # df -h |
File system Size extended to 10GB now.
To be continued .. with Various types of file systems:
No comments:
Post a Comment