调整大小/挂载点(但它不在lvm中)

use*_*298 2 linux

我按照下面的步骤做了

sr1-server:/dev # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              38G   35G 1022M  98% /
udev                  3.9G   88K  3.9G   1% /dev

sr1-server:/dev # fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00083481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         262     2104483+  82  Linux swap / Solaris
/dev/sda2   *         263        5221    39833167+  83  Linux
sr1-server:/dev # fdisk /dev/sda

The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

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

Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00083481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         262     2104483+  82  Linux swap / Solaris

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

Command (m for help): p

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00083481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         262     2104483+  82  Linux swap / Solaris
/dev/sda2             263        6527    50323612+  83  Linux

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
sr1-server:/dev # fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00083481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         262     2104483+  82  Linux swap / Solaris
/dev/sda2             263        6527    50323612+  83  Linux
sr1-server:/dev # resize2fs /dev/sda2
resize2fs 1.41.1 (01-Sep-2008)
The filesystem is already 9958291 blocks long.  Nothing to do!

sr1-server:/dev # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              38G   35G 1022M  98% /
udev                  3.9G   88K  3.9G   1% /dev

sr1-server:/dev #
sr1-server:/dev #
sr1-server:/dev # reboot

Broadcast message from root (pts/1) (Sat Jul 27 06:24:26 2013):

The system is going down for reboot NOW!
sr1-server:/dev #
Run Code Online (Sandbox Code Playgroud)

但在此之后我无法连接。无论是对还是错?如何拯救服务器?

Flu*_*lup 6

我发现自己不由自主地大喊“nooooooo!” 当我阅读你的成绩单时。似乎您在挂载正在运行的系统上尝试调整根文件系统的大小。您更改了分区表,但内核没有重新读取它(仔细阅读消息)。然后 resize2fs 没有发生,因为使用了旧的分区长度。

如果我是对的,这就是你所做的,那真是个坏主意。只尝试调整未挂载的分区的大小,永远不要对正在运行的系统上的根分区做任何事情。

现在最好的办法是从应急媒体启动并尝试找出您的分区表和文件系统处于什么状态。您需要对服务器进行控制台访问才能进行任何类型的恢复。

  • @Flup 一般来说,调整分区大小没有问题,即使它是根分区。我已经在 ext4 上这样做了几次,它被明确支持。 (2认同)