从新硬盘调整分区大小

从新硬盘调整分区大小

我刚刚用 1TB 硬盘替换了我的 500GB 硬盘。我使用 duper 将 500GB 复制到 1TB。现在我正尝试扩展分区 ( /dev/sda3) 以利用新空间。以下是我尝试过的(最新)命令。我想使用 with 而不是 without 来执行,gparted因为我只能通过 SSH 访问该机器。

tiny@ubuntu:~$ lsblk
NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 931.5G  0 disk 
├─sda1                 8:1    0   512M  0 part /boot/efi
├─sda2                 8:2    0   488M  0 part /boot
└─sda3                 8:3    0 929.4G  0 part 
  └─ubuntu--vg-root 252:0    0 464.8G  0 lvm  /
tiny@ubuntu:~$ sudo resize2fs /dev/mapper/ubuntu--vg-root 
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 121839616 (4k) blocks long.  Nothing to do!

tiny@ubuntu:~$ sudo lvextend /dev/mapper/ubuntu--vg-root /dev/sda3
  No free extents on physical volume "/dev/sda3".
  No specified PVs have space available.
tiny@ubuntu:~$ 

答案1

以下是具体操作:

sudo pvresize /dev/sda3
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-root
sudo resize2fs /dev/mapper/ubuntu--vg-root

输出如下:

tiny@ubuntu:~$ lsblk
NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 931.5G  0 disk 
├─sda1                 8:1    0   512M  0 part /boot/efi
├─sda2                 8:2    0   488M  0 part /boot
└─sda3                 8:3    0 929.4G  0 part 
  └─ubuntu--vg-root 252:0    0 464.8G  0 lvm  /
tiny@ubuntu:~$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                           95G     0   95G   0% /dev
tmpfs                          19G   11M   19G   1% /run
/dev/mapper/ubuntu--vg-root  458G  239G  198G  55% /
tmpfs                          95G     0   95G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                          95G     0   95G   0% /sys/fs/cgroup
/dev/sda2                     473M  120M  329M  27% /boot
/dev/sda1                     511M  3.4M  508M   1% /boot/efi
tmpfs                          19G     0   19G   0% /run/user/1000
tiny@ubuntu:~$ sudo pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
tiny@ubuntu:~$ sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-root
  Size of logical volume ubuntu-vg/root changed from 464.78 GiB (118984 extents) to 929.41 GiB (237929 extents).
  Logical volume root successfully resized.
tiny@ubuntu:~$ lsblk
NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                    8:0    0 931.5G  0 disk 
├─sda1                 8:1    0   512M  0 part /boot/efi
├─sda2                 8:2    0   488M  0 part /boot
└─sda3                 8:3    0 929.4G  0 part 
  └─ubuntu--vg-root 252:0    0 929.4G  0 lvm  /
tiny@ubuntu:~$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                           95G     0   95G   0% /dev
tmpfs                          19G   11M   19G   1% /run
/dev/mapper/ubuntu--vg-root  458G  239G  198G  55% /
tmpfs                          95G     0   95G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                          95G     0   95G   0% /sys/fs/cgroup
/dev/sda2                     473M  120M  329M  27% /boot
/dev/sda1                     511M  3.4M  508M   1% /boot/efi
tmpfs                          19G     0   19G   0% /run/user/1000
tiny@ubuntu:~$ sudo resize2fs /dev/mapper/ubuntu--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/ubuntu--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 30, new_desc_blocks = 59
The filesystem on /dev/mapper/ubuntu--vg-root is now 243639296 (4k) blocks long.

tiny@ubuntu:~$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                           95G     0   95G   0% /dev
tmpfs                          19G   11M   19G   1% /run
/dev/mapper/ubuntu--vg-root  915G  239G  637G  28% /
tmpfs                          95G     0   95G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                          95G     0   95G   0% /sys/fs/cgroup
/dev/sda2                     473M  120M  329M  27% /boot
/dev/sda1                     511M  3.4M  508M   1% /boot/efi
tmpfs                          19G     0   19G   0% /run/user/1000
tiny@ubuntu:~$

相关内容