Configure local Storage Flashcards
/dev
All system devices are located in /dev
To create a new partition using fdisk
fdisk /dev/sdb
- use m -> for help
- use p -> to print
- use n -> to create a partition
- use L -> to view different file system we can use
- use w -> to write changes
partprobe command
If you don't see the partition that was just created, you can reboot the system or use the partprobe command # partprobe Which tells the kernel to re-read all partition
Parted command
parted(parted) print all
or type
# parted -l(parted) select /dev/sdb
(parted) mktable gpt create a gpt partition tables
- to create a primary partition with the ext4 type(from 1 mb to 400GB)
(parted) mkpart primary ext4 1MB 400GB
(parted) rm 2 remove a partition
- to use all the remaining space, use -1 as end position
- If at a later stage, after creating a partition, you want to change the type of partition, don’t drop and recreate the partition. Format the partition as you want and parted will normally detect the new type
Example of a swap partition with 2GB
(parted) mkpart primary linux-swap 400GB 402GB
To set the first partition as bootable in parted
(parted) set 1 boot on
type set 1 boot off to remove the bootable flag
parted remove a partition
(parted) rm 2
LVM
Logical Volume Manager. It is the default volume management system
- Uses a collection of disks- a single volue can span multiple disks
- not all disks need to be the same size
- each disk is referred to as a ‘Physical Volume’ (PV)- physical volumes are collected in to ‘volume groups’ (VG)- A volume group is split into ‘logical volumes’ (LV)
- logical volumes contain the file systems
- LVM allows for online resizing, reduces system downtime
- PV’s and LV’s are broken up into chunks of data, called extents
- Logical volumes can be grown or shrunk by either increasing or decreasing the extents used, or by increasing or decreasing the amount of disk space used (MG, GB, etc)
- LVM provides the ability to create volume backups through snapshots(no need for filesystem downtime)
- the /boot partition cannot be on a logical volume, grub cannot real LVM volumes
- Volume groups are located at /dev/mapper command line and GUI tools (System-config-lvm)
Creating Logical volume
First step is to convert any disk or partition into physical volumes
# fdisk /dev/sdb
- press the t key to change the partition’s type, then press entercommand
(m for help): t
- next type (L) to view the different hex code, then press entercommand
(m for help): L
- The one for LVM is 8e, so enter 8e and press enter
hex code(type L to list codes): 8e
-type w to savecommand
(m for help): w
-step 2 create a physical volume: # pvcreate /dev/sdb1 - to check on the physical volume: # pvs - to view more details: #pvdisplay
- step 3 lump volumes into a volume group # vgcreate vg_new /dev/sdb1 /dev/sdc1 - to check on the volume group # vgs # vgdisplay
- step 4 create logical volume
# lvcreate -L 800M -n lv_new vg_new - to verify
# lvs
To grow a logical volume
lvresize -L 900 MB /dev/vg_new/lv_new
to shrink the logical volume
# resize2fs /dev/vg_new/lv_new 800MB # lvresize -L 800MB /dev/vg_new/lv_new
to remove a volume from a volume group
pvremove /dev/sdb1
if the volume doesn’t exist, you can create it and add physical volumes in one shot
vgextend myvolgroup /dev/sdc
to assign a new physical volume to an existing volume
vgextend myvolgroup /dev/sdd
to remove a physical volume from a volume group
vgreduce myVolGroup /dev/sdc
to delete logical volumes
lvremove /dev/myVolGroup/vol0
you can scan for block devices that can be used as physical volumes
lvmdiskscan
pvscan command
scans all supported LVM block devices in the system for physical volumes. It shows all physical devices found #pvscan