Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_fs_mgm_lvm [2018/11/16 09:40] – [Volume Group Creation] andonovjlinux_fs_mgm_lvm [2020/09/11 07:25] (current) andonovj
Line 1: Line 1:
-======Create a File system======+=====Overview===== 
 +File system management on Linux is pretty easy once a person has experience and knowledge of what he is doing. 
 + 
 +====File system Management==== 
 +File systems can be two kinds: 
 + 
 +  * Non-Journal File systems: ext2.  
 +These file systems do not keep logs and can have corrupted data if there has been a power outage. The pluses of these file systems is their fast read/write speed. 
 +  * Journal File systems: ext3,ext4.  
 + 
 +These file systems keep a log (journal) which slows them down, however it is up to the System Admin to decide if he/she is willing to sacrifice speed for consistency.
  
  
Line 196: Line 206:
 </sxh> </sxh>
  
 +
 +======Extend File system======
 +To extend a file system we need several things:
 +
 +  - Check if the new raw disk has been added
 +  - Format the disk
 +  - Create Physical Volume from the partition
 +  - Add the disk to the volume group
 +  - Extend the logical volume to which the file system (which we want to increase) is mounted
 +  - Resize the file system
 +
 +So let's get started :)
 +
 +=====Check the disk=====
 +In order to check the disk, we can simply use the "fdisk command"
 +
 +
 +<sxh bash>
 +[root@oratest2 ~]# fdisk -l
 +
 +Disk /dev/sda: 108 MB, 108134400 bytes
 +4 heads, 32 sectors/track, 1650 cylinders
 +Units = cylinders of 128 * 512 = 65536 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sda1                    1633      104448   83  Linux
 +
 +Disk /dev/sdb: 21.4 GB, 21476016128 bytes
 +215 heads, 36 sectors/track, 5419 cylinders
 +Units = cylinders of 7740 * 512 = 3962880 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sdb1                      5420    20971520   8e  Linux LVM
 +
 +Disk /dev/sdc: 73.0 GB, 73019817984 bytes
 +90 heads, 44 sectors/track, 36014 cylinders
 +Units = cylinders of 3960 * 512 = 2027520 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sdc1                     36014    71307264   8e  Linux LVM
 +
 +Disk /dev/sdd: 75.1 GB, 75161927680 bytes
 +255 heads, 63 sectors/track, 9137 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sdd1                      9137    73392921   83  Linux
 +
 +Disk /dev/sde: 75.1 GB, 75161927680 bytes     <- OUR NEW DISK
 +255 heads, 63 sectors/track, 9137 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +
 +Disk /dev/sde doesn't contain a valid partition table   <- WITHOUT PARTITION
 +[root@oratest2 ~]# fdisk /dev/sde
 +>sxh>
 +
 +
 +=====Format the disk=====
 +Again with "fdisk" we can format the disk as follows:
 +
 +
 +<sxh bash>
 +[root@oratest2 ~]# fdisk /dev/sde
 +Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 +Building a new DOS disklabel. Changes will remain in memory only,
 +until you decide to write them. After that, of course, the previous
 +content won't be recoverable.
 +
 +
 +The number of cylinders for this disk is set to 9137.
 +There is nothing wrong with that, but this is larger than 1024,
 +and could in certain setups cause problems with:
 +1) software that runs at boot time (e.g., old versions of LILO)
 +2) booting and partitioning software from other OSs
 +   (e.g., DOS FDISK, OS/2 FDISK)
 +Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 +
 +Command (m for help): p
 +
 +Disk /dev/sde: 75.1 GB, 75161927680 bytes
 +255 heads, 63 sectors/track, 9137 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +
 +Command (m for help): n
 +Command action
 +     extended
 +     primary partition (1-4)
 +p
 +Partition number (1-4):
 +Value out of range.
 +Partition number (1-4): 1
 +First cylinder (1-9137, default 1):
 +Using default value 1
 +Last cylinder or +size or +sizeM or +sizeK (1-9137, default 9137):
 +Using default value 9137
 +
 +Command (m for help): w
 +The partition table has been altered!
 +</sxh>
 +
 +Now the disks' partition, will be visible from OS side:
 +
 +
 +<sxh bash>
 +Disk /dev/sde: 75.1 GB, 75161927680 bytes
 +255 heads, 63 sectors/track, 9137 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +
 +   Device Boot      Start         End      Blocks   Id  System
 +/dev/sde1                      9137    73392921   83  Linux
 +</sxh>
 +
 +
 +After a partition is created we can create a physical volume on that partition:
 +
 +
 +=====Create physical Volume=====
 +
 +<sxh bash>
 +[root@oratest2 ~]# pvcreate /dev/sde1
 +  Physical volume "/dev/sde1" successfully created
 +[root@oratest2 ~]#
 +[root@oratest2 ~]#
 +</sxh>
 +
 +That volume can be seen as follows:
 +
 +
 +<sxh bash>
 +[root@oratest2 ~]# pvdisplay
 + "/dev/sde1" is a new physical volume of "69.99 GB"
 +  --- NEW Physical volume ---
 +  PV Name               /dev/sde1
 +  VG Name                                     <- NO ASSOCIATED VOLUME GROUP
 +  PV Size               69.99 GB
 +  Allocatable           NO
 +  PE Size (KByte)       0
 +  Total PE              0
 +  Free PE               0
 +  Allocated PE          0
 +  PV UUID               ZOA0V3-QvMG-ihYN-WQIg-j1WZ-FjcX-e4dphP
 +</sxh>
 +
 +Now, it is time to finally associate our Physical volume with a volume group:
 +
 +
 +=====Add the disk to a volume group=====
 +Firstly, we have to partition the new bare metal :)
 +
 +<sxh bash>
 +[root@matar ~]# fdisk /dev/sde
 +Welcome to fdisk (util-linux 2.23.2).
 +
 +Changes will remain in memory only, until you decide to write them.
 +Be careful before using the write command.
 +
 +Device does not contain a recognized partition table
 +Building a new DOS disklabel with disk identifier 0xdabe3889.
 +
 +Command (m for help): n
 +Partition type:
 +     primary (0 primary, 0 extended, 4 free)
 +     extended
 +Select (default p): p
 +Partition number (1-4, default 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
 +Partition 1 of type Linux and of size 10 GiB is set
 +
 +Command (m for help): w
 +The partition table has been altered!
 +
 +Calling ioctl() to re-read partition table.
 +Syncing disks.
 +[root@matar ~]# 
 +</sxh>
 +
 +
 +Then, we have to check, which is the volume group which we want to extend> Please BE SURE, you know the volume group of the logical volume on which your File system is mounted and which you wish to extend. This can be seen from the "df" command:
 +
 +<sxh bash>
 +[root@oratest2 ~]# df -h
 +Filesystem            Size  Used Avail Use% Mounted on
 +/dev/mapper/ORATEST_DATA_VG01-lvol0  68G   50G   16G  77% /u01/data     <- The file system I want to extend
 +               ^
 +               |
 +           The logical volume :)
 +</sxh>
 +
 +Once we find the logical volume, we can find the associated logical group, using the lvdispaly command:
 +
 +
 +<sxh bash>
 +  --- Logical volume ---
 +  LV Name                /dev/ORATEST_DATA_VG01/lvol0              <- Logical Volume
 +  VG Name                ORATEST_DATA_VG01                         <- Volume group
 +  LV UUID                G6Ln3Y-ZEOK-rPQe-XgFM-v8v1-a06s-DrQ3Ne
 +  LV Write Access        read/write
 +  LV Status              available
 +  # open                 1
 +  LV Size                68.GB
 +  Current LE             35836
 +  Segments               2
 +  Allocation             inherit
 +  Read ahead sectors     auto
 +  - currently set to     256
 +  Block device           253:8
 +</sxh>
 +
 +
 +After we are 1000% sure, we can extend the Volume group as follows:
 +
 +
 +<sxh bash>
 +[root@oratest2 data]# vgextend ORATEST_DATA_VG01 /dev/sde1    <-We added the new partition (/dev/sde1) to the volume group (ORATEST_DATA_VG01) 
 +  Volume group "ORATEST_DATA_VG01" successfully extended
 +</sxh>
 +
 +
 +After, we have added the physical volume to the volume group, we can see that the amount of our FREE sectors increased from 0 -> 18172 
 +<sxh bash>
 +[root@oratest2 data]# vgdisplay
 +  --- Volume group ---
 +  VG Name               ORATEST_DATA_VG01
 +  System ID
 +  Format                lvm2
 +  Metadata Areas        2
 +  Metadata Sequence No  3
 +  VG Access             read/write
 +  VG Status             resizable
 +  MAX LV                0
 +  Cur LV                1
 +  Open LV               1
 +  Max PV                0
 +  Cur PV                2
 +  Act PV                2
 +  VG Size               139.98 GB
 +  PE Size               4.00 MB
 +  Total PE              35836
 +  Alloc PE / Size       17664 / 69.00 GB
 +  Free  PE / Size       18172 / 70.98 GB
 +  VG UUID               1UbWQt-wzjX-KlWF-O7Ds-wiVt-wdYH-WfzmMw
 +</sxh>
 +
 +Since we are sure that the logical volume, on which our filesystem is mounted is: "ORATEST_DATA_VG01-lvol0", we can extend the logical volume as follows:
 +
 +
 +<sxh bash>
 +[root@oratest2 data]# lvextend -l +18172 /dev/mapper/ORATEST_DATA_VG01-lvol0
 +  Extending logical volume lvol0 to 139.98 GB
 +</sxh>
 +
 +Finally we can resize the File system as follows:
 +
 +
 +<sxh bash>
 +[root@oratest2 data]# resize2fs /dev/mapper/ORATEST_DATA_VG01-lvol0
 +resize2fs 1.39 (29-May-2006)
 +Filesystem at /dev/mapper/ORATEST_DATA_VG01-lvol0 is mounted on /u01/data; on-line resizing required
 +Performing an on-line resize of /dev/mapper/ORATEST_DATA_VG01-lvol0 to 36696064 (4k) blocks.
 +The filesystem on /dev/mapper/ORATEST_DATA_VG01-lvol0 is now 36696064 blocks long.
 +
 +[root@oratest2 data]# df -h
 +
 +/dev/mapper/ORATEST_DATA_VG01-lvol0 138G   50G   82G  38% /u01/data
 +</sxh>
 +
 +
 +Phew! That was something :) This is how you extend filesystem in Linux, to have more space for useless data :) Cheers :)
 +
 +
 +======Refresh the SCSI-Disk information======
 +If you add a disk on VM, it MIGHT not be there IMMEDIATELY so you have two options:
 +
 +  * Restart the server
 +  * Rescan the disks
 +
 +So since restarting of the server isn't always possible to restart the server. Luckly we have a command for that:
 +
 +<Code:bash|Re-scan SCSIs>
 +echo "- - -" > /sys/class/scsi_host/host0/scan
 +echo "- - -" > /sys/class/scsi_host/host1/scan
 +echo "- - -" > /sys/class/scsi_host/host2/scan
 +echo "- - -" > /sys/class/scsi_host/host3/scan
 +</Code>
 +
 +After that the disk should be available using fdisk:
 +
 +<sxh bash>
 +Disk /dev/sdp: 107.3 GB, 107374182400 bytes
 +255 heads, 63 sectors/track, 13054 cylinders
 +Units = cylinders of 16065 * 512 = 8225280 bytes
 +
 +Disk /dev/sdp doesn't contain a valid partition table
 +</sxh>
  • linux_fs_mgm_lvm.1542361215.txt.gz
  • Last modified: 2019/10/18 20:04
  • (external edit)