Difference between revisions of "Chroot"

From Christoph's Personal Wiki
Jump to: navigation, search
(New page: A '''chroot''' on Linux operating systems is an operation that changes the apparent root directory for the current running process and its children. The modified environment is called ...)
 
(Copy files while in Rescue Mode)
Line 27: Line 27:
 
  $ chroot /mnt /bin/bash
 
  $ chroot /mnt /bin/bash
  
* Copy the files to a remote/destination server:
+
* Copy the files to a remote/destination server (using [[rsync]]):
  $ rsync -avr /path/to/data/dir user@x.x.x.x:/path/to/dest/data/dir
+
  $ rsync -e 'ssh -p 22' -avl --stats --progress /path/to/data/dir user@x.x.x.x:/path/to/dest/data/dir
+
 
 
* Exit the chrooted jail
 
* Exit the chrooted jail
 
  $ sync
 
  $ sync

Revision as of 12:40, 3 November 2014

A chroot on Linux operating systems is an operation that changes the apparent root directory for the current running process and its children. The modified environment is called a "chroot jail".

Copy files while in Rescue Mode

Note: The following section shows how to copy files from a Category:Rackspace Cloud Server while in Rescue Mode.

  • Find out which is your "real" root device (i.e., the one that is not the Rescue Mode's root device / the one already mounted):
$ fdisk -l
  • Mount "real" root device and required filesystem dirs:
$ mount /dev/xvdb1 /mnt
$ mount -o bind /dev /mnt/dev
$ mount -o bind /sys /mnt/sys
$ mount -o bind /dev/shm /mnt/dev/shm
$ mount -o bind /proc /mnt/proc
$ #***** OR *****:
$ mount /dev/xvdb1 /mnt
$ mount -t proc none /mnt/proc
$ mount --rbind /sys /mnt/sys
$ mount --rbind /dev /mnt/dev
  • Set up networking for your chrooted jail:
$ ln -s /etc/resolv.conf /mnt/etc/resolv.conf
  • Chroot into your jail:
$ chroot /mnt /bin/bash
  • Copy the files to a remote/destination server (using rsync):
$ rsync -e 'ssh -p 22' -avl --stats --progress /path/to/data/dir user@x.x.x.x:/path/to/dest/data/dir
  • Exit the chrooted jail
$ sync
$ exit
$ umount -lf /mnt/{dev,sys,proc}
$ umount /mnt

Finally, exit "Rescue Mode" and you are done.

Converting a root filesystem to ext4

Note: The following section shows how to convert the root filesystem from ext3 to ext4 on a Category:Rackspace Cloud Server while in Rescue Mode.

  • Assuming your root device is /dev/xvda1, before you enter Rescue Mode, change your /etc/fstab entry for root from:
/dev/xvda1  /  ext3  errors=remount-ro,noatime,barrier=0 0 1

to:

/dev/xvda1  /  ext4  errors=remount-ro,noatime,barrier=0 0 1

then enter Rescue Mode (do not reboot your server before entering Rescue Mode).

  • While in Rescue Mode, find out which device is your "real" root device (i.e., not the Rescue Mode's root device):
$ fdisk -l
  • Then run a filesystem check on the "real" root filesystem:
$ fsck.ext3 -pf /dev/xvdb1
  • Enable all the ext4 features on the root filesystem:
$ tune2fs -O extents,uninit_bg,dir_index /dev/xvdb1
  • Run another filesystem check on the root filesystem (it will most likely find and fix errors. This is completely normal):
$ fsck.ext4 -yfD /dev/xvdb1

You should now be able to exit Rescue Mode and your root filesystem will be using ext4.