How To Resize ext3 Partitions Without Losing Data - Page 3
On this page
4 Merge Two ext3 Partitions
In this example I have my system partition /dev/sda1 again (about 6GB of size) which is followed directly by the partition /dev/sda3 (about 4GB of size) on the hard disk. /dev/sda3 is mounted to the /data directory and doesn't hold files needed by the Linux system, just user data. The current partitioning looks like this:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 5.8G 4.1G 1.6G 73% /
varrun 94M 132K 94M 1% /var/run
varlock 94M 0 94M 0% /var/lock
udev 10M 56K 10M 1% /dev
devshm 94M 0 94M 0% /dev/shm
lrm 94M 18M 77M 19% /lib/modules/2.6.17-10-generic/volatile
/dev/sda3 3.5G 72M 3.3G 3% /data
To merge /dev/sda1 and /dev/sda3, we have to delete /dev/sda3 and then enlarge /dev/sda1 as described in chapter 3. This means that all data on /dev/sda3 will be lost, so if you need it later on please back it up somewhere else and then restore it to the new and bigger /dev/sda1 afterwards!
Now we open /etc/fstab and remove the line for /dev/sda3 there if it exists:
vi /etc/fstab
The new file without /dev/sda3 could look like this:
# /etc/fstab: static file system information. # # |
Then we unmount /dev/sda3 and run fdisk to delete it. This can still be done on the original system as /dev/sda3 doesn't contain system files:
umount /dev/sda3
fdisk /dev/sda
(Yes, it's /dev/sda, not /dev/sda1.)
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Type m to get a list of all commands:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Now let's delete /dev/sda3:
Command (m for help): d
Partition number (1-5): 3
Afterwards we write the new partition table to the disk:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
Now we shut down the system:
shutdown -r now
and boot into our Knoppix Live-CD (or your rescue system). From here on the steps are identical to chapter 3, beginning with
su
umount /dev/sda1
so please refer to that chapter.