Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a drive with this configuration:

fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000f1b8b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2612    20971520   83  Linux
/dev/sda3           60736       60801      525312   82  Linux swap / Solaris

There is 478GB unallocated space, how would I go about adding this space to /dev/sda1 without losing the data that is currently on /dev/sda1? (the filesystem is ext4) The OS is debian 6. Thank you in advance. :)
(it is a server with only SSH, no GUI for running stuff like gparted)

share|improve this question
    
I can netboot the server and use it while the drive is unmounted. –  Seb Mar 6 '13 at 20:08
    
Sorry 'bout the criss cross, lol -- I put that stuff into an answer. –  TAFKA 'goldilocks' Mar 6 '13 at 20:15
    
This particular item has been covered many many times within the SE sites. It would be best to do just a little bit more research before posting a question. –  mdpc Mar 7 '13 at 2:17
add comment

2 Answers

up vote 3 down vote accepted

Enlarge the partition: fdisk -u /dev/sda.

p to print the partition table, take note of the number, start, end, type of sda1.

Delete it: d:

Recreate it with same number (1), start and type but with a bigger end (taking care not to overlap with other partitions). Try to align things on a megabyte boundary that is for end, make it a multiple of 2048 minus 1.

Then w to write and q to quit.

The partition table will have been modified but the kernel will not be able to take that into account as some partitions are mounted.

So you'll need to reboot. The system should boot just fine.

Once rebooted, resize the filesystem so it spreads to the extent of the enlarged partition:

resize2fs /dev/sda1

Which for ext4 will work just fine even on a live FS.

share|improve this answer
    
Worked great :) thanks. –  Seb Mar 6 '13 at 21:11
add comment

You can't do it safely while the partition is mounted, meaning you need to boot some other partition and do it from there.

gparted is a nice, easy GUI for this purpose. In our deleted comment exchange you mentioned it would not start because of "can't access display" -- this implies you aren't in X; since it is a GUI it won't work without that.

Of course, if you don't have another partition to use, you'll need a live CD or something -- I think they usually come with gparted. Your best bet is probably the actual gparted live CD, which looks to have a reasonably recent latest stable version (and will fit on a CD, which is nice since the "live CD" is rapidly becoming the "live DVD").

I've never had gparted cause a problem but of course do back your important tish up first.

share|improve this answer
    
I can't use gparted as I only have SSH access (it is a headless server). I am able to unmount the HDD, as the system does not run on /dev/sda. –  Seb Mar 6 '13 at 20:17
1  
If you don't have physical access to the system and thus can't usefully unmount and change the partition, I think you are out of luck, or at least into very sketchy territory -- eg, you could attempt to use fdisk while mounted, select (x)pert, (c)hange number of cylinders. But I have not done this and would only do so if there was absolutely no other choice. –  TAFKA 'goldilocks' Mar 6 '13 at 20:25
    
I just said that I can unmount the partition. I can even netboot the whole server and go in from another server, which would be just like using a Live CD (just without a GUI). –  Seb Mar 6 '13 at 20:28
    
@Seb : my bad, sorry. –  TAFKA 'goldilocks' Mar 6 '13 at 21:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.