Pages

Monday 17 February 2014

How to setup your own package repository

Sometimes you'll find you need to be able to collect a bunch of rpm packages you have together in one place and you want to make them available to your systems running yum. It is pretty easy to do.
Overview
A package repository used by yum is simply a directory with one or more RPMs plus some "meta information" used by yum to be able to easily access information (dependencies, file lists, etc.) for the RPMs. yum can then to access this directory over ftp/http or a file URI (including over NFS).
Steps
Collect the packages together in one directory. You can make as many sub-directories as you want, but there needs to be a top level directory where they all live. That's where we're going to form our repository.
Yum uses a digest of the information stored in each RPM to do its work. This information is created using the 'createrepo' program. If you don't have createrepo installed you can install it with:
    yum install createrepo
If you are generating your repository on a machine that doesn't use RPMs, you can download createrepo from http://createrepo.baseurl.org/ and build/install it manually.
Once you have createrepo installed you need to run it. It only requires one argument which is the directory in which you would like to generate the repository data. So if the packages directory we made in step 1 is in /srv/my/repo then you would run:
    createrepo /srv/my/repo
You should see a lot of things fly by but it should finish without an error. In the end you should have a directory named /srv/my/repo/repodata with at least 4 files in it. Maybe more.
To make this repository known to yum you need to add a .repo file to your yum configuration. On the systems where you want to use this repo you need to make a new file in/etc/yum.repos.d/. The file can be named anything but the extension on the file has to be .repo. Let's call this one 'myrepo.repo'.
In the file you just need to include the following:
   [myrepo]
   name = This is my repo
   baseurl = url://to/get/to/srv/my/repo/
That's all you need in that file. The 'baseurl' line is the path that machine uses to get to the repository. If the machine has direct access to it or mounts it as a filesystem you can use a baseurl line like:
     baseurl = file:///srv/my/repo/
NB: there are 3 slashes (/) following the file:, not 2. That is correct.
If you access the file via an http or https server you would use something like:
     baseurl = http://servername/my/repo
More details about client-side repo configuration can be found in the yum.conf man page.
Now, every time you modify, remove or add a new RPM package to /srv/my/repo you need to recreate the repository metadata. You do that by running createrepo the same way you did in step 2.
Recommended options
While running plain createrepo on it's own will work, and is generally the most compatible, it is recommended that you add extra options if you know you've only got newer yum clients.
--database, this creates the .sqlite databases on the server saving time on every client. There is no downside to doing this, as older versions of yum will just ignore the .sqlite files and get the .xml files.
--unique-md-filenames, this names all the metadata files be uniquely. This is most useful if you are using mirrors. Versions of yum before 3.2.10 will not clean up correctly.
--changelog-limit, limit changelog entries to save on download time.
--deltas --oldpackagedirs, this creates delta information, to save on download time. Clients must have yum-presto installed to take advantage of this data.
More Advanced options
createrepo --update: Sometimes you have a lot of packages in your repsitory and regenerating the meta data for each package when only a few packages have been added or changed is just too time consuming. This is where --update comes in handy. You run createrepo just like you did before but you pass the --update flag to it. Like this:
      createrepo --update /srv/my/repo
Now, createrepo will only update the items which have been changed, been added or been removed since the last time the meta data was generated.
createrepo -x package_file_name: Suppose you have a few packages in your repository directory but you really don't want the unsuspecting world to see them. You can exclude packages easily with createrepo:
      createrepo -x filename -x filename2 -x filename* /srv/my/repo
You can sign a repository after it has been created by running:
    gpg --detach-sign --armor repodata/repomd.xml
This will create a repomd.xml.asc file in the repodata directory which for modern versions of yum this will allow yum to verify that the repository metadata came from the owner of the gpg key.
You can change the internal checksum used
     createrepo --checksum /srv/my/repo
This should only be needed if you are creating the repodata on a machine with a newer version of python than on the clients (or one with python-hashlib installed).
If you want to learn more about using createrepo to create and maintain your own package repository please see the createrepo man page or the other documents in this collection.
Source: baseurl.org

Adding Additional Hard Disk(s) in Centos

Doing the Work

