How extend linux partition with?(after success to extend : fail to boot computer)
Solution 1
Disk partitions are linear chunks of your disk. You can't have a partition that starts at the top, has a hole in it, and continues somewhere else.
Usual warning: messing with your partition layout is one of the faster ways to lose all your data. Make sure you have a backup of anything important, and take your time - don't rush past warnings or errors the tools report.
Since sda2
is a swap device, it doesn't contain any useful information when the OS is not running; so you can just delete it.
Once that is done, you should be able to extend sda1
to however much you want, and re-create a swap partition.
You should also consider using lvm
. It is quite handy and will allow you to control your disk usage more finely. See Setting Up LVM- Without A Clean Install for example.
Solution 2
Like Mat said, you can't have partitions out of non-contiguous space, so if you want to enlarge sda1
, you need to take sda2
out of the way.
Again, as Mat said, as sda2
is a swap partition, there's nothing you need to keep there, so you can just get rid of it.
For short, you want/need to do as follows
- get
sda2
out of the way - make
sda1
bigger - create another swap partition
Now, for the small print and important details
-
Disable the swap space before getting rid of the partition —
swapoff /dev/sda2
should do it, and after that you can get rid ofsda2
simply by removing the partition from the partition table Remove
sda2
from the partition table using some partition table editor utility -gparted
,cfdisk
,fdisk
(here, focus on picking one you feel comfortable with — after all messing with an alien tool, such as usinggparted
if you've got no clue where the options are, orfdisk
if you don't know what are the commands, is just a shortcut to get rid of your precious data (you can picture Andy Serkis saying "my precious data")Now you have unallocated space after
sda1
— you can now enlarge the partition to 90 GB. This, if I'm not mistaken, is just changing the partition table so that it lists the new, larger size for the partition. Depending on the partitioning tool, this and the next step may be bundled in the same option/feature.After enlarging the partition, you can finally extend/grow the filesystem which lives in the partition so that it spans the full size of the partition. This requires a filesystem-aware tool. I've been able to grow ext2/ext3 partitions from
gparted
, I don't know about ext4 — if ext4 is to ext3 as ext3 is to ext2 (just additions), then I'd guess the same toolgparted
uses for ext2/ext3 should be able to handle ext4.Finally, you can recreate your swap partition. Bonus credit if you create it as
sda2
(which should happen unless you create an extended partition), as you won't have to change your configuration files to use the new swap. Useswapon
to start using the new swap partition with no reboot.
Please note that, although all steps but 4 are (probably) possible to carry on a live system which is using the disk and has sda1
mounted, step 4 above must be done with sda1
unmounted. In the end, it's probably easier if you do all of it from a live CD — there is a gparted livecd, you can try that. But any other live CD should do, as far as it has the partitioning tool, the filesystem growing tool, and is recent enough to handle your hardware (unless you're using a bleeding edge northbridge or SATA controller, or trying to partition a terabyte drive from Damn Small Linux (well, maybe it actually works, I just remember the userland tools are unable to deal with >4GB files, which is a totally different issue), you shouldn't have to worry about this).
Related videos on Youtube
mmarinero
Updated on September 18, 2022Comments
-
mmarinero over 1 year
I have Ubuntu and I want to enlarge the disk space of /dev/sda1 from 10GB to 90GB.
gparted Ubuntu 9.04 live cd show:
Partition File System Size /dev/sda1 ext4 10GB /dev/sda2 linux-swap 4GB unallocated unallocated 146000
I would like to get this disk map:
Partition File System Size /dev/sda1 ext4 90GB /dev/sda2 linux-swap 4GB unallocated unallocated 56000
I click on /dev/sda1 and option resize only gives the option to reduce and not enlarge disk.
If gparted cannot handle this, are there other tools that would?
(I think that I should merge /dev/sda1 with unallocated but I don't know how to do it.)
Update:failing boot - unable to enter to my ubuntu OS, infinite loop in begining(solve the problem to enlarge partition but blocked to enter to my partition OS):
What I done:
- delete /dev/sda2
- resize /dev/sda1 to 160GB
- create /dev/sda2 with size 4GB primary partition and make it linux-swap
- restart PC and remove ubuntu live cd - result: unable to access to my installed before ubuntu OS.
my current map according gparted ubuntu live cd:
Partition File System Size /dev/sda1 ext4 156GB /dev/sda2 linux-swap 4GB
Update2:
reinstall bootloader(Mat idea - thank you very much) https://help.ubuntu.com/community/Grub2#Reinstalling_GRUB2 Thanks,
-
Admin about 12 yearsIs there any error message when it fails to boot Ubuntu? How old is your BIOS? Error messages would help. Maybe you're hitting some disk addressing limitation. (If that's the case, the solution would involve moving the bootloader files to a separate partition, to be mounted as
/boot
in the running system -- this partition would have to be at the beginning of the disk, and carry the bootloader files (if you're using a bootloader that has external files, such asGNU GRUB
) and the kernel images (and initrds, if you're using that too)) -
Admin about 12 yearsno error, just not getting to screen with ubuntu options.My BIOS 4 years old (hp pavalion - but i replace the hp hardisk with windows VISTA to new empty hard disk that have on him the ubuntu.) I get in beggening the bios screen of HP then black screen and then again bios screen of hp and again..(infinite loop).
-
Admin about 12 years@Yosef: try re-installing your bootloader
-
Admin about 12 yearsthanks, How can i reinstall my bootloader?i can only use ubuntu live cd
-
Admin about 12 yearsTry searching for "ubuntu reinstall bootloader from livecd", lots of promising results.
-
Admin about 12 years
-
phemmer about 12 yearsThis is correct with a couple points worth noting. After resizing the partition, a reboot will be required for the system to re-read the partition table (not required if the filesystem can be unmounted though). Also part 4 can be done on a live system.
resize2fs
is capable of resizing mounted filesystems. -
Prakash about 12 yearsThis is just an additional hint to Comment by @Patrick in @njsg's answer. If you have gparted installed
partprobe /dev/sda
will rescan the partition table without rebooting. -
mmarinero about 12 yearsplease see my update
-
mmarinero about 12 yearsplease see my update