Unix disk partition

From DISI
Revision as of 22:35, 28 June 2016 by Benrwong (talk | contribs) (Edited to include various other sections of partition management from the Lab Manual)
Jump to navigation Jump to search

How to make a partition, label the partition and create a file system type.

In /media I created a directory backup

fdisk -l  -> To see a list of devices.  Say the device is listed as /dev/sdf

Note the size, so for our example: Disk /dev/sdf: 3000.6 GB, 3000592981504 bytes

parted /dev/sdf
print

It should say this:

(parted) print                                                       	 
Error: /dev/sdf: unrecognised disk label   	

If not, exit and try to select the device again.

(parted) mklabel gpt
(parted) mkpart logical 0TB 3TB
(parted) print                                                   	 
Model: Initio INIC-1610P (scsi)
Disk /dev/sdf: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
  
Number  Start   End 	Size	File system  Name 	Flags
 1  	1049kB  3001GB  3001GB  xfs      	logical 
(parted)	
(parted) quit

Now when you type fdisk -l you should see under /dev/sdf a “/dev/sdf1” line Now type:

pvcreate /dev/sdf1
pvdisplay -> sanity check
vgcreate nfs_backup_vg /dev/sdf1
vgdisplay -> sanity check
lvcreate -l 100%FREE -n nfs_backup_lv nfs_backup_vg
mkfs.xfs -L nfs_backup /dev/mapper/nfs_backup_vg-nfs_backup_lv
mount -t xfs /dev/mapper/nfs_backup_vg-nfs_backup_lv /media/backup

HOW to partition a disk without logical partitioning

parted /dev/sdf
print
It should say this:
(parted) print                                                            
Error: /dev/sdf: unrecognised disk label       

If not, exit and try to select the device again.

(parted) mklabel gpt
(parted) mkpart physical 0TB 3TB
(parted) print                                                        
Model: Initio INIC-1610P (scsi)
Disk /dev/sdf: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
1      1049kB  3001GB  3001GB  xfs          logical
(parted) quit
mkfs.ext4 /dev/sdf1

How to reduce the size of an LVM

reference: http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/

I wanted to reduce the logical volume down to only 30 GB

umount /dev/mapper/vg_beatles-lv_home
vgchange -a y
e2fsck -f /dev/mapper/vg_beatles-lv_home
resize2fs /dev/mapper/vg_beatles-lv_home 27G ===> 27 GB 90% of the total new size will be (ie 30 * 90)
lvreduce -L 30G /dev/mapper/vg_beatles-lv_home  ⇒ 30 GB is new size
resize2fs /dev/mapper/vg_beatles_home

HOW TO INCREASE THE SIZE OF A LVM

reference: http://www.tecmint.com/extend-and-reduce-lvms-in-linux/

Unmount the directory

[root@RH66-57-147 ~]# umount /home/abs

check to see how much free space is available:

fdisk/parted, etc +
[root@RH66-57-147 ~]# vgdisplay
 --- Volume group ---
 VG Name               vg_abs
 System ID
 Format                lvm2
 Metadata Areas        1
 Metadata Sequence No  2
 VG Access             read/write
 VG Status             resizable
 MAX LV                0
 Cur LV                1
 Open LV               0
 Max PV                0
 Cur PV                1
 Act PV                1
 VG Size               23.28 GiB
 PE Size               4.00 MiB
 Total PE              5960
 Alloc PE / Size       596 / 2.33 GiB
 Free  PE / Size       5364 / 20.95 GiB
 VG UUID               cRha4g-sJjB-D1up-xqoE-tuOY-wc6N-ph9bcK 
--- Volume group --- VG Name vg_rh6657147 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 59.51 GiB PE Size 4.00 MiB Total PE 15234 Alloc PE / Size 15234 / 59.51 GiB Free PE / Size 0 / 0 VG UUID kN78rf-N4ln-eIPz-cduY-BrLu-rcKL-lKBvgk [root@RH66-57-147 ~]# lvextend -l +5364 /dev/vg_abs/lv_abs Size of logical volume vg_abs/lv_abs changed from 2.33 GiB (596 extents) to 23.28 GiB (5960 extents). Logical volume lv_abs successfully resized
[root@RH66-57-147 ~]# e2fsck -f /dev/vg_abs/lv_abs e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg_abs/lv_abs: 11/152608 files (0.0% non-contiguous), 26863/610304 blocks
[root@RH66-57-147 ~]# resize2fs /dev/vg_abs/lv_abs resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg_abs/lv_abs to 6103040 (4k) blocks. The filesystem on /dev/vg_abs/lv_abs is now 6103040 blocks long.

How to add swap space (for Oracle)

To see which device is being used for swap:

swapon -s

To see the size of ram and swap space:

free -m
[root@RH63-58-230 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       8232956 0       -1
[root@RH63-58-230 ~]# free -m
            total       used       free     shared    buffers     cached
Mem:         15941        830      15110          4         26        283
-/+ buffers/cache:        520      15420
Swap:         8039          0       8039
Need to add 7902 MBs, taking 8 GB out of home (cuz it has 400 G)
[root@RH63-58-230 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rh6358230-lv_root
                      50G  3.1G   44G   7% /
tmpfs                 7.8G   76K  7.8G   1% /dev/shm
/dev/sdh1             477M   61M  391M  14% /boot
/dev/mapper/vg_rh6358230-lv_home
                     401G   71M  380G   1% /home
umount /dev/mapper/vg_rh6358230-lv_home
vgchange -a y
e2fsck -f /dev/mapper/vg_rh6358230-lv_home
resize2fs /dev/mapper/vg_rh6358230-lv_home 354G ===> 354 GB will be 90% of home size
lvreduce -L 392G /dev/mapper/vg_rh6358230-lv_home  ==⇒ 392 GB is new home size
resize2fs /dev/mapper/vg_rh6358230-lv_home
mount -a
df -h ==> to check
swapoff -v /dev/mapper/vg_rh6358230-lv_swap
lvm lvresize /dev/mapper/vg_rh6358230-lv_swap -L +8G
mkswap /dev/mapper/vg_rh6358230-lv_swap
swapon -va
free -m ==> to check
=================================================
The other way to create swap space (I use this way if I have to take from the root partition)
[root@OEL65-58-92 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          2002        725       1277          0         19        593
-/+ buffers/cache:        112       1889
Swap:         4031          0       4031
Needed to add 12GB of swap space:
swapoff -v /dev/mapper/vg_oel655892-lv_swap
dd if=/dev/zero of=/swapext bs=1M count=12288
chmod 600 /swapext
mkswap /swapext
swapon /swapext
vim /etc/fstab
Add:  /swapext    swap         swap    defaults        0 0
swapon -a
swapon -s  ==> to check
free -m   ==> to check