=====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.
====Device recognition====
First, when we add a new disk, we should be able to see it with the following command:
[root@lparaca ~]# fdisk -l
Disk /dev/sdh: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
**********************************************
====Partition Creation====
After that we have to create a partition for that device using the same command, a device can have 4 primary partitions and many more extended partitions. Here we will create a primary partition for device /dev/sdh
[root@lparaca ~]# fdisk /dev/sdh
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x36089e2c.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n <- Create partition
Command action
e extended
p primary partition (1-4)
p <- Primary
Partition number (1-4):
Value out of range.
Partition number (1-4): 1 <- Partition ID in case you have others
First cylinder (1-2610, default 1):
Using default value 1 <- First Cylinder
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610 <- Last Cylinder
Command (m for help): w <- Write the changes into the header
We can see now that the partition has been created
[root@lparaca ~]# ls /dev/sdh*
/dev/sdh **/dev/sdh1**
====Volume Group Creation====
After we have physical partition, we can create a volume group (e.g. group of physical volumes)
root@lparaca ~]# vgcreate oravg /dev/sdh1
Physical volume "/dev/sdh1" successfully created
Volume group "oravg" successfully created
[root@lparaca ~]#
====Logical Volume and File system creation====
After we have the physical Volume we can start slicing it into pieces called Logical Volumes as follows:
===Logical Volume===
Size LV Name VG Name
[root@lparaca ~]# lvcreate -L 19G -n orahome oravg
Logical volume "lvol0" created.
[root@lparaca ~]#
We can also display the stats of the newly created logical volume with:
root@lparaca ~]# lvdisplay /dev/orahome/lvol0
--- Logical volume ---
LV Path /dev/orahome/lvol0
LV Name lvol0
VG Name orahome
LV UUID hHtiIK-1kSn-RgIF-Aw8Y-M3WT-88HD-ZIXD6q
LV Write Access read/write
LV Creation host, time lparaca, 2018-01-11 11:18:08 +0100
LV Status available
# open 0
LV Size 19.00 GiB
Current LE 4864
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
===File System===
Once the logical volume is created, we can create a file system on it. There are two main types of file systems:
* Journal File systems: ext3, ex4
* Non-Journal: ext2
We will create a journal file system to prevent from corruption in case of a power outage.
[root@lparaca ~]# mkfs.ext4 /dev/orahome/lvol0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1245184 inodes, 4980736 blocks
249036 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
152 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@lparaca ~]#
Once the file system is created we can mount, but before that we have to edit the /etc/fstab, indificated what and where we mount it:
#
# /etc/fstab
# Created by anaconda on Thu Jan 11 10:24:16 2018
#
# 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/vg_lparaca-lv_root / ext4 defaults 1 1
UUID=d05f17dc-5506-446d-802b-10b0e8528411 /boot ext4 defaults 1 2
/dev/mapper/vg_lparaca-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
**/dev/orahome/lvol0 /u01/app/oracle/product/11.2.0/ ext4 defaults 0 0 **
====Mount of the file system====
Once the file system is created and the /etc/fstab file edited as mentioned above, we can MOUNT the file system as follows:
[root@lparaca ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jan 11 10:24:16 2018
#
# 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/vg_lparaca-lv_root / ext4 defaults 1 1
UUID=d05f17dc-5506-446d-802b-10b0e8528411 /boot ext4 defaults 1 2
/dev/mapper/vg_lparaca-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/orahome/lvol0 /u01/app/oracle/product/11.2.0/ ext4 defaults 0 0
[root@lparaca ~]# mkdir -p /u01/app/oracle/product/11.2.0/
[root@lparaca ~]# mount /u01/app/oracle/product/11.2.0/
[root@lparaca ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_lparaca-lv_root
18G 1.7G 15G 10% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/sda1 477M 28M 425M 7% /boot
/dev/mapper/orahome-lvol0
19G 44M 18G 1% **/u01/app/oracle/product/11.2.0**
[root@lparaca ~]#
======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"
[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 * 2 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 1 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 1 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 1 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:
[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
e extended
p 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!
Now the disks' partition, will be visible from OS side:
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 1 9137 73392921 83 Linux
After a partition is created we can create a physical volume on that partition:
=====Create physical Volume=====
[root@oratest2 ~]# pvcreate /dev/sde1
Physical volume "/dev/sde1" successfully created
[root@oratest2 ~]#
[root@oratest2 ~]#
That volume can be seen as follows:
[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
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 :)
[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:
p primary (0 primary, 0 extended, 4 free)
e 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 ~]#
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:
[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 :)
Once we find the logical volume, we can find the associated logical group, using the lvdispaly command:
--- 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
After we are 1000% sure, we can extend the Volume group as follows:
[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
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
[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
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:
[root@oratest2 data]# lvextend -l +18172 /dev/mapper/ORATEST_DATA_VG01-lvol0
Extending logical volume lvol0 to 139.98 GB
Finally we can resize the File system as follows:
[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
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:
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
After that the disk should be available using fdisk:
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