[Ovirt-devel] [PATCH 3/3] modified edit-livecd to work with ext4 fs images

David Huff dhuff at redhat.com
Thu Aug 20 16:29:06 UTC 2009


---
 edit-livecd |   68 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/edit-livecd b/edit-livecd
index f519d5e..483daa1 100755
--- a/edit-livecd
+++ b/edit-livecd
@@ -142,10 +142,10 @@ mnt() {
     addExit "df | grep $mp > /dev/null 2>&1 && umount -v $mp"
 }

-# Create new ext2 filesystem and copy contents of one into the other
-# Size of ext2 filesystem is same as original size unless size parameter
+# Create new filesystem and copy contents of one into the other
+# Size of filesystem is same as original size unless size parameter
 # is passed in
-create_ext2fs() {
+create_fs() {
     local input_file=$1
     local input_dir=$2
     local output_file=$3
@@ -157,14 +157,14 @@ create_ext2fs() {
         size=$(( $size_mb * 1024 ))
     fi

-    echo ">>> Mounting old ext3fs"
-    mnt "-t ext2 $input_file -o ro,loop" $input_dir
+    echo ">>> Mounting old fs image"
+    mnt "-t $fs_type $input_file -o ro,loop" $input_dir
     ext_type=$(df -P -T $WDIR/$input_dir | tail -1 | awk '{print $2}')
     ext_max=$(df -P -T $WDIR/$input_dir | tail -1 | awk '{print $3}')
     ext_used=$(df -P -T $WDIR/$input_dir | tail -1 | awk '{print $4}')
     ext_avail=$(df -P -T $WDIR/$input_dir | tail -1 | awk '{print $5}')

-    echo ">>> extfs image=$input_file"
+    echo ">>> old ext3fs image=$input_file info:"
     echo ">>> type=$ext_type max_size=$ext_max current_size=$ext_used available=$ext_avail"

     local new_size=
@@ -179,13 +179,13 @@ create_ext2fs() {

     echo ">>> Size selected for new $output_file: $new_size"

-    echo ">>> Creating new ext3fs"
+    echo ">>> Creating new fs"
     dd if=/dev/zero of=$output_file bs=1024 count=0 seek=${new_size}
-    mkfs.ext2 -b 4096 -m 1 -L "ovirt-node-image" -F $output_file
+    mkfs -t $fs_type -b 4096 -m 0 -L "ovirt-node-image" -F $output_file
     tune2fs -i 0 -c 0 -Odir_index -ouser_xattr,acl $output_file

-    echo ">>> Mounting new ext3fs"
-    mnt "-t ext2 $output_file -o rw,loop" $output_dir
+    echo ">>> Mounting new fs"
+    mnt "-t $fs_type $output_file -o rw,loop" $output_dir

     SELINUX_ENFORCING=$(getenforce)
     case $SELINUX_ENFORCING in
@@ -194,20 +194,21 @@ create_ext2fs() {
         *) echo "Do not run $0 with selinux in disabled mode" ; exit 1 ;;
     esac

-    echo ">>> Copying data from old ext3fs to new ext3fs"
+    echo ">>> Copying data from old fs to new fs"
     rsync -aX $WDIR/$input_dir/ $WDIR/$output_dir/

-    echo -e ">>> $(df $WDIR/$input_dir | tail -1)"
-    echo -e ">>> $(df $WDIR/$output_dir | tail -1)"
-    umount $WDIR/$output_dir
+    echo -e ">>> OLD fs image: $(df -T $WDIR/$input_dir | tail -1)"
+    echo -e ">>> NEW fs Image: $(df -T $WDIR/$output_dir | tail -1)"
+    
+	umount $WDIR/$output_dir
     umount $WDIR/$input_dir

     if [ "$SELINUX_ENFORCING" = "Enforcing" ]; then
         setenforce Enforcing
     fi

-    e2fsck -f -y $output_file || :
-    e2fsck -f -y $output_file || :
+	echo ">>> Running fsck on new fs"
+    fsck -t $fs_type -f -y $output_file || :
 }

 addExit "rm -rf $WDIR"
@@ -228,18 +229,24 @@ rsync -a $WDIR/cd/ $WDIR/cd-w/
 # create writable copy of the filesystem for the new compressed
 # squashfs filesystem
 rsync -a $WDIR/sq/ $WDIR/sq-w/
-echo ">>> Old LiveCD Size: $(du -b $CD)"
-echo ">>> Old Squash Size: $(du -b $WDIR/cd/LiveOS/squashfs.img)"
-echo ">>> Old ext3fs Size: $(du -b $WDIR/sq-w/LiveOS/ext3fs.img)"

-# Create copy of original ext2fs in case user wants to make
-# the file system larger than the original
-create_ext2fs $WDIR/sq-w/LiveOS/ext3fs.img ex-ro $WDIR/ext3fs-rw.img ex-rw $SIZE
+# get info
+cd_size=$(du -b $CD)
+sq_size=$(du -b $WDIR/cd/LiveOS/squashfs.img)
+fs_size=$(du -b $WDIR/sq-w/LiveOS/ext3fs.img)
+fs_type=$(file $WDIR/sq-w/LiveOS/ext3fs.img | awk '{print $5}')
+
+echo ">>> LiveCD iso Size: $cd_size"
+echo ">>> Squash image Size: $sq_size"
+echo ">>> fs image Size: $fs_size"
+echo ">>> fs type: $fs_type"

-echo ">>> New ext3fs Size: $(du -b $WDIR/ext3fs-rw.img)"
+# Create copy of original fs image in case user wants to make
+# the file system larger than the original
+create_fs $WDIR/sq-w/LiveOS/ext3fs.img ex-ro $WDIR/ext3fs-rw.img ex-rw $SIZE

-echo ">>> Mounting new ext3fs"
-mnt "-t ext2 $WDIR/ext3fs-rw.img -o rw,loop" ex-rw
+echo ">>> remounting new fs"
+mnt "-t $fs_type $WDIR/ext3fs-rw.img -o rw,loop" ex-rw

 echo ">>> Updating CD content"
 if [ -n "$CODE" ]; then
@@ -277,12 +284,15 @@ while :; do
   read
 done

+echo ">>> New fs image size: $(du -b $WDIR/ext3fs-rw.img)"
+
 # Copy the filesystem again to make sure we minimize the image
-create_ext2fs $WDIR/ext3fs-rw.img ex-rw $WDIR/ext3fs-min.img ex-min $SIZE
+echo ">>> Copying the filesystem again to minimize the image"
+create_fs $WDIR/ext3fs-rw.img ex-rw $WDIR/ext3fs-min.img ex-min $SIZE

-echo ">>> Min ext3fs Size: $(du -b $WDIR/ext3fs-min.img)"
+echo ">>> Min fs image Size: $(du -b $WDIR/ext3fs-min.img)"

-# Move the minimized ext2 filesystem into the squash directory
+# Move the minimized filesystem into the squash directory
 mv -v $WDIR/ext3fs-min.img $WDIR/sq-w/LiveOS/ext3fs.img

 echo ">>> Compressing filesystem"
@@ -314,6 +324,8 @@ mkisofs \

 echo ">>> Implanting ISO MD5 Sum"
 implantisomd5 --force "$OUTPUT_FILE"
+
+echo ">>> Old LiveCD Size: $cd_size"
 echo ">>> New LiveCD Size: $(du -b $OUTPUT_FILE)"

 # The trap ... callbacks will unmount everything.
-- 
1.6.2.5




More information about the ovirt-devel mailing list