Como aumentar o tamanho da partição principal em um sistema CentOS sobre ssh?

2

Eu tenho isso:

###########################
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        20G  2.1G   17G  12% /
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   34M  1.9G   2% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup

###########################
# fdisk -l
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 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 label type: dos
Disk identifier: 0x00044686

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        4096    40962047    20478976   83  Linux
/dev/sda2        40962048    42008575      523264   82  Linux swap / Solaris

###########################
# mount
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=2009752k,nr_inodes=502438,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=27,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)

###########################
(parted) print
Model: ATA HGST HUS724020AL (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
 1      2097kB  21.0GB  21.0GB  primary  ext4            boot
 2      21.0GB  21.5GB  536MB   primary  linux-swap(v1)

Como você pode ver, um HDD com 2Tb é dividido em 20Gb para root e um pouco mais para swap. Depois de instalar e configurar todos os serviços notei esse problema ... agora eu quero estender a partição principal. Eu não quero montar o resto do espaço em /home e essas coisas. É um pequeno servidor de produção com uma tarefa específica, por isso quero todo o espaço na partição principal.

O problema é que eu pesquisei no Google e tudo que encontrei é "use live CD" ou "inicialize no modo de recuperação", mas não posso fazer isso, só posso trabalhar com ssh , então tenho medo de Eu perco todos os dados e tenho que reinstalar e reconfigurar tudo, então eu prefiro perguntar antes de começar a fazer alguma coisa e foder tudo.

    
por Jorge Fuentes González 14.10.2015 / 13:32

1 resposta

1

Ok, consegui fazer isso. Aqui está como:

Removida a partição de troca com

# swapoff /dev/sda2

Em seguida, iniciei fdisk :

# fdisk /dev/sda

Listou as informações das partições, preocupadas com a coluna Start da primeira partição:

Command (m for help): p

Device    Boot      Start         End      Blocks   Id  System
/dev/sda1    *       4096    47029167  1903512536   83  Linux
/dev/sda2        47029168    57029167    50000000   83  Linux

Removidas as duas partições:

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 1 has been deleted.

Command (m for help): d
Partition number (1): 1
Partition 1 has been deleted.

Criaram novas partições com novos tamanhos, mas a partir de Start (4096) em vez do padrão:

Command (m for help): n
Select (default p): p
Partition number (1, default 1): 1
First sector (2048-3907029167, default 2048): 4096 //Important. Notice that is not the same as the default (in my case).
Last sector (default 3907029167): 3807029167 //I've put less to have spare space for partition 2

Command (m for help): n
Select (default p): p
Partition number (2, default 2): 2
First sector (2048-3907029167, default 2048): 3807029168 //Important. Notice that starts with 20148 because is the first empty space detected, but in reality I want it AFTER the first partition, so I've put another number (in my case).
Last sector (default 3907029167): 3907029167

Em seguida, defini o sinal Boot de sda1 :

Command (m for help): a
Partition number (1,2, default 2): 1

Em seguida, reinicie e execute (após a reinicialização):

# resize2fs /dev/sda1

E então está tudo bem:

################################
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.8T  2.1G  1.7T   1% /
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G  9.5M  2.0G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup

################################
# fdisk -l
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 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 label type: dos
Disk identifier: 0x00044686

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        4096  3807029167  1903512536   83  Linux
/dev/sda2      3807029168  3907029167    50000000   83  Linux

Agora preciso criar a troca novamente e pronto.

    
por 14.10.2015 / 15:14