Search:  
Gentoo Wiki

HOWTO_Modify_and_resize_partitions_on_a_remote_machine

These Gentoo is being used more and more in production environments, collocation facilities, etc., which are far away and require sys admins to travel every time they need to do major system administration.

In order to help obviate some of those trips, here is some documentation that will help you re-partition, resize and fsck your drives without going on site.

Please note that this creates a very minimal system on your swap drive to work from. Things like local domains names etc. will not be carried over to the shell of the minimal system.

Login to you system and ...

1. Turn swap off:

  1. swapoff /dev/hda2

2. Make the disk an ext3 system.

  1. mke2fs -j /dev/hda2

3. Verify the system is healthy. This is required so that the system doesn't complain on restart.)

  1. e2fsck /dev/hda2

4. Mount the drive and put the Stage 3 gentoo base on it and extract.

mkdir -p /tmp/restore mount /dev/hda2 /tmp/restore cd /tmp/restore wget http://whatever-mirror.com/gentoo/releases/x86/curren/stages/stage3-x86-2008.0.tar.bz2 tar xvjpf stage3-*.tar.bz2

5. Copy the resolve.conf, modules.autoload.d files and your modules of your extant partition into the /lib directory on the new partition.

  1. cp /etc/modules.autoload.d/* /tmp/restore/etc/modules.autoload/
  2. cp -R /lib/modules /tmp/restore/lib
  3. cp /etc/resolv.conf /tmp/restore/etc

6. Modify the passwd, group, and shadow files to permit you to login and su to root. In this example "username" is whatever user you use to su to root.

  1. grep username /etc/passwd >>/tmp/restore/etc/passwd
  2. grep username /etc/shadow >>/tmp/restore/etc/shadow

Now edit /tmp/restore/etc/shadow so that it's root line exactly resembles that of your current /etc/shadow

There are two ways:

(by hand)

  1. grep root /etc/shadow
  2. nano -w /tmp/restore/etc/shadow

(or automated)

  1. grep root /etc/shadow >/tmp/tmp.shadow
  2. grep -v root /tmp/restore/etc/shadow >>/tmp/tmp.shadow
  3. mv /tmp/tmp.shadow /tmp/restore/etc/shadow

Add ",username" onto the end of the "wheel" group to permit yourself to su.

  1. nano -w /etc/group

(This command could replace all of the above: cd /etc; cp passwd shadow group /tmp/restore/etc )

Also, make sure to create a directory for username

  1. mkdir /home/username

6. Ensure that sshd launches after reboot

  1. echo "/etc/init.d/sshd start" >> /tmp/restore/etc/conf.d/local.start

7. Modify fstab to list only those partitions that you wish to mount after reboot. Make sure to exclude boot.

  1. nano /etc/fstab

8. Modify /tmp/restore/etc/conf.d/net to use the correct ip address and netmask after reboot so that you can log back in. (Depending on your setup you may also want to modify /etc/ssh/sshd_config - but by logging in as "username" and using "su" you should be fine with the default).

There are two ways:

(by hand)

  1. nano /etc/conf.d/net

Or (automated)

  1. cp /etc/conf.d/net /tmp/restore/etc/conf.d/net

(depending on your situation, perhaps also: # cp /etc/ssh/sshd_config /tmp/restore/etc/ssh/sshd_config)


9. Modify your boot configuration so that the default reboot uses this new system.

For grub, the process is:

  1. mount /dev/hda1 /boot
  2. nano -w /boot/grub/grub.conf

On the same line as the kernel, put a space, then real_root=/dev/hda2 Also, make sure to leave the previous installation available, should you something crash, requiring you to go on site.

Here is my grub.conf file:


default 0 timeout 10

title=Gentoo boot to swap root (hd0,0) kernel /boot/kernel-genkernel-x86-2.6.23-gentoo-r6 real_root=/dev/hda2

title=Gentoo primary root (hd0,0) kernel /boot/kernel-genkernel-x86-2.6.23-gentoo-r6


10. Unmount and run e2fsck mark /dev/hda2 as healthy so there are no complaints after reboot.

  1. cd /
  2. umount /dev/hda2
  3. e2fsck /dev/hda2

11. Reboot

  1. reboot

12. Now you can ssh back into the system and run e2fsck or do whatever to your untouched disk partitions. To resize it, you could use "parted", but not without these few steps, which involves some use of experimental software:

To emerge "parted" you must sync first, then get it.

  1. emerge --sync
  2. emerge parted

If you now try to use parted to resize your main partition, you may receive the error "Filesystem has incompatible feature." A bug report here ( http://lists.alioth.debian.org/pipermail/parted-commits/2007-October/000295.html ) shows the features that are compatible. To check which features your system uses type:

  1. tune2fs -l /dev/hda3 (hda3 is the drive to be resized.)

On the system that this author is testing, the incompable feature is "resize inode"

To remove it:

  1. tune2fs -O ^resize_inode /dev/hda3

After you must clean the drive, and interactively confirm two or more changes. It's pretty fast:

  1. e2fsck /dev/hda3

e2fsck 1.40.8 (13-Mar-2008) Filesystem does not have resize_inode enabled, but s_reserved_gdt_blocks is 1024; should be zero. Fix<y>? yes

Resize_inode not enabled, but the resize inode is non-zero. Clear<y>? yes

Adding dirhash hint to filesystem.

/dev/hda3 was not cleanly unmounted, check forced. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Block bitmap differences: -(13--1036) -1557 -(32781--33804) -(98317--99340) -(163853--164876) -(229389--230412) -(294925--295948) -(819213--820236) -(884749--885772) -(1605645--1606668) -(2654221--2655244) -(4096013--4097036) -(7962637--7963660) -(11239437--11240460) -(20480013--20481036) -(23887885--23888908) Fix<y>? yes

Free blocks count wrong for group #0 (0, counted=1025). Fix<y>? yes

Free blocks count wrong for group #1 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #3 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #5 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #7 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #9 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #25 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #27 (17298, counted=18322). Fix<y>? yes

Free blocks count wrong for group #49 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong for group #81 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong for group #125 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong for group #243 (0, counted=1024). Fix<y>? yes

Free blocks count wrong for group #343 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong for group #625 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong for group #729 (31216, counted=32240). Fix<y>? yes

Free blocks count wrong (37909100, counted=37924461). Fix<y>? yes

/dev/hda3: ***** FILE SYSTEM WAS MODIFIED ***** /dev/hda3: 326341/24279264 files (2.4% non-contiguous), 10539411/48463872 blocks

And finally, run parted:

  1. parted /dev/hda3

It will complain about "experimental" software, but this author has gone through without without any errors so far.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Modify_and_resize_partitions_on_a_remote_machine"

Last modified: Fri, 05 Sep 2008 06:41:00 +0000 Hits: 1,074