Note:
- This tutorial is available in an Oracle-provided free lab environment.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Work with File Systems on Oracle Linux
Introduction
In the following tutorial, you’ll perform various tasks related to the Oracle Linux file system.
Objectives
- Display the current partition table
- List mounted file systems
- Partition disk devices
- Create and mount file systems on partitions
- Modify the file system table to mount the file systems on reboots
- Increase the amount of swap space
- Remove partitions and additional swap space
Prerequisites
- A system with Oracle Linux installed
- Two or more block devices attached to the system
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
Verify the Block Volumes Exist
The free lab environment creates two additional block volumes during deployment and attaches them to the Oracle Linux instance.
-
Open a terminal and connect via ssh to the ol-server node.
ssh oracle@<ip_address_of_ol_server>
-
Use the
lsblk
command to verify the block volumes are available on the system.lsblk
Note: The command output shows three block devices:
sda
,sdb
, andsdc
.
List the Current Disk Partitions
-
Display the current partition table and pipe the output to
grep
to list all/dev/sd
disk devices.sudo fdisk -l | grep /dev/sd
Note: The lab system has three disk devices,
/dev/sda
,/dev/sdb
,/dev/sdc
.- The device
/dev/sda
is a 46.6 GB disk containing three partitions of various types and sizes:/dev/sda1
is a 100 MB Extensible Firmware Interface (EFI partition),/dev/sda2
is a 1 GB Linux file system, with/dev/sda3
being a 45.5 GB Linux Logical Volume Manager (LVM). - Partitions
/dev/sda1
and/dev/sda2
are the primary boot devices. - Partition
/dev/sda3
is mapped to the root file system. - Disk device,
/dev/sdb
, is a 50 GB disk without any partitions. - Disk device,
/dev/sdc
, is a 50 GB disk without any partitions.
- The device
-
Use the
df
command to list the mounted partitions. The order of the devices might be different, and some numbers might vary.df -h
- The first partition,
sda1
, on the hard drive contains the Unified Extensible Firmware Interface (UEFI) boot loader files and is mounted on/boot/efi
. - The second partition,
sda2
, is mounted on/boot
. - The file systems mounted on
/
and/var/oled
are logical volumes.
- The first partition,
Create an MBR Partition
In this section, use the fdisk
utility to create a Master Boot Record (MBR) partition.
-
Use the
fdisk
command to partition/dev/sdb
.sudo fdisk /dev/sdb
The interactive program opens with a short statement on its use, information about the device selected, and a command prompt.
-
Enter
m
at the prompt to display thefdisk
menu.Note: The menu groups the available options by their function.
-
Enter
n
to add a new MBR primary partition.- The MBR stores partition information at the beginning of a disk and is limited to four primary partitions.
- One of the four partitions can be designated as an extended partition. This partition can then be subdivided into multiple logical partitions.
-
Enter
p
, followed by the number1
for the first primary partition. -
Press Enter to accept the default (2048) as the start of the first sector.
-
Enter
+500M
to set the last sector using the size notation.fdisk
returns a message telling you that the new partition is of the type ‘Linux’ with a size of 500 MiB. -
Enter
p
to print the new partition.Some of the information the print option displays is:
- The disk device name:
/dev/sdb1
. - The disk label type:
dos
, which indicates an MBR partition table. - The partition type:
Linux
.
- The disk device name:
-
Enter
w
to save the new partition.fdisk
notes that the partition has changed, is being re-read byioctl()
, and that the disk is synchronizing. -
Use the
fdisk -l
command to list the partition table on/dev/sdb
. Thefdisk -l
command uses the lowercase letterl
option, and not the numeral 1.sudo fdisk -l /dev/sdb
Create a GPT Partition
-
Use the
fdisk -l
command to list the current partitions on/dev/sdc
.sudo fdisk -l /dev/sdc
Note: The disk does not have any partitions.
-
Use the
fdisk
command to create a GUID Partition Table (GPT) partition on/dev/sdc
.sudo fdisk /dev/sdc
fdisk
outputs the summary as it did before about the disk.- GPT partitions are ideal for disks larger than 2 TB.
- In this lab, you use a 50 GB disk.
- If this disk was larger than 2 TB, a warning displays affirming the size of the disk and indicating that it cannot be used as a DOS partition table.
-
Enter
g
to add a new GPT partition.The output confirms the creation of a new GPT disk label.
-
Enter
n
, followed by the number1
for the first sector partition. -
Press Enter to accept the default (2048) as the start of the first sector.
-
Enter Enter to set the last sector using the default size of
104857566
.fdisk
returns a message telling you of the new partition of the type ‘Linux’ with a size of 50 GiB. -
Enter
p
to print the new partition.Some of the information the print option displays is:
- The disk device name:
/dev/sdc1
. - The disk label type:
gpt
, which indicates an GPT partition table. - The partition type:
Linux
.
- The disk device name:
-
Enter
w
to save the new partition.fdisk
notes that the partition changed, being re-read byioctl()
, and the disks are synchronizing.
Create an ext4 File System on the MBR Partition
In this section, you create a file system on /dev/sdb1
.
-
Use the
mkfs
command to make anext4
file system on the disk and assign it the label ofTest
.sudo mkfs -t ext4 -L Test /dev/sdb1
-
Use the
blkid
command to display the attributes of the/dev/sdb1
block device.blkid /dev/sdb1
Create a xfs File System on the GPT Partition
In this section, you create an xfs
file system on /dev/sdc1
.
-
Use the
mkfs
command to make anxfs
file system on the disk and assign it the label ofDev
.sudo mkfs -t xfs -L Dev /dev/sdc1
-
Use the
blkid
command to display the attributes of the/dev/sdc1
block device.blkid /dev/sdc1
Mount the File Systems
In this section, you create mount points and mount the file systems to the mount points.
-
Use the
mkdir
command to create the mount points.sudo mkdir /Test sudo mkdir /Dev
-
Use the
mount
command to mount/dev/sdb1
to/Test
, and/dev/sdc1
to/Dev
.sudo mount /dev/sdb1 /Test sudo mount /dev/sdc1 /Dev
-
Use the
df
command to display the mounted file systems.df -h
-
Use the
mount
command and pipe the output togrep
to display the/Test
file system.mount | grep /Test
Note:
- Notice that the output shows the default mount options on
/Test
. - Refer to the
man mount
page for more information on these and other mount options.
- Notice that the output shows the default mount options on
-
Use the
mount
command and pipe the output togrep
to display the/Dev
file system.mount | grep /Dev
Note: Refer to the
man mount
page for more information on these and other mount options. -
Use the command
cat /proc/mounts
to view the status of all mounted file systems. Pipe the output totail
and display the last six lines.cat /proc/mounts | tail -6
The
mounts
file is part of the proc virtual file system. Themounts
file, like other files in the/proc
directory, does not exist. It is a representation of file system status in file form.
Update the fstab File
In this section, you update the /etc/fstab
file to mount the new file systems on reboots.
-
Use the
blkid
command to obtain theUUID
values for/dev/sdb1
and/dev/sdc1
to use in the next step.blkid /dev/sdb1 blkid /dev/sdc1
Note: Oracle recommends using the device universally unique identifier (UUID) instead of
/dev
path names to avoid naming issues across reboots. -
Add the new entries to
/etc/fstab
and reload the systemd daemon.echo "$(blkid /dev/sdb1 | awk '{print $3}') /Test ext4 defaults 0 0" | sudo tee -a /etc/fstab echo "$(blkid /dev/sdc1 | awk '{print $3}') /Dev xfs defaults 0 0" | sudo tee -a /etc/fstab sudo systemctl daemon-reload
Updating the
/etc/fstab
automatically mounts included file systems after the system reboots. Thesystemd
daemon needs to be reloaed for the system to see the changes to the/etc/fstab
file.Important: If you add an iSCSI remote block volume, you must include the
_netdev
mount option or your instance will become unavailable after the next reboot. -
Use the
umount
command to unmount the file systems.sudo umount /Dev /Test
-
Use the
mount –a
command to mount all file systems in/etc/fstab
file.sudo mount -a
-
Use the command
df -h
to verify your new file systems are mounted.df -h
Increase Swap Space
In this section, you increase the amount of swap space by creating, initializing, and enabling a swap file.
-
Use the
swapon
command to display the current amount of swap space.swapon -s
-
Use the command
grep -i swap /proc/meminfo
to display the amount of swap space.grep -i swap /proc/meminfo
-
Use the
free
command to display the amount of swap space.free -h
-
Use the
dd
command to create a swap file.sudo dd if=/dev/zero of=/.swapfile2 bs=1024 count=1048576
-
Change the permissions on the swap file.
sudo chmod 600 /.swapfile2
The
mkswap
andswapon
commands will display a warning about insecure permissions without this change as the file defaults to permissions of0644
. -
Use the
mkswap
command to initialize the swap file.sudo mkswap /.swapfile2
-
Use the
swapon
command to enable swapping on the swap file.sudo swapon /.swapfile2
-
Use the following commands to display the updated swap space.
swapon -s grep -i swap /proc/meminfo free -h
If you need the additional swap space after a reboot, add the new swap file to the /etc/fstab
file.
Remove Partitions and Additional Swap Space
In this section, you remove your partitions, remove the entries in the file system table, and remove the additional swap space.
-
Remove the entries from
/etc/fstab
.sudo sed -i "/^$(blkid /dev/sdb1 | awk '{print $3}')/d" /etc/fstab sudo sed -i "/^$(blkid /dev/sdc1 | awk '{print $3}')/d" /etc/fstab sudo systemctl daemon-reload
You can confirm the removal of the entries by running
tail -n 5 /etc/fstab
, which prints the last 5 lines of the file. -
Use the
umount
command to unmount the file systems.sudo umount /Dev /Test
-
Use the
fdisk
command to delete the partition on/dev/sdb
.sudo fdisk /dev/sdb
-
Enter
d
to delete partition 1. -
Enter
p
to print the partition table and confirm there are no partitions. -
Enter
w
to save the partition table and exit thefdisk
utility.
-
-
Use the
fdisk
command to delete the partition on/dev/sdc
.sudo fdisk /dev/sdc
-
Enter
d
to delete partition 1. -
Enter
p
to print the partition table and confirm there are no partitions. -
Enter
w
to save the partition table and exit thefdisk
utility.
-
-
Use the
parted
command to change the label on/dev/sdc
fromgpt
tomsdos
sudo parted /dev/sdc
-
Enter
mklabel msdos
to create anmsdos
label. -
Enter
Yes
to continue. -
Enter
print
to the partition table to confirm the label change. -
Enter
quit
to exit theparted
utility.
-
-
Use the
rmdir
command to remove the/Dev
and/Test
mount point directories.sudo rmdir /Dev /Test
-
Use the
swapoff
command to disable swapping to/.swapfile2
.sudo swapoff /.swapfile2
-
Use the
rm
command to remove/.swapfile2
.sudo rm /.swapfile2
For More Information
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Work with File Systems on Oracle Linux
F45077-07
April 2024