8.5-7 mkfs、dumpe2fs、resize2fs

8.5 mkfs: Create a Linux file system

The mkfs command is used to create, format and create a file system on the specified device (or hard disk partition, etc.). Partition tools such as fdisk and parted are equivalent For people who build houses, divide the house (hard disk) into several rooms (partitions), mkfs is equivalent to decorating different rooms (creating file systems). Only the decorated houses (with file systems) can move in, and so are partitions. Similarly, only after formatting and creating a file system (a mechanism for accessing data) can it be used to access data.
mkfs [option] [device name]
-t Specify the type of file system to be created
-c Check for bad disk blocks when creating a file system
-v Display detailed information

< div>

mkfs is just a front-end command, it will call the corresponding command mkfs.fstype after specifying the file system type through the -t parameter. Therefore, you can directly use the mkfs.ext4 command to create an ext4 file system.
[[email protected] ~]# ls /sbin/mkfs*

/sbin/mkfs /sbin/mkfs.ext2 /sbin/mkfs.ext4 /sbin/mkfs.xfs
/sbin/mkfs.cramfs /sbin/mkfs.ext3 /sbin/mkfs.ext4dev

Create a file system through the mkfs command (-t Parameter) example



[[email protected]
~]# mkfs -t ext4 -v /dev/sdb
mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
fs_types
for mke2fs.conf resolution: 'ext4', ' default'
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
Fragment size
=4096 (log=2)
Stride
=0 blocks, Stripe width=0< span style="color: #000000;"> blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables:
done
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Create a file system through mkfs.ext4

[[email Protected] ~]# mkfs.ext4 /dev/sdb

mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
....
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

8.6 dumpe2fs: Export ext2/ext3/ext4 file system information

The dumpe2fs command is used to export ext2/ext3/ Relevant information inside the ext4 file system, for example: the composition of the file system includes information such as super fast, block group, inode, block and so on.
The parameter options and description of the dumpe2fs command
-b Print the block information reserved in the file system
-h Only display super block information
-i Read the file system information from the specified file system image file
-x Print the information block in hexadecimal format Members

View system inode information

[[emailprotected] ~]# dumpe2fs /dev/sda1|< span style="color: #0000ff;">egrep -i "inode size| inode count"

dumpe2fs
1.41.12 (17-May-2010)
Inode count:
128016 #<==Unit;
Inode size:
128 #<== /The boot partition defaults to 128 characters Festival.


[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "inode size|inode count"
dumpe2fs
1.41.12 (17-May-2010)
Inode count:
1738080
Inode size:
256 #<==Ordinary partition defaults to 256 bytes .


[[email protected]
~]# df -i
Filesystem Inodes IUsed IFree IUse
% Mounted on
/dev/mapper/vg_cs6-lv_root
1738080 23534 1714546 2% /
tmpfs
238145 1 238144 1% /dev/shm
/dev/sda1 128016 38 127978 1% /boot


[[email protected]
~]# dumpe2fs /dev/sda1|egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
512000 #<==The total number of blocks in the partition.
Reserved block count:
25600
Block size:
1024 #<==/boot partition default 1024 words Knot is 1K
[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
6948864
Reserved block count:
347443
Block size:
4096 #<==Ordinary partition 4K=4096 words Festival.

8.7 resize2fs: adjust the size of ext2/ext3/ext4 file system

resize2fs command Used to expand or shrink the unmounted ext2/ext3/ext4 file system. In Linux2.6 or higher
version of the kernel, this command also supports online expansion of the mounted file system. This command is often used for partitions after LVM expansion
.
-p Print the progress bar of the completed task
-f Force the operation

Example of dynamically modifying the partition size

This situation is usually caused when the system partition was not planned, and now I want to resize the partition. Assuming that you want to operate on the partition on /dev/sdb, expand /mnt/data1.
[[emailprotected] ~]# df -h

Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/< span style="color: #000000;">shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1
/dev/sdb2 194M 1.8M 182M 1% /mnt/data2
[[email protected]
~]# touch /mnt/data1/{1..5}.html
[[email protected]
~]# touch /mnt/data2/{1..5}.html

Tip: /dev/sdb is a 1GB disk, and now it is divided into two primary partitions sdb1 , Sdb2 are respectively 200MB, and the remaining 800MB is not partitioned. Now you need to merge the sdb2 partition and the sdb1 partition to achieve the expansion of sdb1. Note that in this case, do not operate in the production scene, only for demonstration purposes. The production scene is generally planned in advance and there will be no expansion requirements, and it is not I/O intensive. The application can adopt LVM to realize the dynamic expansion of the specification.
The following are the actual steps for expansion.
1) Record the cylinder start information of the partition:
[[email protected] ~] # fdisk -l /dev/sdb


Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux

2) Uninstall the partition :
[[email protected] ~]# umount /mnt/data1

