You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Difference between revisions of "Help:Resize root partition"

From Wikitech
Jump to navigation Jump to search
imported>Bstorm
m (Reverted edits by Dalda (talk) to last revision by BryanDavis)
imported>SRodlund
 
Line 1: Line 1:
'''Resizing the root partition''' of an OpenStack hosted virtual machine is not for the faint of heart, but seems to be possible.
+
#REDIRECT [[Help:Resize root partition of an OpenStack hosted virtual machine]]
 
 
{{Justanote|Do not attempt this unless you have strong system administration skills and are willing to lose the complete contents of the VM. Cloud Services staff will not assist you in recovering from a failed attempt at resizing the root partition of a VM.}}
 
 
 
Each VM has a disk image that contains three partitions by default: a 20G root partition, a 0.5G swap partition, and the rest of the disk as an LVM container that is initially uninitialized. The <code>role::labs::lvm::srv</code> Puppet role can be used to create an LVM partition filling the entire container that is mounted at <tt>/srv</tt>. This is often the best way to utilize the disk. There are some use cases however where you really want one very large root partition. There is no GUI method to achieve this with OpenStack/Horizon/Wikitech, but it can be attempted manually.
 
 
 
== Basic steps ==
 
# Disable current swap partition
 
# Edit the <code>/dev/vda</code> partition map
 
## Delete all current partitions
 
## Create new larger partition 1 (must start at same offset as original partition)
 
## Create new swap partition
 
## Save changes
 
# Reboot the VM
 
# Enable the new swap partition
 
 
 
Note: When editing the partition table, you must use <code>fdisk -c=dos</code> so that the new root partition will start on the same physical boundary as the initial partition.
 
 
 
== Example session ==
 
<syntaxhighlight lang="shell-session">
 
$ ssh my-cool-instance
 
$ free
 
            total      used      free    shared    buffers    cached
 
Mem:      4048264    1900868    2147396      5848    193556    906968
 
-/+ buffers/cache:    800344    3247920
 
Swap:      499708          4    499704
 
$ sudo swapoff --all
 
$ free
 
            total      used      free    shared    buffers    cached
 
Mem:      4048264    1900952    2147312      5848    193564    906968
 
-/+ buffers/cache:    800420    3247844
 
Swap:            0          0          0
 
$ sudo fdisk -c=dos /dev/vda
 
 
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
 
        switch off the mode (with command 'c').
 
Command (m for help): p
 
 
 
Disk /dev/vda: 42.9 GB, 42949672960 bytes
 
16 heads, 63 sectors/track, 83220 cylinders, total 83886080 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
 
Disk identifier: 0x00031db0
 
 
 
  Device Boot      Start        End      Blocks  Id  System
 
/dev/vda1              63    37998046    18998992  83  Linux
 
Partition 1 does not end on cylinder boundary.
 
/dev/vda2        37998592    38998015      499712  82  Linux swap / Solaris
 
Partition 2 does not end on cylinder boundary.
 
/dev/vda3        38998016    83886079    22444032  8e  Linux LVM
 
Partition 3 does not end on cylinder boundary.
 
 
 
Command (m for help): d
 
Partition number (1-4): 3
 
 
 
Command (m for help): d
 
Partition number (1-4): 2
 
 
 
Command (m for help): d
 
Selected partition 1
 
 
 
Command (m for help): n
 
Partition type:
 
  p  primary (0 primary, 0 extended, 4 free)
 
  e  extended
 
Select (default p): p
 
Partition number (1-4, default 1): 1
 
First sector (63-83886079, default 63):
 
Using default value 63
 
Last sector, +sectors or +size{K,M,G} (63-83886079, default 83886079): 82886656
 
 
 
Command (m for help): n
 
Partition type:
 
  p  primary (1 primary, 0 extended, 3 free)
 
  e  extended
 
Select (default p): p
 
Partition number (1-4, default 2): 2
 
First sector (82886657-83886079, default 82886657):
 
Using default value 82886657
 
Last sector, +sectors or +size{K,M,G} (82886657-83886079, default 83886079):
 
Using default value 83886079
 
 
 
Command (m for help): t
 
Partition number (1-4): 2
 
Hex code (type L to list codes): 82
 
Changed system type of partition 2 to 82 (Linux swap / Solaris)
 
 
 
Command (m for help): p
 
 
 
Disk /dev/vda: 42.9 GB, 42949672960 bytes
 
16 heads, 63 sectors/track, 83220 cylinders, total 83886080 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
 
Disk identifier: 0x00031db0
 
 
 
  Device Boot      Start        End      Blocks  Id  System
 
/dev/vda1              63    82886656    41443297  83  Linux
 
/dev/vda2        82886657    83886079      499711+  82  Linux swap / Solaris
 
 
 
Command (m for help): w
 
The partition table has been altered!
 
 
 
Calling ioctl() to re-read partition table.
 
 
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
 
The kernel still uses the old table. The new table will be used at
 
the next reboot or after you run partprobe(8) or kpartx(8)
 
Syncing disks.
 
 
 
$ sudo reboot
 
W: molly-guard: SSH session detected!
 
Please type in hostname of the machine to reboot: my-cool-instance
 
 
 
Broadcast message from bd808@my-cool-instance
 
        (/dev/pts/0) at 17:34 ...
 
 
 
The system is going down for reboot NOW!
 
$ packet_write_wait: Connection to UNKNOWN: Broken pipe
 
 
 
$ ssh my-cool-instance
 
Linux mw-base 3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016 x86_64
 
Ubuntu 14.04.3 LTS
 
The last Puppet run was at Thu Apr  7 17:36:00 UTC 2016 (1 minutes ago).
 
Last login: Thu Apr  7 17:37:30 2016 from bastion-01.bastion.eqiad.wmflabs
 
$ free
 
            total      used      free    shared    buffers    cached
 
Mem:      4048240    1498572    2549668      11352      53488    748044
 
-/+ buffers/cache:    697040    3351200
 
Swap:            0          0          0
 
$ sudo mkswap /dev/vda2
 
Setting up swapspace version 1, size = 499704 KiB
 
no label, UUID=1fac41ba-958a-4650-b72c-aedccf59452e
 
$ sudo swapon --all
 
$ free
 
            total      used      free    shared    buffers    cached
 
Mem:      4048240    1657788    2390452      14364      59604    802148
 
-/+ buffers/cache:    796036    3252204
 
Swap:      499704          0    499704
 
$ df -h
 
Filesystem      Size  Used Avail Use% Mounted on
 
udev            2.0G  12K  2.0G  1% /dev
 
tmpfs          396M  396K  395M  1% /run
 
/dev/vda1        39G  17G  21G  44% /
 
none            4.0K    0  4.0K  0% /sys/fs/cgroup
 
none            5.0M    0  5.0M  0% /run/lock
 
none            2.0G    0  2.0G  0% /run/shm
 
none            100M    0  100M  0% /run/user
 
</syntaxhighlight>
 
 
 
[[Category:Cloud VPS]]
 

Latest revision as of 19:27, 14 February 2020