侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Linux 在线增加原有硬盘容量

2023-12-04 星期一 / 0 评论 / 0 点赞 / 77 阅读 / 5119 字

需求说明: 现在有一个硬盘单独挂载到了某个分区下面,但是容量满了又不能将内容迁移走,这样就只能增加原来硬盘的容量,原来分区容量10G,现在需要将硬盘扩大到15G,将容量加到分区内,这里面涉及到危险的操

需求说明:

现在有一个硬盘单独挂载到了某个分区下面,但是容量满了又不能将内容迁移走,这样就只能增加原来硬盘的容量,原来分区容量10G,现在需要将硬盘扩大到15G,将容量加到分区内,这里面涉及到危险的操作就是要修改分区表

测试说明:

Ubuntu 14.10   文件系统类型:ext4 

原先容量10G,写入文件后,将硬盘扩展至15G

#df –hFilesystem      Size  Used Avail Use% Mounted on/dev/sda1        57G  1.9G   53G   4% /none            4.0K     0  4.0K   0% /sys/fs/cgroupudev            988M  4.0K  988M   1% /devtmpfs           201M  492K  200M   1% /run/dev/sdb1       9.8G   37M  9.2G   1% /data

 

# 取消挂载

# umount /data

# 删除分区并重新建立分区

# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.25.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Command (m for help): d

Selected partition 1

Partition 1 has been deleted.

 

Command (m for help): p

Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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

Disklabel type: dos

Disk identifier: 0x41b124e6

 

Command (m for help): n

Partition type

   p   primary (0 primary, 0 extended, 4 free)

   e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-31457279, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-31457279, default 31457279):

 

Created a new partition 1 of type 'Linux' and of size 15 GiB.

 

Command (m for help): p

Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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

Disklabel type: dos

        Disk identifier: 0x41b124e6

Device     Boot Start      End  Sectors Size Id Type

/dev/sdb1        2048 31457279 31455232  15G 83 Linux

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

 

扩展分区大小

# resize2fs /dev/sdb1 14.9Gresize2fs 1.42.10 (18-May-2014)resize2fs: Invalid new size: 14.9G

# 如果是下面的情况就会报错,扩展容量不能大于总block

root@ubuntu:~# resize2fs /dev/sdb1 15Gresize2fs 1.42.10 (18-May-2014)The containing partition (or device) is only 3931904 (4k) blocks.You requested a new size of 3932160 blocks.

#检查文件系统正确性

root@ubuntu:~# e2fsck -f /dev/sdb1e2fsck 1.42.10 (18-May-2014)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/sdb1: 1836/655360 files (0.2% non-contiguous), 83256/2621184 blocks

# 将分区挂载到相应目录

# mount /dev/sdb1 /data

# df –h

root@ubuntu:~# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        57G  1.9G   53G   4% /

none            4.0K     0  4.0K   0% /sys/fs/cgroup

udev            988M  4.0K  988M   1% /dev

tmpfs           201M  492K  200M   1% /run

/dev/sdb1        15G   38M   14G   1% /data

 

 硬盘扩展完成,请查看文件内容是否变动

 

广告 广告

评论区