Rāda ziņas ar etiķeti ubuntu. Rādīt visas ziņas
Rāda ziņas ar etiķeti ubuntu. 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.

piektdiena, 2017. gada 6. janvāris

Ubuntu server extend disk partition in ssh without LiveCD

How to extend partition in Ubuntu from terminal without gparted and livecd

My vm disk was full. Kind VM adminstrator extended disk. How can you extend partition.
In Windows 2012 it is easy on the fly operation. In Ubuntu server they (google advisers) offer to boot LiveCD and run GParted. What if boot from CD is not an option? I have only ssh access. Well
(parted) print list
Shows volume already is extended but you have to create and format partition and then mount it somewhere.
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  256MB   255MB   primary   ext2         boot
 2      257MB   129GB   129GB   extended
 5      257MB   21.0GB  20.7GB  logical                lvm

  • Extend logical partition

$ mkpart logical ext3 21.1GB 129GB

Check that new partition appears in list
Type parted and then type print all

 (parted) print all
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  256MB   255MB   primary   ext2         boot
 2      257MB   129GB   129GB   extended
 5      257MB   21.0GB  20.7GB  logical                lvm
 6      21.0GB  129GB   108GB   logical

As you can notice partition is numbered automatically sda6

  • Format partiton

$ mkfs.ext4 /dev/sda6

  • Mount somewhere
Mount in empty directory or separate partition. I want it in empty directory, so

$ mount /dev/sda6 /var/data

  • Make  changes permanent  

$ echo "/dev/sda6 /var/data ext4 defaults 0 0" | sudo tee -a /etc/fstab

  • Restart the system

$ shutdown -r now