• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

Extend Linux partition

I tried to run the following commands:
dd if=/dev/zero of=/swapfile2 bs=1024 count=2097152
mkswap /swapfile2
swapon /swapfile2

and got back:

[root@localhost Downloads]#     dd if=/dev/zero of=/swapfile2 bs=1024 count=2097152
dd: writing `/swapfile2': No space left on device
1023361+0 records in
1023360+0 records out
1047920640 bytes (1.0 GB) copied, 47.1536 seconds, 22.2 MB/s
[root@localhost Downloads]#     mkswap /swapfile2
Setting up swapspace version 1, size = 1047916 kB
[root@localhost Downloads]#     swapon /swapfile2
[root@localhost Downloads]# /swapfile2 swap swap defaults 0 0
bash: /swapfile2: Permission denied

[root@localhost Downloads]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              3960348   3953756         0 100% /
/dev/sda3            1006916148    204412 954738248   1% /home
/dev/sda1                46633     17249     26976  40% /boot
tmpfs                  1455992         0   1455992   0% /dev/shm
.host:/              1452148732 829045272 623103460  58% /mnt/hgfs

How can i increase the size of the /dev/sda2 area?

Thank you
1 Solution
You cannot.  You are not using LVMs.  However, you could use /home partition.  That has a lot of capacity.  And make sure remove the file you created on the root partition.
Boot up from PartedMagic LiveCD and reize partitions. PartedMagic is one of the best partition manager.

Joseph GanSystem AdminCommented:
First remove the /swapfile2 under root to free up root.
Then copy files under /home (about 200M) to root temperaly.
Repartition /dev/sda3 to be new /home and swap.
Copy files back to /home.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

There is one more tool to achieve your  goal with good how to.

To resize /dev/sda2 (which is a partition):
Use GParted to resize the partitions.  

You could use /home/swapfile2 as /home (/dev/sda3 partition) has lots of space.
tamirmiloAuthor Commented:
Thanks all.
 The problem that i have is that i am using vmware - and the linux CENTOS is starting too fast and i can not get into mode that will read boot disk. I tried to change settings in the *.vmx file but that did not help as well.
Also, the CENTOS installation that i have is not interactive and i can not set the required size (otherwise i would create a new install)
I will probably use the area under /home.

It's easy to enlarge a Linux partition, epically a virtual Linux.

What you need to do is:

1. change the virtual disk size to make it bigger.
2. install another Linux VM,  then add the existing VM's disk file into the second Linux VM as secondary HD
3. boot the second VM, run
fdisk -l

you should see the secondary disk as something like /dev/sdb.
You can use tools like parted/cfdisk  to resize the partition, then extend the file system.

here are some notes I made to resize a EXT3 partition:

Example for a non-root partition /dev/sdb1 mounted on /srv/backup
•      Resize the harddrive in your virtualisation application
•      Umount the partitions that requires to be resized
o      umount /srv/backup
•      Make a Filesystem check in  your partition on that device
o      fsck -n /dev/sdb1
•      Now the partition is clean but it is still using Ext3. Ext3 can not be resize but ext2 can. So we need to convert the partition ext3 to ext2. The conversion is basically done disabling journal on ext3
o      tune2fs -O ^has_journal /dev/sdb1
•      Now we need to make another filesystem check on ext2 format
o      e2fsck -f /dev/sdb1
•      Delete partition /dev/xvdb1 and create it again with the new size
o      cfdisk /dev/sdb  
### this step is very important, cfdisk seem working better than parted to delete/recreate the sdb partition.

•      Do a filesystem check to make sure that everything is running smoothly
o      fsck -n /dev/sdb1
•      Run the resize command so ext2 knows about the enlarged size of the partition
o      resize2fs /dev/sdb1
•      Turn on journal again (Making it ext3)
o      tune2fs -j /dev/sdb1
•      Remount the parttion
o      mount /srv/backup
•      Check the size
o      df  -h

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now