Exercise 1: Disk Management - Basic Storage

Here are some key issues pertaining to basic storage that have been addressed and are crucial for exam preparation.


Exercise 1: Basic Storage

Q1. Add 5 new disks in your VM each of 2 GB in size.

 

Q2. Create a new partition of 1 GB in the disk /dev/sdb.

[root@server ~]# gdisk /dev/nvme0n2 
GPT fdisk (gdisk) version 1.0.7
 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
 
Found valid GPT with protective MBR; using GPT.
 
Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-10485726, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-10485726, default = 10485726) or {+-}size{KMGTP}: +1G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'
 
Command (? for help): p
Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): FA72ACD0-02EC-4442-B381-1BB02D112EAD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 8388541 sectors (4.0 GiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
 
Command (? for help): w
 
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
 
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n2.
lThe operation has completed successfully.

Q3. Format this partition with XFS filesystem.

[root@server ~]# mkfs.xfs -f /dev/nvme0n2p1
meta-data=/dev/nvme0n2p1         isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
 
[root@server ~]# blkid /dev/nvme0n2p1 
/dev/nvme0n2p1: UUID="4acfbb7f-e1ad-4893-ba19-116ff77e7458" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="48baa3ce-ced6-4f59-b616-b9f5fe608cb7"

Q4. Mount the new partition on /pisdata1 directory such that it get mounted automatically at boot time.

# Add the below line to /etc/fstab
[root@server /]# cat /etc/fstab 
/dev/nvme0n2p1					/pisdata1	xfs	defaults	0	0
 
[root@server /]# mount -a 
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
[root@server /]# systemctl daemon-reload 
 
[root@server /]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0  600M  0 part /boot/efi
├─nvme0n1p2 259:2    0    1G  0 part /boot
└─nvme0n1p3 259:3    0 18.4G  0 part 
  ├─cs-root 253:0    0 16.4G  0 lvm  /
  └─cs-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:4    0    5G  0 disk 
└─nvme0n2p1 259:6    0    1G  0 part /pisdata1
nvme0n3     259:8    0    6G  0 disk 

Q5. Create a 512MB disk partition in the same disk /dev/sdb for increasing swap space.

[root@server /]# gdisk /dev/nvme0n2 
GPT fdisk (gdisk) version 1.0.7
 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
 
Found valid GPT with protective MBR; using GPT.
 
Command (? for help): n 
Partition number (2-128, default 2): 
First sector (34-10485726, default = 2099200) or {+-}size{KMGTP}: 
Last sector (2099200-10485726, default = 10485726) or {+-}size{KMGTP}: +512M
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'
 
Command (? for help): p
Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): FA72ACD0-02EC-4442-B381-1BB02D112EAD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 7339965 sectors (3.5 GiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3147775   512.0 MiB   8200  Linux swap
 
Command (? for help): w
 
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
 
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n2.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
 
[root@server /]# partprobe /dev/nvme0n2 
[root@server /]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0  600M  0 part /boot/efi
├─nvme0n1p2 259:2    0    1G  0 part /boot
└─nvme0n1p3 259:3    0 18.4G  0 part 
  ├─cs-root 253:0    0 16.4G  0 lvm  /
  └─cs-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:4    0    5G  0 disk 
├─nvme0n2p2 259:5    0  512M  0 part 
└─nvme0n2p1 259:6    0    1G  0 part /pisdata1
nvme0n3     259:8    0    6G  0 disk 

Q6. Format the newly created disk partition with swap filesystem.

[root@server /]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0  600M  0 part /boot/efi
├─nvme0n1p2 259:2    0    1G  0 part /boot
└─nvme0n1p3 259:3    0 18.4G  0 part 
  ├─cs-root 253:0    0 16.4G  0 lvm  /
  └─cs-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:4    0    5G  0 disk 
├─nvme0n2p2 259:5    0  512M  0 part 
└─nvme0n2p1 259:6    0    1G  0 part /pisdata1
nvme0n3     259:8    0    6G  0 disk 
 
# Format the partition to swap filesystem 
[root@server /]# mkswap /dev/nvme0n2p2 
mkswap: /dev/nvme0n2p2: warning: wiping old swap signature.
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=27cfc47f-fd30-4904-bcc5-11713ddd25b5
 
# Activate the SWAP
[root@server /]# swapon /dev/nvme0n2p2 
 
[root@server /]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0  600M  0 part /boot/efi
├─nvme0n1p2 259:2    0    1G  0 part /boot
└─nvme0n1p3 259:3    0 18.4G  0 part 
  ├─cs-root 253:0    0 16.4G  0 lvm  /
  └─cs-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:4    0    5G  0 disk 
├─nvme0n2p2 259:5    0  512M  0 part [SWAP]
└─nvme0n2p1 259:6    0    1G  0 part /pisdata1
nvme0n3     259:8    0    6G  0 disk 
 
# Previously the Swap total was 2Gi , now it has been added 512MiB
[root@server /]# free -h
               total        used        free      shared  buff/cache   available
Mem:           3.5Gi       1.1Gi       1.8Gi        25Mi       812Mi       2.4Gi
Swap:          2.5Gi          0B       2.5Gi
 

Q7. Initialize this swap partition now as well as it should get initialized automatically during boot-time.

# Add the below line to /etc/fstab
[root@server /]# vim /etc/fstab
/dev/nvme0n2p2                                  none    swap    defaults        0       0
 
[root@server ~]# reboot
 
[root@server ~]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0          11:0    1 1024M  0 rom  
nvme0n1     259:0    0   20G  0 disk 
├─nvme0n1p1 259:1    0  600M  0 part /boot/efi
├─nvme0n1p2 259:2    0    1G  0 part /boot
└─nvme0n1p3 259:3    0 18.4G  0 part 
  ├─cs-root 253:0    0 16.4G  0 lvm  /
  └─cs-swap 253:1    0    2G  0 lvm  [SWAP]
nvme0n2     259:4    0    5G  0 disk 
├─nvme0n2p1 259:5    0    1G  0 part /pisdata1
└─nvme0n2p2 259:6    0  512M  0 part [SWAP]
nvme0n3     259:7    0    6G  0 disk 
 
[root@server ~]# free -h 
               total        used        free      shared  buff/cache   available
Mem:           3.5Gi       1.1Gi       1.9Gi        25Mi       711Mi       2.4Gi
Swap:          2.5Gi          0B       2.5Gi
 
All systems normal

© 2025 2023 Sanjeeb KC. All rights reserved.