Managing storage on Linux hosts
This section includes basic procedures for managing storage on a Linux host.
Identifying storage devices and their configuration
This procedure identifies block storage devices attached to a host and demonstrates how devices are configured.
- Use a terminal session to log in to the target host as root or as a user with superuser privileges.
-
Display the block storage devices attached to the host and their configuration.
lsblk --output=NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
The following example result shows three disks (sda, sdb, and sdc) and one CD/DVD drive (sr0). - Disk sda has two primary partitions: - Partition sda1 is devoted to /boot, and formatted with the XFS file system. - Partition sda2 includes the following logical volumes, which are managed by LVM: - a swap volume, formatted as such - a volume for root (/), formatted as XFS - a volume for /home, formatted as XFS
Example result:
NAME SIZE TYPE FSTYPE MOUNTPOINT sda 128G disk |-sda1 500M part xfs /boot |-sda2 127.5G part LVM2_member |-centos_c15246-swap 24.8G lvm swap |-centos_c15246-root 50G lvm xfs / |-centos_c15246-home 52.6G lvm xfs /home sdb 768G disk sdc 768G disk sr0 1024M rom
For more information about lsblk, enter man lsblk.
Creating primary partitions
To perform this procedure, you need:
- The password of the root user account on a Linux host or a user account that belongs to the wheel group.
- A Linux host with at least one local or remote disk.
This procedure demonstrates how to create primary partitions on a disk. Each primary partition can be formatted as a file system or swap space, used in a device mapper thin pool, or reserved for future use. Each disk must have one primary partition, and can have up to four. If you are uncertain whether a disk is partitioned, see the preceding topic.
Data present on the disk you select is destroyed by this procedure. Before proceeding, ensure that data is backed up or no longer needed.
- Log in to the target host as root or as a user with superuser privileges.
-
Start the partition table editor for the target disk.
In this example, the target disk is /dev/sdb, and it has no entries in its partition table.
cfdisk /dev/sdb
The cfdisk command provides a text user interface (TUI) for editing the partition table. The following list describes how to navigate through the interface:
- To select an entry in the table, use the up and down arrow keys. The current entry is highlighted.
- To select a command from the menu at the bottom of the interface, use the left and right arrows or Tab and Shift-Tab. The current command is highlighted.
- To choose a command, press Enter.
- To return to the previous level of the menu, press Esc.
- To exit the interface, select Quit and then press Enter.
For more information about cfdisk, enter man cfdisk.
-
Create a new partition.
Repeat the following substeps to create up to four primary partitions.
- Select the table entry with the value Free Space in the FS Type column.
- Select [New] and press Enter.
- Select [Primary] and press Enter.
-
At the Size (in MB) prompt, enter the size of the partition to create in megabytes, and then press Enter.
To accept the default value (all free space on the disk), press Enter.
-
Optional: Note: If you created a single partition that uses all available disk space, skip this substep. Select [Beginning] and press Enter.
-
Write the partition table to disk, and then exit the partition table editor.
- Select [Write] and press Enter.
-
At the confirmation prompt, enter yes and then press Enter.
You can ignore the warning about a bootable partition.
-
Select [Quit] and press Enter.
Creating a swap partition
To perform this procedure, you need:
- A host with one or more local disks, with at least one unused primary partition.
- The password of the root account on the host or a user that is a member of the wheel group.
Perform this procedure to configure a primary partition on a local disk as swap space. Typically, configuring one swap partition or swap file on each local disk maximizes swap space performance.
This procedure does not use LVM tools to create a swap space. For more information about LVM, refer to your operating system documentation.
- Log in to the target host as root or as a user with superuser privileges.
-
Identify one or more primary partitions for use as swap space.
lsblk -p --output=NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
-
Create and enable swap space on each target primary partition.
-
Disable swapping on all swap devices.
swapoff -a
-
Create swap space.
Repeat the following command for each primary partition to use as swap space.
Replace Device with the path of a primary partition:
mkswap Device
-
Update the file system table.
Repeat the following command for each swap partition created in the previous substep.
Replace Device with the path of a swap partition:
echo "Device swap swap defaults 0 0" >> /etc/fstab
-
Enable swapping on all swap devices.
swapon -a
-