How to use UUID and blkid to manage devices

Having trouble with device mapping at reboot (iscsi device mapping can change at every reboot) ?

Use UUID (Universal Unique Identifier)!

 

Say you have two iSCSI targets on your Linux. They show, for example, as disks /dev/sdc and /dev/sdd the first time you discover them (with iscsiadm) :

# sfdisk -s

/dev/sda:  20971520
/dev/sdb: 104857600
/dev/sdc: 2122317824
/dev/sdd: 2122317824

Using fdisk or parted you will create the devices /dev/sdc1 and /dev/sdd1 :

# sfdisk -l /dev/sdc

Disk /dev/sdc: 264216 cylinders, 255 heads, 63 sectors/track

Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start     End   #cyls    #blocks   Id  System

/dev/sdc1          0+ 264215  264216- 2122314988+  83  Linux

/dev/sdc2          0       -       0          0    0  Empty

/dev/sdc3          0       -       0          0    0  Empty

/dev/sdc4          0       -       0          0    0  Empty

Disk /dev/sdd: 264216 cylinders, 255 heads, 63 sectors/track

Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start     End   #cyls    #blocks   Id  System

/dev/sdd1          0+ 264215  264216- 2122314988+  83  Linux

/dev/sdd2          0       -       0          0    0  Empty

/dev/sdd3          0       -       0          0    0  Empty

/dev/sdd4          0       -       0          0    0  Empty

Then you can create the two file systems and mount them:

# mkfs -t ext3 /dev/sdc1

# mount -t ext3 /dev/sdc1 /VLS1

# mkfs -t ext3 /dev/sdd1

# mount -t ext3 /dev/sdd1 /VLS2

You need to add the file system in /etc/fstab in order to automatically mount them at startup.

However let’s first reboot the system to check if everything is alright.

At you surprise after reboot you can’t mount /dev/sdc1 and /dev/sdd1.

If you check with sfdisk –l  you can see that /dev/sdc1 and /dev/sdd1 still exist but /dev/sde1 and /dev/sdf1 appeared out of nowhere …

Actually, your two iSCSI disks are now /dev/sde1 et sdf1 (but sdc1 can also be sdd1 at the new reboot and so on …) thanks to the magic of Linux’s dynamic mapping of devices (udev).

That’s where UUID is your best friend !

UUID (Universal Unique Identifier) enable to uniquely identify you device. UUID is not changing at every reboot the way device files (/dev/sdX ou /dev/hdX …) are.

For instance you may know MAC addresses are unique identifier for network cards, well MAC addresses are UUID (version 1).

So if you can get the UUID for your two file systems your problem is solved.

On linux you can get a file system UUIDs with command “blkid” (“vol_id” command can sometimes be used for old Linux versions).

blkid can be found into util-linux package.

# blkid /dev/sdc1

/dev/sdc1: UUID="01066206-c67c-47d1-83a9-d61791fff943" SEC_TYPE="ext2" TYPE="ext3"

# blkid /dev/sdd1

/dev/sdd1 UUID="cea28516-ca98-4ac4-954f-6710b6ac36c7" SEC_TYPE="ext2" TYPE="ext3"

 

Then add the following lines to /etc/fstab :

UUID=4a496f92-6840-4736-a0d5-5b9916113835       /VLS1   ext3 _netdev    0 0
UUID=cab5e3ec-4797-4227-98e8-e9bca3c3f766       /VLS2   ext3 _netdev    0 0

“_netdev” substitute to the usual “default” because network needs to be up before iSCSI filesystems mount.

Now your iSCSI file systems will be automatically mounted after every reboot (well, as long as your iSCSI server is up ?).

Samba troubleshooting : NT_STATUS_BAD_NETWORK_NAME

Tip : if you’ve configured a samba server and you know you configuration should work, but you can’t connect from a Windows server, try to run smbclient from a linux server.

You will have more information to work with.

Try to run :

# smbclient –L myhost1 –U myusername

Domain=[ myhost1] OS=[Unix] Server=[Samba 3.5.6-86.el6]

Sharename       Type      Comment

---------       ----      -------

sqldump Disk      dumps sql

IPC$            IPC       IPC Service (Samba Server Version 3.5.6-86.el6)

Domain=[ myhost1] OS=[Unix] Server=[Samba 3.5.6-86.el6]

Server               Comment

---------            -------

Workgroup            Master

---------            -------

 

For instance the share sqldump should be ok to connect with but when I try to connect with smbclient, I get the following error:

tree connect failed: NT_STATUS_BAD_NETWORK_NAME

 

Try to disable SELinux, even temporarly with :

echo 0 > /selinux/enforce

And try again, it should work.

 

For more information on how to disable SELinux try this link:

http://www.crypt.gen.nz/selinux/disable_selinux.html

Migrate a subversion repository – Migrer un référentiel subversion

This is how to migrate a subversion repository from one server to another (the same technique can be used to upgrade the repository’s version, with some limitations).
Voici comment migrer un référentiel subversion d’un serveur à un autre (la même technique peut servir pour mettre à jour la version d’un référentiel, avec quelques limitations cependant).

Extract your repository on host1:

Extraire le référentiel sur host1 :

[myhost1]$ /usr/local/svn144/bin/svnadmin dump /REFERENTIELS/APP/CRUSERS > /tmp/CRUSERS__150411.dmp

* Dumped revision 0.

* Dumped revision 1.

* Dumped revision 2.

* Dumped revision 3.

 

Send the dump file to host2 :

Envoyer le fichier dump vers host2 :

[myhost1]$ scp /tmp/CRUSERS__150411.dmp myhost2:/tmp/

