Solved

Extend Linux partition

Posted on 2011-03-10
7
611 Views
Last Modified: 2012-05-11
Hello,
I tried to run the following commands:
dd if=/dev/zero of=/swapfile2 bs=1024 count=2097152
mkswap /swapfile2
swapon /swapfile2

and got back:


Complete!
[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
0
Comment
Question by:tamirmilo
7 Comments
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:point_pleasant
Comment Utility
Boot up from PartedMagic LiveCD and reize partitions. PartedMagic is one of the best partition manager.

http://partedmagic.com/doku.php
0
 
LVL 16

Expert Comment

by:Joseph Gan
Comment Utility
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:upanwar
Comment Utility
There is one more tool to achieve your  goal with good how to.

http://www.howtoforge.com/partitioning_with_gparted    
0
 
LVL 12

Expert Comment

by:mccracky
Comment Utility
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.
0
 

Author Comment

by:tamirmilo
Comment Utility
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.

0
 
LVL 7

Accepted Solution

by:
jackiechen858 earned 500 total points
Comment Utility
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






0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now