Extending Partitions and File Systems of a SCSI Data Disk on Linux (fdisk)
Scenarios
In Linux, after the capacity expansion succeeded, the additional disk space needs to be allocated to an existing partition or a new partition.
This topic uses SUSE Linux Enterprise Server 11 SP4 64bit to describe how to allocate the additional space of an attached SCSI data disk to a partition using fdisk.
Currently, a disk has been attached to a server, and the original disk capacity is 10 GB. In addition, a 10-GB space has been added to the disk on the management console, and the total disk capacity should be 20 GB. However, the additional space cannot be viewed on the server. The following operations guide you to view the additional space and extend the partition.
The method for allocating the additional space varies depending on the server OS. This document is used for reference only. For the detailed operations and differences, see the corresponding OS documents.
- Create a new partition (services will not be interrupted).
Creating a new partition after expansion does not require the original partitions to be unmounted. Therefore, the impacts on services are minor than re-creating an existing partition. This method is recommended for system disks or disks carrying services that cannot be interrupted.
If the MBR partition style is used, ensure that the disk capacity does not exceed 2 TB and the number of partitions does not reach the upper limit after the expansion.
- Re-create an existing partition (services will be interrupted).
If the MBR partition style is used and the number of partitions has reached the upper limit, you can only allocate the additional space to an existing partition. Re-creating an existing partition does not delete its data, but requires the partition to unmount. Therefore, services will be interrupted.
If the MBR partition style is used and the disk capacity after expansion will exceed 2 TB, the space exceeding 2 TB cannot be used. To make use of that space, change the disk partition style from MBR to GPT. Data on the disk will be cleared during such a change. Therefore, back up the disk data before changing the partition style.
Performing the expansion operations with caution. Misoperation may lead to data loss or exceptions. Therefore, you are advised to use CBR to back up the disk data before expansion. For details, see Managing Backups.
Prerequisites
- You have logged in to the server.
- For how to log in to an ECS, see the Elastic Cloud Server User Guide.
- For how to log in to a BMS, see the Bare Metal Server User Guide.
- You have attached the disk to the server, and the additional space has not been allocated.
Re-creating an Existing Partition
The following procedure shows you how to make use of the additional space of a disk attached to a server by extending the /dev/sda1 partition and mounting the partition on /mnt/sdc. During this process, services will be interrupted.
- Run the following command to view the disk partition information:
fdisk -l
Information similar to the following is displayed:ecs-xen-02:/home/linux # fdisk -l Disk /dev/xvda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00065c40 Device Boot Start End Blocks Id System /dev/xvda1 2048 41945087 20971520 82 Linux swap / Solaris /dev/xvda2 * 41945088 83892223 20973568 83 Linux /dev/xvda3 83892224 209715199 62911488 83 Linux Disk /dev/sda: 10.7 GB, 10737418240 bytes 64 heads, 32 sectors/track, 10240 cylinders, total 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2f1c057a Device Boot Start End Blocks Id System /dev/sda1 2048 20971519 10484736 83 Linux
In the command output, 10 GB has been added to the /dev/sda data disk on the management console, and the total capacity should be 20 GB. However, the additional space is not included in the command output. In this case, run the following command to update the data disk capacity on the server:
- Run the following command to update the data disk capacity on the server:
echo 1 > /sys/class/scsi_device/%d:%d:%d:%d/device/rescan &
In the command, %d:%d:%d:%d indicates a folder in the /sys/class/scsi_device/ directory and can be obtained using ll /sys/class/scsi_device/.
Information similar to the following is displayed: (2:0:0:0 indicates the folder to be obtained.)cs-xen-02:/sys/class/scsi_device # ll /sys/class/scsi_device/ total 0 lrwxrwxrwx 1 root root 0 Sep 26 11:37 2:0:0:0 -> ../../devices/xen/vscsi-2064/host2/target2:0:0/2:0:0:0/scsi_device/2:0:0:0
Example command:
echo 1 > /sys/class/scsi_device/2:0:0:0/device/rescan &
- After the disk capacity is updated, run the following command to view the disk partition information again:
fdisk -l
Information similar to the following is displayed:ecs-xen-02:/sys/class/scsi_device # fdisk -l Disk /dev/xvda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00065c40 Device Boot Start End Blocks Id System /dev/xvda1 2048 41945087 20971520 82 Linux swap / Solaris /dev/xvda2 * 41945088 83892223 20973568 83 Linux /dev/xvda3 83892224 209715199 62911488 83 Linux Disk /dev/sda: 21.5 GB, 21474836480 bytes 64 heads, 32 sectors/track, 20480 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2f1c057a Device Boot Start End Blocks Id System /dev/sda1 2048 20971519 10484736 83 Linux
In the command output, the additional space has been added to the /dev/sda data disk, and the update succeeded. The /dev/sda disk has one partition only, /dev/sda1. Take note of start and end sectors of the /dev/sda1 partition. These values will be used during the partition re-creation. The partition's start sector is 2048, and its end sector is 20971519.
- Run the following command to unmount the partition:
umount /mnt/sdc
- Run the following command to enter fdisk and enter d to delete the /dev/sda1 partition:
fdisk /dev/sda1
Information similar to the following is displayed:[ecs-xen-02:/sys/class/scsi_device # fdisk /dev/sda Command (m for help): d Selected partition 1 Command (m for help):
- Enter n and press Enter to create a new partition.
Entering n creates a new partition.
Information similar to the following is displayed:Command (m for help): n Command action e extended p primary partition (1-4)
There are two types of disk partitions:- Choosing p creates a primary partition.
- Choosing e creates an extended partition.
- Ensure that the entered partition type is the same as the partition had before. In this example, a primary partition is used. Therefore, enter p and press Enter to create a primary partition.
Information similar to the following is displayed:
p Partition number (1-4, default 1):
In the command output, Partition number specifies the primary partition number.
- Ensure that the entered partition number is the same as the partition had before. In this example, partition number 1 is used. Therefore, enter 1 and press Enter.
Information similar to the following is displayed:
Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048):
In the command output, First sector specifies the start sector.
Data will be lost if the following operations are performed:- Select a start sector other than the partition had before.
- Select an end sector smaller than the partition had before.
- Ensure that the entered start sector is the same as the partition had before. In this example, start sector 2048 is recorded in 3. Therefore, enter 2048 and press Enter.
Information similar to the following is displayed:
First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
In the command output, Last sector specifies the end sector.
- Ensure that the entered end sector is larger than or equal to the end sector recorded in 3. In this example, the recorded end sector is 20971519, and the default end sector is used. Therefore, enter 41943039 and press Enter.
Information similar to the following is displayed:
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Command (m for help):
The partition is created.
- Enter p and press Enter to view details about the new partition.
Information similar to the following is displayed: (Details about the /dev/sda1 partition are displayed.)
Command (m for help): p Disk /dev/sda: 21.5 GB, 21474836480 bytes 64 heads, 32 sectors/track, 20480 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2f1c057a Device Boot Start End Blocks Id System /dev/sda1 2048 41943039 20970496 83 Linux Command (m for help):
- Enter w and press Enter to write the changes to the partition table.
Information similar to the following is displayed: (The partition is successfully created.)
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
In case that you want to discard the changes made before, you can exit fdisk by entering q.
- Perform the following operations based on the file system of the disk:
- For the ext3 or ext4 file system
- Run the following command to check the correctness of the file system on /dev/sda1:
e2fsck -f /dev/sda1
Information similar to the following is displayed:ecs-xen-02:/sys/class/scsi_device # e2fsck -f /dev/sda1 e2fsck 1.41.9 (22-Aug-2009) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sda1: 11/655360 files (0.0% non-contiguous), 79663/2621184 blocks
- Run the following command to extend the size of the file system on /dev/sda1:
resize2fs /dev/sda1
Information similar to the following is displayed:ecs-xen-02:/sys/class/scsi_device # resize2fs /dev/sda1 resize2fs 1.41.9 (22-Aug-2009) Resizing the filesystem on /dev/sda1 to 5242624 (4k) blocks. The filesystem on /dev/sda1 is now 5242624 blocks long.
- Run the following command to mount the new partition on /mnt/sdc:
mount /dev/sda1 /mnt/sdc
- Run the following command to check the correctness of the file system on /dev/sda1:
- For the xfs file system
- Run the following command to mount the new partition on /mnt/sdc:
mount /dev/sda1 /mnt/sdc
- Run the following command to extend the size of the file system on /dev/sda1:
sudo xfs_growfs /dev/sda1
- Run the following command to mount the new partition on /mnt/sdc:
- For the ext3 or ext4 file system
- Run the following command to view the mount result:
df -TH
Setting Automatic Mounting at System Start
To automatically mount partitions at system starts, do not specify partitions, for example, /dev/xvdb1, in /etc/fstab because the sequence of cloud devices, and therefore their names may change during the server stop or start. You are advised to use the UUID in /etc/fstab to set automatic mounting at system start.
UUID is the unique character string for disk partitions in a Linux system.
- Run the following command to query the partition UUID:
blkid Disk partition
For example, run the following command to query the UUID of the /dev/xvdb1 partition:
blkid /dev/xvdb1
Information similar to the following is displayed:
[root@ecs-b656 test]# blkid /dev/xvdb1 /dev/xvdb1: UUID="1851e23f-1c57-40ab-86bb-5fc5fc606ffa" TYPE="ext4"
The UUID of the /dev/xvdb1 partition is displayed.
- Run the following command to open the fstab file using the vi editor:
vi /etc/fstab
- Press i to enter the editing mode.
- Move the cursor to the end of the file and press Enter. Then, add the following information:
UUID=1851e23f-1c57-40ab-86bb-5fc5fc606ffa /mnt/sdc ext3 defaults 0 2
UUID=1851e23f-1c57-40ab-86bb-5fc5fc606ffa /mnt/sdc ext4 defaults 0 2
The preceding content is used for reference only. Add the information that is used in the environment. The parameters are described as follows:- The first column indicates the partition UUID obtained in 1.
- The second column indicates the directory on which the partition is mounted. You can query the mount point using the df -TH command.
- The third column indicates the file system format of the partition. You can query the file system format using the df -TH command.
- The fourth column indicates the partition mount option. Normally, this parameter is set to defaults.
- The fifth column indicates the Linux dump backup option.
- 0: not use Linux dump backup. Normally, dump backup is not used, and you can set this parameter to 0.
- 1: use Linux dump backup.
- The sixth column indicates the fsck option, that is, whether to use fsck to check the attached disk during startup.
- 0: not use fsck.
- If the mount point is the root partition (/), this parameter must be set to 1.
When this parameter is set to 1 for the root partition, this parameter for other partitions must start with 2 so that the system checks the partitions in the ascending order of the values.
- Press Esc, enter :wq, and press Enter.
The system saves the configurations and exits the vi editor.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot