Difference between pages "User:D2 racing" and "User:Apple/projects/Transplant"

(Difference between pages)
(d2_racing)
 
(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:
{{Person
+
''a.k.a. I like my Linux how I like my women... <s>easy to set up</s>flexible.''
|Full name=Sylvain Alain
+
|Email=d2_racing@hotmail.com
+
|Nick=d2_racing
+
|Geoloc=46.784751, -71.3550042
+
|Location name=Ste-Foy,Québec,Canada
+
|Roles={{Role
+
|Role type=Staff
+
|Role desc=Staffer
+
|Start date=2010/09/01
+
}}
+
|Maintains=
+
|Blogs=
+
}}
+
Sylvain Alain was born in March 26 1979. He owned a computer for the first time when he was 10, a Tandy 1000 SL2 without a HDD. After finishing his High School(École secondaire), he went to the CEGEP(exist only in Quebec) to complete his CEGEP diploma in computer science (DEC Technologie des Systèmes Ordinés). In 2000, he started to work as a programmer for the Gouvernment IRS in Quebec City. Years later, he was promote as Security Analyst for the Gouvernment.  
+
  
He started to use Linux in 1997 when he had to install a Red Hat CD to pass an exam. At that time, Linux was use a lot at his CEGEP, because it was the first CEGEP to ban Microsoft product. Indeed, he didn't have the chance to code a single line inside a Microsoft Environment....still today :P
+
This is a script to backup and/or transfer a working Funtoo installation onto a fresh install (on the same or a different host).
  
He started to use Linux on daily based during the year 2002-2003 with Debian Woody,Fedora Core 2 and 3, Ubuntu, Mandrake 10 etc ...
+
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.
  
He started to use Gentoo back in 2005 after a course at the University Laval in Quebec City.
+
==The Script==
  
He joined the Gentoo Global moderator staff in december 2008 because of his French/English knowledge and also because of his technical skills.  
+
{| 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!
  
He started to use Funtoo when Daniel Robbins released one of the first versions of Metro(1.3) back in 2008-2009 to build some custom Gentoo-Quebec stage3.
+
# Copyright 2010 Daniel Cordero
 +
# Licensed under the GPLv2
  
Finally, in September 2010, he started with the same 4 friends Funtoo-Quebec website(Guy Fontaine,Laurent Duchesne,Claude Fleury,Bernard Tremblay) to help his good friend Daniel Robbins and to offer the French support for Funtoo.
+
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
  
He created with his 4 friends Gentoo-Quebec website in december 2007 after using Gentoo for 2 years on daily base. And in September 2010, Funtoo-Quebec was officially create to support the French community.
+
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)!

Latest revision as of 14:19, 17 November 2010

a.k.a. I like my Linux how I like my women... easy to set upflexible.

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

Code: /usr/local/bin/transplant

#!/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

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):

# tar xvJf --exclude "*.tar" funtoo-overlay.tar.xz -C /mnt/gentoo


Take a peek at the list of files in $HOST_FILES and edit them to the host's specification.

Template:Info

Template:Info

Chroot in and run (I suggest in a screen, nohup or another VT):

# env-update; source /etc/profile # emerge -uDN world


Wait (or finish configuration). Remember to make a kernel and # boot-update (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 $ groups) and unpack home-overlay.tar. If you have anything in usrlocal-overlay.tar you can unpack that too.

Template:Info

If all goes well, reboot (and remove the install environment)!