Monday, September 15, 2008

Repartition hard drive Fedora Core 3 (FC3)

Recently I repartitioned the Hard Drive of a FC3 box. Steps taken as described hereinunder. Maybe the description can be used as tutorial.

B.R.
satimis

--- Description ---
Goal:
to repartition existing Hard Drive, adding 3 new partitions, namely /home, /lfs and /livecd and each having size 10G, 6G and 1G respectively.
/lfs (for building LinuxFromScratch using “Fedora Core 3” as host)
/livecd (for building LiveCD from LinuxFromScratch)
Operation System: Fedora Core 3
Bootloader: GRUB


A. Preparation before repartition
To find out the existing partitions
 
Code:
# fdisk -l /dev/hda
Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device  Boot  Start End Blocks    Id System
/dev/hda1   * 1 13 104391    83 Linux
/dev/hda2  14 2563 20482875    83 Linux
/dev/hda3  2564 2690 1020127+    82 Linux swap
/dev/hda4  2691 4865 17470687+   5 Extended
/dev/hda5  2691 4865 17470656    83 Linux
To find out the size of Hard Drive/each partition and the system of each partition
 
Code:
# df -hT
Filesystem     Type Size     Used      Avail      Use%     Mounted on
/dev/hda2      ext3        20G      3.7G      15G       20%        /
/dev/hda1      ext3        99M      14M       80M      15%        /boot
none              tmpfs     125M     0           125M     0%         /dev/shm
/dev/hda5      ext3       17G       1.5G      15G      10%        /home

B. Repartition Steps

1. Boot into “init 1”, Single User Mode
During booting – on Bootloader window
1.1. Select the most recent kernel (using the “UP and “DOWN” arrows)
1.2. Press the "e" key to edit the commands for that kernel before booting
1.3. On next screen, choose the line mentioning "kernel /vmlinuz.........." and press "e" key again (also using the “UP and “DOWN” arrows)
1.4. On next screen, at the END of the line of "grub edit > kernel /vmlinuz..." hit space bar once to get a space before typing and type "init 1" without the (quotation marks) and then press "Enter" key.
1.5. Now coming back to previous screen and a line with "init 1" indicated at its end will appear. Press the "b" key to continue booting to “init 1” (text mode)

2.
sh-3.00# mount /dev/hda5 /mnt
Already mount
(This may not be true, please see steps 8. below)

3.
sh-3.00# mkdir /home2 && cp -ar /mnt/* /home2/

4.
sh-3.00# umount /dev/hda5
(no printout)

5.
Used fdisk to delete the partition (/dev/hda5) and to create 3 new partitions in the space left.

Remark:
d = delete a partition
m = print the menu
n = add a new partition
q = quit without saving change
w = write table to disk and exit

sh-3.00# fdisk /dev/hda
Command (m for help): (type) d
Partition number (1-5): (type) 5

Command (m for help): (type) n
First cylinder (2691-4865, default 2691): press [Enter]
Using default value 2691

Last cylinder of +size or +sizeM or +sizeK (2691-4865, default 4865): (type) +10000M and press [Enter]

Command (m for help): (type) n and press [Enter]
First cylinder (3908-4865, default 390: press [Enter]
Using default value 3908
Last cylinder of +size or +sizeM or +sizeK (3908-4865, default 4865): (type) +6000M and press [Enter]

Command (m for help): (type) n and press [Enter]
First cylinder (4638-4865, default 463: press [Enter]
Using default value 4638
Last cylinder of +size or +sizeM or +sizeK (4638-4865, default 4865): press [Enter]

Command (m for help): (type) w and press [Enter]

Partition table has been altered!
Calling ioctl() to read partition table
Warning: Re-reading the partition table failed with error 16: Device and resource busy
The kernel still uses the old table
The new table will be used at the next reboot
Syncing disk

6.
sh-3.00# (type) reboot and press [Enter]

FedoraCore3 rebooted automatically. Finally it came to warning screen suggesting to run “fsck” to fix problems.

Remark: Ignore it. Don't take any action. The trick is here. The PC is now already booted to “init 1”, the Single User Mode.

7.
Continue
# mkfs -t ext3 /dev/hda5
# mkfs -t ext3 /dev/hda6
# mkfs -t ext3 /dev/hda7
(all no printout)

8.
# cp -ar /home2/* /home/
Another trick happened here. It seemed copying all data back to /home but nothing actioned. The Hard Drive was working with the pilot light on.

9.
# mkdir /mnt/lfs
# mkdir /mnt/livecd

10.
Edited /etc/fstab
# nano /etc/fstab

Original /etc/fstab before editing;
 
Code:
# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/               /                                 ext3      defaults                 1 1
LABEL=/boot        /boot                          ext3      defaults                 1 2
none                     /dev/pts                      devpts  gid=5,mode=620   0 0
none                     /dev/shm                    tmpfs    defaults                 0 0
LABEL=/home      /home                        ext3      defaults                 1 2
none                      /proc                         proc      defaults                  0 0
none                      /sys                           sysfs     defaults                 0 0
/dev/hda3              swap                         swap     defaults                 0 0
/dev/hdd                /media/cdrom            auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
/dev/hdc                /media/cdrecorder    auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
/dev/fd0                /media/floppy            auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
Changed
 
Code:
LABEL=/home        /home                      ext3      defaults                1 2
to
 
Code:
/dev/hda5               /home                      ext3      defaults                1 2
Added:
 
Code:
/dev/hda6               /mnt/lfs                    ext3     defaults                 1 2
/dev/hda7               /mnt/livecd               ext3     defaults                1 2
/etc/fstab after editing;
 
Code:
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/               /                                 ext3      defaults                 1 1
LABEL=/boot        /boot                          ext3      defaults                 1 2
none                     /dev/pts                     devpts  gid=5,mode=620   0 0
none                     /dev/shm                   tmpfs    defaults                 0 0
/dev/hda5               /home                      ext3      defaults                 1 2
none                       /proc                        proc     defaults                  0 0
none                       /sys                          sysfs    defaults                 0 0
/dev/hda3               swap                        swap    defaults                 0 0
/dev/hda6               /mnt/lfs                     ext3     defaults                 1 2
/dev/hda7               /mnt/livecd               ext3     defaults                 1 2
/dev/hdd                 /media/cdrom           auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
/dev/hdc                /media/cdrecorder     auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
/dev/fd0                /media/floppy              auto    pamconsole,exec,noauto,fscontext=system_u:object_r:removable_t,managed 0 0
11.
# reboot
Rebooted PC again

PC rebooted without problem to Login screen. I was not allowed to login as user, saying /home/user/ not found. But I was allowed to login as Root.

12.
After login as Root I discovered /home being empty. Started Kconsole
# cp -ar /home2/* /home/

Logout and relogin. This time I was allowed to login as “user”


Remark:
1)Using /lfs and /mnt/lfs is only following the LFS instruction
2)Better using -v flag to replace -r flag
cp -av /home2/* /home/
to copy all data back
 

No comments: