Solved

Extend Linux partition

Posted on 2011-03-10
7
615 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
ID: 35096083
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
ID: 35096471
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
ID: 35103680
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 12

Expert Comment

by:upanwar
ID: 35104801
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
ID: 35110156
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
ID: 35110364
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
ID: 35111994
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

770 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