大网数据广告活动
服务器运维问答

How to extend a non-root partition of a Ubuntu VM by command line (and without GParted)

· 52CE 我爱测

After increasing the disk size from 200GB to 300GB of a Hyper-V VM in which Ubuntu Server is installed lsblk shows the following root@ubuntu:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 15G 0 disk ├─sda1 8:1 0 243M …

问题原文

原帖链接 · Jey DWork · CC BY-SA 3.0

After increasing the disk size from 200GB to 300GB of a Hyper-V VM in which Ubuntu Server is installed lsblk shows the following

root@ubuntu:~# lsblk
NAME                                    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                                       8:0    0    15G  0 disk
├─sda1                                    8:1    0   243M  0 part /boot
├─sda2                                    8:2    0     1K  0 part
└─sda5                                    8:5    0  14.8G  0 part
  ├─ubuntu--vg-root (dm-0)   252:0    0  14.2G  0 lvm  /
  └─ubuntu--vg-swap_1 (dm-1) 252:1    0   508M  0 lvm  [SWAP]
sdb                                       8:16   0   300G  0 disk
└─sdb1                                    8:17   0   200G  0 part /media/storage
sr0                                      11:0    1  1024M  0 rom

Now we simply want that sdb1 which is currently mounted at /media/storage (but could be temporarily unmounted without problems) gets increased to 300GB so that it uses all space on sdb.

Simply using resize2fs doesn't seem to work. What does work is booting from a GParted CD and performing a resize operation. However, as this is a non-root partition which can be unmounted this seems to be an overkill. So is there a simple way to this with the command line? (Unfortunately googling brings up really lots of stuff with GParted or about root partitions etc. pp. which does not apply here.)

已采纳解答

原帖链接 · Vikelidis Kostas · CC BY-SA 3.0

resize2fs will resize the filesystem not the partition. You have to resize your partition (sdb1) before resizing the filesystem.

If you don't want to use parted then you can use fdisk.

Initially you have to find the starting sector of sdb1 partition. To do that simply execute:

fdisk -l /dev/sdb

and note down the number in the Start column

Then:

fdisk /dev/sdb

then press d to delete the first partition.

then press n to create a new partition.

then press p to indicate that it will be a primary partition.

then press 1 to indicate that it will be the first partition.

The next step is very important. fdisk will ask for the First sector of the new partition. Use the number you noted earlier.

then fdisk will ask for the last sector. By default fdisk will promt for the last sector of the disk so use that default value.

then press w and fdisk will write the partition table to disk.

You can now resize the filesystem using the resize2fs command

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。