Disk commands
[root@vps /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 223.6G 0 disk
├─sda1 8:1 1 768M 0 part /boot
├─sda2 8:2 1 217G 0 part /
└─sda3 8:3 1 5.9G 0 part [SWAP]
sdb 8:16 1 1.8T 0 disk
└─sdb1 8:17 1 1.8T 0 part /allbackup
sdc 8:32 1 3.7T 0 disk /backup3
/usr/bin/mount /dev/sdb1 /allbackup
/usr/bin/mount /dev/sdc /backup3
resize2fs: Bad magic number in super-block while trying to open
use xfs_growfs
xfs file system support only extends not reduce. So if you want to resize the filesystem use xfs_growfs rather than resize2fs.
lsblk
blkid
xfs_growfs /dev/xvda2
Identifying the File System for a Volume
To verify the file system in use for each volume on your instance, connect to your instance and run the file -s command.
Example: File Systems on a Nitro-based Instance
The following example shows a Nitro-based instance that has a boot volume with an XFS file system and an additional volume with an XFS file system.
[ec2-user ~]$
sudo file -s /dev/nvme?n*
/dev/nvme0n1: x86 boot sector ...
/dev/nvme0n1p1: SGI XFS filesystem data ...
/dev/nvme0n1p128: data
/dev/nvme1n1: SGI XFS filesystem data ...
Example: File Systems on a T2 Instance
The following example shows a T2 instance that has a boot volume with an ext4 file system and an additional volume with an XFS file system.
[ec2-user ~]$
sudo file -s /dev/xvd*
/dev/xvda: DOS/MBR boot sector ..
/dev/xvda1: Linux rev 1.0 ext4 filesystem data ...
/dev/xvdf: SGI XFS filesystem data ...
Extending a Partition (If Needed)
Your EBS volume might have a partition that contains the file system and data. Increasing the size of a volume does not increase the size of the partition. Before you extend the file system on a resized volume, check whether the volume has a partition that must be extended to the new size of the volume.
Use the lsblk command to display information about the block devices attached to your instance. If a resized volume has a partition and the partition does not reflect the new size of the volume, use the growpart command to extend the partition. For information about extending an LVM partition, see Extending a logical volume .
Example: Partitions on a Nitro-based Instance
The following example shows the volumes on a Nitro-based instance:
[ec2-user ~]$
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1 259:0 0 30G 0 disk /data
nvme0n1 259:1 0 16G 0 disk
└─nvme0n1p1 259:2 0 8G 0 part /
└─nvme0n1p128 259:3 0 1M 0 part
- The root volume,
/dev/nvme0n1
, has a partition,/dev/nvme0n1p1
. While the size of the root volume reflects the new size, 16 GB, the size of the partition reflects the original size, 8 GB, and must be extended before you can extend the file system. - The volume
/dev/nvme1n1
has no partitions. The size of the volume reflects the new size, 30 GB.
To extend the partition on the root volume, use the following growpart command. Notice that there is a space between the device name and the partition number.
[ec2-user ~]$
sudo growpart /dev/nvme0n1 1
You can verify that the partition reflects the increased volume size by using the lsblk command again.
[ec2-user ~]$
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1 259:0 0 30G 0 disk /data
nvme0n1 259:1 0 16G 0 disk
└─nvme0n1p1 259:2 0 16G 0 part /
└─nvme0n1p128 259:3 0 1M 0 part
Example: Partitions on a T2 Instance
The following example shows the volumes on a T2 instance:
[ec2-user ~]$
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 30G 0 disk
└─xvdf1 202:81 0 8G 0 part /data
- The root volume,
/dev/xvda
, has a partition,/dev/xvda1
. While the size of the volume is 16 GB, the size of the partition is still 8 GB and must be extended. - The volume
/dev/xvdf
has a partition,/dev/xvdf1
. While the size of the volume is 30G, the size of the partition is still 8 GB and must be extended.
To extend the partition on each volume, use the following growpart commands. Note that there is a space between the device name and the partition number.
[ec2-user ~]$
sudo growpart /dev/xvda 1
[ec2-user ~]$
sudo growpart /dev/xvdf 1
You can verify that the partitions reflect the increased volume size by using the lsblk command again.
[ec2-user ~]$
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 16G 0 part /
xvdf 202:80 0 30G 0 disk
└─xvdf1 202:81 0 30G 0 part /data
Extending the File System
Use a file system-specific command to resize each file system to the new volume capacity. For a file system other than the examples shown here, refer to the documentation for the file system for instructions.
Example: Extend an ext2, ext3, or ext4 file system
Use the df -h command to verify the size of the file system for each volume. In this example, both
/dev/xvda1
and /dev/xvdf
reflect the original size of the volumes, 8 GB.[ec2-user ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.9G 6.2G 24% /
/dev/xvdf1 8.0G 45M 8.0G 1% /data
...
Use the resize2fs command to extend the file system on each volume.
[ec2-user ~]$
sudo resize2fs /dev/xvda1
[ec2-user ~]$
sudo resize2fs /dev/xvdf1
You can verify that each file system reflects the increased volume size by using the df -h command again.
[ec2-user ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 16G 1.9G 14G 12% /
/dev/xvdf1 30G 45M 30G 1% /data
...
Example: Extend an XFS file system
Use the df -h command to verify the size of the file system for each volume. In this example, each file system reflects the original volume size, 8 GB.
[ec2-user ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 8.0G 1.6G 6.5G 20% /
/dev/nvme1n1 8.0G 33M 8.0G 1% /data
...
To extend the XFS file system, install the XFS tools as follows, if they are not already installed.
[ec2-user ~]$
sudo yum install xfsprogs
Use the xfs_growfs command to extend the file system on each volume. In this example,
/
and /data
are the volume mount points shown in the output for df -h.[ec2-user ~]$
sudo xfs_growfs -d /
[ec2-user ~]$
sudo xfs_growfs -d /data
You can verify that each file system reflects the increased volume size by using the df -h command again.
[ec2-user ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 16G 1.6G 15G 10% /
/dev/nvme1n1 30G 33M 30G 1% /data
...
mount: /dev/sda is write-protected, mounting read-only
mount /dev/sda4/ second
use partition 4 here
/usr/bin/mount /dev/sda4/ second
to check partition number use lsblk
[root@local /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 9.1T 0 disk
sdb 8:16 0 1.8T 0 disk
├─sdb1 8:17 0 1G 0 part /boot
├─sdb2 8:18 0 16G 0 part [SWAP]
└─sdb3 8:19 0 1.8T 0 part /
sdc 8:32 0 1.8T 0 disk
├─sdc1 8:33 0 1G 0 part
├─sdc2 8:34 0 16G 0 part
└─sdc3 8:35 0 1.8T 0 part /secondary
To mount the sda disk, which currently does not have any partitions, you need to create a partition on it, format it with XFS, and then mount it. Here’s how to do it:
Create a Partition on /dev/sda:
Use fdisk or parted to create a partition. Here's an example using fdisk:
sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
The size of this disk is 9.1 TiB (10000831348736 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Created a new DOS disklabel with disk identifier 0xe3d82c16.
It looks like you're working with a large disk (9.1 TiB) that requires a GUID Partition Table (GPT) instead of the older DOS partition table format. Below are the steps to create a GPT partition table, create a partition, format it with XFS, and then mount it.
Step 1: Create a GPT Partition Table
Launch fdisk to create a new partition table:
You are already inside the fdisk utility. To create a GPT partition table, follow these steps:
Press g to create a new empty GPT partition table.
Press w to write the changes to the disk.
Here’s how it should look:
Command (m for help): g
Created a new GPT disklabel (GUID: ...).
Command (m for help): w
The partition table has been altered.
Step 2: Create a New Partition
Create a new partition on the GPT disk:
After creating the GPT, you can create a new partition:
Press n to create a new partition.
Press 1 to select the first partition.
Press Enter to accept the default first sector.
Press Enter again to accept the default last sector (this will use the entire disk).
Press w to write the changes.
Here’s how it should look:
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-18753868799, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-18753868799, default 18753868799):
Created a new partition 1 of type 'Linux filesystem' and of size 9.1 TiB.
Command (m for help): w
The partition table has been altered.
Step 3: Format the New Partition with XFS
Format the newly created partition with XFS:
After creating the partition, you need to format it. Assuming the new partition is /dev/sda1, run the following command:
sudo mkfs.xfs /dev/sda1
[root@local /]# sudo mkfs.xfs /dev/sda1
meta-data=/dev/sda1 isize=512 agcount=10, agsize=268435455 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=2441608955, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=521728, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Step 4: Create a Mount Point
Create a directory to mount the new partition:
mkdir -p /png_cloud_data
sudo mount /dev/sda1 /png_cloud_data
Comments
Post a Comment