2
# Ensure parted doesn't change the type of a partition to match its FS.
4
# Copyright (C) 2009-2012 Free Software Foundation, Inc.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
. "${srcdir=.}/init.sh"; path_prepend_ ../parted
22
require_scsi_debug_module_
24
grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
25
skip_ 'this system lacks a new-enough libblkid'
27
# create memory-backed device
28
scsi_debug_setup_ dev_size_mb=550 > dev-name ||
29
skip_ 'failed to create scsi_debug device'
30
scsi_dev=$(cat dev-name)
32
# Create an empty partition of "type fat32", and then create an actual
33
# ext2 partition in it. Then "unset" the already unset LVM flag on that
34
# partition and ensure that parted doesn't "helpfully" change the partition
35
# type to match the newly-detected FS type.
37
parted -s $scsi_dev mklabel msdos mkpart primary fat32 64s 80000s || fail=1
39
parted -s $scsi_dev u s p
42
wait_for_dev_to_appear_ $p1 || fail=1
43
mkfs.ext2 $p1 || fail=1
45
# print as hex, the type of the first partition
46
msdos_p1_type() { od -An --skip=450 -N1 -tx1 "$1"; }
48
# Initially, it is 0x0c (FAT32).
49
type=$(msdos_p1_type $scsi_dev) || fail=1
50
type=${type# } # remove leading space
53
*) fail_ "expected initial type of 0c (FAT32)";;
56
parted -s $scsi_dev u s p
57
parted -s $scsi_dev set 1 lvm off || fail=1
59
# Before parted-2.1, the above would mistakenly change it to 0x83,
60
# to match the file system now residing in that partition.
61
type=$(msdos_p1_type $scsi_dev) || fail=1
62
type=${type# } # remove leading space
65
*) fail_ "parted changed the type of partition 1 from 0c to $type";;
68
# Ensure that setting the "lvm" flag still works.
69
parted -s $scsi_dev set 1 lvm on || fail=1
70
parted -s $scsi_dev u s p > out || fail=1
71
grep lvm out || { fail=1; cat out; }