Hello Curiousadmin,
OK. Based on some testing, the following steps should do the job for
you. The first few steps do the file system resizing and adjusting the
partition sizes / create the new one(s).
FILE SYSTEM AND PARTITION CHANGES
I've marked a few steps with (* and #a/#b) if the file system is
really messed up. From the numbers you mention, it appears you want
about 40G for the new partition. The /data1 partition will be about
180G after this is done. Adjust the numbers (e.g., 171G, +180G) if you
want different sizes.
[1] Verify that the partition to shrink (/dev/sdb2) is not mounted.
Use umount if necessary.
[2] (* not needed) e2fsck -f /dev/sdb2
to check the file system / verify it is in a consistent state. -f
forces the check. See
http://www.die.net/doc/linux/man/man8/e2fsck.8.html
for more options if desired.
[3] (* not needed) resize2fs -p /dev/sdb2 171G
Resize the file system to the desired size. I suggest a size about 5%
smaller than 180G because you don't have to get the partition size
exactly right (and you will quickly resize to use all the space in
step 5a). This took a several minutes on my system (3G) but with the
33G used on your system it could be an hour or so. I suggest not
stopping this step once started (or it will corrupt your file system).
See
http://www.die.net/doc/linux/man/man8/resize2fs.8.html
for more options if desired.
[4] fdisk /dev/sdb
p
to print the partition table / confirm what you have already reported.
d
2
to delete the second partition
n
p
2
1045 (should be the default value)
+180G
to create the second primary partition with size 180G (slightly less usable)
p
to print the table / note the last cylinder of the second partition
n
p
3
[last cylinder of 2nd partition + 1] (should be the default value)
[last cylinder of the disk] (should be the defaut value)
to create the third primary partition sized to take the rest of the
disk. If you want two partitions instead of one, you can create a 3rd
and 4th primary partition if desired. Just repeat the steps using the
appopriate values.
w
to write the partition table. You will get a few messages before fdisk
exits and you are back to the command line prompt. For explanations of
fdisk, the man page at
http://www.die.net/doc/linux/man/man8/fdisk.8.html
is not nearly as helpful as a tutorial in the Gentoo handbook at
http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=4#doc_chap3
or the Linux partition HOWTO at
http://www.tldp.org/HOWTO/Partition/partition-5.html
Both of the latter explain the commands once you run fdisk much better
than the man page does.
NOTE: before 4a, e2fsck -f /dev/sdb2 may be necessary (it was not in my testing).
[5a] (* not needed) resize2fs -p /dev/sdb2
to resize the partition on sdb2 to use the entire space. On my system
this was pretty quick - but you may see a message about adding inodes.
[5b] (*) mke2fs -j -L /data1 /dev/sdb2
If the partition was messed up, just rebuild it with this command
line. This turns on journaling (ext3) and sets the file system label
to /data1. You may want to review
http://www.die.net/doc/linux/man/man8/mke2fs.8.html
for additional options.
[6] mke2fs -j -L /usr /dev/sdb3
to create the file system (type ext3) on the new partition. Repeat
with a different label if you create two partitions instead of one.
The label by the way is optional but can help in case you move
partitions / add disks by avoiding the use of physical disk partition
names.
At this point, you have the partitions set up the way you want them
but the new one will not be mounted at start up and the new partition
does not have the contents desired.
COPYING FILES
Adjust the command line parameters (e.g., sdb4 for sdb3, var for usr)
if you need to repeat the commands for more than one partition.
To move the contents at this point, you need to mount the old & new
partitions at a temporary location. Something like
mkdir /tmp/sdb2
mkdir /tmp/sdb3
mount -t ext3 /dev/sdb2 /tmp/sdb2
mount -t ext3 /dev/sdb3 /tmp/sdb3
should do the job. The first two steps create empty directories to act
as mount points and the last two steps mount the drives in the
corresponding directories.
To copy the files, I suggest using a bulk copy program such as rsync.
http://www.die.net/doc/linux/man/man1/rsync.1.html
Yes - I know it is a program normally used to copy files across the
network, but it works just fine locally as well. There are a LOT of
options to rsync, but the simplest method is something like
rsync -a /tmp/sdb2/usr/ /tmp/sdb3
which will copy all the files from the old partition at /usr/ (and
recursively all sub directories) in "archive mode" which preserves
ownership, permissions, time stamps, etc. The only thing this does NOT
do is to preserve hard links (a single file located at more than one
spot in the hierarchy). If you must preserve hard links, use
rsync -aH /tmp/sdb2/usr/ /tmp/sdb3
but the documentation indicates it is MUCH slower. Another note - be
sure to include the trailing slash on the source directory - it is
described in the man page as well, but this forces the contents of
/usr/ to appear in /tmp/sdb3 (and not in /tmp/sdb3/usr).
If you have a backup / restore program you could use that instead to
copy the files.
After copying the files and confirming they are correct - you should
probably remove them from the old location. Use
\rm -rf /usr
[be VERY careful with entering this command...]
to remove the files from the old location.
FIXING /etc/fstab
Now - the changes to the fstab file are pretty straight forward. See
http://www.die.net/doc/linux/man/man5/fstab.5.html
for an explanation of the fields in the file.
The lines you showed should be kept as-is. For the new partition(s),
you need to add lines like these:
LABEL=/usr /usr ext3 defaults 1 2
The LABEL= parameter refers to the file system label added above. The
/usr parameter refers to where the file system will be mounted. This
should be an empty directory (but if not empty its contents are
ignored after the mount is done). The ext3 parameter refers to the
file system type. Now "defaults" mean that the default mount options
are used. See
http://www.die.net/doc/linux/man/man8/mount.8.html
for explanations of the mount options. The last two options refer to
when the file system is dumped (for backups) and when it is mounted at
start up (in this case, after the root partition).
CLEANUP
At this point, unmount the partitions, and I suggest you check them
one last time before you reboot.
umount /tmp/sdb2
umount /tmp/sdb3
e2fsck -f /dev/sdb2
e2fsck -f /dev/sdb3
to complete the file system checks. Then reboot (a variety of methods).
CONCLUSION
At this point, your system should be up and running OK with the new
partitions. Please make a clarification request if you have ANY
problems with the steps described or if any step is unclear. I would
be glad to follow up as needed.
Good luck with your work.
--Maniac |