今天给家里的旧笔记本装Ubuntu Server,安装过程中它本来是240GB的固态硬盘,结果实际系统只分配了100GB,为了防止后续用完的时候再分配可能把数据玩没,尽早调整一下。
先看看目前分区挂载的状态
shrewd@x200:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 382M 1.6M 381M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 12G 82G 12% /
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 127M 1.7G 7% /boot
tmpfs 382M 4.0K 382M 1% /run/user/1000
可以看到根目录就只有98G
看一下现在盘的分区是个什么情况
shrewd@x200:~$ sudo fdisk -l
Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: Lenovo-LS510-2.5
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: gpt
Disk identifier: 962A17FB-79F5-418D-AF75-AF88D78952D1
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 468858879 464660480 221.6G Linux filesystem
选择你要调整的硬盘并输入print查看硬盘信息
shrewd@x200:~$ sudo parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA Lenovo-LS510-2.5 (scsi)
Disk /dev/sda: 240GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 2150MB 2147MB ext4
3 2150MB 240GB 238GB
刚发现如果文件系统是LVM的就不是在这里调整。我的是在这里,如下
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 100 GiB, 107374182400 bytes, 209715200 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
最后调整要修改的逻辑分区
shrewd@x200:~$ sudo parted /dev/mapper/ubuntu--vg-ubuntu--lv
GNU Parted 3.4
Using /dev/mapper/ubuntu--vg-ubuntu--lv
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 107GB 107GB ext4
(parted) resizepart 2
Warning: /dev/mapper/ubuntu--vg-ubuntu--lv is being used. Are you sure you want to continue?
Yes/No? yes
End? [107GB]? 129GB
(parted) q