Difference between pages "File:D2 Racing.JPG" and "User:Apple/projects/Transplant"

(Difference between pages)
Jump to navigation Jump to search
(make redirect more direct)
 
(Created page with "''a.k.a. I like my Linux how I like my women... <s>easy to set up</s>flexible.'' This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (o...")
 
Line 1: Line 1:
#REDIRECT [[File:D2 racing.jpg]]
''a.k.a. I like my Linux how I like my women... <s>easy to set up</s>flexible.''
 
This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (on the same or a different host).
 
It won't speed up an install and it doesn't make it easier, but with it you can do a single reboot
and have a complete working system without tedious config file editing.
 
==The Script==
 
{| width="100%" cellpadding=0 cellspacing=0 style="margin: .5em 0; background-color: #f2fff2; border: solid 1px #bfffbf;"
| style="background-color: #c1ffc1; border: solid 1px #a0ffa0; border-bottom: 1px solid #888; font-size: 0.9em" | '''Code:''' /usr/local/bin/transplant
|-
| style="padding: 0 0.5em; font-family=monospace, fixed; white-space: pre;"|
<tt><nowiki>
#!/bin/bash
# I use heavy amounts of bashisms
# ...see if you can find them all!
 
# Copyright 2010 Daniel Cordero
# Licensed under the GPLv2
 
test "$PWD" = "$HOME" && cd /tmp # I don't clean up after myself
 
# When I say "list", I mean space-separated (ahem... $IFS) list.
NETIF_LIST="" # List of interface initscripts
SERVICES="" # List of services to be placed into default runlevel
HOST_FILES="" # List of host-specific /etc files
ETC_FILES="" # List of generic/shared /etc files
HOME_FILES="" # List of files in $HOME
HOME_FOLDERS="" # List of folders in $HOME
 
mkdir -p etc/{portage/{package.use,savedconfig,profile},runlevels/default}
mkdir -p etc/init.d
mkdir -p home/$USER
mkdir -p usr/lib/X11/xdm
mkdir -p var/lib/portage
mkdir -p host
 
rsync -ar --exclude .keep {/usr/,}local/
rsync -r /etc/portage/{package.use,savedconfig,profile} etc/portage
 
for service in $SERVICES; do
ln -sf /etc/init.d/$service etc/runlevels/default/$service
done
 
for netif in $NETIF_LIST; do
ln -sf /etc/init.d/netif.tmpl etc/init.d/netif.$netif
done
 
for home_folder in $HOME_FOLDERS; do
rsync -ra $HOME/$home_folder/ home/$USER/$home_folder
done
 
for home_file in $HOME_FILES; do
cp -a $HOME/$home_file home/$USER/$home_file
test x"$home_file" = "x.xinitrc" && ln -sf .xinitrc home/$USER/.xsession
done
 
 
for etc_file in $ETC_FILES; do
(test "x$(dirname $etc_file)" != "x." && \
test ! -d "$(dirname $etc_file)") && \
mkdir -p etc/$(dirname $etc_file)
cp -a /etc/$etc_file etc/$(dirname $etc_file)/$(basename $etc_file)
done
 
for host_file in ${HOST_FILES}; do
(test "x$(dirname $host_file)" != "x." && \
test ! -d "$(dirname $host_file)") && \
mkdir -p host/$(dirname $host_file)
cp -a /etc/$host_file host/$(dirname $host_file)/$(basename $host_file)
done
 
cp -a {/,}usr/lib/X11/xdm/Xsetup_0
cp -a {/,}var/lib/portage/world
 
tar cf $(hostname)-overlay.tar host/
tar cf usrlocal-overlay.tar local/
tar cf home-overlay.tar home/
tar cf funtoo-overlay.tar etc/ usr/ var/ \
home-overlay.tar usrlocal-overlay.tar $(hostname)-overlay.tar
# DESTRUCTIVE
xz funtoo-overlay.tar # non-destructive
</nowiki>
</tt>
|}
 
==Usage==
 
Fill in the 6 variables at the top of the script. You'll constantly be adding more files as the original system gets more customised.
 
When you're ready (or as a cron job), run the script and save the resulting tarball somewhere.
 
Boot your install environment. Partition, format and unpack (or work up to) a stage3. Grab a portage tree.
 
Unpack the main tarball (you probably don't want to unpack the other tarballs yet):
 
{{Root|<nowiki># tar xvJf --exclude "*.tar" funtoo-overlay.tar.xz -C /mnt/gentoo
</nowiki>}}
 
Take a peek at the list of files in $HOST_FILES and edit them to the host's specification.
 
{{Info|You cannot expect every host to have the exact geometry or architecture as the original host. If, by some miracle, the two are exactly alike, go ahead and unpack the host tarball (probably into <tt>/tmp</tt>).}}
 
{{Info|The host tarball uses the prefix <tt>host/</tt> instead of the regular <tt>etc/</tt>. This is for your protection (and a limitation of the script... but mostly protection).}}
 
Chroot in and run (I suggest in a screen, nohup or another VT):
{{Root|<nowiki># env-update; source /etc/profile
# emerge -uDN world</nowiki>}}
 
Wait (or finish configuration). Remember to make a kernel and <tt># boot-update</tt> (and installing the bootloader to MBR if necessary).
 
Add an identical user (it's not in the script, but you might want to save the output of <tt>$ groups</tt>) and unpack <tt>home-overlay.tar</tt>. If you have anything in <tt>usrlocal-overlay.tar</tt> you can unpack that too.
 
{{Info|If you're installing on a different architecture, the contents of <tt>/usr/local</tt> may be useless for your CPU.
If you're lucky, it may be all architecture-independent/interpreted scripts, or nothing at all.}}
 
If all goes well, reboot (and remove the install environment)!