Posts Tagged Linux
Maybe you have been in the situation where a process (program or service) in the system dies or ends abruptly and needs to be relaunched no matter what. You can try to monitor the process from time to time and restart it if it’s not found, but it could be a little complicated because you have to make a cron rule to check the process existence, filter the prceoss, etc. What if there would be a way to relaunch a process if it dies?…There is a way, it’s called daemontools which basically scan the process and relaunch it if it’s not detected.
Here I’ll show you how to install and configure this tool on Linux.
On Debian you can install daemontools as root by typing this:
root@raspberrypi: # aptitude install daemontools-run daemontools
For Debain spin-off like Ubuntu would be the same. On Red Hat and alike you must check if there is a package for this tool.
You have to make a directory for the service (program) you want to monitor. In this example I would use qbittorrent-nox, a bittorrent client that runs on the background (nox = no for X environment):
root@raspberrypi:~# mkdir /etc/service/qbittorrent-nox
Then you have to write and script that start the process. It must be called “run“. Use your prefered text editor, for instance vi:
root@raspberrypi:~# vi /etc/service/qbittorrent-nox/run
And add the call to the program. In this case I wanted to launch qbitorrent-nox as the user pi, so I invoked it with sudo:
#!/bin/sh sudo -u pi qbittorrent-nox
Finally change permissions to make it executable:
root@raspberrypi:~# chmod +x /etc/service/qbittorrent-nox/run
Checking the process with ps
You can check if the process is running the using ps command and filtering the output with grep:
root@raspberrypi:~# ps ax | grep qbit 3064 ? S 0:00 supervise qbittorrent-nox 3068 ? S 0:00 sudo -u pi qbittorrent-nox 3080 ? Sl 13:09 qbittorrent-nox 9926 pts/0 S+ 0:00 grep qbit
But there’s a better way to check if the process is running, using daemontools. By the way, daemon-tools means tools for handling daemons (programs or services).
Checking the process with daemontools
If you want to check if the process is running and how lomg it ha been up, use the svtat command passing the service directory, as show next:
root@raspberrypi:~# svstat /etc/service/qbittorrent-nox /etc/service/qbittorrent-nox: up (pid 3066) 205846 seconds
In this case, my qbittorrent-nox process (program/service) has been running for almost two days and a half.
Stoping the scan
If you need to stop scanning the process, for instance if you need to stop it for a while to change a setting, use the svc command with the following option:
root@raspberrypi:~# svc -d /etc/service/qbittorrent-nox
After this, check it one more time:
root@raspberrypi:~# svstat /etc/service/qbittorrent-nox /etc/service/qbittorrent-nox: down 2 seconds, normally up
Now the process won’t be checked for be relounched if it stops or dies.
Restaring the scan
In order to restart the scan, use the svc command as followed:
root@raspberrypi:~# svc -u /etc/service/qbittorrent-nox
One more time, check whether it’s running with svstat:
root@raspberrypi:~# svstat /etc/service/qbittorrent-nox /etc/service/qbittorrent-nox: up (pid 12805) 1 seconds
Due to I wanted to use my Rasperry Pi as a media center but I didn’t want to put lot of devices on my nightstand I came up with this idea. My Rasperry, a hard drive and a usb hub look like corronchos (loricariidaes) but they are behind the TV.
If you want to do something similar you can use stickers for holding photo frames (Command, Scoth, 3M, etc), and this way you can save some space and avoid to deal with a lot of devices on your room.
I’ve already install XBMC as my media center and also qbittorrent Web as my “download” center. But one piece was missing: a subtitle downloader program. I knew about subdownloader, so I decide to give it a try on my Rasperry Pi but it is not on Raspbian repos…what can you do?
Easy, just add Debian’s official repos for Sid and install it. Remember, Debian supports lot of architecture, even armhf. Let’s see how to do it…
- Edit file /etc/apt/sources.list to include sid’s repos:
deb http://ftp.debian.org/debian/ sid main contrib non-free
- Update the package list:
- Install SubDonwloader:
aptitude install subdownloader
- Edit file /etc/apt/sources.list to delete sid’s repos (it’s enough by commenting the line with #):
#deb http://ftp.debian.org/debian/ sid main contrib non-free
- Update the package list one more time:
Now you can run the program on your Rasperry Pi locally or using ssh…but keep in mind it would run a little slow. Enjoy it!
Reference: SubDownloader project page
This article shows how to update the DynDNS information with the IP supplies by your Internet provider from a router with OpenWrt, so every time your provider shanges the router’s IP, your DynDns doman will point to the new IP. Below are the stpes to follow with your OpenWrt
- Update the package list
root@fluffy:~# opkg update Downloading http://downloads.openwrt.org/backfire/10.03.1/ar71xx/packages/Packages.gz. Inflating http://downloads.openwrt.org/backfire/10.03.1/ar71xx/packages/Packages.gz. Updated list of available packages in /var/opkg-lists/packages.
- Install the last version of ddns-scripts:
Downloading http://downloads.openwrt.org/backfire/10.03.1/ar71xx/packages/ddns-scripts_1.0.0-17_all.ipk. Configuring ddns-scripts. Collected errors: * resolve_conffiles: Existing conffile /etc/config/ddns is different from the conffile in the new package. The new conffile will be placed at /etc/config/ddns-opkg.
- Edit the configuration file /etc/config/ddns with your DynDNS account information:
config 'service' 'myddns' option 'enabled' '1' option 'service_name' 'dyndns.org' option 'ip_source' 'network' option 'ip_network' 'wan' option 'force_interval' '72' option 'force_unit' 'hours' option 'check_interval' '10' option 'check_unit' 'minutes' option 'domain' 'mydomain.dyndns.org' option 'username' 'myusername' option 'password' 'mypassword'
Update and debug
In order to updte the IP addrewaa the first time you can use the following script:
root@fluffy:~# /usr/lib/ddns/dynamic_dns_updater.sh myddns update_url=http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP] force seconds = 259200 check seconds = 600 time_since_update = 144 hours Running IP check... current system ip = 184.108.40.206 registered domain ip = 220.127.116.11 update necessary, performing update ... updating with url="http://myusername:mypassword%[email protected]/nic/update?hostname=mydomain.dyndns.org&myip=18.104.22.168 Connecting to members.dyndns.org (22.214.171.124:80) - 100% |*****************************************************************************************************| 19 --:--:-- ETA Update Output: good 126.96.36.199 update complete, time is: Sat Sep 24 00:01:14 VET 2011
In this example myddns is the name of the service I configured in file /etc/config/ddns.
Reference: OpenWrt DDNS Client
I had been using my Raspberry Pi with a 4 GB – class 4 SD card Kingston until it decided to die (since I burn the image the first time that SD card was a little problematic). Because I didn’t have another 2GB or higher SD card, I decided to do a research to check if I could use the first partition as boot and another partition from an external USB hard drive of 320 GB. Effectively it can be done and I describe the steps on this article.
I decided to use the Raspbian image Raspbian 2013-02-09-wheezy-raspbian.img, but first I had to do a trick: dump the image to a 8 GB pen drive to be able separate the /boot partition and the remaining file system.
Dumping Raspbian to the pen drive
Just dump the Raspbian image as it were a SD card, but instead of using /dev/mmcblk0 do it on your pen drive:
# dd bs=4M if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.img of=/dev/sdb
Extracting the boot image
In order to extract the Raspbian’s boot image just dump the first partition of the pen drive:
# dd if=/dev/scb1 of=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.boot.img
Extracting the operating system
Do the same to extract the file system where the operating systems resides:
# dd if=/dev/sdc2 of=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.fsext4.img
Partition /boot on SD card
You will still need a SD card to boot your Rasperry, but it not longer need to be 2GB, in fact it could be much less, even 64 MB (I use a 1 GB I found). To do so you need to make a partition with GParted of about 60 MB as show in the next picture:
Now copy the image content of the first image you dumped previously:
# dd if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.boot.img of=/dev/sdb1
Once you have copied the data you must mount that partition and then edit the file /media/usb0/cmdline.txt (change /media/usb0 according to the mounting point), and put the following:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait
Here is important to put root=/dev/sda1 so the Raspberry uses the first partition of the external USB hard drive as the root partition, I mean, the “/” directory at boot.
Partitioning the external USB hard drive
Connect the hard drive to a PC and make the partitions as shown in the next picture. The first partition will content the file system and the second one will be used for saving data (you can define later that in the /etc/fstab of your the RaspBerry Pi).
File system partition “/”
Now you can dump the Raspian image you got to the first partition of the USB hard drive. To do so type this:
# dd if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.fsext4.img of=/dev/sdc1
Fixing the size partition
As you can see in the last picture, the partition was created with 9 GB, but if you mount the partition it will report only 2 GB because the Raspian image has that size by default. To fix this you must umount the partiton and and resize the file system:
# umount /dev/sdc1# e2fsck -f /dev/sdc1e2fsck 1.42.5 (29-Jul-2012) 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 Raspbian: 66488/114688 files (0.1% non-contiguous), 346538/458240 blocks# resize2fs /dev/sdc1resize2fs 1.42.5 (29-Jul-2012) Resizing the filesystem on /dev/sdc1 to 2304000 (4k) blocks. The filesystem on /dev/sdc1 is now 2304000 blocks long.
After that check the available space. It should report something like this:
# df -h/dev/sdc2 285G 191M 271G 1% /media/Data /dev/sdc1 8.7G 1.3G 7.0G 16% /media/Raspbian
If you follow these steps, your Rasperry Pi will boot from a USB hard drive.
- It’s a fact that a hard drive have a higher price than a SD card but you have to consider the later will suffer more, specially a file system with journal can kill the SD card, so it’s not crazy to think in an external USB hard drive.
- This hard drive and keyword are powered by the Rasperry Pi without problems. But if I connect something more, for instance a mouse, it can’t handle all and the device reboots.
- Using a hard drive can solve the SD card compatibility issue (recommended class 6 type). In my case I used a Sandsik of 1 GB, class 4 and it worked perfectly.
- Probably you can use dd and extract the /boot and file system partitions, but due I didn’t know the exact size and because I was a little lazy a decide to dump the Rasbian image on a pen drive and extract the images that way.
If you want to install XBMC on your Raspberry Pi using Raspbian and got dependency problems, you can download it from this repo by adding the following line to /etc/apt/sources.list
# XBMC Repo deb http://archive.mene.za.net/raspbian wheezy contrib
Then update and install XBMC:
# aptitude update # aptitude install xbmc
After that, you can start it on boot and increase the priority level by editing file /etc/default/xbmc with these parameters:
# Set this to 1 to enable startup ENABLED=1# The user to run XBMC as USER=pi# Adjust niceness of XBMC (decrease for higher priority) NICE=-10
Remember to disable the LXDE or XFCE start on boot (you can ue rasp-config). Enjoy it!
Reference: XBMC for Raspberry Pi
If by chances you have a slow connection but in another place have a better connection (school, university, work, etc.) and have a computer with Debian which on the same architecture (x86, x64, etc.) with almost the same software selection, you can do this little trick to carry part of the downloaded packages:
Computer with good connection
Update and upgrade the computer with good connection:
root@dell~# aptitude update aptitude safe-upgrade
On Debian and alike distros the downloaded packages are stored in /var/cache/apt/archives, so you can copy the content of that directory into a pen-drive or external hard drive:
cp -r /var/cache/apt/archives /media/usb0
Computer with poor connection
Update the package list. Despite you have a poor connection , you still need Internet to retrieved the package’s information:
root@cupcake:~# aptitude update root@cupcake:~# aptitude safe-upgrade The following packages will be upgraded: bind9-host dnsutils evolution-data-server evolution-data-server-common gdm3 gnome-shell gnome-shell-common google-chrome-stable gvfs gvfs-backends gvfs-bin gvfs-common gvfs-daemons gvfs-libs host icedtea-netx icedtea-netx-common krb5-locales libbind9-80 libc-bin libc-dev-bin libc6 libc6:i386 libc6-dev libc6-i386 libc6-i686:i386 libcairo-gobject2 libcairo2 libcamel-1.2-33 libdbus-glib-1-2 libdns88 libebackend-1.2-2 libebook-1.2-13 libecal-1.2-11 libedata-book-1.2-13 libedata-cal-1.2-15 libedataserver-1.2-16 libedataserverui-3.0-1 libglib2.0-0 libglib2.0-0:i386 libglib2.0-bin libglib2.0-data libgssapi-krb5-2 libgssapi-krb5-2:i386 libisc84 libisccc80 libisccfg82 libk5crypto3 libk5crypto3:i386 libkrb5-3 libkrb5-3:i386 libkrb5support0 libkrb5support0:i386 liblwres80 libperl5.14 libproxy0 libssh-4 libxen-4.1 libxenstore3.0 locales multiarch-support openssh-client openssh-server perl perl-base perl-modules python python-minimal vim vim-common vim-runtime vim-tiny xserver-xorg-video-nouveau The following packages are RECOMMENDED but will NOT be installed: xserver-xephyr 73 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 103 MB of archives. After unpacking 16.6 MB will be used. Do you want to continue? [Y/n/?] n
Here you can see it needs to download 103 MB. Say no by typing “n”, and copy the packages from the pen-drive to /var/cache/apt/archives/:
# cp -R /media/C6A7-9F3C/archives/* /var/cache/apt/archives/
Now update the package list and try to upgrade the packages one more time:
root@cupcake:~# aptitude update root@cupcake:~# aptitude safe-upgrade The following packages will be upgraded: bind9-host dnsutils evolution-data-server evolution-data-server-common gdm3 gnome-shell gnome-shell-common google-chrome-stable gvfs gvfs-backends gvfs-bin gvfs-common gvfs-daemons gvfs-libs host icedtea-netx icedtea-netx-common krb5-locales libbind9-80 libc-bin libc-dev-bin libc6 libc6:i386 libc6-dev libc6-i386 libc6-i686:i386 libcairo-gobject2 libcairo2 libcamel-1.2-33 libdbus-glib-1-2 libdns88 libebackend-1.2-2 libebook-1.2-13 libecal-1.2-11 libedata-book-1.2-13 libedata-cal-1.2-15 libedataserver-1.2-16 libedataserverui-3.0-1 libglib2.0-0 libglib2.0-0:i386 libglib2.0-bin libglib2.0-data libgssapi-krb5-2 libgssapi-krb5-2:i386 libisc84 libisccc80 libisccfg82 libk5crypto3 libk5crypto3:i386 libkrb5-3 libkrb5-3:i386 libkrb5support0 libkrb5support0:i386 liblwres80 libperl5.14 libproxy0 libssh-4 libxen-4.1 libxenstore3.0 locales multiarch-support openssh-client openssh-server perl perl-base perl-modules python python-minimal vim vim-common vim-runtime vim-tiny xserver-xorg-video-nouveau The following packages are RECOMMENDED but will NOT be installed: xserver-xephyr 73 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 2,474 kB/103 MB of archives. After unpacking 16.6 MB will be used. Do you want to continue? [Y/n/?]
As you can see, now it needs 2,4 MB, much less than originally needed and it will last much less in downloading with a poor connection like the Venezuela’s 3G networks (put here your preferred mobile operator’s name).
My Raspberry Pi has arrived…and sooner than expected (they say in three weeks). I would say it just took one week to ship it to Venezuela. In my case I bought it at RS Raspberry Pi Store and the shipment was direct to Venezuela. And yes, IPOSTEL shipments do arrive.
Here I leave some picture of the unboxing…
I just need a SD card, which must be class 4…at the moment I continue experimenting with the QEMU image as I mentioned in my last post.
I bought a Raspberry Pi but it will take three weeks until it arrives (add three more weeks thanks to the postal service) so I decided to see what I can read about the Raspberry. Then it occur to me the idea of trying to emulate the Raspberry Pi and it came to my mind QEMU, because the Raspberry Pi has a ARM1176 processor. Doing a quick research I found this blog where explains how to do it. But I didn’t want to use the Rasberry project’s image but one of the Raspbian variations, in particular the Hexxeh image. Finally, and because I wanted to do some tests without the need of a graphic interface, I did a research to make a bridge on QEMU. Then I set the image as suggested by the Raspbian page, because it comes too plain, so I uninstall LXDE in favor of XFCe with Slim. Here I explain how to do so:
I downloaded the Raspbian Hexxeh image and applied the changes sugested:
- I installed the SSH server and regenerated the keys (you have to do this because everybody downloads that image and the keys must be unique). Just to this:
# rm /etc/ssh/ssh_host_* # dpkg-reconfigure openssh-server
- I upgraded the package list
- I installed XFCE and Slim (login manager) and uninstall LXDE because I thinks it’s ugly an heavier than XFCE.
- I updated the timezone to Caracas, and set the time with ntp.
- I set the locales to US_us UTF8
- I set the keyboard layout to Latin American Spanish.
If you want custom this image as above follow the steps explained at the Raspbian Hexxeh web page.
Raspbian on QEMU
Now to run Raspbian on QEMU you must follow these steps:
- Download the kernel for this proccesor:
$ wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu
- Extract the Raspbian image downloaded. I put the Hexxeh image as example, but you can try any other image:
$ unzip raspbian-r3.zip
- Run QEMU with the following options:
$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2" -hda raspbian-r3/raspbian-r3.img
Keep in mind that is an emulation so no all the Raspberry’s hardware is supported. For example when booting the image you can see that the first partition is not loaded, which corresponds to the /boot partition, which is supplied by the downloaded kernel .
Setting the briged on QEMU
Another thing I wanted to do was to be able to access the emulation from a remote computer. The idea behind this is not to depend on a graphic environment but to be able to access the Raspberry image with ssh to, for example, be able to install packages with aptitude. To do so I had to make a bridge as explained next:
Installing the needed packages
First, you must download these packages:
# aptitude install bridge-utils uml-utilities
Granting permissions with sudo
In order add the network interfaces to the bridge you have to grant permissions to the user who launch the virtual machine. To do so you have to set sudo using the visudo command:
# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"# Host alias specification# User alias specification# Cmnd alias specification Cmnd_Alias QEMU=/sbin/ifconfig, \ /sbin/brctl # User privilege specification root ALL=(ALL:ALL) ALL lgallard ALL=NOPASSWD: QEMU# Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
In this case lgallard is the user that is allowed to run ifconfig and brctl.
Setting the bridge
You have to set the file /etc/network/interfaces to bring up the bridge automatically . To do so you must disable the interfaces to be added to the bridge (for instance, ifdown eth0) and define just the bridge as explained below:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).# The loopback network interface auto lo iface lo inet loopback# The bridge network interface(s)auto br0iface br0 inet dhcp bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off
After this you can bring up the bridge by typing this:
# ifup br0
QEMU init script (/etc/eqemu-ifup)
This script let you bring up the network interfaces and the bridge with QEMU. To do so you have to edit /etc/qemu-ifup with the following info:
#!/bin/sh #sudo -p "Password for $0:" /sbin/ifconfig $1 172.20.0.1 echo "Executing /etc/qemu-ifup" echo "Bringing up $1 for bridged mode..." sudo /sbin/ifconfig $1 0.0.0.0 promisc up echo "Setting tap0" sudo tunctl -t tap0 -u lgallard echo "Adding $1 to br0..." sudo /sbin/brctl addif br0 $1 sleep 2
Here I leave some screenshots with the QEMU emulation:
As you can see in the last screenshot, not all is installed on the image, so if something doesn’t work you have to download it. In this case you can install midory browser:
# aptitude install midory
Or any other browser you prefer.
Here I explain how to set up a mirror for Debian an Ubuntu repositories, on a Debian server. The steps explained next can be found on other sites, except how to deal with the repository’s keyrings. For instance, on the Ubuntu’s tutorial they explain how to install the keyrings assuming the server you are installing the mirror has Ubuntu running, but what if it’s running on a Debian server?
As I mentioned, I used debmirror for mirroring both distros. There are other programs, like apt-cacher, but I chose debmirror because I wanted to mirror all Debian and Ubuntu repos. So, in order to install debmirror just type the following as root:
aptitude install debmirror
Installing the keyrings
Now it’s time for installing the repositories’ keyrings. Because I wanted a mirror for Debian and other for Ubuntu, I had to download both keyrings packages and import the keyrings from them:
To install the keyrings for Debian’s repos the latest debian-archive-keyrings must be downloaded, for instance from testing:
# wget http://ftp.us.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2012.4_all.deb
Then the package’s content must be extracted in the root’s home directory:
# dpkg-deb -x debian-archive-keyring_2012.4_all.deb ~
And finally import the keyrings:
# gpg --no-default-keyring --keyring /home/repo/keyrings/debian/trustedkeys.gpg --import /root/usr/share/keyrings/debian-archive-keyring.gpg gpg: keyring `/home/repo/keyrings/debian/trustedkeys.gpg' created gpg: key B98321F9: public key "Squeeze Stable Release Key " imported gpg: key 473041FA: public key "Debian Archive Automatic Signing Key (6.0/squeeze) " imported gpg: key 65FFB764: public key "Wheezy Stable Release Key " imported gpg: key 46925553: public key "Debian Archive Automatic Signing Key (7.0/wheezy) " imported gpg: Total number processed: 4 gpg: imported: 4 (RSA: 4) gpg: no ultimately trusted keys found
On Ubuntu I did something similar. I downloaded the latest ubuntu-keyring package up-to-date, from quantal’s repos:
# wget http://pa.archive.ubuntu.com/ubuntu/pool/main/u/ubuntu-keyring/ubuntu-keyring_2012.05.19_all.deb
Then I proceed to extract the package content in the root’s home directory and import the keyrinngs:
# dpkg-deb -x ubuntu-keyring_2012.05.19_all.deb ~# gpg --no-default-keyring --keyring /home/repo/keyrings/ubuntu/trustedkeys.gpg --import /root/usr/share/keyrings/ubuntu-archive-keyring.gpggpg: keyring `/home/repo/keyrings/ubuntu/trustedkeys.gpg' created gpg: key 437D05B5: public key "Ubuntu Archive Automatic Signing Key " imported gpg: key FBB75451: public key "Ubuntu CD Image Automatic Signing Key " imported gpg: key C0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) " imported gpg: key EFE21092: public key "Ubuntu CD Image Automatic Signing Key (2012) " imported gpg: Total number processed: 4 gpg: imported: 4 (RSA: 2) gpg: no ultimately trusted keys found
The debmirror script
The script is an adaptation of the the one at Ubuntu’s documentation, I saved as /home/repo/scripts/debian.sh with the following values:
#!/bin/sh# Don't touch the user's keyring, have our own instead export GNUPGHOME=/home/repo/keyrings/ubuntu # Architecture. For Ubuntu can be i386, powerpc or amd64. arch=i386,amd64 # Minimum Ubuntu system requires main, restricted # Section (One of the following - main/restricted/universe/multiverse). section=main,multiverse,universe,restricted # Release of the system (Quantal, Precise, etc) release=quantal,quantal-security,quantal-updates,quantal-backports,precise,precise-security,precise-updates,precise-backports # Server name, minus the protocol and the path at the end server=us.archive.ubuntu.com # Path from the main server, so http://my.web.server/$dir, Server dependant inPath=/ubuntu # Protocol to use for transfer (http, ftp, hftp, rsync) proto=http # Directory to store the mirror in outPath=/home/repo/mirrors/ubuntu # Start script debmirror -a $arch \ --no-source \ --md5sums \ --progress \ --passive \ --verbose \ -s $section \ -h $server \ -d $release \ -r $inPath \ -e $proto \
For Debian I used other parameters and save it as /home/repo/scripts/debian.sh with this values:
#!/bin/sh # Don't touch the user's keyring, have our own instead export GNUPGHOME=/home/repo/keyrings/debian # Architecture (i386, powerpc, amd64, etc.) arch=i386,amd64 # Section (main,contrib,non-free) section=main,contrib,non-free # Release of the system (squeeze,lenny,stable,testing,etc) release=squeeze # Server name, minus the protocol and the path at the end server=ftp.us.debian.org # Path from the main server, so http://my.web.server/$dir, Server dependant inPath=/debian # Protocol to use for transfer (http, ftp, hftp, rsync) proto=http # Directory to store the mirror in outPath=/home/repo/mirrors/debian # Start script debmirror -a $arch \ --no-source \ --md5sums \ --progress \ --passive \ --verbose \ -s $section \ -h $server \ -d $release \ -r $inPath \ -e $proto \ $outPath
Note: On both cases you have to make the scripts executable, check the connection with the chosen servers and check if you have enough space available for hosting the mirrors.
Scheduled job (crontab)
Once the scripts are working, you can create a cron for keep the mirrors synced. For example, to run he scripts at midnight every day you can put the following in the /etc/crontab:
0 0 * * * root /home/repo/scripts/debian.sh 0 0 * * * root /home/repo/scripts/ubuntu.sh
Publishing the mirrrors
I published the mirror via http with Apache, the web server:
aptitude install apache2
By default on Debian, Apache uses /var/www as root directory. Thus in order to set the mirrors just make the symbolic links to that directory:
# ln -s /home/repo/mirrors/ubuntu /var/www/ # ln -s /home/repo/mirrors/debian /var/www/
Setting the clients
On the client side, you have to edit the /etc/apt/sources.list file according to the Linux version used on the client.
For Ubuntu precise (12.04) you have to put something like this in the /etc/apt/sources.list file:
deb http://192.168.1.1/ubuntu/ precise main restricted universe multiverse deb http://192.168.1.1/ubuntu/ precise-updates main restricted universe multiverse deb http://192.168.1.1/ubuntu/ precise-backports main restricted universe multiverse deb http://192.168.1.1/ubuntu/ precise-security main restricted universe multiverse
In this case the IP addresses 192.168.1.1 belongs to the server hosting the mirrors, which were published via http with Apache. Change to other IP or a DNS entry according to your configuration.
For Debian Squeeze you must have the following in your /etc/apt/sources.list:
deb http://192.168.1.1/debian squeeze main contrib non-free deb http://192.168.1.1/debian-security squeeze/updates main contrib non-free
For both cases after doing these changes you have to update the package list:
Once the package list has been updated you can use those repositories.