2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 17:23:08 +00:00

Merge pull request #1131 from immarvin/ongenimagemount2

fix issue#1122@github;create /dev under chroot env based on /dev on host;use lazy mount for sysfs and procfs to make sure they are umounted no matter whether busy
This commit is contained in:
Xiaopeng Wang 2016-05-18 11:24:29 +08:00
commit 11cdf72972
2 changed files with 26 additions and 17 deletions

View File

@ -91,15 +91,18 @@ sub mount_chroot {
my $rootimage_dir = shift;
#postinstall script of some packages might access the /proc, /sys and /dev filesystem
#For Redhat7 or above, mount these directories readonly from host to avoid error messages
#For Redhat7 or above, mount /proc,/sys from host to avoid error messages
#For Redhat7 or above, create /dev according to /dev on the host to avoid error messages
#For Redhat6 or below, mount these directories might introduce error messages
if(majversion($osver) > 6){
system("mkdir -p $rootimage_dir/proc");
system("mount proc $rootimage_dir/proc -t proc -o ro");
system("mount proc $rootimage_dir/proc -t proc");
system("mkdir -p $rootimage_dir/sys");
system("mount sysfs $rootimage_dir/sys -t sysfs -o ro");
system("mount sysfs $rootimage_dir/sys -t sysfs");
system("mkdir -p $rootimage_dir/dev");
system("mount devtmpfs $rootimage_dir/dev -t devtmpfs -o ro");
#system("mount devtmpfs $rootimage_dir/dev -t devtmpfs");
system("cd /dev;find .|cpio -H newc -o >$rootimage_dir/dev/dev.archive;cd -");
system("cd $rootimage_dir/dev;cpio -idum<./dev.archive;rm -f ./dev.archive;cd -");
}
}
@ -109,9 +112,10 @@ sub umount_chroot {
my $rootimage_dir = shift;
if(majversion($osver) >6){
system("umount $rootimage_dir/proc");
system("umount $rootimage_dir/sys");
system("umount $rootimage_dir/dev");
system("umount -l $rootimage_dir/proc");
system("umount -l $rootimage_dir/sys");
#system("umount -l $rootimage_dir/dev");
system("rm -rf $rootimage_dir/dev/*");
}
}

View File

@ -1970,13 +1970,17 @@ sub mount_chroot {
#postinstall script of package installation
#might access the /proc, /sys and /dev filesystem
#mount them from host read-only
#mount /proc, /sys from host
#create /dev based on /dev/ on host
system("mkdir -p $rootimage_dir/proc");
system("mount proc $rootimage_dir/proc -t proc -o ro");
system("mount proc $rootimage_dir/proc -t proc");
system("mkdir -p $rootimage_dir/sys");
system("mount sysfs $rootimage_dir/sys -t sysfs -o ro");
system("mount sysfs $rootimage_dir/sys -t sysfs");
system("mkdir -p $rootimage_dir/dev");
system("mount devfs $rootimage_dir/dev -t devfs -o ro");
#system("mount devtmpfs $rootimage_dir/dev -t devtmpfs");
system("cd /dev;find .|cpio -H newc -o >$rootimage_dir/dev/dev.archive;cd -");
system("cd $rootimage_dir/dev;cpio -idum<./dev.archive;rm -f ./dev.archive;cd -");
if ($pkgdir) {
if (-d $pkgdir) {
@ -2009,21 +2013,22 @@ sub mount_chroot {
sub umount_chroot {
my $rootimage_dir = shift;
system("umount $rootimage_dir/proc");
system("umount $rootimage_dir/sys");
system("umount $rootimage_dir/dev");
system("umount -l $rootimage_dir/proc");
system("umount -l $rootimage_dir/sys");
#system("umount -l $rootimage_dir/dev");
system("rm -rf $rootimage_dir/dev/*");
system("umount $rootimage_dir/mnt/pkgdir");
system("umount -l $rootimage_dir/mnt/pkgdir");
rmdir("$rootimage_dir/mnt/pkgdir");
my @data = `grep /mnt/otherpkgdir /proc/mounts | cut -f2 -d' ' | sort -r`;
foreach (@data) {
`umount $_`;
`umount -l $_`;
}
rmdir("$rootimage_dir/mnt/otherpkgdir");
if (-d "$rootimage_dir/mnt/kerneldir") {
system("umount $rootimage_dir/mnt/kerneldir");
system("umount -l $rootimage_dir/mnt/kerneldir");
rmdir("$rootimage_dir/mnt/kerneldir");
}
}