Disk partition
Disk Partition:
1. Create normal partition
#
fdisk –l (show all partition table)
#
fdisk /dev/sda
#
command (m For help): m
#
command (m For help): n
Press Enter twice
+500M
#
command (m For help): w for save
#
partprobe /dev/sda
#
partprobe /dev/sda8
#
mkfs.ext4 /dev/sda8
#
mount (You can mount this raw partition on a loc at file sys tree)
2. Swap Partition:
In
it’s simplest sense, the SWAP partition acts as an overflow to memory (RAM). If
memory is filled up completely, any additional applications will be run off of
the SWAP partition rather than memory. This sounds like an easy way to increase
the amount of usable memory without actually getting more RAM, but that isn’t
the case. RAM is the ideal hardware for memory because it’s extremely quick, unlike
hard drives which are, relatively speaking, extremely slow. A SWAP partition
can also help move some items from your memory to your hard drive in order to
leave more room in memory for more important items.
Advantages:
·
Provides
overflow space when memory fills up completely
·
Can
move rarely-needed items away from high-speed memory
·
Allows
to hibernate
Disadvantages:
·
Takes
up space on hard drive as SWAP partitions do not resize dynamically
·
Can
increase wear and tear to hard drive
·
Does
not necessarily improve performance
#
free -m ; memory info physical memory
& swap space
#
fdisk -l
#
fdisk /dev/sda
Command
(m for help): p
Command
(m for help): n
2
enter
+500M
Command
(m for help): t (You need to
change type of your partition)
Command
(m for help): 9 (Partition
number)
Command
(m for help): 82 (Hex code for
Swap Partition)
Command
(m for help): w
#
partprobe /dev/sda (update partition table)
#
swapoff -a
#
free -m
#
mkswap /dev/sda9 (to format partition)
Setting
up swapspace version 1, size = 511996 KiB
no
label, UUID=7906ac34-4e2a-4b06-b57d-79dd6c66399a
#
swapon /dev/sda9 or UUID=7906ac34-4e2a-4b06-b57d-79dd6c66399a
(either dir path or UUID) (swapon add
the swap partition with existing swap space)
#
blkid /dev/sda9
#
vim /etc/fstab
Type
this at last line: UUID=7906ac34-4e2a-4b06-b57d-79dd6c66399a
swap defaults 0 0
#
mount -a
#
swapoff -a
#
swapon -a
#
free -m
or
#
reboot
3. LVM Partition:
·
All
LVM command Accept a “-v” argument which can be entered multiple times like
–vvv, -vvvvvvv etc to increase output verbosity.
·
#
fdisk /dev/sda
#
command (m For help): p
#
command (m For help): t
: 10
: 8e
: w
#
partprobe /dev/sda
#
partprobe /dev/sda10
# pvcreate –v /dev/sda10 (Create Physical
Volume incl one or more partitions) (pvremove /dev/sda10 to remove PV)
# lvmdiskscan
command to to see all block devices used as
PV from existing partition
#
pvs or pvdisplay (Summary of created PV)
#
vgcreate newvg /dev/sda10 (Create Volume Group incl one or more PVs)
·
vgremove newvg to remove VG
·
vgreduce newvg /dev/sda10 to remove specific PV from VG
·
vgsplit newvg newvg2 /dev/sda10 to
split a VG and make a new VG taking PV from older VG
·
vgmerge newvg newvg2 to merge separate VGs
#
vgs or vgdisplay (Scanning your created VG)
#
lvcreate -L 800M -n newlv newvg /dev/sda10 (optional, to mention from which disk
partition of VG should be taken for LV)
·
lvextend –L +50 /dev/newvg/newlv to extend
the vol of LV by 50 MB
·
lvcreate –l 100 –n newlv2 newvg to create
a LV with LE (LV extents)
·
lvremove /dev/newvg/newlv2 to remove LV (You can
either specify LV name or LV dir)
·
lvcreate –l 50 –n newlv3 newvg /dev/sda10:0-25 /dev/sda11:0-25 to create
LV extents taking extents from different partitions
·
lvreduce –l -4 /dev/newvg/newlv3 to remove 4 extents from LV (newlv3)
#
lvs or lvdisplay (Summary of created LVs, add - -units
G to show partition size
in GB)
#
lvchange –pr /dev/newvg/newlv (To change user permission of LV)
#
mkfs.ext4 /dev/newvg/newlv
#
mkdir /mnt/lv1
#
mount /dev/newvg/newlv /mnt/lv1
# blkid /dev/sda10
#
vim /etc/fstab (Type this at last line: /dev/newvg/newlv
/mnt/lv1 ext4 defaults 0 0)
No comments