[[email protected]
~]# umount /mnt/data2

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/< span style="color: #000000;">shm
/dev/sda1 477M 28M 424M 7% /boot

3) Repartition:


[[email protected]
~]# fdisk /dev/sdb

WARNING: DOS
-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command
'u').

Command (m
for help): d
Partition number (
1-4): 1

Command (m
for help): d
Selected partition
2

Command (m
for help): n
Command action
e extended
p primary partition (
1-4)
p
Partition number (
1-4): 1
First cylinder (
1-130, default 1):
Using default value
1
Last cylinder,
+cylinders or +size{K,M,G} (1-130, default 130): 52

Command (m
for help): p

Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 52 417658+ 83 Linux

Command (m
for help): w
The partition table has been altered
!

Calling ioctl() to re
-read partition table.
Syncing disks.
[[email protected]
~]# partprobe /dev/sdb
[[email protected]
~]# mount /dev/sdb1 /mnt/data1
[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/< span style="color: #000000;">shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1


[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found
[[email Protected]
~]# resize2fs /dev/sdb1 #<==Resize the disk online,
resize2fs
1.41.12 (17-May-2010)
Filesystem at
/dev/sdb1 is mounted on /mnt/data1; on-line resizing required
old desc_blocks
= 1, new_desc_blocks = 2
Performing an on
-line resize of /dev/sdb1 to 417656 ( 1k) blocks.
The filesystem on
/dev/sdb1 is now 417656 blocks long span>.

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/< span style="color: #000000;">shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 392M 2.3M 369M 1% /mnt/data1
[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found

#<==But the data is still only in sdb1, and the data in sdb2 is lost. This method is not suitable for expansion in production scenarios. A more standardized method is to expand the capacity through LVM logical volume management. After the expansion, resize2fs is also required for final expansion.

The mkfs command is used to create, format and create a file system on the specified device (or hard disk partition, etc.). The partition tools such as fdisk and parted are equivalent to the person who builds the house. , Divide the house (hard disk) into several rooms (partitions), mkfs is equivalent to decorating different rooms (creating file systems), only the decorated houses (with file systems) can be moved in, and the partitions are the same, only formatting After the file system (the mechanism for accessing data) is created, it can be used to access data.

mkfs [option] [device name]

-t Specify the type of file system to be created

-c Check for bad disk blocks when creating a file system

-v Display detailed information

< p>

mkfs is just a front-end command. After specifying the file system type through the -t parameter, it will call the corresponding command mkfs.fstype. Therefore, you can directly use the mkfs.ext4 command to create an ext4 file system.

[[emailprotected] ~]# ls /sbin/mkfs*

/sbin/mkfs /sbin/mkfs.ext2 /sbin/mkfs.ext4 /sbin/mkfs.xfs
/sbin/mkfs.cramfs /sbin/mkfs.ext3 /sbin/mkfs.ext4dev

[[emailprotected] ~ ]# ls /sbin/mkfs*

/sbin/mkfs /sbin/mkfs.ext2 /sbin/mkfs.ext4 /sbin/mkfs.xfs
/sbin/mkfs.cramfs /sbin/mkfs.ext3 /sbin/mkfs.ext4dev



[[email protected]
~]# mkfs -t ext4 -v /dev/sdb
mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
fs_types
for mke2fs.conf resolution: 'ext4', ' default'
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
Fragment size
=4096 (log=2)
Stride
=0 blocks, Stripe width=0< span style="color: #000000;"> blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables:
done
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.



[[email protected]
~]# mkfs -t ext4 -v /dev/sdb
mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
fs_types
for mke2fs.conf resolution: 'ext4', ' default'
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
Fragment size
=4096 (log=2)
Stride
=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block
=0
Maximum filesystem blocks
=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables:
done
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[[email protected] ~]# mkfs.ext4 /dev/sdb

mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
....
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

8.6 dumpe2fs:导出ext2/ext3/ext4文件系统信息

dumpe2fs命令用于导出ext2/ext3/ext4文件系统内部的相关信息,例如:文件系统的组成包含超级快、块组、inode、block等信息。
 
dumpe2fs命令的参数选项及说明
 
-b    打印文件系统中预留的块信息
-h    仅显示超级块信息
-i    从指定的文件系统映像文件中读取文件的系统信息
-x    以16进制格式打印信息块成员

[[email protected] ~]# mkfs.ext4 /dev/sdb

mke2fs
1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway
? (y,n) y
Filesystem label
=
OS type: Linux
Block size
=4096 (log=2)
....
Creating journal (
8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every
25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

dumpe2fs命令用于导出ext2/ext3/ext4文件系统内部的相关信息,例如:文件系统的组成包含超级快、块组、inode、block等信息。

 

dumpe2fs命令的参数选项及说明

 

-b    打印文件系统中预留的块信息

-h    仅显示超级块信息

-i    从指定的文件系统映像文件中读取文件的系统信息

-x    以16进制格式打印信息块成员

[[email protected] ~]# dumpe2fs /dev/sda1|egrep -i "inode size|inode count"

dumpe2fs
1.41.12 (17-May-2010)
Inode count:
128016 #<==单位;个。
Inode size:
128 #<== /boot 分区默认128字节。


[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "inode size|inode count"
dumpe2fs
1.41.12 (17-May-2010)
Inode count:
1738080
Inode size:
256 #<==普通分区默认256字节。


[[email protected]
~]# df -i
Filesystem Inodes IUsed IFree IUse
% Mounted on
/dev/mapper/vg_cs6-lv_root
1738080 23534 1714546 2% /
tmpfs
238145 1 238144 1% /dev/shm
/dev/sda1 128016 38 127978 1% /boot


[[email protected]
~]# dumpe2fs /dev/sda1|egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
512000 #<==分区的block总量。
Reserved block count:
25600
Block size:
1024 #<==/boot分区默认1024字节即1K
[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
6948864
Reserved block count:
347443
Block size:
4096 #<==普通分区4K=4096字节。

 

[[email protected] ~]# dumpe2fs /dev/sda1|egrep -i "inode size|inode count"

dumpe2fs
1.41.12 (17-May-2010)
Inode count:
128016 #<==单位;个。
Inode size:
128 #<== /boot 分区默认128字节。


[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "inode size|inode count"
dumpe2fs
1.41.12 (17-May-2010)
Inode count:
1738080
Inode size:
256 #<==普通分区默认256字节。


[[email protected]
~]# df -i
Filesystem Inodes IUsed IFree IUse
% Mounted on
/dev/mapper/vg_cs6-lv_root
1738080 23534 1714546 2% /
tmpfs
238145 1 238144 1% /dev/shm
/dev/sda1 128016 38 127978 1% /boot


[[email protected]
~]# dumpe2fs /dev/sda1|egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
512000 #<==分区的block总量。
Reserved block count:
25600
Block size:
1024 #<==/boot分区默认1024字节即1K
[[email protected]
~]# dumpe2fs /dev/mapper/vg_cs6-lv_root |egrep -i "block size|block count"
dumpe2fs
1.41.12 (17-May-2010)
Block count:
6948864
Reserved block count:
347443
Block size:
4096 #<==普通分区4K=4096字节。

    resize2fs命令用于扩容或收缩未挂载的ext2/ext3/ext4文件系统。在Linux2.6或更高

版本的内核中,该命令还支持在线扩容已经挂载的文件系统,该命令常用来针对LVM扩容

后的分区使用。

 

-p    打印完成任务的进度条

-f    强制执行操作

 

动态修改分区大小的例子

    出现这种情况一般是当初对系统分区的时候没有规划好,现在想要重新调整分区的大小。假设是要对/dev/sdb上的分区进行操作,将/mnt/data1扩容。

[[email protected] ~]# df -h

Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1
/dev/sdb2 194M 1.8M 182M 1% /mnt/data2
[[email protected]
~]# touch /mnt/data1/{1..5}.html
[[email protected]
~]# touch /mnt/data2/{1..5}.html

 

[[email protected] ~]# df -h

Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1
/dev/sdb2 194M 1.8M 182M 1% /mnt/data2
[[email protected]
~]# touch /mnt/data1/{1..5}.html
[[email protected]
~]# touch /mnt/data2/{1..5}.html

提示:/dev/sdb是一块1GB的磁盘,现在分了两个主分区sdb1、sdb2,分别是200MB,剩余800MB未分区。现在需要把sdb2分区和sdb1分区合并,以实现对sdb1的扩容,注意,此种情况不要在生产场景操作,仅作为演示用,生产场景一般是事先规划好不会出现扩容需求,非I/O密集应用可以采用LVM实现规范动态扩容。

 

以下是扩容实战步骤。

1)记录分区的柱面起始信息:

 

[[email protected] ~]# fdisk -l /dev/sdb


Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux

[[email protected] ~]# fdisk -l /dev/sdb


Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux

2)卸载分区:

 

[[email protected] ~]# umount /mnt/data1

[[email protected]
~]# umount /mnt/data2

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot

 

[[email protected] ~]# umount /mnt/data1

[[email protected]
~]# umount /mnt/data2

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot

3)重新分区:

 

[[email protected]
~]# fdisk /dev/sdb

WARNING: DOS
-compatible mode is deprecated. Its strongly recommended to
switch off the mode (command c) and change display units to
sectors (command
u).

Command (m
for help): d
Partition number (
1-4): 1

Command (m
for help): d
Selected partition
2

Command (m
for help): n
Command action
e extended
p primary partition (
1-4)
p
Partition number (
1-4): 1
First cylinder (
1-130, default 1):
Using default value
1
Last cylinder,
+cylinders or +size{K,M,G} (1-130, default 130): 52

Command (m
for help): p

Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 52 417658+ 83 Linux

Command (m
for help): w
The partition table has been altered
!

Calling ioctl() to re
-read partition table.
Syncing disks.
[[email protected]
~]# partprobe /dev/sdb
[[email protected]
~]# mount /dev/sdb1 /mnt/data1
[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1


[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found
[[email protected]
~]# resize2fs /dev/sdb1 #<==在线调整磁盘大小,
resize2fs
1.41.12 (17-May-2010)
Filesystem at
/dev/sdb1 is mounted on /mnt/data1; on-line resizing required
old desc_blocks
= 1, new_desc_blocks = 2
Performing an on
-line resize of /dev/sdb1 to 417656 (1k) blocks.
The filesystem on
/dev/sdb1 is now 417656 blocks long.

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 392M 2.3M 369M 1% /mnt/data1
[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found

 #<==但是数据还是只有sdb1里的了,sdb2的数据丢失了。此种方法不适合生产场景扩容,比较规范方法是通过LVM逻辑卷管理进行扩容,扩容后也需要resize2fs进行最终实现扩容。

 

[[email protected]
~]# fdisk /dev/sdb

WARNING: DOS
-compatible mode is deprecated. Its strongly recommended to
switch off the mode (command c) and change display units to
sectors (command
u).

Command (m
for help): d
Partition number (
1-4): 1

Command (m
for help): d
Selected partition
2

Command (m
for help): n
Command action
e extended
p primary partition (
1-4)
p
Partition number (
1-4): 1
First cylinder (
1-130, default 1):
Using default value
1
Last cylinder,
+cylinders or +size{K,M,G} (1-130, default 130): 52

Command (m
for help): p

Disk
/dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical): 512 bytes / 512 bytes
I
/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:
0x1bc7d413

Device Boot Start End Blocks Id System
/dev/sdb1 1 52 417658+ 83 Linux

Command (m
for help): w
The partition table has been altered
!

Calling ioctl() to re
-read partition table.
Syncing disks.
[[email protected]
~]# partprobe /dev/sdb
[[email protected]
~]# mount /dev/sdb1 /mnt/data1
[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 194M 1.8M 182M 1% /mnt/data1


[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found
[[email protected]
~]# resize2fs /dev/sdb1 #<==在线调整磁盘大小,
resize2fs
1.41.12 (17-May-2010)
Filesystem at
/dev/sdb1 is mounted on /mnt/data1; on-line resizing required
old desc_blocks
= 1, new_desc_blocks = 2
Performing an on
-line resize of /dev/sdb1 to 417656 (1k) blocks.
The filesystem on
/dev/sdb1 is now 417656 blocks long.

[[email protected]
~]# df -h
Filesystem Size Used Avail Use
% Mounted on
/dev/mapper/vg_cs6-lv_root
26G 834M 24G
4% /
tmpfs 931M
0 931M 0% /dev/shm
/dev/sda1 477M 28M 424M 7% /boot
/dev/sdb1 392M 2.3M 369M 1% /mnt/data1
[[email protected]
~]# ls /mnt/data1
1.html 2.html 3.html 4.html 5.html lost+found

Leave a Comment

Your email address will not be published.