Rāda ziņas ar etiķeti resize. Rādīt visas ziņas
Rāda ziņas ar etiķeti resize. Rādīt visas ziņas

trešdiena, 2017. gada 20. decembris

How to extend linux vm drive and partition and recreate swap file without gparted and without gui

Preface.

 HDD which is actually bunch of files in vm, emulating HDD are extended via VMwareVCenter. I need to increase my primary partition in Ubuntu Linux VMware virtual machine. In other words  "/" must be extended.  In this example parted and fdisk which are preinstalled in all modern linux systems will be used. 

How to extend root partition /

First we need to extend device. In my situation there are problem- after device /dev/sda1 are /dev/sda2 so I need firstly to move /dev/sda2 to the end of HDD partition.
Fdisk shows I can increase /dev/sda2 but cannot /dev/sda1
root@Log:/# fdisk -l
Disk /dev/sda: 450 GiB, 483183820800 bytes, 943718400 sectors
Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048 615234375 615232328 293.4G 83 Linux
/dev/sda2       617187328 629145599  11958272   5.7G 82 Linux swap / Solaris
As you can see there are 943 mil sectors but only 629 occupied.
So I first need to move swap to the end of disk.

Move swap partition

All commands must be typed as root user, in ubuntu type sudo su or type sudo before each command. Before deleting swap partition, stop all active applications like database and web servers. After moving swap partition must be at the end of disk /dev/sda
Type fdisk /dev/sda and then type
p to print info about partitions
d to delete swap partition
2 number of partition
n to create new partition
p to make partition primary
2 number of partition
calculate sectors, partition take, subtract from the last sector and provide to numbers First sector of partition and last sector. Some spreadsheet could help.