Configure local Storage Flashcards

1
Q

/dev

A

All system devices are located in /dev

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

To create a new partition using fdisk

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

partprobe command

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parted command

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Example of a swap partition with 2GB

A

(parted) mkpart primary linux-swap 400GB 402GB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To set the first partition as bootable in parted

A

(parted) set 1 boot on

type set 1 boot off to remove the bootable flag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

parted remove a partition

A

(parted) rm 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

LVM

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Creating Logical volume

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

To grow a logical volume

A

lvresize -L 900 MB /dev/vg_new/lv_new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

to shrink the logical volume

A
# resize2fs /dev/vg_new/lv_new 800MB
# lvresize -L 800MB /dev/vg_new/lv_new
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

to remove a volume from a volume group

A

pvremove /dev/sdb1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

if the volume doesn’t exist, you can create it and add physical volumes in one shot

A

vgextend myvolgroup /dev/sdc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

to assign a new physical volume to an existing volume

A

vgextend myvolgroup /dev/sdd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

to remove a physical volume from a volume group

A

vgreduce myVolGroup /dev/sdc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

to delete logical volumes

A

lvremove /dev/myVolGroup/vol0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

you can scan for block devices that can be used as physical volumes

A

lvmdiskscan

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

pvscan command

A
scans all supported LVM block devices in the system for physical volumes. It shows all physical devices found
#pvscan
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The following command disallows the allocation of physical extents on /dev/sdc1

A
# pvchange -x n /dev/sdc1
you can use the -xy arguments of the pvchange command to allow allocation where it had previously been disallowed
20
Q

to resize a physical volume

A

you should use the pvresize command

21
Q

To change the maximum number of logical volumes of volume group vg00 to 128

A

vgchange -l 128 /dev/vg00

22
Q

The following will deactivate the volume group my-volume-group

A

vgchange -a n my-volume-group volume group are activated by default

23
Q

To remove a volume group that contains no logical volumes

A

vgremove officeVG

24
Q

to split the physical volumes of a volume group and create a new volume group

A
use vgsplit command. Logical volumes cannot be split between volume groups
 # vgsplit bigvg smallvg /dev/ram15
25
Q

to combine volume groups

A

vgmerge -v databases my-vs

26
Q

renaming an existing volume group vg02 to my_volume_group

A
# vgrename /dev/vg02 /dev/my_volume_group
# vgrename vg02 my_volume_group
27
Q

Creating a striped logical volume across 2 physical volumes with a stripe of 64 KB

A

lvcreate -L 50G -i2 -I64 -n gfslv vg0 gfslv is the name of LV, while vg0 is the name of the VG

28
Q

An example where the stripe will use sectors 0-50 of /dev/sda1 and sectors 50-100 of /dev/sdb1

A

lvcreate -l 100 -i2 -nstripelv testvg /dev/sda1:0-50 /dev/sdb1:50-100

29
Q

to create a mirror volume

A

lvcreate -L 50G -ml -n mirrorlv vg0

30
Q

steps to create a snapshot of a logical volume

A
# mkdir /mnt snapshot    directory to mount the snapshot
# lvcreate -L 100M -s -n lvmsnapshot /dev/vg-new/lv-new   creates the snapshot
# lvs   to view the snapshot createdto restore data from a snapshot, you need to first mount it
# mount -t ext4 /dev/vg-new/lvsnapshot /mnt/snapshotThen you can copy the data back rom /mnt/snapshot
31
Q

to remove a snapshot

A
# umount /mnt/snapshot
# lvremove /dev/vg-new/mvsnapshot
32
Q

GUI to manage LVM

A
System-config-lvm not installed by default
# yum install system-config-lvm
to access you can call from the terminal or from the GUISystem - Administration - logical volume Management
33
Q

to find the UUID of a device

A
#blkid
you can also use this command
# dump2fs /dev/sdb1 | grep UUID
34
Q

add UUID to /etc/fstab

A
# vi /etc/fstab
add entry similarUUID=[strings of numbers & letters obtained] /mydata ext4 defaults 1 2
35
Q

To label a filesystem

A
#e2label /dev/mapper/data luksdrive
then you can add entry to /etc/fstabLABEL=luksdrive /mydata ext4 defaults 1 2
You can also assign a label to a disk with this command
#tune2fs -L test /dev/sdb1other commands
# mke2fs -L newlabel /dev/hdb1
# mkfs.ext3 -L newlabel /dev/hdb1- mkswap -L swaplabel /dev/hdbxx
36
Q

