2

I have this:

###########################
# 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)

As you see, one HDD with 2Tb that is divided in 20Gb for root and a bit more for swap. After installing and configuring all the services I noticed this problem... now I want to extend the main partition. I don't want to mount the rest of the space in /home and such things. Is a small production server with a specific task so I want all the space in the main partition.

The thing is that I've searched Google and all I found is "use live CD" or "boot into rescue mode" but I cannot do this, I can only work via ssh, so I'm afraid that I lose all the data and I have to reinstall and reconfigure everything, so I prefer asking before starting doing something and fuck everything up.

1 Answer 1

1

Ok, I managed to do it. Here is how:

Removed the swap partition with

# swapoff /dev/sda2

Then started fdisk:

# fdisk /dev/sda

Listed the partitions info, caring about the Start column of the first partition:

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

Removed both partitions:

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.

Created new partitions with new sizes, but starting at Start (4096) instead of the default one:

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

Then I've set the Boot flag of sda1:

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

Then rebooted and ran (after reboot):

# resize2fs /dev/sda1

And then everything is fine:

################################
# 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

Now I have to create the swap again and done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .