Expanding linux disk to a directory

Demand

To append /dev/sda3 to /home , you need to mount the /dev/sda3 to a subdirectory under the /home directory or merge the /dev/sda3 into an existing /home partition. Here are the detailed steps for both methods:

Method 1: Mount /dev/sda3 to a /home subdirectory

Create a Mount Point directory

First, create a new directory under the /home directory as Mount Point. For example, create a directory named docker :

sudo mkdir /home/docker

2. Mount /dev/sda3

Use the mount command to mount /dev/sda3 to the newly created directory:

sudo mount /dev/sda3 /home/docker

3. Edit /etc/fstab files

To ensure that the system automatically mounts the /dev/sda3 after a reboot, you need to edit the /etc/fstab file.

Open the /etc/fstab file with your favorite text editor, such as nano or vim :

sudo nano /etc/fstab

Add the following line at the end of the file:

/dev/sda3 /home/docker ext4 defaults 0 0

Save and close the file.

4. Confirm successful mounting

Use the df -h command to confirm that /dev/sda3 has been successfully mounted to the /home/docker :

df -h

The output should contain /dev/sda3 Mount Point.

Method 2: Merge /dev/sda3 into an existing /home partition

  1. Confirm if /dev/sda3 have been merged

First, confirm that the /dev/sda3 have been merged into the /dev/mapper/centos-home . You can use the pvs and vgs commands to view information about physical volumes and volume groups.

sudo pvs
sudo vgs

From the output of pvs and vgs , /dev/sda2 is the only physical volume (PV), and it has been fully allocated to the volume group (VG) centos . This means that /dev/sda3 is not included in the centos volume group.

Since /dev/sda3 is not included in the centos volume group, you need to add it to the volume group and then expand /home logical volume.

  1. Add /dev/sda3 to centos volume group

First, use the pvcreate command to initialize the /dev/sda3 to a physical volume:

sudo pvcreate /dev/sda3

Then, use the vgextend command to add /dev/sda3 to the centos volume group:

sudo vgextend centos /dev/sda3
  1. Extended /home Logical Volume

Now you can use the lvextend command to add /dev/sda3 space to /home logical volume:

sudo lvextend -l +100%FREE /dev/mapper/centos-home
  1. Extended file system

Use the resize2fs command to extend the file system:

sudo resize2fs /dev/mapper/centos-home

From the error message, the resize2fs command cannot find a valid filesystem superblock for the /dev/mapper/centos-home . This usually means that there is no correct filesystem on the /dev/mapper/centos-home , or that the filesystem is corrupted.

  1. Confirm file system type

Use the blkid command to check /dev/mapper/centos-home filesystem type:

sudo blkid /dev/mapper/centos-home

As you can see from blkid ‘s output, the filesystem type on the /dev/mapper/centos-home is xfs , not ext4 . Therefore, you need to use the xfs_growfs command to extend the xfs filesystem, not resize2fs .

  1. Extend the xfs file system using xfs_growfs commands
sudo xfs_growfs /dev/mapper/centos-home
  1. Confirm expansion successful

Use the df -h command to confirm that the size of the /home partition has increased:

df -h

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注