Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_fs_mgm_lvm [2018/11/16 09:40] – [Volume Group Creation] andonovj | linux_fs_mgm_lvm [2020/09/11 07:25] (current) – andonovj | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Create a File system====== | + | =====Overview===== |
+ | File system | ||
+ | |||
+ | ====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: | ||
</ | </ | ||
+ | |||
+ | ======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/ | ||
+ | Units = cylinders of 128 * 512 = 65536 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | Disk /dev/sdb: 21.4 GB, 21476016128 bytes | ||
+ | 215 heads, 36 sectors/ | ||
+ | Units = cylinders of 7740 * 512 = 3962880 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | Disk /dev/sdc: 73.0 GB, 73019817984 bytes | ||
+ | 90 heads, 44 sectors/ | ||
+ | Units = cylinders of 3960 * 512 = 2027520 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | Disk /dev/sdd: 75.1 GB, 75161927680 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | Disk /dev/sde: 75.1 GB, 75161927680 bytes <- OUR NEW DISK | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | Disk /dev/sde doesn' | ||
+ | [root@oratest2 ~]# fdisk /dev/sde | ||
+ | >sxh> | ||
+ | |||
+ | |||
+ | =====Format the disk===== | ||
+ | Again with " | ||
+ | |||
+ | |||
+ | <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 | ||
+ | | ||
+ | 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/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | | ||
+ | |||
+ | Command (m for help): n | ||
+ | Command action | ||
+ | | ||
+ | | ||
+ | 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: | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | Disk /dev/sde: 75.1 GB, 75161927680 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | |||
+ | 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 "/ | ||
+ | [root@oratest2 ~]# | ||
+ | [root@oratest2 ~]# | ||
+ | </ | ||
+ | |||
+ | That volume can be seen as follows: | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | [root@oratest2 ~]# pvdisplay | ||
+ | "/ | ||
+ | --- NEW Physical volume --- | ||
+ | PV Name / | ||
+ | VG Name <- NO ASSOCIATED VOLUME GROUP | ||
+ | PV Size 69.99 GB | ||
+ | Allocatable | ||
+ | PE Size (KByte) | ||
+ | Total PE 0 | ||
+ | Free PE 0 | ||
+ | Allocated PE 0 | ||
+ | PV UUID | ||
+ | </ | ||
+ | |||
+ | 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: | ||
+ | | ||
+ | | ||
+ | Select (default p): p | ||
+ | Partition number (1-4, default 1): | ||
+ | First sector (2048-20971519, | ||
+ | Using default value 2048 | ||
+ | Last sector, +sectors or +size{K, | ||
+ | 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 " | ||
+ | |||
+ | <sxh bash> | ||
+ | [root@oratest2 ~]# df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | ^ | ||
+ | | | ||
+ | The logical volume :) | ||
+ | </ | ||
+ | |||
+ | Once we find the logical volume, we can find the associated logical group, using the lvdispaly command: | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | --- Logical volume --- | ||
+ | LV Name / | ||
+ | VG Name ORATEST_DATA_VG01 | ||
+ | LV UUID G6Ln3Y-ZEOK-rPQe-XgFM-v8v1-a06s-DrQ3Ne | ||
+ | LV Write Access | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 68.GB | ||
+ | Current LE 35836 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | </ | ||
+ | |||
+ | |||
+ | After we are 1000% sure, we can extend the Volume group as follows: | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | [root@oratest2 data]# vgextend ORATEST_DATA_VG01 / | ||
+ | Volume group " | ||
+ | </ | ||
+ | |||
+ | |||
+ | 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 | ||
+ | System ID | ||
+ | Format | ||
+ | Metadata Areas 2 | ||
+ | Metadata Sequence No 3 | ||
+ | VG Access | ||
+ | VG Status | ||
+ | MAX LV 0 | ||
+ | Cur LV 1 | ||
+ | Open LV 1 | ||
+ | Max PV 0 | ||
+ | Cur PV 2 | ||
+ | Act PV 2 | ||
+ | VG Size | ||
+ | PE Size 4.00 MB | ||
+ | Total PE 35836 | ||
+ | Alloc PE / Size 17664 / 69.00 GB | ||
+ | Free PE / Size 18172 / 70.98 GB | ||
+ | VG UUID | ||
+ | </ | ||
+ | |||
+ | Since we are sure that the logical volume, on which our filesystem is mounted is: " | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | [root@oratest2 data]# lvextend -l +18172 / | ||
+ | Extending logical volume lvol0 to 139.98 GB | ||
+ | </ | ||
+ | |||
+ | Finally we can resize the File system as follows: | ||
+ | |||
+ | |||
+ | <sxh bash> | ||
+ | [root@oratest2 data]# resize2fs / | ||
+ | resize2fs 1.39 (29-May-2006) | ||
+ | Filesystem at / | ||
+ | Performing an on-line resize of / | ||
+ | The filesystem on / | ||
+ | |||
+ | [root@oratest2 data]# df -h | ||
+ | |||
+ | / | ||
+ | </ | ||
+ | |||
+ | |||
+ | 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 "- - -" > / | ||
+ | echo "- - -" > / | ||
+ | echo "- - -" > / | ||
+ | echo "- - -" > / | ||
+ | </ | ||
+ | |||
+ | After that the disk should be available using fdisk: | ||
+ | |||
+ | <sxh bash> | ||
+ | Disk /dev/sdp: 107.3 GB, 107374182400 bytes | ||
+ | 255 heads, 63 sectors/ | ||
+ | Units = cylinders of 16065 * 512 = 8225280 bytes | ||
+ | |||
+ | Disk /dev/sdp doesn' | ||
+ | </ |