Once your drive is plugged, detected by the system bios and you are booted into your system open a terminal and type: su –login
  1. Finding the hard disk devices your computer sees attached.
  2. [root@quetzalcoatl ~]# fdisk -l
    
    Disk /dev/sda: 20.8 GB, 20847697920 bytes
    16 heads, 63 sectors/track, 40395 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1        1016      512032+  83  Linux
    /dev/sda2            1017        5079     2047752   82  Linux swap / Solaris
    /dev/sda3            5080       40395    17799264   83  Linux
    
    Disk /dev/sdb: 120.0 GB, 120034123776 bytes
    16 heads, 63 sectors/track, 232581 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1      232581   117220792+  83  Linux
    Disk /dev/sdi: 250.0 GB, 250059350016 bytes
    255 heads, 63 sectors/track, 30401 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdi1               1       30401   244196001   83  Linux
    Disk /dev/sdj: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdj1               1        9729    78148161   83  Linux
    
    Disk /dev/sdk: 120.0 GB, 120034123776 bytes
    16 heads, 63 sectors/track, 232581 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdk1   *           1      232576   117218241   83  Linux
    
    Disk /dev/sdl: 251.0 GB, 251000193024 bytes
    255 heads, 63 sectors/track, 30515 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk /dev/sdl doesn't contain a valid partition table
    
    
  3. At the bottom we see: “Disk /dev/sdl doesn’t contain a valid partition table“, this is what we are looking for, now we can create the partitions. For this example, we’re taking a 250GB Maxtor hard disk and using the entire space as one large partition. If you want more than one partition on your new disk you can alter this when you choose the size of your new partitions using +sizeM (megabytes) or +sizeK (Kilobytes).
  4. [root@quetzalcoatl ~]# fdisk /dev/sdl
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.
    
    
    The number of cylinders for this disk is set to 30515.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-30515, default 1): <enter>
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-30515, default 30515): <enter>
    Using default value 30515
    
    Command (m for help):
    
  5. Now that we’ve created the partition scheme we’d like, we need to write the changes to the disk partition table.
  6. Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@quetzalcoatl ~]#
    
  7. Now we need to create a filesystem on the new partition. For this howto we will use the native linux filesystem (ext3 or type 83). Make note of the superblock backups for this new disk in case an fsck is required and the main journal is corrupted or missing. You can point fsck to a backup superblock provided you thought ahead and recorded them.
  8. [root@quetzalcoatl ~]# mkfs.ext3 /dev/sdl1
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    30654464 inodes, 61277926 blocks
    3063896 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    1871 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
            4096000, 7962624, 11239424, 20480000, 23887872
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    This filesystem will be automatically checked every 24 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@quetzalcoatl ~]# 
    
  9. Mounting the new disk on /mnt/250GB so we can put data on it and use it normally. First, we create the directory with the mkdir command. Second we mount the disk device into our newly created directory /mnt/250GB as read/write. Note: if you have trouble with directory permissions or not being allowed to write to the directory see: man chmod | man chown.
  10. [root@quetzalcoatl ~]# mkdir /mnt/250GB && mount -t ext3 /dev/sdl1 /mnt/250GB rw
    [root@quetzalcoatl ~]# 
    
  11. Setting your drive up to automount on boot. For this we’ll edit the /etc/fstab file and add in the appropriate line save/exit. We’ll then tell the system to execute the fstab file with: mount -a  and finally we’ll use: df -h to verify that the disk is indeed mounted and the system sees it where we expect.
  12. [root@quetzalcoatl ~]# nano /etc/fstab
    # This file is edited by fstab-sync - see 'man fstab-sync' for details
    LABEL=/1                /                       ext3    defaults        1 1
    LABEL=/boot1            /boot                   ext3    defaults        1 2
    none                    /dev/pts                devpts  gid=5,mode=620  0 0
    none                    /dev/shm                tmpfs   defaults        0 0
    none                    /proc                   proc    defaults        0 0
    none                    /sys                    sysfs   defaults        0 0
    LABEL=SWAP-hda2         swap                    swap    defaults        0 0
    /dev/sdb1                /mnt/sdb120             ext3 rw
    /dev/sdi1                /mnt/sdi250             ext3 rw
    /dev/sdj1                /mnt/sdj80              ext3 rw
    /dev/sdk1                /mnt/sdk120             ext3 rw
    /dev/sdl1                /mnt/sdl250             ext3 rw 
    /dev/fd0                /media/floppy1          auto    pamconsole,exec,noauto,utf8,managed 0 0
    /dev/sdd                /media/cdrom            auto    pamconsole,exec,noauto,managed 0 0
    /dev/sdc                /media/cdrecorder       auto    pamconsole,exec,noauto,managed 0 0
    [root@quetzalcoatl ~]# mount -a
    [root@quetzalcoatl ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3              17G   15G  1.8G  90% /
    /dev/sda1             485M   52M  408M  12% /boot
    >
    none                  506M     0  506M   0% /dev/shm
    /dev/sdb1             111G   97G  8.3G  93% /mnt/sdb120
    /dev/sdi1             230G  216G  2.6G  99% /mnt/sdi250
    /dev/sdj1              74G   67G  2.8G  97% /mnt/sdj80
    /dev/sdk1             111G  100G  4.9G  96% /mnt/sdk120
    /dev/sdl1             231G  188M  219G   1% /mnt/sdl250
    [root@quetzalcoatl ~]# 
    

Source : Centoshelp.org