RHCSA7 Exam Notes #3: Configure local storage
List, create, delete partitions on MBR and
GPT disks
MBR older method used with BIOS computers < 2.2TB, 4 Primary
Partitions Max, < 12 logical partitions per drive recommended
GPT part of UEFI standard, < 2 ZetaBytes, 128 Primary Partitions
/dev/xxyN (/device
file directory/xx=type of device -usually sd, y=which device, N=partition
number – first 4 are for primary/extended – logical partitions start at 5 and
upwards)
Disk Partitions are mounted to a Directory to make them usable –
i.e. if /dev/sda5 is mounted on /usr/ all files written under /usr/ would
reside on /dev/sda5
Read: Linux 7 Installation Guide – section – “An Introduction to
Disk Partitions” for an excellent primer in Linux Disk Partitions
Run command
“parted /dev/sd[a-z]” with root privileges to target a particular disk with the
following commands:
print (lists partitions - number=partition
number, i.e. 1 is /dev/sda1)
mklabel
msdos (needed on
all new disks)
mkpart
primary ext3 1 2001 (creates a primary
partition with an ext3 filesystem from 1MB to 2001MB on disk)
You can
also just use the mklabel and mkpart commands on their own and step through the
prompts. Next: Exit parted with q
partprobe
/dev/sdc (force the kernel
to re-read the updated partition table)
parted
/dev/sdc print (check
partitions)
/usr/sbin/mkfs
–t ext3 /dev/sdc1 (create the file
system)
Now give
the partition a label to help identify the associated mount point to create
later:
e2label
/dev/sdc1 /work
mkdir /work (creates
/work directory)
partprobe /dev/sdc (force kernel to
re-read updated partition table)
mount
/dev/sdc1 /work
Now to make
the mount permanent:
blkid –o
list (gives list of UUIDs – use the
terminal copy and paste commands here)
vi
/etc/fstab (edit to add new partition
mount, use boot one as template but change xfs to ext3 as highlighted below!!)
UUID=XXXX
/work ext3 defaults 1 2
“mount –a”
to test and “mount | grep /work” to check
To remove unmounts
the partitions and run “parted sdc” and list partitions with print
rm 1 (deletes partition 1)
Quit with q
and edit /etc/fstab to remove the line added earlier. Reboot
Now if you
run “cat /proc/partitions” you should no longer see sdc1
Create and remove physical volumes, assign
physical volumes to volume groups, and create and delete logical Volumes
system-config-lvm was dropped with GNOME3 in RHEL7 so good
luck finding that! All work has to be command line with LVM as a result.
Add a new disk to your test system. Reboot and check using “fdisk
-l” what the name is, in my case it appeared as /dev/sdb
pvcreate /dev/sdb (creates
a partition on sdb to initialise the disk)
pvdisplay /dev/sdb (Displays details of the physical volumes)
pvdisplay /dev/sdb (Displays details of the physical volumes)
vgcreate -s 8 vg01 /dev/sdb (creates
vg01 volume group with 8MB PE size, can add other partitions also by appending
/dev/sdc1 /dev/sdf etc to command)
vgdisplay -v vg01 (displays
details of vg01)
lvcreate -L 3000 -n dbvol vg01 (creates 3GB logical volume dbvol in volume group vg01)lvcreate -L 1500 -n myball vg01 (creates second logical volume)
lvdisplay -v vg01 (Displays details of vg01 volume group)
lvcreate -L 3000 -n dbvol vg01 (creates 3GB logical volume dbvol in volume group vg01)lvcreate -L 1500 -n myball vg01 (creates second logical volume)
lvdisplay -v vg01 (Displays details of vg01 volume group)
To Extend Space:
pvcreate /dev/sdc
vgextend vg01 /dev/sdc (adds sdc to vg01 volume group)
lvextend -L +2GB /dev/vg01/dbvol (extends dbvol by 2GB, or set absolute size with 5GB)
lvresize -L 2.5GB /dev/vg01/myball (resizes myball to 2.5GB, or use + to add space, can also reduce space by lowering figure or using -1GB for instance)
pvcreate /dev/sdc
vgextend vg01 /dev/sdc (adds sdc to vg01 volume group)
lvextend -L +2GB /dev/vg01/dbvol (extends dbvol by 2GB, or set absolute size with 5GB)
lvresize -L 2.5GB /dev/vg01/myball (resizes myball to 2.5GB, or use + to add space, can also reduce space by lowering figure or using -1GB for instance)
Remove Volumes:
lvremove /dev/vg01/myball (Do this for dbvol also then proceed to the next step)
vgreduce vg01 /dev/sdc /dev/sdb (removes sdb/sdc from vg01)
vgremove vg01 (removes vg01)
pvremove /dev/sdb /dev/sdc (removes sdb/sdc partitions)
lvremove /dev/vg01/myball (Do this for dbvol also then proceed to the next step)
vgreduce vg01 /dev/sdc /dev/sdb (removes sdb/sdc from vg01)
vgremove vg01 (removes vg01)
pvremove /dev/sdb /dev/sdc (removes sdb/sdc partitions)
Create and configure LUKS-encrypted
partitions and logical volumes to prompt for password and mount a decrypted
file system at boot
rpm -qa | grep cryptsetup (confirms
encryption packages are install, should be by default)
I recreated the logical volumes used in the last section to test against:
cryptsetup -v -y luksFormat /dev/vg01/dbvol (ensure the F in luksFormat is uppercase!)
cryptsetup –v luksOpen /dev/vg01/dbvol dbvol_luks (ensure the O in luksOpen is uppercase! Assigns name to volume to create a device file in /dev/mapper directory)
ls -l /dev/mapper | grep dbvol_luks (checks device is present in mapper file)
mkfs -t ext4 /dev/mapper/dbvol_luks (construct ext4 file system in the logical volume)
mkdir /dbvol_luks (create mount point)
mount /dev/mapper/dbvol_luks /dbvol_luks (mount file system, check with “df”)
edit /etc/crypttab file and add the following line:I recreated the logical volumes used in the last section to test against:
cryptsetup -v -y luksFormat /dev/vg01/dbvol (ensure the F in luksFormat is uppercase!)
cryptsetup –v luksOpen /dev/vg01/dbvol dbvol_luks (ensure the O in luksOpen is uppercase! Assigns name to volume to create a device file in /dev/mapper directory)
ls -l /dev/mapper | grep dbvol_luks (checks device is present in mapper file)
mkfs -t ext4 /dev/mapper/dbvol_luks (construct ext4 file system in the logical volume)
mkdir /dbvol_luks (create mount point)
mount /dev/mapper/dbvol_luks /dbvol_luks (mount file system, check with “df”)
dbvol_luks /dev/vg01/dbvol_luks none (this will prompt for password on startup)
edit /etc/fstab and add the following line:
/dev/mapper/dbvol_luks /dbvol_luks ext4 defaults 1 2
edit /etc/fstab and add the following line:
/dev/mapper/dbvol_luks /dbvol_luks ext4 defaults 1 2
Reboot, supply password on startup and check mount status:
mount | grep dbvol_luks
mount | grep dbvol_luks
NOTE: when rebooting
it hangs, tried volume group and partition but it’s not working out for me.
Will troubleshoot and update when I have a stable config. (took out fstab from
partition method and got prompted at gui!?!)
Configure systems to mount file systems at
boot by Universally Unique ID (UUID) or label
blkid -o list (make
sure you run this command as root, gives device UUIDs)
e2label /dev/sdb myball2 (labels partition myball2)
Use either of the two methods in /etc/fstab to mount file systems on bootup:
UUID=xxxx /home ext4 defaults 1 2
LABEL=myball2 /hiccup ext4 defaults 1 2
e2label /dev/sdb myball2 (labels partition myball2)
Use either of the two methods in /etc/fstab to mount file systems on bootup:
UUID=xxxx /home ext4 defaults 1 2
LABEL=myball2 /hiccup ext4 defaults 1 2
Add new partitions and logical volumes, and
swap to a system non-destructively
parted /dev/sdb
mklabel / msdos / yes (Assign a label to the disk, must be done on new disk)
mkpart / primary / [ext4/linux-swap] / 1 / 2g (Create a ext4 / Swap partition of 2GB)print (Verify)
partprobe /dev/sdb (force kernel to re-read the updated partition table)
grep sdb /proc/partitions
mklabel / msdos / yes (Assign a label to the disk, must be done on new disk)
mkpart / primary / [ext4/linux-swap] / 1 / 2g (Create a ext4 / Swap partition of 2GB)print (Verify)
partprobe /dev/sdb (force kernel to re-read the updated partition table)
grep sdb /proc/partitions
mkswap /dev/sdc swapon
/dev/sdc
mkswap /dev/vg01/myball swapon /dev/vg01/myball
swapon -s (confirm new swap areas are activated)
mkswap /dev/vg01/myball swapon /dev/vg01/myball
swapon -s (confirm new swap areas are activated)
vmstat -s
Edit /etc/fstab to activate on system boot:
UUID=XXXX swap swap defaults 0 0
/dev/vg01/myball swap swap defaults 0 0
swapoff /dev/sdc swapoff /dev/vg01/myball
UUID=XXXX swap swap defaults 0 0
/dev/vg01/myball swap swap defaults 0 0
swapoff /dev/sdc swapoff /dev/vg01/myball
Edit /etc/fstab to remove swap entries and reboot to validate