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

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

我按照下面的步骤进行了操作

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 #

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

答案1

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

如果我说的没错,而你确实这么做了,那么这真是个坏主意。只尝试调整未挂载的分区的大小,并且永远不要对正在运行的系统上的根分区进行任何操作。

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

答案2

我在 kvm 客户机上对普通分区进行了测试,没有 lvm 就无法进行在线调整大小,这是我调整分区大小后的结果,我使用partprobeblockdev && sfdisk

 partprobe /dev/vdb

Error: Partition(s) 1 on /dev/vdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.

 blockdev --rereadpt /dev/vdb

BLKRRPART: Device or resource busy


sfdisk -R /dev/vdb

BLKRRPART: Device or resource busy
sfdisk: This disk is currently in use.

答案3

唉,你使用的fdisk是圆柱显示模式。我想它现在的启动地址与以前略有不同。

如果您的服务器有任何救援模式(可以启动的救援系统、可以连接的串行终端等),您应该尝试一下,看看出了什么问题。

相关内容