在服务器运行时增加 debian 服务器 VM 系统分区

在服务器运行时增加 debian 服务器 VM 系统分区

我有一个 debian 8 webserver VMware VM,它的硬盘空间不足。我在 VMware 中增加了硬盘大小。然后我想将未分配的空间添加到系统分区。我对 linux 不是很熟悉,所以我尝试了几种方法,但没有成功。

fdisk -l 的输出:

root@WebserverLinux:/# fdisk -l

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: 0x28bb70d9

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048  80383999 80381952 38,3G 83 Linux
/dev/sda2       80386046  83884031  3497986  1,7G  5 Extended
/dev/sda3       80384000  80386045     2046 1023K 83 Linux
/dev/sda4       83884032 167772159 83888128   40G 8e Linux LVM
/dev/sda5       80386048  83884031  3497984  1,7G 82 Linux swap / Solaris

Partition table entries are not in disk order.

服务器运行时,应使用 sda4 的空间来扩展 sda1。

有任何想法吗?

编辑:这是我根据 Zoredache 的回答所做的,我可以将其写入磁盘而不会丢失数据吗?(已制作 Hyperviser 快照,但我想避免使用它)

root@WebserverLinux:/home/ruko# swapoff -a
root@WebserverLinux:/home/ruko# fdisk /dev/sda
[32m
Welcome to fdisk (util-linux 2.25.2).
[0mChanges will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m

Help:
[1m
  DOS (MBR)
[0m   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag
[1m
  Generic
[0m   d   delete a partition
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
[1m
  Misc
[0m   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)
[1m
  Save & Exit
[0m   w   write table to disk and exit
   q   quit without saving changes
[1m
  Create a new label
[0m   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): d
Partition number (1-5, default 5): 5

Partition 5 has been deleted.

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

Partition 4 has been deleted.

Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

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): 1
First sector (2048-167772159, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-167772159, default 167772159): 164274175

Created a new partition 1 of type 'Linux' and of size 78,3 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (164274176-167772159, default 164274176): 
Last sector, +sectors or +size{K,M,G,T,P} (164274176-167772159, default 167772159): 

Created a new partition 2 of type 'Linux' and of size 1,7 GiB.

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): a
Partition number (1,2, default 2): 1

The bootable flag on partition 1 is enabled now.

Command (m for help): 

DerfK 请求的输出:

root@WebserverLinux:/# pvscan
bash: pvscan: Command not found.
root@WebserverLinux:/# lvscan
bash: lvscan: Command not found.
root@WebserverLinux:/# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=1022487,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,relatime,size=1639588k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=23,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=819796k,mode=700,uid=1000,gid=1000)
root@WebserverLinux:/#

答案1

服务器运行时,应使用 sda4 的空间来扩展 sda1。

看起来这不可能。问题是 sda1 似乎不在 LVM 中,并且 sda4 的空间与 sda1 的空间不连续。

我不确定 sda3 发生了什么。但如果它不重要,你可以删除它,并且你的系统可以暂时不交换就运行,那么你也许可以将其最小化为一次快速重启。

  1. 禁用交换swapoff -a
  2. 删除 sda2、sda3、sda4、sda5
  3. 删除并重新创建 sda1,确保起始扇区相同,并有一个更大的新结尾。为交换文件系统留出空间。(或者考虑切换到使用托管在根文件系统上的交换文件)
  4. 如果使用交换分区,则在 sda1 之后创建一个新的交换分区
  5. 重启
  6. 执行resize2fs /dev/sda1,扩展文件系统来利用新的空间。

PS:在开始更改任何内容之前,请进行完整备份,或者至少在虚拟机管理程序中创建快照。

相关内容