source: MondoRescue/branches/3.3/mondo/src/restore-scripts/mondo/mr-label-partitions-as-necessary@ 3732

Last change on this file since 3732 was 3732, checked in by Bruno Cornec, 4 years ago

Force btrfs relabelling to avoid question from the cmd

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 4.2 KB
Line 
1#!/bin/sh
2#
3# $Id: mr-label-partitions-as-necessary 3732 2019-11-18 00:43:47Z bruno $
4#
5############################################
6
7
8read_partition_line() {
9 local label mountpt command format device d m dev
10
11 dev=`echo "$1" | awk '{print $1}'`
12 d=`echo "$dev" | cut -c1`
13 format=`echo "$1" | awk '{print $3}'`
14 label=`echo "$dev" | cut -s -d'=' -f2`
15 if [ "$d" = "/" ] && [ "$label" = "" ]; then
16 m=`echo "$1" | awk '{print $2}'`
17 # We force UUID even if nothing in fstab as some new distro like RHEL7 rely on it
18 [ "$format" = "reiserfs" ] && opttun="-u" || opttun="-U"
19 label=`awk '{print $2,$5}' $mountlist | grep -E "^$m " | awk '{print $2}'`
20 else
21 if [ "`echo "$1" | grep -E 'LABEL='`" != "" ] ; then
22 [ "$format" = "reiserfs" ] && opttun="-l" || opttun="-L"
23 elif [ "`echo "$1" | grep -E 'UUID='`" != "" ] ; then
24 [ "$format" = "reiserfs" ] && opttun="-u" || opttun="-U"
25 else
26 LogIt "Nothing to do on $1"
27 return
28 fi
29 fi
30 mountpt=`awk '{print $1,$5}' $mountlist | grep " $label$" | awk '{print $1}'`
31
32 if [ ! "$mountpt" ] ; then
33 LogIt "Not labeling anything as ($label) because ($mountpt) is not a mountpoint"
34 elif [ ! "$label" ] ; then
35 LogIt "Not labeling ($mountpt) as anything because ($label) is not a label/uuid"
36 else
37 if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] || [ "$format" = "ext4" ]; then
38 if [ "$format" = "ext4" ] && [ -x "/sbin/tune4fs" ]; then
39 command="/sbin/tune4fs $opttun $label $mountpt"
40 else
41 command="tune2fs $opttun $label $mountpt"
42 fi
43 LogIt "Running $command"
44 $command
45 elif [ "$format" = "reiserfs" ]; then
46 command="reiserfstune $opttun $label $mountpt"
47 LogIt "Running $command"
48 $command
49 elif [ "$format" = "btrfs" ]; then
50 echo "$1" | awk '{print $4}' | grep -q 'subvol='
51 if [ $? -eq 0 ]; then
52 LogIt "Nothing to do on btrfs subvol"
53 return
54 fi
55 if [ "$opttun" = "-U" ]; then
56 # Also see https://btrfs.wiki.kernel.org/index.php/Project_ideas#Filesystem_UUID_change_-_off-line
57 device=`awk '{print $1,$5}' $mountlist | grep -E " $label" | awk '{print $1}'`
58 command="btrfstune -f $opttun $label $device"
59 else
60 command="btrfs filesystem label $mountpt $label"
61 fi
62 LogIt "Running $command"
63 $command
64 elif [ "$format" = "xfs" ]; then
65 command="xfs_admin $opttun $label $mountpt"
66 LogIt "Running $command"
67 $command
68 elif [ "$format" = "fat" ] || [ "$format" = "vfat" ]; then
69 if [ "$opttun" = "-U" ]; then
70 if [ -x "/usr/bin/mr-label" ]; then
71 command="/usr/bin/mr-label -U $label $mountpt"
72 LogIt "Running $command"
73 $command
74 else
75 LogIt "No command available to update a UUID of a FAT/VFAT FS"
76 fi
77 else
78 if [ -x "/usr/sbin/dosfslabel" ]; then
79 command="/usr/sbin/dosfslabel $mountpt $label"
80 LogIt "Running $command"
81 $command
82 else
83 LogIt "No dosfslabel command available to label a FAT/VFAT FS"
84 fi
85 fi
86 elif [ "$format" = "swap" ] ; then
87 if [ "$opttun" = "-U" ]; then
88 typelabel="UUID"
89 else
90 typelabel="Label"
91 fi
92 if [ -x "/sbin/swaplabel" ]; then
93 # Better choice
94 command="/sbin/swaplabel $opttun $label $mountpt"
95 else
96 if [ "$opttun" = "-U" ]; then
97 LogIt "Really running dd conv=notrunc of=$mountpt obs=1 seek=1036"
98 echo -n "$label" | perl -ne 's/-//g;chomp;print pack "H*",$_' | dd conv=notrunc "of=$mountpt" obs=1 seek=1036
99 command=/bin/true
100 else
101 command="mkswap -f $opttun $label $mountpt"
102 fi
103 fi
104 LogIt "Creating $typelabel $label on swap partition $mountpt"
105 LogIt "Running $command"
106 $command
107 else
108 LogIt "I am NOT going to run tune2|4fs/reiserfstune: the partition is format '$format', which doesn't like tune2|4fs/reiserfstune anyway"
109 fi
110 fi
111}
112
113
114# ---------------------------------------------
115
116LogIt "Identifying your drives with FS tune tool"
117if [ "$#" -ne "1" ] ; then
118 LogIt "mr-label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
119 exit 1
120fi
121mountlist=$1
122noof_blank_lines=0
123read line
124# We end after 50 empty lines, which hopefully means we reach the end of the file
125while [ "$noof_blank_lines" -le "50" ] ; do
126 if [ "$line" = "" ] ; then
127 noof_blank_lines=$(($noof_blank_lines+1))
128 else
129 noof_blank_lines=0
130 read_partition_line "$line"
131 fi
132 read line
133done
134LogIt "Labeling complete."
135exit 0
Note: See TracBrowser for help on using the repository browser.