navigation
Home
admin
|
Fichiers et systèmes de fichiers
November 8th, 2016
|
| Table des matières |  |
- Nombre de fichiers ouverts pour le système
- Nombre de fichiers ouverts par processus
- XFS
- Gestion des quotas disques avec XFS
- Gestion des quotas disques avec ext4
- Gestion des ACL
- Visualiser un fichier binaire
- Editer un fichier binaire
- Visualiser les octets d'un fichier texte
- Visualiser un fichier image
- Visualiser un fichier vidéo
- Montage d'un fichier iso
- Manipulation des systèmes de fichiers
- Périphériques de type loop
- Histoires d'encodages
- Nombre magique
- Reduire la taille d'une partition NTFS
- Augmenter la taille d'une partition XFS ou EXT4
- Sauvegarder la table des partitions
- Restaurer la table des partitions
- partprobe
- Comparaisons
- Utilisation de parted
- Utilisation de find
- Divers
| Nombre de fichiers ouverts pour le système |  |
Type the following command:
Sample outputs:
fs.file-nr = 1020 0 70000 |
Where,
1020 The number of allocated file handles.
0 The number of unused-but-allocated file handles.
70000 The system-wide maximum number of file handles.
On peut vérifier le nombre max de fichiers ouverts :
lsof is not an accurate way of getting the number of File Descriptors that are currently open !
why ?
There are two reasons lsof | wc -l doesn't count file descriptors. One is that it lists things that aren't open files, such as loaded dynamically linked libraries and current working directories; you need to filter them out. Another is that lsof takes some time to run, so can miss files that are opened or closed while it's running; therefore the number of listed open files is approximate. Looking at /proc/sys/fs/file-nr gives you an exact value at a particular point in time. |
Pour régler cette valeur : /etc/sysctl.conf, variable fs.file-max
Sources :
http://unix.stackexchange.com/questions/66235/how-to-display-open-file-descriptors-but-not-using-lsof-command
http://www.cyberciti.biz/tips/linux-procfs-file-descriptors.html
| Nombre de fichiers ouverts par processus |  |
Le max se règle dans le fichier /etc/security/limits.conf
On peut observer ces limites par processus (par ex le 3256) :
cat /proc/3256/limits
[...]
Max open files 1024 1024 files
[...] |
ou voir les fichiers ouverts par processus :
Pour regarder les fichiers ouverts pour chacun des processus :
ps -ef |awk '{print "lsof -p "$2"|wc -l"}'|sh|sort -n |uniq|tail -5
137
138
139
140
141 |
| Notes sur XFS |  |
tune2fs
tune2fs ne fonctionne pas avec XFS.
On utilisera plutôt xfs_info
[root@rhel7-1 local]# xfs_info /
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=4589568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@rhel7-1 local]# |
fsck
The file system consistency checking commands for XFS file systems are xfs_check and xfs_repair -n. Unlike fsck, neither xfs_check nor xfs_repair are invoked automatically on system startup. They should be used only if you suspect a file system consistency problem.
Source : http://docs.cray.com/books/S-2377-22/html-S-2377-22/z1029470303.html
resize2fs - xfs_growfs
Il n'est pas possible de diminuer la taille d'un système de fichier XFS :
http://xfs.org/index.php/Shrinking_Support
| Gestion des quotas disques avec XFS |  |
/etc/fstab
/dev/sdb1 /eleves xfs prjquota,usrquota 0 0 |
Vérification
xfs_quota -x -c report /eleves |
avec l'option human et sans la précision du FS
xfs_quota -x -c 'report -h' |
Définition simple
xfs_quota -x -c 'limit bsoft=1950m bhard=2048m toto /eleves' |
Définition de plusieurs utilisateurs
cat get_users2A.txt |awk '{print "xfs_quota -x -c \x27limit bsoft=1950m bhard=2048m "$1"\x27 /eleves"}' |sh |
(le fichier get_users2A.txt contient les identifiants des utilisateurs)
| Gestion des quotas disques avec ext4 |  |
Modifier fstab et ajouter l'option userquota
Exemple :
/dev/da1s2g /home ufs rw,userquota 1 2 |
définir les quotas d'un utilisateur :
On peut mettre en oeuvre des quotas en définissant le nombre max de blocks ou d'inodes autorisés.
Nous choisissons d'utiliser les blocks.
Pour connaitre la taille d'un block d'un file system :
tune2fs -l /dev/sdb1 |grep "Block size"
4096 |
Ainsi pour ce système de fichiers, chaque block fait 4Ko.
On veut mettre des quotas à 500 Mo :
500 Mo = 500 000 Ko qui correspondent à 500 000 / 4 blocks soit 125 000 blocks.
On mettra une limite soft à 115 000 blocks et une limite hard à 125 000 blocks.
Vérification :
Source : http://www.freebsd.org/doc/fr/books/handbook/quotas.html
Surveillance :
# quotacheck /mnt/disk/
quotacheck: Les quotas pour users sont actif sur le point de montage /mnt/disk si bien que quotacheck risque d'endommager le fichier.
Veuillez désactiver les quotas ou utiliser -f pour forcer la vérification. |
Les quotas doivent être désactivés pour assurer la vérification :
# quotaoff /mnt/disk/
# quotacheck /mnt/disk/ |
pas de message , c'est ok
On réactive :
Source : http://serveurfelix.myds.me/~Felix/HTTrack/doku4897.html?id=administration_linux:administration_linux:gestion_des_peripheriques_de_stockage
| Gestion des ACL |  |
Création d'un répertoire de test
mkdir test
chown root:root test
chmod 770 test |
Seul root peut accéder à ce répertoire.
Mise en place des ACL
setfacl -m permissions test |
ou permissions sont de la forme : préfixe:[utilisateurOuGroupe:]droits
avec
préfixe : u, g ou o
droits : composition avec r,w,x,-
On peut rajouter un "d" devant le "m" de la commande setfacl. On définit ainsi les droits par défaut (à noter que ca n'est pas tjs nécessaire : on peut simplement limiter l'accès à un répertoire et les fichiers créés dans ce répertoire par les personnes autorisées seront protégés).
exemple :
setfacl -R -m u:user1:rwx rep |
setfacl -R -m g:groupe1:rws rep |
Suppression des ACL
supprimera toute l'ACL du fichier test
Vérification des ACL
Source : http://fr.openclassrooms.com/informatique/cours/les-acl-access-control-lists-sous-linux
Sauvegarde des ACL
getfacl --skip-base -R /dossier/dossier/ > fichier |
Restauration des ACL
setfacl --restore=fichier |
Source : http://lea-linux.org/documentations/Gestion_des_ACL
| Visualiser un fichier binaire |  |
| Editer un fichier binaire |  |
| Visualiser les octets d'un fichier texte |  |
En ascii et hexa
En ascii et octal
| Visualiser un fichier image |  |
| Visualiser un fichier vidéo |  |
| Montage d'un fichier iso |  |
mount -o loop /root/FC4-i386-DVD.iso /mnt_bis/ |
| Manipulations des systèmes de fichiers |  |
Label d'une partition
voir la commande e2label
e2label /dev/sda1 : obtenir de label du disque
e2label /dev/sda1 /boot : labellé le disque
Informations sur une partition
ou
UUID, Label, etc...
Remplir un disque
Certains utiliseront une boucle avec une concaténation de fichier :
cat f1 f1 > f2;cat f2 f2 > f1 |
mais il y a plus simple :
dd if=/dev/zero of=grosfichier bs=1M count=1000
dd: writing `grosfichier': No space left on device
|
construit un fichier d'1 Go (1000x1Mo)
blkid
blkid permet de récupérer des infos sur les partitions : label, UUID :
# blkid
/dev/sda1: LABEL="/boot" UUID="c58c2711-5dcb-4ddd-b370-0d4faf072576" TYPE="ext4"
/dev/sda2: UUID="fdb83e38-a50a-45e0-982e-e0cf04f57797" TYPE="swap"
/dev/sda3: UUID="Tk5ZSB-1ytH-137g-Og3k-Z3pg-fZj2-Pv0mRk" TYPE="LVM2_member"
/dev/sda5: UUID="0K3e98-mWCD-S1Jf-38c7-HUEV-KOyl-WGMrCO" TYPE="LVM2_member"
/dev/sda6: UUID="4pInAh-Gltk-m364-jaZl-FkI0-fv8y-zHNS2v" TYPE="LVM2_member"
/dev/sda7: UUID="NhbZkO-GiWB-677v-fK5P-qxlp-kspl-G0nSM7" TYPE="LVM2_member"
/dev/sda8: UUID="cLR3Cb-S36v-LfSd-hc1d-MHnR-ghi4-GvjD2M" TYPE="LVM2_member"
/dev/mapper/vg_1-lv_root: UUID="a05f80d0-a321-497a-8a24-409897a1ef57" TYPE="ext4"
/dev/mapper/vg_3-lv_home4: UUID="0e3de340-1b6a-4ac8-b1e3-f7010dddcbe8" TYPE="ext4"
/dev/mapper/vg_2-lv_home2: UUID="3d96ee8e-f2f0-4573-901f-725ca92b3f2a" TYPE="ext4" |
lsblk
lsblk permet d'avoir une vue intéressante des partitions :
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 111,8G 0 disk
ââsda1 8:1 0 200M 0 part
ââsda2 8:2 0 74,4G 0 part
ââsda3 8:3 0 13,9G 0 part
ââsda4 8:4 0 21,4G 0 part /
ââsda5 8:5 0 1,9G 0 part [SWAP] |
| Périphériques de type loop |  |
Permettent de simuler des partitions physiques.
Exemple :
dd if=/dev/zero of=part1 bs=1M count=100M
losetup /dev/loop1 part1 // on associe le fichier part1 au périphérique loop1
mkfs.ext3 /dev/loop1
mount /dev/loop1 /mnt |
| Histoires d'encodages |  |
Liste complète des codes ( caractères )
http://www.table-ascii.com/
Encodage du système par défaut
Pour modifier l'encodage (debian) :
Encodage de fichiers
file -i <nom du fichier>
hexdump -C <nom du fichier>
od -xc <nom du fichier>
|
Modification de l'encodage d'un fichier
iconv -f iso8859-1 -t utf8 fichier > new_fichier |
Modification de l'encodage du nom d'un fichier
echo D* | iconv -f iso8859-1 -t utf8 |
Modification de l'encodage d'une chaine pour afficher dans une URL
L'objectif est de transformer (entre autres) les "é" en "%E9"
A partir d'un codage iso-8859-1 :
<?php
print(urlencode($argv[1]">;
?>
|
A partir d'un codage utf-8 :
<?php
print(urlencode(utf8_decode($argv[1]">);
?>
|
iconv: séquence d'échappement non permise
On peut rajouter l'option -c à la commande.
Source man page : "-c : Omit invalid characters from output."
Certains caractères vont être supprimés.
Pour faire plus fin, on peut regarder les caractères qui causent pb :
od -bc fichier # affichage en octal + ascii |
puis les transformer avant de lancer la commande iconv :
sed -e "s/\o342\o200\o231/\'/g" -e "s/\o342\o200\o223/-/g" fichier | iconv -c -f utf8 -t latin1 > fichier_sortie |
ascii2uni
convert 7-bit ASCII representations to UTF-8 Unicode
-a I : Convert hexadecimal UTF-8 with each byte's hex preceded by an =-sign (e.g. =C3=A9) . This is the Quoted Printable format defined by RFC 2045.
| Nombre magique |  |
Octets plac�s en d�but de fichier. Ils permettent de d�terminer le type du fichier.
Exemple : Pour les images png, 8 octets :
$ od -xc image.png |head
0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
211 P N G \r \n 032 \n \0 \0 \0 \r I H D R
0000020 0000 7d02 0000 df01 0208 0000 aa00 f92d
\0 \0 002 } \0 \0 001 337 \b 002 \0 \0 \0 252 - 371
[...] |
| R�duire la taille d'une partition NTFS |  |
1/ d�fragmenter
2/ apt-get install ntfsprogs gparted
3/ ntfsresize -f -v -s 60G /dev/sda5
4/ fdisk : supprimer puis recr�er la partition ("same starting cylinder (sector) and using a larger size than" point 3/)
That's all folks !!!
Source : http://darkstar.ucd.ie/timosh/links/ntfsresize.html
Une erreur du genre de celle ci-dessous ?
sudo ntfsresize -P -i -f -v /dev/sda5
ntfsresize v2.0.0 (libntfs 10:0:0)
Device name : /dev/sda5
NTFS volume version: 3.1
Cluster size : 4096 bytes
Current volume size: 63523799552 bytes (63524 MB)
Current device size: 50815747584 bytes (50816 MB)
ERROR: Current NTFS volume size is bigger than the device size!
Corrupt partition table or incorrect device partitioning? |
pas de panique, un (merveilleux) gars a trouv� une solution :
http://gparted-forum.surf4.info/viewtopic.php?id=13937
grand merci � lui !!!
Note du 23/1/2012 : j'ai fait le point 4 avec gparted et tout s'est bien pass� ;-)
| Augmenter la taille d'une partition XFS ou EXT4 |  |
1/ Sauvegarder la table des partitions
2/ Retailler la table des partitions avec fdisk ou parted
3/ rebooter ? cf partprobe
4/ Agrandir le FS
xfs
Les syst�mes de fichiers XFS doivent �tre mont�s pour �tre redimensionn�s et le point de montage doit �tre donn� � la place du nom de p�riph�rique.
# xfs_growfs /home |
Source : http://www.tldp.org/pub/Linux/docs/HOWTO/translations/fr/text/LVM-HOWTO.txt
ext4
Par d�faut, resizefs agrandit le FS au max de la partition.
# resizefs /dev/sdb1 |
| Sauvegarder la table des partitions |  |
sfdisk -d /dev/sda > sda_table_partitions |
| Restaurer la table des partitions |  |
sfdisk /dev/sda < sda_table_partitions |
| partprobe |  |
Apr�s un fdisk, il arrive qu'on ait le message suivant :
WARNING: Re-reading the partition table failed with error 5: Input/output error.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8) |
Comme indiqu� dans le message, une solution est d'utiliser partprobe (qui arrive avec parted).
apt-get install parted
partprobe /dev/sdb |
Cela ne fonctionne pas si la partition est mont�e...
| Comparaisons |  |
Diff�rents outils peuvent �tre utilis�s pour comparer des fichiers :
md5sum
cksum
sum
Une id�e de doc : http://www.itworld.com/nlsnunixchecksum061116
| Utilisation de parted |  |
parted
print
unit GB
print
unit cyl
mkpart extended 64438c 500Gb
quit
mkfs.ext3...
|
| Utilisation de find |  |
Rechercher les fichiers qui ont �t� modifi�s depuis 24 heures tout en excluant un r�pertoire
find / -name "rep_a_exclure" -prune -o -mtime 1 -print |
-o : ou
(pour info -a : et)
Tout ceux qui ont rep_a_exclure dans leur chemin sont supprim�s (c'est ce que fait le -prune)
Les autres (apr�s le -o), s'ils ont �t� modifi�s dans les derni�res 24 heures sont affich�s (-print)
Site int�ressant : http://www.grymoire.com/Unix/Find.html
Rechercher des fichiers en excluant deux r�pertoires
On recherche le fichier contact.php en excluant les r�pertoires private et kure-share.
find . -name private -prune -o -name kure-share -prune -o -name contact.php -exec ls -al {} \; |
| Divers |  |
Partitions : num�ro de la partition, UUID et type
# blkid
/dev/sda1: UUID="6a008aa5-609e-4627-8c00-2a24a2c79c7c" TYPE="swap"
/dev/sda2: UUID="04d40c41-5d8f-4f29-8369-f6fc553381b1" SEC_TYPE="ext2" TYPE="ext3" |
autre solution :
# file -s /dev/sda6
/dev/sda6: Linux rev 1.0 ext4 filesystem data, UUID=c69b325c-88c1-411e-adc4-c7b19ecd0ec3 (needs journal recovery) (extents) (large files) (huge files) |
A quoi correspond la taille affich�e pour chaque r�pertoire dans un ls -l ?
It's the size necessary to store the meta-data about files (including the file names contained in that directory). The number of files / sub-directories at a given time might not map directly to the size reported, because once allocated, space is not freed if the number of files changes. This behaviour makes sense for most use cases (where disk space is cheap, and once a directory has a lot of files in it, it will probably have them again in future), and helps to reduce fragmentation.
For example:
$ mkdir testdir
$ cd testdir
$ ls -ld .
drwxr-xr-x 2 matthew matthew 4096 2007-12-03 20:28 ./
$ for ; do touch some_longish_file_name_$i; done
$ ls -ld .
drwxr-xr-x 2 matthew matthew 36864 2007-12-03 20:29 ./
$ rm some_longish_file_name_*
$ ls -ld .
drwxr-xr-x 2 matthew matthew 36864 2007-12-03 20:29 ./
$ cd ..
$ ls -ld testdir
drwxr-xr-x 2 matthew matthew 36864 2007-12-03 20:29 testdir/
$ rmdir testdir ; mkdir testdir
$ ls -ld testdir
drwxr-xr-x 2 matthew matthew 4096 2007-12-03 20:29 testdir/
Here you see that when even empty files are created, the directory size increases - the file names and meta data must be stored somewhere, and it is in the directory object itself. In this case the file names and other meta-data fit in 9 4k blocks (36864 = 4096 * 9).
Deleting the files does not reduce the space used by the directory object - only removing the directory and re-creating it frees the space.
|
Source : http://www.linuxquestions.org/questions/linux-newbie-8/directory-size-includes-size-of-604159/
Monter une deuxi�me fois un FS
mount --bind / /home/bruno/rep |
Inode, atime, ctime, mtime
Note : stat fournit en plus des infos particuli�rement int�ressantes : date de derni�re modif, dernier acc�s, dernier changement d'inode.
Access - the last time the file was read
Modify - the last time the file was modified (content has been modified)
Change - the last time meta data of the file was changed (e.g. permissions)
Source : http://unix.stackexchange.com/questions/2802/what-is-the-difference-between-modify-and-change-in-stat-command-context
Un point apr�s les droits sur les fichiers ?
bruno@Nestor:~/forma1$ ls -al
drwxr-xr-x. 2 bruno bruno 4096 oct. 21 11:55 ab |
"The dot after file permissions in 'ls' long output denotes that the file in question has a SELinux security context, no matter if SELinux is enabled or not"
Source : http://www.linuxquestions.org/questions/linux-newbie-8/what-means-a-dot-after-the-file-permission-796947/#post4738411
Why do we need to specify partition type in fdisk ? Pourquoi d�finir le type de la partition ?
"The partition type is for devices that need to know what type of filesystem you are putting on that partition. Linux seems to be clever enough to just ignore the type, and knows what the filesystem is no matter what. However, there are some devices that will only be able to read your disk if the filesystem type matches the actual filesystem that you put on the disk.
[...]
I found out recently why it matters what the filesystem type is. I setup a usb stick for putting songs on to use in a media player, however I didn't set the filesystem type correctly, even though the actual filesystem was vfat. The music player had no idea how to read the drive, it worked once the partition type was set correctly. I also had the same problem on a mac, a usb stick with the wrong partition type couldn't be read even though the actual filesystem was fine."
Source : http://unix.stackexchange.com/questions/18510/why-do-we-need-to-specify-partition-type-in-fdisk-and-later-again-in-mkfs
|
|
Contact
|
|---|
Pour m'envoyer un mail, Pour me laisser un commentaire :richard.brunooo chez gmail.com |  |
|
|