subvr@myhost2's password:

CRUSERS__150411.dmp

 

Create the new target repository on host2 :

Créer le nouveau référentiel cible sur host2 :

[myhost2]$ svnadmin create /REPO/OPE/CRUSERS

 

Load the dump file on the new repository:

Charger le fichier dump dans le nouveau référentiel :

[myhost2]$ svnadmin load /REPO/OPE/CRUSERS < /tmp/CRUSERS__150411.dmp

<<< Started new transaction, based on original revision 1

------- Committed revision 1 >>>

<<< Started new transaction, based on original revision 2

------- Committed revision 2 >>>

<<< Started new transaction, based on original revision 3

------- Committed revision 3 >>>

 

To keep the configuration of the repository (authentication, password … ), copy the content of “conf” directory on your source repository (myhost1) to the “conf” directory of the target repository (myhost2).

Pour garder la configuration du référentiel (authentification, mots de passe …), copier le contenu du répertoire « conf » du référentiel source (myhost1), vers le répertoire « conf » du référentiel cible (myhost2).

[myhost1]$ pwd

/REFERENTIELS/APP/CRUSERS/conf

 [myhost1]$ ls

authz  listeuser  passwd  svnserve.conf

[myhost1]$ scp * myhost2:/REFERENTIELS/OPE/CRUSERS/conf/

subvr@myhost2's password:

authz                                                                                                               100%  684     0.7KB/s   00:00

listeuser                                                                                                           100%   66     0.1KB/s   00:00

passwd                                                                                                              100%  309     0.3KB/s   00:00

svnserve.conf                                                                                                       100%   73     0.1KB/s   00:00

 

Check the result (“verify” does an repository integrity check) :

Vérifier le résultat (vérification de l’intégrité du référentiel avec “verify”) :

[myhost2]$ svnadmin verify /REPO/OPE/CRUSERS

* Verified revision 0.

* Verified revision 1.

* Verified revision 2.

* Verified revision 3.

Using smbclient – Utilisation de smbclient

smbclient is useful alternative to ftp, sftp and smbmount if you want to access to a Windows environment from Linux, because :

smbmount : you have to be root (or configure sudo)

ftp : secure Windows and Linux won’t have active ftp server.

sftp : you have to install a client on Windows.

smbclient est une alternative bien utile à ftp, sftp et smbmount pour accéder à un environnement Windows depuis Linux, car :

smbmount : il faut être route (ou mettre en place sudo)

ftp : les Windows et Linux sécurisés n’ont pas de server ftp actif.

sftp : il faut installer un client sur Windows.

 

Using smbclient with example :

Utilisation de smbclient en exemple :

Show the share on the Windows:

Affichage des partages Windows :

$ smbclient -L myhost -U myusername

Password:

Domain=[FRTS0072] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Windows Server 2003 R2 5.2]

Sharename       Type      Comment

---------       ----      -------

IPC$            IPC       Remote IPC

C$              Disk      Default share

ADMIN$          Disk      Remote Admin

D$              Disk      Default share

E$              Disk      Default share

Domain=[myhost] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Windows Server 2003 R2 5.2]

Server               Comment

---------            -------

Workgroup            Master

---------            -------

Connecting, browsing, uploading and downloading:

Connexion, navigation, téléchargement :

 

$ smbclient //myhost/C$ -U myusername

Password:

Domain=[myhost] OS=[Windows Server 2003 R2 3790 Service Pack 2] Server=[Windows Server 2003 R2 5.2]

Listing files on Windows – Liste des fichiers sur le Windows

smb: \> ls

AUTOEXEC.BAT                        A        0  Fri Oct  9 19:06:19 2009

boot.ini                          AHS      222  Fri Oct 16 10:19:18 2009

CONFIG.SYS                          A        0  Fri Oct  9 19:06:19 2009

Documents and Settings              D        0  Fri Oct  9 19:12:22 2009

Intel                               D        0  Fri Oct  9 19:25:08 2009

IO.SYS                           AHSR        0  Fri Oct  9 19:06:19 2009

MSDOS.SYS                        AHSR        0  Fri Oct  9 19:06:19 2009

NTDETECT.COM                     AHSR    47772  Wed Mar 22 13:00:00 2006

ntldr                            AHSR   297072  Fri Oct  9 19:54:49 2009

OpenManage                          D        0  Sat Feb 19 11:01:23 2011

pagefile.sys                      AHS 2145386496  Sat Feb 19 11:21:26 2011

Program Files                      DR        0  Sat Feb 19 10:50:13 2011

Program Files (x86)                DR        0  Sat Feb 19 11:05:04 2011

RECYCLER                          DHS        0  Wed Mar 24 18:34:18 2010

System Volume Information         DHS        0  Fri Oct  9 19:12:09 2009

WINDOWS                             D        0  Sun Mar 27 03:02:58 2011

34683 blocks of size 2097152. 28612 blocks available

Listing local files – Liste des fichiers locaux

smb: \> !ls

mnt  pscp.exe

Upload file – Upload d’un fichier

smb: \> put pscp.exe

putting file pscp.exe as \pscp.exe (8470.6 kb/s) (average 8470.6 kb/s)

smb: \> pwd

Current directory is \\myhost\C$\

Download a file – Téléchargement d’un fichier

smb: \Documents and Settings\Administrator\Desktop\old_log\> get cfg3CPU.log

getting file \Documents and Settings\Administrator\Desktop\old_log\cfg3CPU.log of size 47472 as cfg3CPU.log (5151.0 kb/s) (average 8426.8 kb/s)

smb: \Documents and Settings\Administrator\Desktop\old_log\> exit