Mounting a specific logical volume by UUID

A

blkid | grep lv_vol&raquo_space; /etc/fstab
- then edit /etc/fstab
the lvdisplay command also generates the UUID of a logical volume
# lvdisplay logicalVolumeName | grep UUID

37
Q

manually mounting filesystems can also be done via label

A

mount -L labelname /mnt/point1

38
Q

to display all partitions with their corresponding UUID and labels

A
# blkid
# ls -l /dev/disk/by-uuid/
# tree /dev/disk 
On the graphical end, you can install gparted
# yum install gparted
39
Q

-adding a partition using fdisk(summarize)

A
#fdisk /dev/sdb
2 - type p to print
3 - type 1
4 - hit enter twice
5 - type t
6 - type 82
7 - type w
40
Q

adding a logical volume fdisk(summarize

A
#fdisk /dev/sdd
type p
type n
type 1
type t
type L
type 8e
type w
41
Q

to make a swap partition(summarize)

A
# mkswap /dev/sdc1    to activate: 
#swapon /dev/sdc1       to check it
 #swapon -s     Add it to /etc/fstab
#echo "/dev/sdc1 swap swap defaults 0 0" >> /etc/fstab to remove swap logical volume
# swapoff /dev/...
42
Q

Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot

A
Install the LUKS package
#yum install -y cryptsetup-luks
Activate LUKS module
#modprobe dm_crypt
Check the module is running
#lsmod | grep dm_crypt
Create a logical volume(here called lv_vol with a size of 100MB in the vg volume group)
#lvcreate --size 100M --name -v_vol vg
Convert the new logical volume to the LUKS format:
#cryptsetup luksFormat /dev/vg/lv_vol
Open and give a name to the LUKS logical volume (here vol):
#cryptsetup luksOpen /dev/vg/lv_vol vol
Create an EXT4 file system on the LUKS logical volume
#mkfs.ext4 /dev/mapper/vol

Create the /etc/crypttab file and add the following line:vol /dev/vg/lv_vol /root/luks.key

Note: if you put ‘none’ instead of ‘/root/luks.key’, you will be asked for the passphrase at each boot at the console

Create the /root/luks.key file for example to store the passphrase:mypassphrase
Add the passphrase to the LUKS logical volume
#cryptsetup luksAddKey /dev/vg/lv_vol /root/luks.key
edit /etc/fstab file and add the following line (be careful when editing the /etc/fstab file or configure a virtual console):/dev/mapper/vol    /vol   ext4    defaults   1   2
Create the mount point
#mkdir /vol
Mount the LUKS logical volume
#mount /vol
43
Q

To unmount a LUKS-encrypted file system

A
Unmount a LUKS-encryted file system by its mounting point in the /etc/fstab file (here /vol),
#unmount /vol
To unmount a LUKS-encrypted file system by its LUKS name (here vol), type:
#umount /dev/mapper/volTo remove a LUKS-encrypted file system, follow:unmount the LUKS file system (here /vol):
#umount /vol
Close the LUKS logical volume:
#cryptsetup luksClose /dev/mapper/volRemove the logical volume
#lvremove /dev/vg/lv_volRemove the file where the passphrase is store
#rm /root/luks.keyEdit the /etc/crypttab and /etc/fstab files and remove the entries associated with the LUKS logical volume
44
Q

Configure Systems to mount file systems at boot by Universally Unique ID (UUID) or label

A

Find the UUID of a devide
#blkid
once found enter in /etc/fstab UUID=f8b69….. /mynew_data ext4 defaults 1 2
Then mount
#mount -a
To mount using a label, first you need to create the label
#e2label /dev/mapper/mynew_data luksdrive
Then add to /etc/fstabLABEL=luksdrive /mynew_data ext4 defaults 1 2

45
Q

To create a volume group (here called vg using a physical volume /dev/vda) with a physical extent size of 8MB, type:

A

vgcreate -s 8m vg /dev/vda

46
Q

Alternatively, if you do not have a spare partition for swap, you can always use a file on existing one:

A
  1. Create an empty file on e.g. /mnt/ partition (size 50MB):

dd if=/dev/zero of=/mnt/swap.file bs=1M count=50
chmod 0600 /mnt/swap.file

  1. Set up a Linux swap area on that file:

mkswap /mnt/swap.file

  1. Add an entry to your /etc/fstab file:

/mnt/swap.file swap swap 0 0

  1. Enable newly added swap area:

swapon -a

  1. Check if the system is using it:

swapon -s