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

Last change on this file since 3542 was 3542, checked in by Bruno Cornec, 8 years ago
  • Rename all mondorestore scripts with the mr- prefix and adapt callers
  • Place these scripts in /usr/bin on the restore media
  • Fix a mindi bug where these scripts were not copied anymore with previous modifications around removal of cd
  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 3.8 KB
RevLine 
[1]1#!/bin/sh
2#
[901]3# $Id: mr-label-partitions-as-necessary 3542 2016-03-24 16:48:03Z bruno $
[1]4#
5############################################
6
7
8read_partition_line() {
[3330]9 local label mountpt command format device d m
[1295]10
[3330]11 device=`echo "$1" | awk '{print $1}'`
12 d=`echo "$device" | cut -c1`
[1314]13 format=`echo "$1" | awk '{print $3}'`
[3330]14 label=`echo "$device" | 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
[2028]18 [ "$format" = "reiserfs" ] && opttun="-u" || opttun="-U"
[3330]19 label=`awk '{print $2,$5}' $mountlist | grep -E "^$m " | awk '{print $2}'`
[1295]20 else
[3330]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
[1314]29 fi
[3330]30 mountpt=`awk '{print $1,$5}' $mountlist | grep " $label$" | awk '{print $1}'`
[1295]31
32 if [ ! "$mountpt" ] ; then
[1314]33 LogIt "Not labeling anything as ($label) because ($mountpt) is not a mountpoint"
[1295]34 elif [ ! "$label" ] ; then
[3330]35 LogIt "Not labeling ($mountpt) as anything because ($label) is not a label/uuid"
[1295]36 else
[2087]37 if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] || [ "$format" = "ext4" ]; then
[3008]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
[1295]43 LogIt "Running $command"
44 $command
[2028]45 elif [ "$format" = "reiserfs" ]; then
46 command="reiserfstune $opttun $label $mountpt"
47 LogIt "Running $command"
48 $command
[3330]49 elif [ "$format" = "btrfs" ]; then
50 # Also see https://btrfs.wiki.kernel.org/index.php/Project_ideas#Filesystem_UUID_change_-_off-line
51 command="btrfs filesystem label $mountpt $label"
52 LogIt "Running $command"
53 $command
[3328]54 elif [ "$format" = "xfs" ]; then
55 command="xfs_admin $opttun $label $mountpt"
56 LogIt "Running $command"
57 $command
[3472]58 elif [ "$format" = "fat" ] || [ "$format" = "vfat" ]; then
[3488]59 if [ "$opttun" = "-U" ]; then
60 if [ -x "/usr/bin/mr-label" ]; then
61 command="/usr/bin/mr-label -U $label $mountpt"
62 LogIt "Running $command"
63 $command
64 else
65 LogIt "No command available to update a UUID of a FAT/VFAT FS"
66 fi
[3472]67 else
[3488]68 if [ -x "/sbin/fatlabel" ]; then
69 command="/sbin/fatlabel $mountpt $label"
70 LogIt "Running $command"
71 $command
72 else
73 LogIt "No fatlabel command available to label a FAT/VFAT FS"
74 fi
[3472]75 fi
[1295]76 elif [ "$format" = "swap" ] ; then
77 if [ "$opttun" = "-U" ]; then
[3437]78 typelabel="UUID"
79 else
80 typelabel="Label"
81 fi
82 if [ -x "/sbin/swaplabel" ]; then
83 # Better choice
84 command="/sbin/swaplabel $opttun $label $mountpt"
85 else
86 if [ "$opttun" = "-U" ]; then
87 LogIt "Really running dd conv=notrunc of=$mountpt obs=1 seek=1036"
[3040]88 echo -n "$label" | perl -ne 's/-//g;chomp;print pack "H*",$_' | dd conv=notrunc "of=$mountpt" obs=1 seek=1036
[3437]89 command=/bin/true
[3040]90 else
[3437]91 command="mkswap -f $opttun $label $mountpt"
[3040]92 fi
[1295]93 fi
[3437]94 LogIt "Creating $typelabel $label on swap partition $mountpt"
95 LogIt "Running $command"
96 $command
[1295]97 else
[3008]98 LogIt "I am NOT going to run tune2|4fs/reiserfstune: the partition is format '$format', which doesn't like tune2|4fs/reiserfstune anyway"
[1295]99 fi
[1]100 fi
101}
102
103
104# ---------------------------------------------
105
[3008]106LogIt "Identifying your drives with FS tune tool"
[1]107if [ "$#" -ne "1" ] ; then
[3542]108 LogIt "mr-label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab.new" 1
[1]109 exit 1
110fi
111mountlist=$1
112noof_blank_lines=0
113read line
[2172]114# We end after 50 empty lines, which hopefully means we reach the end of the file
115while [ "$noof_blank_lines" -le "50" ] ; do
[1]116 if [ "$line" = "" ] ; then
[691]117 noof_blank_lines=$(($noof_blank_lines+1))
[1]118 else
[691]119 noof_blank_lines=0
120 read_partition_line "$line"
[1]121 fi
122 read line
123done
124LogIt "Labeling complete."
125exit 0
Note: See TracBrowser for help on using the repository browser.